CallDistanceTransceiver.py: reset modem.ring_count before receiving
[SaveMySugar/python3-savemysugar.git] / plot / session_stats.py
1 #!/usr/bin/env python3
2 #
3 # session_stats.py - gather stats about a SaveMySugar session
4 #
5 # Copyright (C) 2015  Antonio Ospite <ao2@ao2.it>
6 #
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.
11 #
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.
16 #
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/>.
19 #
20 import sys
21 import logging
22
23
24 def session_stats(transmitter_log_filename, receiver_log_filename):
25     transmitter_log = open(transmitter_log_filename)
26     receiver_log = open(receiver_log_filename)
27
28     transmitter_dial_times = []
29     for line in transmitter_log:
30         transmitter_dial_times.append(float(line.split(" ")[0]))
31
32     receiver_ring_times = []
33     for line in receiver_log:
34         receiver_ring_times.append(float(line.split(" ")[0]))
35
36     if len(transmitter_dial_times) != len(receiver_ring_times):
37         logging.error("The two files must contain the same number of lines")
38         sys.exit(1)
39
40     min_call_setup_time = 10000
41     max_call_setup_time = -1
42     for dial_time, ring_time in zip(transmitter_dial_times,
43                                     receiver_ring_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)
48
49     return min_call_setup_time, max_call_setup_time
50
51
52 def main():
53     if len(sys.argv) != 3:
54         print("usage: %s <transmit_log> <receive_log>" % sys.argv[0])
55         sys.exit(1)
56
57     call_setup_min, call_setup_max = session_stats(sys.argv[1], sys.argv[2])
58
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)
62
63
64 if __name__ == "__main__":
65     main()