entropy25 commited on
Commit
0f8c670
Β·
verified Β·
1 Parent(s): aafaeac

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +44 -5
app.py CHANGED
@@ -80,7 +80,34 @@ def create_total_production_chart(df, time_period='daily'):
80
  fig.update_traces(line=dict(color='#1f77b4'))
81
  return fig
82
 
83
- def create_materials_trend_chart(df, time_period='daily', selected_materials=None):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
84
  """Create individual materials trend chart"""
85
  if selected_materials:
86
  df = df[df['material_type'].isin(selected_materials)]
@@ -204,12 +231,11 @@ def main():
204
  # Materials Production Chart Section
205
  st.subheader("🏷️ Materials Production Trends")
206
 
207
- col_mat1, col_mat2, col_mat3 = st.columns([1, 2, 3])
208
 
209
  with col_mat1:
210
  materials_time_view = st.selectbox("Materials Time Period", ["daily", "weekly", "monthly"], key="materials_time")
211
-
212
- with col_mat2:
213
  selected_materials = st.multiselect(
214
  "Select Materials",
215
  options=materials,
@@ -218,7 +244,7 @@ def main():
218
  help="Choose which materials to display"
219
  )
220
 
221
- with col_mat3:
222
  if selected_materials:
223
  materials_chart = create_materials_trend_chart(df, materials_time_view, selected_materials)
224
  st.plotly_chart(materials_chart, use_container_width=True)
@@ -229,6 +255,19 @@ def main():
229
  if 'shift' in df.columns:
230
  st.subheader("πŸŒ“ Shift Analysis")
231
 
 
 
 
 
 
 
 
 
 
 
 
 
 
232
  shift_col1, shift_col2 = st.columns(2)
233
 
234
  with shift_col1:
 
80
  fig.update_traces(line=dict(color='#1f77b4'))
81
  return fig
82
 
83
+ def create_shift_trend_chart(df, time_period='daily'):
84
+ """Create shift production trend chart over time"""
85
+ if time_period == 'daily':
86
+ grouped = df.groupby(['date', 'shift'])['weight_kg'].sum().reset_index()
87
+ fig = px.bar(grouped, x='date', y='weight_kg', color='shift',
88
+ title='πŸ“… Daily Shift Production Trends',
89
+ labels={'weight_kg': 'Weight (kg)', 'date': 'Date', 'shift': 'Shift'},
90
+ barmode='group')
91
+ elif time_period == 'weekly':
92
+ df['week'] = df['date'].dt.isocalendar().week
93
+ df['year'] = df['date'].dt.year
94
+ grouped = df.groupby(['year', 'week', 'shift'])['weight_kg'].sum().reset_index()
95
+ grouped['week_label'] = grouped['year'].astype(str) + '-W' + grouped['week'].astype(str)
96
+ fig = px.bar(grouped, x='week_label', y='weight_kg', color='shift',
97
+ title='πŸ“… Weekly Shift Production Trends',
98
+ labels={'weight_kg': 'Weight (kg)', 'week_label': 'Week', 'shift': 'Shift'},
99
+ barmode='group')
100
+ else: # monthly
101
+ df['month'] = df['date'].dt.to_period('M')
102
+ grouped = df.groupby(['month', 'shift'])['weight_kg'].sum().reset_index()
103
+ grouped['month'] = grouped['month'].astype(str)
104
+ fig = px.bar(grouped, x='month', y='weight_kg', color='shift',
105
+ title='πŸ“… Monthly Shift Production Trends',
106
+ labels={'weight_kg': 'Weight (kg)', 'month': 'Month', 'shift': 'Shift'},
107
+ barmode='group')
108
+
109
+ fig.update_layout(height=400)
110
+ return fig
111
  """Create individual materials trend chart"""
112
  if selected_materials:
113
  df = df[df['material_type'].isin(selected_materials)]
 
231
  # Materials Production Chart Section
232
  st.subheader("🏷️ Materials Production Trends")
233
 
234
+ col_mat1, col_mat2 = st.columns([1, 3])
235
 
236
  with col_mat1:
237
  materials_time_view = st.selectbox("Materials Time Period", ["daily", "weekly", "monthly"], key="materials_time")
238
+
 
239
  selected_materials = st.multiselect(
240
  "Select Materials",
241
  options=materials,
 
244
  help="Choose which materials to display"
245
  )
246
 
247
+ with col_mat2:
248
  if selected_materials:
249
  materials_chart = create_materials_trend_chart(df, materials_time_view, selected_materials)
250
  st.plotly_chart(materials_chart, use_container_width=True)
 
255
  if 'shift' in df.columns:
256
  st.subheader("πŸŒ“ Shift Analysis")
257
 
258
+ # Shift time trend controls
259
+ col_shift_ctrl, col_shift_space = st.columns([2, 2])
260
+
261
+ with col_shift_ctrl:
262
+ shift_time_view = st.selectbox("Shift Time Period", ["daily", "weekly", "monthly"], key="shift_time")
263
+
264
+ # Daily shift trend chart
265
+ st.markdown("**πŸ“ˆ Shift Production Trends**")
266
+ shift_trend_chart = create_shift_trend_chart(df, shift_time_view)
267
+ st.plotly_chart(shift_trend_chart, use_container_width=True)
268
+
269
+ # Shift comparison charts
270
+ st.markdown("**πŸ“Š Shift Comparison Analysis**")
271
  shift_col1, shift_col2 = st.columns(2)
272
 
273
  with shift_col1: