-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSuggest.py
More file actions
100 lines (88 loc) · 3.01 KB
/
Suggest.py
File metadata and controls
100 lines (88 loc) · 3.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import requests
import json
import time
import datetime
from datetime import timedelta
import sys
import dateutil.parser as dp
import os
from sys import platform
import requests, json, time
global url,uuids,sensor_names,sensor_values,actuator_identity,actuator_type,actuator_values
sensor_names=[]
sensor_values=[]
actuator_type=[]
actuator_identity=[]
actuator_values=[]
from giotto_helper import GiottoHelper
from json_setting import JsonSetting
def print2file():
if platform == "linux" or platform == "linux2":
bashCommand = "rm ./Sensor_data/*.csv"
elif platform == "win32":
bashCommand = "del .\Sensor_data\*.csv"
os.system(bashCommand)
print "filescleaned"
allow=0
arr=[]
Sens=giotto_helper.sensorlist()
#print Sens
'''
print sensor_names
print sensor_values
print actuator_type
print actuator_identity
print actuator_values
'''
for sensor in Sens['result']:
lul=sensor['tags']
for ta in lul:
arr.append(ta['name']);
#print arr
if('identity' not in arr):
allow=1
filename=sensor['source_name'] + ","+sensor['source_identifier']+ ","+sensor['name']
arr=[]
try:
for tag in sensor['tags']:
if(sensor['source_name']=='status' or tag['name']=='status'):
allow=1
filename=sensor['source_name'] + ","+sensor['source_identifier']+ ","+sensor['name']
if(tag['name']=='region'):
region=tag['value']
except:
print "No actuator present in the region!"
if(allow==1):
#print sensor['source_name']
data=giotto_helper.get_timeseries_data(sensor['name'],2)
handle=open('./Sensor_data/'+filename+","+region+".csv",'w')
series=(data['data']['series'][0])
for col in series['columns']:
handle.write(str(str(col)+","))
handle.write("\r\n")
for val in series['values']:
st_time=time.mktime(dp.parse(str(val[0])).timetuple())
en_time=time.mktime(dp.parse(str(val[1])).timetuple())
if(val[2]=='on'):
val[2]=1
elif(val[2]=='off'):
val[2]=0
handle.write(str(str((st_time))+","+str((en_time))+","+str(val[2])+"\r\n"))
handle.close()
allow=0
onlytrain()
def onlytrain():
if platform == "linux" or platform == "linux2":
bashCommand ="matlab -nodisplay -r \"cd ./DataProcess; Suggest_Rules\""
elif platform == "win32":
bashCommand ="matlab -nodesktop -r \"cd ./DataProcess; Suggest_Rules\""
os.system(bashCommand)
if __name__ == "__main__":
giotto_setting = JsonSetting('./config.json')
giotto_helper = GiottoHelper()
if(sys.argv[1]=='only_train'):
onlytrain()
elif(sys.argv[1]=='download_train'):
print2file()
else :
print('Please provide valid arguments : only_train & download_train')