1 from datetime import datetime
4 path = "/scratch/July-2018/evaluation/"
6 fileExperiment = "dlink-plug-8hr-data-oct-8-2018.timestamps"
7 fileDetection = "dlink-plug.detection.timestamps"
8 TIME_WINDOW = 15 # detection/signature window of 15 seconds
9 #NEG_TIME_WINDOW = -15 # detection/signature window of 15 seconds
11 # Open training timestamps file and store into a list
12 with open(path + device + "/" + fileExperiment, "r") as experiment:
14 for line in experiment:
15 # Format "%m/%d/%Y %I:%M:%S %p"
16 tsE = datetime.strptime(line, "%m/%d/%Y %I:%M:%S %p\n")
17 tsExperimentList.append(tsE)
19 # Open detection timestamps file and store into a list
20 with open(path + device + "/" + fileDetection, "r") as detection:
22 for line in detection:
23 # Format "%b %d, %Y %I:%M:%S %p"
24 tsD = datetime.strptime(line, "%b %d, %Y %I:%M:%S %p\n")
25 tsDetectionList.append(tsD)
27 if (len(tsExperimentList) > len(tsDetectionList)):
28 maxTimestamps = len(tsExperimentList)
30 maxTimestamps = len(tsDetectionList)
34 while i < maxTimestamps:
35 tsE = tsExperimentList[i]
36 tsD = tsDetectionList[j]
37 # Detection is always a bit later than training trigger
39 # The following happens when we could detect less triggers than the experiment
40 if (delta.seconds > TIME_WINDOW):
41 print("Missing trigger at line: " + str(i) + ", t_experiment: " + str(tsE) + " and t_detection: " + str(tsD))
43 # The following should not happen (we have more detected triggers than the experiment)
44 #elif (delta.seconds < NEG_TIME_WINDOW):
45 # print("Mismatch at t_experiment: " + str(tsE) + " and t_detection: " + str(tsD))
50 print("Done parsing: " + str(i) + " lines")