Summary
I display calender weeks in my pyplot. The calender weeks are distributed over years change but still sorted ascending.
I would like to display the weeks sorted by year.
Anyone an idea for that?
I display calender weeks in my pyplot. The calender weeks are distributed over years change but still sorted ascending.
I would like to display the weeks sorted by year.
Anyone an idea for that?
Hey can you share code snippet for the same?
Ah, I forgot, I am sorry.
places = df['place.name'].unique()
slc_places = st.multiselect('Select the places you want to observe', places)
for place in slc_places:
#allcontainer data has already the last timestamp per container
data = agg_data.loc[agg_data['place.name'] == place]
data = data.reset_index(drop=True)
#add week
data['week'] = data['timestamp'].dt.week
#Add Diff Column
data['diff'] = data[fillingLvl].diff()
data['consumption'] = data['diff'].apply(lambda x: x if x < 0 else 0)
data['additions'] = data['diff'].apply(lambda x: x if x > 0 else 0)
data['consumption_cumulative'] = data['consumption'].cumsum()
data['additions_cumulative'] = data['additions'].cumsum()
st.dataframe(data)
#Chart Filling Level
fig = px.line(data, x='timestamp', y=fillingLvl, color='containerData.productName', title=f'Filling Level for {place}')
st.plotly_chart(fig, use_container_width=True)
### Consumption per week
fig2 = px.bar(data, x='timestamp', y='consumption', color='containerData.productName', title=f'Consumption Level for {place}')
#Avg consumption per produkt per week
avg_consumption_week = data.groupby(['week','containerData.productName'])['consumption'].mean().reset_index()
avg_consumption_week.columns = ['Week', 'Product', 'Avg. Consumption']
fig_avg_consumption_week = px.bar(avg_consumption_week, x='Week', y='Avg. Consumption', color='Product', title=f'Average Consumption per Calendar Week for {place}')
#2. consumption per week per product
optimal_levels = avg_consumption_week.pivot(index='Product', columns='Week', values='Avg. Consumption')
fig5 = go.Figure(data=go.Heatmap(
z=optimal_levels.values,
x=optimal_levels.columns,
y=optimal_levels.index,
colorscale='Viridis'))
fig5.update_layout(
title='Optimal Filling Levels by Product and Week',
xaxis_title='Week',
yaxis_title='Product'
)
#3. Addition per week
fig_addition_week = px.bar(data, x='timestamp', y='additions', color='containerData.productName', title=f'Additions Level for {place}')
# Avg Addition per produkt per week
avg_addition_week = data.groupby(['week','containerData.productName'])['additions'].mean().reset_index()
fig_avg_additions = px.bar(avg_addition_week, x='week', y='additions', color='containerData.productName', title=f'Average Additions per Calendar Week for {place}')
# Addition per week per product
optimal_levels_additions = avg_addition_week.pivot(index='containerData.productName', columns='week', values='additions')
c1, c2 = st.columns(2)
with c1:
st.plotly_chart(fig2, use_container_width=True)
st.plotly_chart(fig_addition_week, use_container_width=True, theme=None)
st.dataframe(avg_consumption_week)
st.dataframe(optimal_levels_additions)
st.plotly_chart(fig5, use_container_width=True)
with c2:
st.plotly_chart(fig_avg_consumption_week, use_container_width=True)
st.plotly_chart(fig_avg_additions, use_container_width=True, theme=None)
st.write('Optimal Filling Level based on Consumption')
st.dataframe(optimal_levels)
st.markdown('---')