# Using plotly.express
# import ipywidgets as widgets
import pandas as pd
import plotly.express as px
import plotly.graph_objects as go
#from IPython.display import display
# now the homebuilt monitor
rooms = ["eng1-undercroft","eng2-vestments","eng3-organ","eng5-vestry","eng6-refectory","homebuilt"]
list_of_traces = []
for x in rooms:
if (x == "homebuilt"):
df = pd.read_csv("./venue-44/" + x + ".csv",encoding='latin-1',usecols=[0,1,2])
df["timestamp"] = pd.to_datetime(df['timestamp'])
else:
df = pd.read_csv("./venue-44/" + x + ".csv",encoding='latin-1',usecols=[0,1,2], header=0, names= ['entry_id', 'time', 'temperature'])
df["timestamp"] = pd.to_datetime(df['time'])
#range_min = df['timestamp'].min()
#range_max = df['timestamp'].max()
#print(range_min, " to ", range_max) # this just uses the range of the last file, not ideal
trace = go.Scatter(customdata=df,
y=df['temperature'],
x = df['timestamp'],
mode='lines',
hoverinfo='all',
name=x,
)
list_of_traces.append(trace)
g = go.FigureWidget(data=list_of_traces,
layout = go.Layout(
yaxis=dict(range=[10,25])
))
# example syntax for two plots on same x-axis - I'd like to show the boiler temperature in
# parallel - but havne't had time to sort the syntax.
#fig = make_subplots(rows=2, cols=1, shared_xaxes=True)
# for i, col in enumerate(cols, start=1):
# fig.add_trace(go.Scatter(x=df[col].index, y=df[col].values), row=i, col=1)
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()