3 # session_stats.py - gather stats about a SaveMySugar session
5 # Copyright (C) 2015 Antonio Ospite <ao2@ao2.it>
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
24 def session_stats(transmitter_log_filename, receiver_log_filename):
25 transmitter_log = open(transmitter_log_filename)
26 receiver_log = open(receiver_log_filename)
28 transmitter_dial_times = []
29 for line in transmitter_log:
30 transmitter_dial_times.append(float(line.split(" ")[0]))
32 receiver_ring_times = []
33 for line in receiver_log:
34 receiver_ring_times.append(float(line.split(" ")[0]))
36 if len(transmitter_dial_times) != len(receiver_ring_times):
37 logging.error("The two files must contain the same number of lines")
40 min_call_setup_time = 10000
41 max_call_setup_time = -1
42 for dial_time, ring_time in zip(transmitter_dial_times,
44 call_setup_time = ring_time - dial_time
45 max_call_setup_time = max(max_call_setup_time, call_setup_time)
46 min_call_setup_time = min(min_call_setup_time, call_setup_time)
47 logging.info("call setup time: %9.6f", call_setup_time)
49 return min_call_setup_time, max_call_setup_time
53 if len(sys.argv) != 3:
54 print("usage: %s <transmit_log> <receive_log>" % sys.argv[0])
57 call_setup_min, call_setup_max = session_stats(sys.argv[1], sys.argv[2])
59 print("\nSession stats:")
60 print("min call setup time: %9.6f" % call_setup_min)
61 print("max call setup time: %9.6f" % call_setup_max)
64 if __name__ == "__main__":