Skip to content
Snippets Groups Projects
Commit 48b8eb86 authored by Berinda van Dijk's avatar Berinda van Dijk
Browse files

Noodzakelijke aanpassingen

parent 3362a985
Branches
No related tags found
No related merge requests found
Pipeline #13424 passed
......@@ -16,6 +16,7 @@ df = pd.concat(li, axis=0, ignore_index=True)
df.drop_duplicates(inplace=True)
df['datetime'] = pd.to_datetime(df['datetime'])
df=df.sort_values(by='datetime').reset_index(drop=True)
def get_by_metadata(metadata_id):
......@@ -30,49 +31,36 @@ last_date = co2.index[-1]
def extendIndex(item): #extend data
if item.index[-1] < last_date:
last_item = item[item.index[-1]]
item.at[last_date] = last_item
item.at[last_date] = item[item.index[-1]]
if item.index[0] > first_date:
first_item = item[item.index[0]]
item.at[first_date] = first_item
item.at[first_date] = item[item.index[0]]
booleans = {
'Raam open': 420,
'Ventilator aan': 2295,
}
fig = make_subplots(rows=len(booleans) + 1, cols=1, shared_xaxes=True)
co2_trace = go.Scatter(x=co2.index, y=co2.values, mode='lines', name='Co2')
# Add traces to figure
#Co2 krijgt de helft van de ruimte, de rest is voor de booleans.
rijhoogtes=[0.5]
rijhoogtes.extend([0.5/len(booleans)]*len(booleans))
fig = make_subplots(rows=len(booleans) + 1, cols=1, shared_xaxes=True, row_heights=rijhoogtes)
#Co2
co2_trace = go.Scatter(x=co2.index, y=co2.values, mode='lines', name="Co2")
fig.add_trace(co2_trace, row=1, col=1)
fig.update_yaxes(title_text='Co2', row=1, rangemode='tozero', fixedrange=True)
#Boolean-variabelen
for index, key in enumerate(booleans):
item = get_by_metadata(booleans[key]).replace({"off": False, 'on': True})
extendIndex(item)
trace = go.Scatter(x=item.index, y=item.values.astype(float), mode='lines', name=key, line_shape='hv')
fig.add_trace(trace, row=index + 2, col=1)
fig.update_yaxes(row=index+2, title_text=key, fixedrange=True,
tickvals=[0,1], ticktext=["nee", "ja"], showgrid=False)
fig.update_xaxes(row=index+2, range=[first_date, last_date], rangeslider=dict(visible=False))
# Customize layout
fig.update_layout(
xaxis=dict(
tickmode='linear',
tick0=co2.index[0],
dtick=86400000 * 7, # milliseconds in a day * 7 (for weekly ticks)
tickformat='%a %d %d',
tickangle=-45
),
yaxis=dict(title='Co2'),
autosize=True,
margin=dict(l=50, r=50, t=50, b=50),
)
for index, key in enumerate(booleans):
fig.update_yaxes(title_text=key, row=index + 2, col=1)
# Update shared axis settings
fig.update_layout(xaxis=dict(domain=[0, 1], rangeslider=dict(visible=False)))
fig.update_xaxes(title_text="Date", row=len(booleans) + 1, col=1)
fig.update_xaxes(range=[co2.index[0], co2.index[-1]], row=2, col=1)
fig.update_layout(autosize=True, showlegend=False, margin=dict(l=50, r=50, t=50, b=50),)
fig.write_html("output/all.html", include_plotlyjs='cdn')
fig.write_html("output/all.html", include_plotlyjs='cdn')
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment