1 from datetime import datetime
4 path = "/scratch/July-2018/experimental_result/smarthome/"
5 #path = "/scratch/July-2018/experimental_result/standalone/"
7 #device = "dlink-plug/self-test"
8 #fileExperiment = "dlink-plug-nov-7-2018.timestamps"
9 #fileDetection = "device-side-detection"
10 #fileDetection = "phone-side-detection"
11 #device = "dlink-plug/timestamps"
12 #fileExperiment = "dlink-plug-smarthome-nov-8-2018.timestamps"
13 #fileDetection = "dlink-plug-smarthome-nov-8-2018.phone.wlan1.detections"
14 #fileDetection = "dlink-plug-smarthome-nov-8-2018.phone.eth0.detections"
15 #fileDetection = "dlink-plug-smarthome-nov-8-2018.device.eth0.detections"
18 #device = "tplink-plug/self-test"
19 #fileExperiment = "tplink-plug-nov-8-2018.timestamps"
20 #fileDetection = "device-side-detection"
21 #fileDetection = "phone-side-detection"
22 #device = "tplink-plug/timestamps"
23 #fileExperiment = "tplink-plug-smarthome-nov-9-2018.timestamps"
24 #fileDetection = "tplink-plug-smarthome-nov-9-2018.eth0.device.detections"
25 #fileDetection = "tplink-plug-smarthome-nov-9-2018.wlan1.phone.detections"
28 #device = "dlink-siren/self-test"
29 #fileExperiment = "dlink-siren-nov-9-2018.timestamps"
30 #fileDetection = "phone-side-detection"
31 #device = "dlink-siren/timestamps"
32 #fileExperiment = "dlink-siren-smarthome-nov-10-2018.timestamps"
33 #fileDetection = "dlink-siren-smarthome-nov-10-2018.eth0.phone.detections"
36 #device = "kwikset-doorlock/self-test"
37 #fileExperiment = "kwikset-doorlock-nov-10-2018.timestamps"
38 #fileDetection = "phone-side-detection"
39 #device = "kwikset-doorlock/timestamps"
40 #fileExperiment = "kwikset-doorlock-smarthome-nov-10-2018.timestamps"
41 #fileDetection = "kwikset-doorlock-smarthome-nov-10-2018.eth0.phone.detections"
44 #device = "st-plug/self-test"
45 #fileExperiment = "st-plug-nov-13-2018.timestamps"
46 #fileDetection = "phone-side-detection"
47 #device = "st-plug/timestamps"
48 #fileExperiment = "st-plug-smarthome-nov-13-2018.timestamps"
49 #fileDetection = "st-plug-smarthome-nov-13-2018.eth0.phone.detections"
52 #device = "arlo-camera/self-test"
53 #fileExperiment = "arlo-camera-nov-13-2018.timestamps"
54 #fileDetection = "phone-side-detection"
55 #device = "arlo-camera/timestamps"
56 #fileExperiment = "arlo-camera-smarthome-nov-15-2018.timestamps"
57 #fileDetection = "arlo-camera-smarthome-nov-15-2018.phone.eth0.detections"
58 #fileDetection = "arlo-camera-smarthome-nov-15-2018.phone.eth0.detections.range-based.complete"
61 #device = "nest-thermostat/self-test"
62 #fileExperiment = "nest-thermostat-nov-15-2018.timestamps"
63 #fileDetection = "phone-side-detection"
64 device = "nest-thermostat/timestamps"
65 fileExperiment = "nest-thermostat-smarthome-nov-16-2018.timestamps"
66 #fileDetection = "nest-thermostat-smarthome-nov-16-2018.phone.eth0.detections"
67 fileDetection = "nest-thermostat-smarthome-nov-16-2018.phone.eth0.range-based.detections"
70 #device = "tplink-bulb/self-test"
71 #fileExperiment = "tplink-bulb-nov-16-2018.timestamps"
72 #fileDetection = "phone-side-detection"
73 #device = "tplink-bulb/timestamps"
74 #fileExperiment = "tplink-bulb-smarthome-nov-19-2018.timestamps"
75 #fileDetection = "tplink-bulb-smarthome-nov-19-2018.phone.wlan1.detections"
78 #device = "hue-bulb/self-test"
79 #fileExperiment = "hue-bulb-aug-7-2018.timestamps"
80 #fileDetection = "phone-side-detection"
83 #device = "wemo-plug/self-test"
84 #fileExperiment = "wemo-plug-nov-20-2018.timestamps"
85 #fileDetection = "phone-side-detection"
86 #device = "wemo-plug/timestamps"
87 #fileExperiment = "wemo-plug-smarthome-nov-21-2018.timestamps"
88 #fileDetection = "wemo-plug-smarthome-nov-21-2018.phone.wlan1.detections"
91 #device = "wemo-insight-plug/self-test"
92 #fileExperiment = "wemo-insight-plug-nov-21-2018.timestamps"
93 #fileDetection = "phone-side-detection"
94 #device = "wemo-insight-plug/timestamps"
95 #fileExperiment = "wemo-insight-plug-smarthome-nov-22-2018.timestamps"
96 #fileDetection = "wemo-insight-plug-smarthome-nov-22-2018.phone.wlan1.detections"
99 #device = "blossom-sprinkler/self-test"
100 #fileExperiment = "blossom-sprinkler-standalone-jan-9-2019.timestamps"
101 #fileExperiment = "blossom-sprinkler-standalone-jan-11-2019.timestamps"
102 #fileExperiment = "blossom-sprinkler-standalone-jan-14-2019.timestamps"
103 #fileDetection = "phone-side-detection"
104 #fileDetection = "device-side-detection"
105 #device = "blossom-sprinkler/timestamps"
106 #fileExperiment = "blossom-sprinkler-smarthome-jan-10-2019.timestamps"
107 #fileExperiment = "blossom-sprinkler-smarthome-jan-11-2019.timestamps"
108 #fileExperiment = "blossom-sprinkler-smarthome-jan-14-2019.timestamps"
109 #fileDetection = "blossom-sprinkler-smarthome-jan-10-2019.device.wlan1.detections"
110 #fileDetection = "blossom-sprinkler-smarthome-jan-11-2019.phone.wlan1.detections"
111 #fileDetection = "blossom-sprinkler-smarthome-jan-14-2019.device.eth0.detections"
112 #fileDetection = "blossom-sprinkler-smarthome-jan-14-2019.phone.eth0.detections"
114 TIME_WINDOW = 15 # detection/signature window of 15 seconds
115 #NEG_TIME_WINDOW = -15 # detection/signature window of 15 seconds
117 # Open training timestamps file and store into a list
118 with open(path + device + "/" + fileExperiment, "r") as experiment:
119 tsExperimentList = []
120 for line in experiment:
121 # Format "%m/%d/%Y %I:%M:%S %p"
122 tsE = datetime.strptime(line, "%m/%d/%Y %I:%M:%S %p\n")
123 tsExperimentList.append(tsE)
125 # Open detection timestamps file and store into a list
126 with open(path + device + "/" + fileDetection, "r") as detection:
128 for line in detection:
129 # Format "%b %d, %Y %I:%M:%S %p"
130 tsD = datetime.strptime(line, "%b %d, %Y %I:%M:%S %p\n")
131 tsDetectionList.append(tsD)
133 if (len(tsExperimentList) > len(tsDetectionList)):
134 maxTimestamps = len(tsExperimentList)
136 maxTimestamps = len(tsDetectionList)
140 while i < maxTimestamps:
141 if(len(tsExperimentList) <= i or len(tsDetectionList) <= j):
144 tsE = tsExperimentList[i]
145 tsD = tsDetectionList[j]
146 # Detection is always a bit later than training trigger
149 #print("tsE: " + str(tsE) + " - tsD: " + str(tsD) + " - delta1: " + str(delta1.seconds) + " - delta2: " + str(delta2.seconds))
150 # The following happens when we could detect less triggers than the experiment
151 if (delta1.seconds > TIME_WINDOW and delta2.seconds > TIME_WINDOW):
152 print("Missing trigger at line: " + str(i) + ", t_experiment: " + str(tsE) + " and t_detection: " + str(tsD))
155 # The following should not happen (we have more detected triggers than the experiment)
156 #elif (delta.seconds < NEG_TIME_WINDOW):
157 # print("Mismatch at t_experiment: " + str(tsE) + " and t_detection: " + str(tsD))
162 print("Done parsing: " + str(i) + " lines")