Skip to content

Commit

Permalink
MRG: Merge pull request #24 from aerosense-ai/enhancement/pre-process…
Browse files Browse the repository at this point in the history
…-sensor-data

Pre-process sensor data
  • Loading branch information
time-trader authored Mar 21, 2023
2 parents 4860140 + 81cef20 commit ff21106
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 33 deletions.
11 changes: 10 additions & 1 deletion dashboard/callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from dash import Input, Output, State

from aerosense_tools.plots import plot_connection_statistic, plot_pressure_bar_chart, plot_sensors
from aerosense_tools.preprocess import RawSignal
from aerosense_tools.queries import ROW_LIMIT, BigQuery
from aerosense_tools.utils import generate_time_range, get_cleaned_sensor_column_names

Expand Down Expand Up @@ -192,7 +193,15 @@ def plot_sensors_graph(
finish=finish,
)

figure = plot_sensors(df, line_descriptions=sensor_types[sensor_name]["variable"])
# Extract only data columns and set index to 'datetime', so that DataFrame is accepted by RawSignal class
data_columns = df.columns[df.columns.str.startswith('f')].tolist()
sensor_data = df[["datetime"] + data_columns].set_index('datetime')
raw_data = RawSignal(sensor_data, sensor_name)
raw_data.measurement_to_variable() # Convert raw data int to float value in SI units
plot_df = raw_data.dataframe.reset_index() # reset index to pass DataFrame to plot_sensors function

figure = plot_sensors(plot_df, line_descriptions=sensor_types[sensor_name]["variable"])
figure.update_layout(height=800)

if data_limit_applied:
return (figure, f"Large amount of data - the query has been limited to the latest {ROW_LIMIT} datapoints.")
Expand Down
114 changes: 85 additions & 29 deletions dashboard/layouts.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,38 +40,94 @@ def create_sensors_tab_layout(app, tab_name, sensor_names, graph_id, data_limit_
TimeRangeSelect(),
html.Br(),
html.Label(html.B("Custom time range")),
html.Label("Start datetime"),
dcc.DatePickerSingle(
id="start-date",
date=datetime.datetime.now().date().isoformat(),
display_format="Do MMM Y",
persistence=True,
disabled=True,
html.Div(
[
html.Div(
[
html.Label("Start datetime"),
dcc.DatePickerSingle(
id="start-date",
date=datetime.datetime.now().date().isoformat(),
display_format="Do MMM Y",
persistence=True,
disabled=True,
),
],
style={"display": "inline-block"},
),
html.Div(
[
html.Label("Hour"),
dash_daq.NumericInput(
id="start-hour", value=0, min=0, max=23, persistence=True
),
],
style={"display": "inline-block"},
),
html.Div(
[
html.Label("Minute"),
dash_daq.NumericInput(
id="start-minute", value=0, min=0, max=59, persistence=True
),
],
style={"display": "inline-block"},
),
html.Div(
[
html.Label("Second"),
dash_daq.NumericInput(
id="start-second", value=0, min=0, max=59, persistence=True
),
],
style={"display": "inline-block"},
),
],
style={"margin": "10px 0"},
),
html.Br(),
html.Label("Hour"),
dash_daq.NumericInput(id="start-hour", value=0, min=0, max=23, persistence=True),
html.Label("Minute"),
dash_daq.NumericInput(id="start-minute", value=0, min=0, max=59, persistence=True),
html.Label("Second"),
dash_daq.NumericInput(id="start-second", value=0, min=0, max=59, persistence=True),
html.Br(),
html.Label("End datetime"),
dcc.DatePickerSingle(
id="end-date",
display_format="Do MMM Y",
persistence=True,
disabled=True,
html.Div(
[
html.Div(
[
html.Label("End datetime"),
dcc.DatePickerSingle(
id="end-date",
display_format="Do MMM Y",
persistence=True,
disabled=True,
),
],
style={"display": "inline-block"},
),
html.Div(
[
html.Label("Hour"),
dash_daq.NumericInput(id="end-hour", value=0, min=0, max=23, persistence=True),
],
style={"display": "inline-block"},
),
html.Div(
[
html.Label("Minute"),
dash_daq.NumericInput(
id="end-minute", value=0, min=0, max=59, persistence=True
),
],
style={"display": "inline-block"},
),
html.Div(
[
html.Label("Second"),
dash_daq.NumericInput(
id="end-second", value=0, min=0, max=59, persistence=True
),
],
style={"display": "inline-block"},
),
],
style={"margin": "10px 0"},
),
html.Br(),
html.Label("Hour"),
dash_daq.NumericInput(id="end-hour", value=0, min=0, max=23, persistence=True),
html.Label("Minute"),
dash_daq.NumericInput(id="end-minute", value=0, min=0, max=59, persistence=True),
html.Label("Second"),
dash_daq.NumericInput(id="end-second", value=0, min=0, max=59, persistence=True),
html.Br(),
html.Br(),
html.Button("Plot", id="refresh-button", n_clicks=0),
html.Button("Check for new installations", id="installation-check-button", n_clicks=0),
],
Expand Down
1 change: 0 additions & 1 deletion docs/source/deploying_the_dashboard.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,3 @@

Deployment
==========

2 changes: 1 addition & 1 deletion docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Aerosense Dashboard

``aerosense-dashboard`` is a data dashboard allowing high-level visualisation of data from the aerosense system.

- The ``data-gateway`` library is responsible for the data collection and ingress to GretaDB and GretaStore.
- The ``data-gateway`` library is responsible for the data collection and ingress to GretaDB and GretaStore.
- The ``aerosense-tools`` library can access and manipulate data from GretaDB or the GretaStore by any python client.

This dashboard uses a combination of its own code and ``aerosense-tools`` to access and visualise data from GretaDB.
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[tool.poetry]
name = "aerosense-dashboard"
version = "0.4.4"
version = "0.4.5"
description = "High-level visualisation for aerosense"
authors = ["Tom Clark", "Marcus Lugg", "Yuriy Marykovsky"]
license = "BSD-3"
Expand Down

0 comments on commit ff21106

Please sign in to comment.