1 from datetime import datetime
4 path = "/scratch/July-2018/training/"
5 device = "dlink-plug/self-test"
6 #fileExperiment = "dlink-plug-8hr-data-oct-8-2018.timestamps"
7 #fileDetection = "dlink-plug.detection.timestamps"
8 #fileExperiment = "dlink-siren-aug-14-2018.timestamps"
9 #fileDetection = "dlink-siren.2018-08-14_experiment.phone_signature_detected_events.txt"
10 fileExperiment = "dlink-plug-oct-17-2018.timestamps"
11 fileDetection = "detection-on-training-device-side"
12 TIME_WINDOW = 15 # detection/signature window of 15 seconds
13 #NEG_TIME_WINDOW = -15 # detection/signature window of 15 seconds
15 # Open training timestamps file and store into a list
16 with open(path + device + "/" + fileExperiment, "r") as experiment:
18 for line in experiment:
19 # Format "%m/%d/%Y %I:%M:%S %p"
20 tsE = datetime.strptime(line, "%m/%d/%Y %I:%M:%S %p\n")
21 tsExperimentList.append(tsE)
23 # Open detection timestamps file and store into a list
24 with open(path + device + "/" + fileDetection, "r") as detection:
26 for line in detection:
27 # Format "%b %d, %Y %I:%M:%S %p"
28 tsD = datetime.strptime(line, "%b %d, %Y %I:%M:%S %p\n")
29 tsDetectionList.append(tsD)
31 if (len(tsExperimentList) > len(tsDetectionList)):
32 maxTimestamps = len(tsExperimentList)
34 maxTimestamps = len(tsDetectionList)
38 while i < maxTimestamps:
39 if(len(tsExperimentList) <= i or len(tsDetectionList) <= j):
42 tsE = tsExperimentList[i]
43 tsD = tsDetectionList[j]
44 # Detection is always a bit later than training trigger
46 # The following happens when we could detect less triggers than the experiment
47 if (delta.seconds > TIME_WINDOW):
48 print("Missing trigger at line: " + str(i) + ", t_experiment: " + str(tsE) + " and t_detection: " + str(tsD))
50 # The following should not happen (we have more detected triggers than the experiment)
51 #elif (delta.seconds < NEG_TIME_WINDOW):
52 # print("Mismatch at t_experiment: " + str(tsE) + " and t_detection: " + str(tsD))
57 print("Done parsing: " + str(i) + " lines")