-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprocess_bus.py
More file actions
69 lines (50 loc) · 2.15 KB
/
Copy pathprocess_bus.py
File metadata and controls
69 lines (50 loc) · 2.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# Authored: Max Pfeiffer - 2018
#
# Reads log files in Cabana's .csv format and produces a .csv file with the
# messages belonging to each unique id. Also produces a file containing the averating message period
#
# Call: python process_bus.py "control.csv" "new.csv" "bus"
# control.csv is the reference log file (i.e. quiescent, no changes)
# new.csv is the variant log file
# bus is the target bus we wish to analyze from the Cabana log
#
# Result: a series of files "idx_messages.csv" for each unique ID in the log
# a periodic timing file, periods.csv, contianing the periods for each
# unique message ID logged into its own output file
#
# Dependencies: Requires that the get_diffs.py, get_unique.py and filter_id.py files
# are in the PWD
#
# This software is free and open to anyone who wishes to use it
#!/usr/bin/python
import sys
import csv
from get_diffs import *
from get_unique import *
from filter_id import *
unique_arb_ids = []
bus_target = sys.argv[3]
id_periods = {} # format = [id, time_old, time_new, avg_time, counter]
# generate a comprehensive list of the IDS in both files, as list_control and list_variant
populate_control_ids()
populate_variant_ids()
# now we want to generate the id lists for the specific output files
detect_lost_ids()
# having generated these lists, lets create the three desired files
save_lost_messages()
# get a list of the unique ids on the target bus
unique_arb_ids = get_unique_ids("lost_log.csv", bus_target)
# call the filter_id.py methods for each unique ID, saving each output and populating the period list
def filter_unique_id(filename, id_list, bus_target):
for arb_id in id_list:
id_periods[arb_id] = filter_id(filename, arb_id, bus_target)
# saves a .csv file withthe average periods
def save_id_periods(id_periods):
avg_periods = open("average_periods.csv", "w+")
period_writer = csv.writer(avg_periods, delimiter = ",")
period_writer.writerow(["ID", "Average Period (Seconds)"])
for arb_id in id_periods:
period_writer.writerow([arb_id, id_periods[arb_id]])
avg_periods.close()
filter_unique_id("lost_log.csv", unique_arb_ids, bus_target)
save_id_periods(id_periods)