-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtelemetry_plot.py
71 lines (55 loc) · 1.78 KB
/
telemetry_plot.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
from flask import Flask
import dash
from dash.dependencies import Input, Output
import dash_core_components as dcc
import dash_html_components as html
from datetime import datetime as dt
import csv
from os import listdir
from os.path import isfile, join
TELEMETRY_PATH = "telemetry/"
server = Flask(__name__)
app = dash.Dash(__name__, server=server)
telemetry_files = [
{"label": f, "value": join(TELEMETRY_PATH, f)}
for f in listdir(TELEMETRY_PATH)
if isfile(join(TELEMETRY_PATH, f))
]
app.layout = html.Div(
[
html.H1("KSP Telemetry Archive"),
dcc.Dropdown(
id="my-dropdown", options=telemetry_files, value=telemetry_files[0]["value"]
),
dcc.Graph(
id="alt-mut"
),
dcc.Graph(
id="g-force-mut"
),
]
)
@app.callback(Output("alt-mut", "figure"), [Input("my-dropdown", "value")])
def update_graph(selected_dropdown_value):
alt = {"x": [], "y": []}
with open(selected_dropdown_value, newline="") as csvfile:
reader = csv.DictReader(csvfile)
for row in reader:
alt["x"].append(row["met"])
alt["y"].append(row["mean_altitude"])
return {"data": [alt], 'layout': {
'title': 'Altitude'
}}
@app.callback(Output("g-force-mut", "figure"), [Input("my-dropdown", "value")])
def update_graph_g_force(selected_dropdown_value):
g_force = {"x": [], "y": []}
with open(selected_dropdown_value, newline="") as csvfile:
reader = csv.DictReader(csvfile)
for row in reader:
g_force["x"].append(row["met"])
g_force["y"].append(row["g_force"])
return {"data": [g_force], 'layout': {
'title': 'G-force'
}}
if __name__ == "__main__":
app.run_server(debug=True)