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"
60 #device = "nest-thermostat/self-test"
61 #fileExperiment = "nest-thermostat-nov-15-2018.timestamps"
62 #fileDetection = "phone-side-detection"
63 #device = "nest-thermostat/timestamps"
64 #fileExperiment = "nest-thermostat-smarthome-nov-16-2018.timestamps"
65 #fileDetection = "nest-thermostat-smarthome-nov-16-2018.phone.eth0.detections"
68 #device = "tplink-bulb/self-test"
69 #fileExperiment = "tplink-bulb-nov-16-2018.timestamps"
70 #fileDetection = "phone-side-detection"
71 #device = "tplink-bulb/timestamps"
72 #fileExperiment = "tplink-bulb-smarthome-nov-19-2018.timestamps"
73 #fileDetection = "tplink-bulb-smarthome-nov-19-2018.phone.wlan1.detections"
76 #device = "hue-bulb/self-test"
77 #fileExperiment = "hue-bulb-aug-7-2018.timestamps"
78 #fileDetection = "phone-side-detection"
81 #device = "wemo-plug/self-test"
82 #fileExperiment = "wemo-plug-nov-20-2018.timestamps"
83 #fileDetection = "phone-side-detection"
84 #device = "wemo-plug/timestamps"
85 #fileExperiment = "wemo-plug-smarthome-nov-21-2018.timestamps"
86 #fileDetection = "wemo-plug-smarthome-nov-21-2018.phone.wlan1.detections"
89 #device = "wemo-insight-plug/self-test"
90 #fileExperiment = "wemo-insight-plug-nov-21-2018.timestamps"
91 #fileDetection = "phone-side-detection"
92 #device = "wemo-insight-plug/timestamps"
93 #fileExperiment = "wemo-insight-plug-smarthome-nov-22-2018.timestamps"
94 #fileDetection = "wemo-insight-plug-smarthome-nov-22-2018.phone.wlan1.detections"
97 #device = "blossom-sprinkler/self-test"
98 #fileExperiment = "blossom-sprinkler-standalone-jan-9-2019.timestamps"
99 #fileExperiment = "blossom-sprinkler-standalone-jan-11-2019.timestamps"
100 #fileExperiment = "blossom-sprinkler-standalone-jan-14-2019.timestamps"
101 #fileDetection = "phone-side-detection"
102 #fileDetection = "device-side-detection"
103 device = "blossom-sprinkler/timestamps"
104 #fileExperiment = "blossom-sprinkler-smarthome-jan-10-2019.timestamps"
105 #fileExperiment = "blossom-sprinkler-smarthome-jan-11-2019.timestamps"
106 fileExperiment = "blossom-sprinkler-smarthome-jan-14-2019.timestamps"
107 #fileDetection = "blossom-sprinkler-smarthome-jan-10-2019.device.wlan1.detections"
108 #fileDetection = "blossom-sprinkler-smarthome-jan-11-2019.phone.wlan1.detections"
109 #fileDetection = "blossom-sprinkler-smarthome-jan-14-2019.device.eth0.detections"
110 fileDetection = "blossom-sprinkler-smarthome-jan-14-2019.phone.eth0.detections"
112 TIME_WINDOW = 15 # detection/signature window of 15 seconds
113 #NEG_TIME_WINDOW = -15 # detection/signature window of 15 seconds
115 # Open training timestamps file and store into a list
116 with open(path + device + "/" + fileExperiment, "r") as experiment:
117 tsExperimentList = []
118 for line in experiment:
119 # Format "%m/%d/%Y %I:%M:%S %p"
120 tsE = datetime.strptime(line, "%m/%d/%Y %I:%M:%S %p\n")
121 tsExperimentList.append(tsE)
123 # Open detection timestamps file and store into a list
124 with open(path + device + "/" + fileDetection, "r") as detection:
126 for line in detection:
127 # Format "%b %d, %Y %I:%M:%S %p"
128 tsD = datetime.strptime(line, "%b %d, %Y %I:%M:%S %p\n")
129 tsDetectionList.append(tsD)
131 if (len(tsExperimentList) > len(tsDetectionList)):
132 maxTimestamps = len(tsExperimentList)
134 maxTimestamps = len(tsDetectionList)
138 while i < maxTimestamps:
139 if(len(tsExperimentList) <= i or len(tsDetectionList) <= j):
142 tsE = tsExperimentList[i]
143 tsD = tsDetectionList[j]
144 # Detection is always a bit later than training trigger
147 #print("tsE: " + str(tsE) + " - tsD: " + str(tsD) + " - delta1: " + str(delta1.seconds) + " - delta2: " + str(delta2.seconds))
148 # The following happens when we could detect less triggers than the experiment
149 if (delta1.seconds > TIME_WINDOW and delta2.seconds > TIME_WINDOW):
150 print("Missing trigger at line: " + str(i) + ", t_experiment: " + str(tsE) + " and t_detection: " + str(tsD))
153 # The following should not happen (we have more detected triggers than the experiment)
154 #elif (delta.seconds < NEG_TIME_WINDOW):
155 # print("Mismatch at t_experiment: " + str(tsE) + " and t_detection: " + str(tsD))
160 print("Done parsing: " + str(i) + " lines")