summaryrefslogtreecommitdiff
path: root/prilohy/web/server.py
blob: 2007c8248e3d9622a9ef490381d895b82391c700 (plain)
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
import dash
import time
import sys
import json
from dash import dcc
from dash import html
from dash import dash_table
import pandas as pd
import plotly.express as px


df = pd.DataFrame()
dg = pd.DataFrame(columns=['lati', 'long', 'alti', 'rssi', 'snr', 'rttt', 'temp', 'humi', 'pres', 'voc'], dtype=float)

with open('save.csv') as f:
    for i, line in enumerate(f):
        dg.loc[i] = pd.Series(json.loads(line))
    savepos = f.tell()

dg = dg.fillna(0.0)

print('len', len(dg.index))
fig = px.scatter_map(dg, lat='lati', lon='long',color="rssi", opacity=0.5, size='temp', size_max=10, map_style="open-street-map", color_continuous_scale='jet', zoom=13, height=500)
#fig.show()


#app = dash.Dash(__name__)
#app.layout = html.Div([
#      html.H4('Dashboard'),
#      #dcc.Interval('graph-update', interval = 10000, n_intervals = 0),
#      dcc.Graph(id='map', figure=fig),
#
#      #dash_table.DataTable( id = 'table', data = df.to_dict('records'), columns=[{"name": i, "id": i} for i in df.columns])])
#      ])

app = dash.Dash()
app.layout = html.Div([
    dcc.Interval('graph-update', interval = 10000, n_intervals = 0),
    dcc.Graph(id='fig', figure=fig),
])

t = 0

@app.callback(
        dash.dependencies.Output('fig','figure'),
        [dash.dependencies.Input('graph-update', 'n_intervals')])
def updateTable(n):
    global dg
    global savepos
    global t
    global fig

    print(time.time() - t)
    t = time.time()

    mi = max(dg.index)
    with open('save.csv') as f:
        f.seek(savepos)
        for i, line in enumerate(f):
            print(line)
            dg.loc[mi+1+i] = pd.Series(json.loads(line)).fillna(0)
        savepos = f.tell()

    return fig

if __name__ == '__main__':
     app.run(debug=True, port=10451)