Voip.ms latency measurement, Full App ===================================== Contents -------- .. toctree:: :maxdepth: 1 Indices and tables ------------------ * :ref:`genindex` * :ref:`modindex` * :ref:`search` Exercise -------- For this week, the goal is to finish the ping app. The new code should do the following: * There should be a method that calculates the average latency: * It should accept two arguments: * The data recieved from the server as done last week * A boolean that will print more details when True * It should calculate the new average for the last 10 pings to the host name * It should print a bar graph in place * IE. after one iteration it will overwrite the previous printed result * Think ANSI escape codes * The main program should run indefinately, looping through the list of host names retreieved from the voip api. * The program should count the number of times it completes a full loop through the server hosts * The program should cleanly terminate on a KeyboardInterrupt * It should move the cursor to the bottom of the screen, print the number of iterations and then exit A useful data structure this week is :py:class:`collections.deque`, however its use is not required. Deque (double ended queue) is a First In - First Out collection that shifts the values automatically as new ones are added. This could be useful for keeping the last 10 pings for each server, however feel free to use any method you can think of. To print the graph you could use a unicode square, for example \u25A0. A reasonable resolution would be each square represents 10 milliseconds. On completion of this exercise, you should be able to run your program and have it do the following: * Print the hostnames that are received from the voip.ms api * Continously loop through the host names, for each one plotting the average latency over the last 10 pings * Terminate cleanly after seeing a KeyboardInterrupt, printing the number of completed loops before exit. Hints ----- The new function signature follows, it is part of the PingRequest class. .. literalinclude:: voip3.py :language: python3 :lines: 81-87 Additionally, here is an example of a continuous main program loop. .. literalinclude:: voip3.py :language: python3 :lines: 140-152 Solution -------- When you are ready to see one possible solution, try :download:`this file `