Update app.py
Browse files
app.py
CHANGED
|
@@ -110,13 +110,48 @@ def create_materials_trend_chart(df, time_period='daily', selected_materials=Non
|
|
| 110 |
return fig
|
| 111 |
|
| 112 |
def create_shift_trend_chart(df, time_period='daily'):
|
| 113 |
-
"""Create shift production trend chart over time"""
|
| 114 |
if time_period == 'daily':
|
|
|
|
| 115 |
grouped = df.groupby(['date', 'shift'])['weight_kg'].sum().reset_index()
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 120 |
elif time_period == 'weekly':
|
| 121 |
df['week'] = df['date'].dt.isocalendar().week
|
| 122 |
df['year'] = df['date'].dt.year
|
|
@@ -125,7 +160,7 @@ def create_shift_trend_chart(df, time_period='daily'):
|
|
| 125 |
fig = px.bar(grouped, x='week_label', y='weight_kg', color='shift',
|
| 126 |
title='π
Weekly Shift Production Trends',
|
| 127 |
labels={'weight_kg': 'Weight (kg)', 'week_label': 'Week', 'shift': 'Shift'},
|
| 128 |
-
barmode='
|
| 129 |
else: # monthly
|
| 130 |
df['month'] = df['date'].dt.to_period('M')
|
| 131 |
grouped = df.groupby(['month', 'shift'])['weight_kg'].sum().reset_index()
|
|
@@ -133,9 +168,9 @@ def create_shift_trend_chart(df, time_period='daily'):
|
|
| 133 |
fig = px.bar(grouped, x='month', y='weight_kg', color='shift',
|
| 134 |
title='π
Monthly Shift Production Trends',
|
| 135 |
labels={'weight_kg': 'Weight (kg)', 'month': 'Month', 'shift': 'Shift'},
|
| 136 |
-
barmode='
|
|
|
|
| 137 |
|
| 138 |
-
fig.update_layout(height=400)
|
| 139 |
return fig
|
| 140 |
"""Create individual materials trend chart"""
|
| 141 |
if selected_materials:
|
|
@@ -248,21 +283,28 @@ def main():
|
|
| 248 |
# Total Production Chart Section
|
| 249 |
st.subheader("π Total Production Trends")
|
| 250 |
|
| 251 |
-
col_total1, col_total2 = st.columns([
|
| 252 |
|
| 253 |
with col_total1:
|
| 254 |
-
total_time_view = st.selectbox("Total Time Period", ["daily", "weekly", "monthly"], key="total_time")
|
| 255 |
-
|
| 256 |
-
with col_total2:
|
| 257 |
total_chart = create_total_production_chart(df, total_time_view)
|
| 258 |
st.plotly_chart(total_chart, use_container_width=True)
|
| 259 |
|
|
|
|
|
|
|
|
|
|
| 260 |
# Materials Production Chart Section
|
| 261 |
st.subheader("π·οΈ Materials Production Trends")
|
| 262 |
|
| 263 |
-
col_mat1, col_mat2 = st.columns([
|
| 264 |
|
| 265 |
with col_mat1:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 266 |
materials_time_view = st.selectbox("Materials Time Period", ["daily", "weekly", "monthly"], key="materials_time")
|
| 267 |
|
| 268 |
selected_materials = st.multiselect(
|
|
@@ -273,27 +315,20 @@ def main():
|
|
| 273 |
help="Choose which materials to display"
|
| 274 |
)
|
| 275 |
|
| 276 |
-
with col_mat2:
|
| 277 |
-
if selected_materials:
|
| 278 |
-
materials_chart = create_materials_trend_chart(df, materials_time_view, selected_materials)
|
| 279 |
-
st.plotly_chart(materials_chart, use_container_width=True)
|
| 280 |
-
else:
|
| 281 |
-
st.info("Please select materials to display trends")
|
| 282 |
-
|
| 283 |
# Shift Analysis
|
| 284 |
if 'shift' in df.columns:
|
| 285 |
st.subheader("π Shift Analysis")
|
| 286 |
|
| 287 |
-
# Shift time trend controls
|
| 288 |
-
|
| 289 |
|
| 290 |
-
with
|
| 291 |
-
|
|
|
|
|
|
|
| 292 |
|
| 293 |
-
|
| 294 |
-
|
| 295 |
-
shift_trend_chart = create_shift_trend_chart(df, shift_time_view)
|
| 296 |
-
st.plotly_chart(shift_trend_chart, use_container_width=True)
|
| 297 |
|
| 298 |
# Shift comparison charts
|
| 299 |
st.markdown("**π Shift Comparison Analysis**")
|
|
|
|
| 110 |
return fig
|
| 111 |
|
| 112 |
def create_shift_trend_chart(df, time_period='daily'):
|
| 113 |
+
"""Create shift production trend chart over time with stacked bars"""
|
| 114 |
if time_period == 'daily':
|
| 115 |
+
# Create stacked bar chart where each bar is one day
|
| 116 |
grouped = df.groupby(['date', 'shift'])['weight_kg'].sum().reset_index()
|
| 117 |
+
|
| 118 |
+
# Pivot to have shifts as columns
|
| 119 |
+
pivot_data = grouped.pivot(index='date', columns='shift', values='weight_kg').fillna(0)
|
| 120 |
+
|
| 121 |
+
fig = go.Figure()
|
| 122 |
+
|
| 123 |
+
# Add day shift (bottom of stack)
|
| 124 |
+
if 'day' in pivot_data.columns:
|
| 125 |
+
fig.add_trace(go.Bar(
|
| 126 |
+
x=pivot_data.index,
|
| 127 |
+
y=pivot_data['day'],
|
| 128 |
+
name='Day Shift',
|
| 129 |
+
marker_color='#FFA500',
|
| 130 |
+
text=pivot_data['day'].round(0),
|
| 131 |
+
textposition='inside'
|
| 132 |
+
))
|
| 133 |
+
|
| 134 |
+
# Add night shift (top of stack)
|
| 135 |
+
if 'night' in pivot_data.columns:
|
| 136 |
+
fig.add_trace(go.Bar(
|
| 137 |
+
x=pivot_data.index,
|
| 138 |
+
y=pivot_data['night'],
|
| 139 |
+
name='Night Shift',
|
| 140 |
+
marker_color='#4169E1',
|
| 141 |
+
base=pivot_data['day'] if 'day' in pivot_data.columns else 0,
|
| 142 |
+
text=pivot_data['night'].round(0),
|
| 143 |
+
textposition='inside'
|
| 144 |
+
))
|
| 145 |
+
|
| 146 |
+
fig.update_layout(
|
| 147 |
+
title='π
Daily Shift Production Trends (Stacked)',
|
| 148 |
+
xaxis_title='Date',
|
| 149 |
+
yaxis_title='Weight (kg)',
|
| 150 |
+
barmode='stack',
|
| 151 |
+
height=400,
|
| 152 |
+
showlegend=True
|
| 153 |
+
)
|
| 154 |
+
|
| 155 |
elif time_period == 'weekly':
|
| 156 |
df['week'] = df['date'].dt.isocalendar().week
|
| 157 |
df['year'] = df['date'].dt.year
|
|
|
|
| 160 |
fig = px.bar(grouped, x='week_label', y='weight_kg', color='shift',
|
| 161 |
title='π
Weekly Shift Production Trends',
|
| 162 |
labels={'weight_kg': 'Weight (kg)', 'week_label': 'Week', 'shift': 'Shift'},
|
| 163 |
+
barmode='stack')
|
| 164 |
else: # monthly
|
| 165 |
df['month'] = df['date'].dt.to_period('M')
|
| 166 |
grouped = df.groupby(['month', 'shift'])['weight_kg'].sum().reset_index()
|
|
|
|
| 168 |
fig = px.bar(grouped, x='month', y='weight_kg', color='shift',
|
| 169 |
title='π
Monthly Shift Production Trends',
|
| 170 |
labels={'weight_kg': 'Weight (kg)', 'month': 'Month', 'shift': 'Shift'},
|
| 171 |
+
barmode='stack')
|
| 172 |
+
fig.update_layout(height=400)
|
| 173 |
|
|
|
|
| 174 |
return fig
|
| 175 |
"""Create individual materials trend chart"""
|
| 176 |
if selected_materials:
|
|
|
|
| 283 |
# Total Production Chart Section
|
| 284 |
st.subheader("π Total Production Trends")
|
| 285 |
|
| 286 |
+
col_total1, col_total2 = st.columns([3, 1])
|
| 287 |
|
| 288 |
with col_total1:
|
|
|
|
|
|
|
|
|
|
| 289 |
total_chart = create_total_production_chart(df, total_time_view)
|
| 290 |
st.plotly_chart(total_chart, use_container_width=True)
|
| 291 |
|
| 292 |
+
with col_total2:
|
| 293 |
+
total_time_view = st.selectbox("Total Time Period", ["daily", "weekly", "monthly"], key="total_time")
|
| 294 |
+
|
| 295 |
# Materials Production Chart Section
|
| 296 |
st.subheader("π·οΈ Materials Production Trends")
|
| 297 |
|
| 298 |
+
col_mat1, col_mat2 = st.columns([3, 1])
|
| 299 |
|
| 300 |
with col_mat1:
|
| 301 |
+
if selected_materials:
|
| 302 |
+
materials_chart = create_materials_trend_chart(df, materials_time_view, selected_materials)
|
| 303 |
+
st.plotly_chart(materials_chart, use_container_width=True)
|
| 304 |
+
else:
|
| 305 |
+
st.info("Please select materials to display trends")
|
| 306 |
+
|
| 307 |
+
with col_mat2:
|
| 308 |
materials_time_view = st.selectbox("Materials Time Period", ["daily", "weekly", "monthly"], key="materials_time")
|
| 309 |
|
| 310 |
selected_materials = st.multiselect(
|
|
|
|
| 315 |
help="Choose which materials to display"
|
| 316 |
)
|
| 317 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 318 |
# Shift Analysis
|
| 319 |
if 'shift' in df.columns:
|
| 320 |
st.subheader("π Shift Analysis")
|
| 321 |
|
| 322 |
+
# Shift time trend controls moved to right
|
| 323 |
+
col_shift_trend1, col_shift_trend2 = st.columns([3, 1])
|
| 324 |
|
| 325 |
+
with col_shift_trend1:
|
| 326 |
+
st.markdown("**π Shift Production Trends**")
|
| 327 |
+
shift_trend_chart = create_shift_trend_chart(df, shift_time_view)
|
| 328 |
+
st.plotly_chart(shift_trend_chart, use_container_width=True)
|
| 329 |
|
| 330 |
+
with col_shift_trend2:
|
| 331 |
+
shift_time_view = st.selectbox("Shift Time Period", ["daily", "weekly", "monthly"], key="shift_time")
|
|
|
|
|
|
|
| 332 |
|
| 333 |
# Shift comparison charts
|
| 334 |
st.markdown("**π Shift Comparison Analysis**")
|