From ff4142da1b71f300e36c2fc21223f6764642868f Mon Sep 17 00:00:00 2001 From: Dan Howe Date: Tue, 17 Sep 2019 08:11:56 +1000 Subject: [PATCH] Consolidate miscellaneous variables in json data --- daqviewer/daqviewer.py | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/daqviewer/daqviewer.py b/daqviewer/daqviewer.py index 615d264..5e4a529 100644 --- a/daqviewer/daqviewer.py +++ b/daqviewer/daqviewer.py @@ -103,12 +103,12 @@ def parse_contents(contents, filename): # Add spectral values to dataframe stats.loc[col, keys] = values + info = {'filename': filename, 'instrument type': inst_type} json_data = {} + json_data['info'] = info json_data['timeseries'] = df.to_json(orient='table') json_data['spectrum'] = dfs.to_json(orient='table') json_data['statistics'] = stats.to_json(orient='table') - json_data['filename'] = filename - json_data['instrument type'] = inst_type return json.dumps(json_data) @@ -128,14 +128,14 @@ def read_json_data(json_data): if json_data is None: return html.Div([]) + info = json.loads(json_data)['info'] df = pd.read_json(json.loads(json_data)['timeseries'], orient='table') ts = [] for col in df.columns: trace = go.Scatter(x=df.index, y=df[col], name=col, opacity=0.8) ts.append(trace) - filename = json.loads(json_data)['filename'] - layout = {'title': filename, 'xaxis': {'rangeslider': {}}} + layout = {'title': info['filename'], 'xaxis': {'rangeslider': {}}} graph_timeseries = dcc.Graph(id='time-series', figure={ 'data': ts, @@ -205,7 +205,7 @@ def read_json_data(json_data): }, ) - if json.loads(json_data)['instrument type'] == 'WP': + if info['instrument type'] == 'WP': elements = html.Div([ graph_timeseries, html.Div([ @@ -224,9 +224,6 @@ def read_json_data(json_data): return elements -##### - - def main(): port = 8050 wb.open('http://localhost:{}'.format(port))