b22e0a381cfdd113720a14b45d268b5c0b7a80c2
[pingpong.git] / python_ml / validate-detection.py
1 from datetime import datetime
2
3
4 path = "/scratch/July-2018/evaluation/"
5 device = "dlink"
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
10
11 # Open training timestamps file and store into a list
12 with open(path + device + "/" + fileExperiment, "r") as experiment:
13         tsExperimentList = []
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)
18
19 # Open detection timestamps file and store into a list
20 with open(path + device + "/" + fileDetection, "r") as detection:
21         tsDetectionList = []
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)
26                 
27 if (len(tsExperimentList) > len(tsDetectionList)):
28         maxTimestamps = len(tsExperimentList)
29 else:
30         maxTimestamps = len(tsDetectionList)
31
32 i = 0
33 j = 0
34 while i < maxTimestamps:
35         tsE = tsExperimentList[i]
36         tsD = tsDetectionList[j]
37         # Detection is always a bit later than training trigger
38         delta = tsD - tsE
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))
42                 i = i + 1
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))
46         #       j = j + 1
47         i = i + 1
48         j = j + 1
49
50 print("Done parsing: " + str(i) + " lines")