-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
51 lines (44 loc) · 1.7 KB
/
app.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
from flask import Flask, render_template
import pandas as pd
import numpy as np
import glob
import json
app = Flask(__name__)
@app.route('/')
@app.route('/graph')
def graph():
files = glob.glob("*.csv")
df=pd.read_csv(files[0], names=['Name','UUID','Major','Minor','formattedtime','time','temperature','humidity','rssi','data'])
#Major over 10 is not the packet we want
df=df[(df.Major < 10)]
renderTo = ['Temperature','Humidity']
option =['temperature','humidity']
ttext=['Temperature on iBeacons','Humidity on iBeacons']
ytext=['Temperature','Humidity']
chartInfo = []
chart_type = 'line'
chart_height = 500
for i in range(2):
chart = {"renderTo": renderTo[i], "type": chart_type, "height": chart_height}
series = getSeries(df,option[i])
title = {"text":ttext[i]}
xAxis = {"type":"datetime"}
yAxis = {"title":{"text":ytext[i]}}
chartInfo.append([chart, series, title, xAxis, yAxis])
return render_template('index.html', chartInfo=chartInfo)
def getSeries(df,option):
#option is 'temperature' 'humidity'
major_type = df.Major.unique()
series = '['
for i in range(len(major_type)):
major = major_type[i]
series += '{"name":"Major ' + str(major) + '","data":['
for index, row in df.iterrows():
if row['Major'] == major:
series += '[' + str(row['time']) + ',' + str(int(row[option])) + '],'
series = series[:-1]
series += ']},'
series = series[:-1] + ']'
return series
if __name__ == "__main__":
app.run(debug = True, host='0.0.0.0', port=8080, passthrough_errors=True)