-
Notifications
You must be signed in to change notification settings - Fork 1
/
flaskApp.py
197 lines (181 loc) · 7.2 KB
/
flaskApp.py
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
# web application GUI
from flask import Flask, render_template, request
import csv
import shutil
from datetime import datetime
from compute import *
app = Flask(__name__)
@app.route('/', methods=['GET','POST'])
def index():
if request.method == 'POST':
select = flask.request.form.get('select')
if select == 'cmxTimes':
return cmxTimes()
# open cmx data
data = []
with open('cmxData.csv') as csvfile:
reader = csv.DictReader(csvfile)
count = 0
arrayCount=0
flag=0
for row in reader:
if row['MAC'] != '' and flag==0:
count = 0
flag = 1
data.append({'MAC':row['MAC'],'timestamps':[{'ts':datetime.utcfromtimestamp(float(row['time'])).strftime('%m-%d,%H:%M'),'rssi':row['rssi']}]})
elif row['MAC'] != '' and flag==1:
arrayCount = arrayCount+1
count = 0
data.append({'MAC':row['MAC'],'timestamps':[{'ts':datetime.utcfromtimestamp(float(row['time'])).strftime('%m-%d,%H:%M'),'rssi':row['rssi']}]})
elif row['MAC'] == '':
count = count+1
data[arrayCount]['timestamps'].append({'ts':datetime.utcfromtimestamp(float(row['time'])).strftime('%m-%d,%H:%M'),'rssi':row['rssi']})
return render_template("index.html",data=data)
@app.route('/cmxTimes', methods=['GET','POST'])
def cmxTimes():
# open cmx data
data = []
with open('cmxData.csv') as csvfile:
reader = csv.DictReader(csvfile)
count = 0
arrayCount=0
flag=0
for row in reader:
if row['MAC'] != '' and flag==0:
count = 0
flag = 1
data.append({'MAC':row['MAC'],'timestamps':{count:row['time']}})
elif row['MAC'] != '' and flag==1:
arrayCount = arrayCount+1
count = 0
data.append({'MAC':row['MAC'],'timestamps':{count:row['time']}})
elif row['MAC'] == '':
count = count+1
data[arrayCount]['timestamps'][count]=row['time']
# print(len(data[0]['timestamps']))
cmxData=getCMXHours(data)
for x in cmxData:
for y in range(len(x['timeData'])):
x['timeData'][y]['firstSeen'] = datetime.utcfromtimestamp(float(x['timeData'][y]['firstSeen'])).strftime('%m-%d,%H:%M')
x['timeData'][y]['lastSeen'] = datetime.utcfromtimestamp(float(x['timeData'][y]['lastSeen'])).strftime('%m-%d,%H:%M')
return render_template("cmxTimes.html",cmxData=cmxData)
@app.route('/hourFilter', methods=['GET','POST'])
def hourFilter():
# open cmx data
data = []
with open('cmxData.csv') as csvfile:
reader = csv.DictReader(csvfile)
count = 0
arrayCount=0
flag=0
for row in reader:
if row['MAC'] != '' and flag==0:
count = 0
flag = 1
data.append({'MAC':row['MAC'],'timestamps':{count:row['time']}})
elif row['MAC'] != '' and flag==1:
arrayCount = arrayCount+1
count = 0
data.append({'MAC':row['MAC'],'timestamps':{count:row['time']}})
elif row['MAC'] == '':
count = count+1
data[arrayCount]['timestamps'][count]=row['time']
# print(len(data[0]['timestamps']))
cmxData=cmxFilterHours(data)
for x in cmxData:
for y in range(len(x['timeData'])):
x['timeData'][y]['firstSeen'] = datetime.utcfromtimestamp(float(x['timeData'][y]['firstSeen'])).strftime('%m-%d,%H:%M')
x['timeData'][y]['lastSeen'] = datetime.utcfromtimestamp(float(x['timeData'][y]['lastSeen'])).strftime('%m-%d,%H:%M')
print(cmxData)
return render_template("filterTimes.html",cmxData=cmxData)
@app.route('/mvSense',methods=['GET','POST'])
def mvSense():
# open mv sense data
data = []
with open('mvData.csv') as csvfile:
reader = csv.DictReader(csvfile)
count = 0
arrayCount=0
flag=0
for row in reader:
print(row['Time In'])
link = getMVLink('Q2EV-2QFS-YRYE',row['Time In'])
link = link.replace('{"url":"',"")
link = link.replace('"}',"")
data.append({'timeIn':datetime.utcfromtimestamp(float(row['Time In'])/1000).strftime('%m-%d,%H:%M'),'timeOut':datetime.utcfromtimestamp(float(row['Time Out'])/1000).strftime('%m-%d,%H:%M'),'count':row['Count'],'link':link})
# print(len(data[0]['timestamps']))
return render_template("mvSense.html",data=data)
@app.route('/cmxActivity',methods=['GET','POST'])
def cmxActivity():
# open cmx data
data = []
with open('cmxData.csv') as csvfile:
reader = csv.DictReader(csvfile)
count = 0
arrayCount=0
flag=0
for row in reader:
if row['MAC'] != '' and flag==0:
count = 0
flag = 1
data.append({'MAC':row['MAC'],'timestamps':{count:row['time']}})
elif row['MAC'] != '' and flag==1:
arrayCount = arrayCount+1
count = 0
data.append({'MAC':row['MAC'],'timestamps':{count:row['time']}})
elif row['MAC'] == '':
count = count+1
data[arrayCount]['timestamps'][count]=row['time']
newData = computeCMXActivity(data)
print(newData)
return render_template("cmxActivity.html",x=newData)
@app.route('/mvActivity',methods=['GET','POST'])
def mvActivity():
# open mv sense data
data = []
with open('mvData.csv') as csvfile:
reader = csv.DictReader(csvfile)
count = 0
arrayCount=0
flag=0
for row in reader:
data.append({'timeIn':row['Time In'],'timeOut':row['Time Out'],'count':row['Count']})
newData = computeMVActivity(data)
# print(len(data[0]['timestamps']))
return render_template("mvActivity.html",x=newData)
@app.route('/correlation',methods=['GET','POST'])
def correlation():
# open cmx data
data = []
with open('cmxData.csv') as csvfile:
reader = csv.DictReader(csvfile)
count = 0
arrayCount=0
flag=0
for row in reader:
if row['MAC'] != '' and flag==0:
count = 0
flag = 1
data.append({'MAC':row['MAC'],'timestamps':[{'ts':row['time'],'rssi':row['rssi']}]})
elif row['MAC'] != '' and flag==1:
arrayCount = arrayCount+1
count = 0
data.append({'MAC':row['MAC'],'timestamps':[{'ts':row['time'],'rssi':row['rssi']}]})
elif row['MAC'] == '':
count = count+1
data[arrayCount]['timestamps'].append({'ts':row['time'],'rssi':row['rssi']})
# open mv sense data
mvData = []
with open('mvData.csv') as csvfile:
reader = csv.DictReader(csvfile)
count = 0
arrayCount=0
flag=0
for row in reader:
mvData.append({'timeIn':row['Time In'],'timeOut':row['Time Out'],'count':row['Count']})
newData = getCorrelation(data,mvData)
return render_template("correlation.html",correlation=newData)
if __name__ == "__main__":
app.run(host='0.0.0.0', port=5001)
# app.debug=True
# app.run()