Adding more execution parameters for experimental results (evaluation).
[pingpong.git] / python_ml / validate-detection.py
1 from datetime import datetime
2
3 #path = "/scratch/July-2018/experimental_result/smarthome/"
4 path = "/scratch/July-2018/experimental_result/standalone/"
5 # D-Link plug
6 #device = "dlink-plug/self-test"
7 #fileExperiment = "dlink-plug-nov-7-2018.timestamps"
8 #fileDetection = "device-side-detection"
9 #fileDetection = "phone-side-detection"
10 #device = "dlink-plug/timestamps"
11 #fileExperiment = "dlink-plug-smarthome-nov-8-2018.timestamps"
12 #fileDetection = "dlink-plug-smarthome-nov-8-2018.phone.wlan1.detections"
13 #fileDetection = "dlink-plug-smarthome-nov-8-2018.phone.eth0.detections"
14 #fileDetection = "dlink-plug-smarthome-nov-8-2018.device.eth0.detections"
15
16 # TP-Link plug
17 #device = "tplink-plug/self-test"
18 #fileExperiment = "tplink-plug-nov-8-2018.timestamps"
19 #fileDetection = "device-side-detection"
20 #fileDetection = "phone-side-detection"
21 #device = "tplink-plug/timestamps"
22 #fileExperiment = "tplink-plug-smarthome-nov-9-2018.timestamps"
23 #fileDetection = "tplink-plug-smarthome-nov-9-2018.eth0.device.detections"
24 #fileDetection = "tplink-plug-smarthome-nov-9-2018.wlan1.phone.detections"
25
26 # D-Link siren
27 #device = "dlink-siren/self-test"
28 #fileExperiment = "dlink-siren-nov-9-2018.timestamps"
29 #fileDetection = "phone-side-detection"
30 device = "dlink-siren/timestamps"
31 fileExperiment = "dlink-siren-smarthome-nov-10-2018.timestamps"
32 fileDetection = "dlink-siren-smarthome-nov-10-2018.eth0.phone.detections"
33
34 # Kwikset door lock
35 device = "kwikset-doorlock/self-test"
36 fileExperiment = "kwikset-doorlock-nov-10-2018.timestamps"
37 fileDetection = "phone-side-detection"
38 #device = "kwikset-doorlock/timestamps"
39 #fileExperiment = "kwikset-doorlock-smarthome-nov-10-2018.timestamps"
40 #fileDetection = "kwikset-doorlock-smarthome-nov-10-2018.eth0.phone.detections"
41
42 # Arlo camera
43 #device = "arlo-camera/self-test"
44 #fileExperiment = "arlo-camera-aug-10-2018.timestamps"
45 #fileDetection = "detection-on-training-phone-side"
46 # Blossom sprinkler
47 #device = "blossom-sprinkler/self-test"
48 #fileExperiment = "blossom-sprinkler-aug-13-2018.timestamps"
49 #fileDetection = "detection-on-training-device-side"
50 # Nest thermostat
51 #device = "nest-thermostat/self-test"
52 #fileExperiment = "nest-aug-15-2018.timestamps"
53 #fileDetection = "detection-on-training-phone-side"
54 # Hue bulb
55 #device = "hue-bulb/self-test"
56 #fileExperiment = "hue-bulb-aug-7-2018.timestamps"
57 #fileDetection = "detection-on-training-phone-side"
58 # TPLink bulb
59 #device = "tplink-bulb/self-test"
60 #fileExperiment = "tplink-bulb-aug-3-2018.timestamps"
61 #fileDetection = "detection-on-training-phone-side"
62 # WeMo Insight Plug
63 #device = "wemo-insight-plug/self-test"
64 #fileExperiment = "wemo-insight-july-31-2018.timestamps"
65 #fileDetection = "detection-on-training-device-side"
66
67 TIME_WINDOW = 15 # detection/signature window of 15 seconds
68 #NEG_TIME_WINDOW = -15 # detection/signature window of 15 seconds
69
70 # Open training timestamps file and store into a list
71 with open(path + device + "/" + fileExperiment, "r") as experiment:
72         tsExperimentList = []
73         for line in experiment:
74                 # Format "%m/%d/%Y %I:%M:%S %p"
75                 tsE = datetime.strptime(line, "%m/%d/%Y %I:%M:%S %p\n")
76                 tsExperimentList.append(tsE)
77
78 # Open detection timestamps file and store into a list
79 with open(path + device + "/" + fileDetection, "r") as detection:
80         tsDetectionList = []
81         for line in detection:
82                 # Format "%b %d, %Y %I:%M:%S %p"
83                 tsD = datetime.strptime(line, "%b %d, %Y %I:%M:%S %p\n")
84                 tsDetectionList.append(tsD)
85                 
86 if (len(tsExperimentList) > len(tsDetectionList)):
87         maxTimestamps = len(tsExperimentList)
88 else:
89         maxTimestamps = len(tsDetectionList)
90
91 i = 0
92 j = 0
93 while i < maxTimestamps:
94         if(len(tsExperimentList) <= i or len(tsDetectionList) <= j):
95                 break;
96         
97         tsE = tsExperimentList[i]
98         tsD = tsDetectionList[j]
99         # Detection is always a bit later than training trigger
100         delta1 = tsD - tsE
101         delta2 = tsE - tsD
102         #print("tsE: " + str(tsE) + " - tsD: " + str(tsD) + " - delta1: " + str(delta1.seconds) + " - delta2: " + str(delta2.seconds))
103         # The following happens when we could detect less triggers than the experiment
104         if (delta1.seconds > TIME_WINDOW and delta2.seconds > TIME_WINDOW):
105                 print("Missing trigger at line: " + str(i) + ", t_experiment: " + str(tsE) + " and t_detection: " + str(tsD))
106                 #print(str(tsD))
107                 i = i + 1
108         # The following should not happen (we have more detected triggers than the experiment)
109         #elif (delta.seconds < NEG_TIME_WINDOW):
110         #       print("Mismatch at t_experiment: " + str(tsE) + " and t_detection: " + str(tsD))
111         #       j = j + 1
112         i = i + 1
113         j = j + 1
114
115 print("Done parsing: " + str(i) + " lines")