Making sure that merging would fail if there is a situation where two sequences are...
[pingpong.git] / python_ml / validate-detection.py
1 from datetime import datetime
2
3
4 path = "/scratch/July-2018/training/"
5 # D-Link plug
6 #device = "dlink-plug/self-test"
7 #fileExperiment = "dlink-plug-oct-17-2018.timestamps"
8 #fileDetection = "detection-on-training-device-side"
9 #fileDetection = "detection-on-training-phone-side"
10 # TP-Link plug
11 device = "arlo-camera/self-test"
12 fileExperiment = "arlo-camera-aug-10-2018.timestamps"
13 fileDetection = "detection-on-training-phone-side"
14 #fileDetection = "detection-on-training-phone-side"
15 TIME_WINDOW = 15 # detection/signature window of 15 seconds
16 #NEG_TIME_WINDOW = -15 # detection/signature window of 15 seconds
17
18 # Open training timestamps file and store into a list
19 with open(path + device + "/" + fileExperiment, "r") as experiment:
20         tsExperimentList = []
21         for line in experiment:
22                 # Format "%m/%d/%Y %I:%M:%S %p"
23                 tsE = datetime.strptime(line, "%m/%d/%Y %I:%M:%S %p\n")
24                 tsExperimentList.append(tsE)
25
26 # Open detection timestamps file and store into a list
27 with open(path + device + "/" + fileDetection, "r") as detection:
28         tsDetectionList = []
29         for line in detection:
30                 # Format "%b %d, %Y %I:%M:%S %p"
31                 tsD = datetime.strptime(line, "%b %d, %Y %I:%M:%S %p\n")
32                 tsDetectionList.append(tsD)
33                 
34 if (len(tsExperimentList) > len(tsDetectionList)):
35         maxTimestamps = len(tsExperimentList)
36 else:
37         maxTimestamps = len(tsDetectionList)
38
39 i = 0
40 j = 0
41 while i < maxTimestamps:
42         if(len(tsExperimentList) <= i or len(tsDetectionList) <= j):
43                 break;
44         
45         tsE = tsExperimentList[i]
46         tsD = tsDetectionList[j]
47         # Detection is always a bit later than training trigger
48         delta1 = tsD - tsE
49         delta2 = tsE - tsD
50         #print("tsE: " + str(tsE) + " - tsD: " + str(tsD) + " - delta1: " + str(delta1.seconds) + " - delta2: " + str(delta2.seconds))
51         # The following happens when we could detect less triggers than the experiment
52         if (delta1.seconds > TIME_WINDOW and delta2.seconds > TIME_WINDOW):
53                 print("Missing trigger at line: " + str(i) + ", t_experiment: " + str(tsE) + " and t_detection: " + str(tsD))
54                 i = i + 1
55         # The following should not happen (we have more detected triggers than the experiment)
56         #elif (delta.seconds < NEG_TIME_WINDOW):
57         #       print("Mismatch at t_experiment: " + str(tsE) + " and t_detection: " + str(tsD))
58         #       j = j + 1
59         i = i + 1
60         j = j + 1
61
62 print("Done parsing: " + str(i) + " lines")