Scaling the standalone data#

The standalone monitors can’t get time from the internet, and they don’t have a real time clock because that would cost a bit extra (around £1) and take extra time to build. That means their sense of time drifts. Usually they think time goes slower than it really does. We know what time the user starts the monitor and downloads the data on their phone, so it’s possible to use that to scale the data linearly over the elapsed time. Since readings are only every five minutes and the last reading can be anything from just before the data is downloaded to just after, this is still approximate, but tends to be better than using the data unscaled. We’re still working on the scaling procedure - it’s tricky because the monitor may have been turned on and off several times, at least until we start fielding the next model. This plot is for our tech lead to consider.

Hide code cell source
# import ipywidgets as widgets
import pandas as pd
import plotly.express as px
import plotly.graph_objects as go   

# :TODO: general case, look for all the files with the same venue number and plot together,
# loop over them, and do this in the main book; get location from the file itself.
dfScaled = pd.read_csv("./venue-2/venue_2h_with_device_58BF25DB81A1-scaled.csv")
dfUnscaled = pd.read_csv("./venue-2/venue_2h_with_device_58BF25DB81A1-unscaled.csv")
dfScaled = dfScaled[(dfScaled.temperature >-10)] # eliminate rogue data
dfUnscaled = dfUnscaled[(dfUnscaled.temperature >-10)] # eliminate rogue data


trace1 = go.Scatter(customdata=dfScaled, 
                    y=dfScaled['temperature'], 
                    x = dfScaled['timestamp'], 
                    mode='lines', 
                    hoverinfo='all', 
                    name='hall (scaled)',
                    )

trace2 = go.Scatter(customdata=dfUnscaled, 
                    y=dfUnscaled['temperature'], 
                    x = dfUnscaled['timestamp'], 
                    mode='lines', 
                    hoverinfo='all', 
                    name='hall (unscaled)',
                    )


g = go.FigureWidget(data=[trace1,trace2],
                    layout = go.Layout(
                        yaxis=dict(range=[-3,25])
                    ))

fig = go.Figure(g)
fig.update_layout(showlegend=True, 
              autosize = True, 
              width=1000, 
              height=500,
)

fig.update_layout(
    hovermode='x unified',
   # range=[range_min, range_max],
    hoverlabel=dict(
        bgcolor="white",
        # font_size=16,
        font_family="Rockwell"
    )
)

#Add range slider
fig.update_layout(
    xaxis=dict(
        rangeselector=dict(
            buttons=list([
                dict(
                     label="All",
                     step="all"
                     ),
                                dict(count=1,
                     label="Hour",
                     step="hour",
                     stepmode="todate"),
                dict(count=1,
                     label="Day",
                     step="day",
                     stepmode="backward"),
                dict(count=7,
                     label="Week",
                     step="day",
                     stepmode="backward"),
                dict(count=1,
                     label="Year",
                     step="year",
                     stepmode="backward")
            ])
        ),
        rangeslider=dict(
            visible=True,
        ),
        type="date"
    )
)


#fig.add_hline(y=16, annotation_text='16C - usual minimum for children', annotation_font_color="blue", line_color='red', layer='above', line_dash='dash')
# fig.update_yaxes(range = [-5, dfCollatedDataSet['temperature'].max()+5])
fig.show()
/opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages/jupyter_client/session.py:721: UserWarning: Message serialization failed with:
Out of range float values are not JSON compliant
Supporting this message is deprecated in jupyter-client 7, please make sure your message is JSON-compliant
  content = self.pack(content)