GMARTINEZMILLA commited on
Commit
7303227
·
1 Parent(s): 03ad142

bugfix: Manufacturers Alerts

Browse files
Files changed (1) hide show
  1. app.py +6 -38
app.py CHANGED
@@ -284,6 +284,7 @@ if page == "Summary":
284
  )}
285
  )
286
  # Customer Analysis Page
 
287
  elif page == "Customer Analysis":
288
  st.markdown("""
289
  <h2 style='text-align: center; font-size: 2.5rem;'>Customer Analysis</h2>
@@ -297,6 +298,7 @@ elif page == "Customer Analysis":
297
  customer_code = st.selectbox(
298
  "Search and Select Customer Code",
299
  df['CLIENTE'].unique(), # All customer codes
 
300
  format_func=lambda x: str(x), # Ensures the values are displayed as strings
301
  help="Start typing to search for a specific customer code"
302
  )
@@ -323,35 +325,10 @@ elif page == "Customer Analysis":
323
  # Convert cliente_id to string
324
  predict_data['cliente_id'] = predict_data['cliente_id'].astype(str)
325
 
326
- st.write("Columns in predict_data:", predict_data.columns)
327
- st.write("First few rows of predict_data:")
328
- st.write(predict_data.head())
329
-
330
  with st.spinner("Filtering data..."):
331
- # If selected_manufacturer is not None, filter by manufacturer, otherwise use all
332
- if selected_manufacturer:
333
- customer_data = predict_data[predict_data['marca_id_encoded'] == selected_manufacturer]
334
- else:
335
- # Sum all manufacturers if no specific manufacturer is selected
336
- customer_data = predict_data.groupby(['cliente_id', 'fecha_mes']).agg({
337
- 'precio_total': 'sum',
338
- 'ventas_predichas': 'sum'
339
- }).reset_index()
340
-
341
- st.write("Filtered customer_data:")
342
- st.write(customer_data.head())
343
-
344
- # Historical data filtering based on whether a manufacturer is selected or not
345
- if selected_manufacturer:
346
- filtered_historical_data = historical_data[
347
- (historical_data['cliente_id'] == customer_code) &
348
- (historical_data['marca_id_encoded'] == selected_manufacturer)
349
- ]
350
- else:
351
- # Sum the historical data for all manufacturers if none is selected
352
- filtered_historical_data = historical_data[
353
- historical_data['cliente_id'] == customer_code
354
- ].groupby('fecha_mes')['precio_total'].sum().reset_index()
355
 
356
  with st.spinner("Generating sales predictions..."):
357
  if not customer_data.empty:
@@ -375,10 +352,7 @@ elif page == "Customer Analysis":
375
  results['ventas_predichas'] = y_pred
376
 
377
  # Load actual data from df_agg_2024
378
- actual_sales = df_agg_2024[df_agg_2024['cliente_id'] == customer_code]
379
-
380
- if selected_manufacturer:
381
- actual_sales = actual_sales[actual_sales['marca_id_encoded'] == selected_manufacturer]
382
 
383
  if not actual_sales.empty:
384
  # Merge predictions with actual sales
@@ -393,12 +367,6 @@ elif page == "Customer Analysis":
393
  # Ensure any missing sales data is filled with 0
394
  results['ventas_reales'].fillna(0, inplace=True)
395
 
396
- # Filter historical data by customer and manufacturer, if one is selected
397
- filtered_historical_data = historical_data[
398
- (historical_data['cliente_id'] == customer_code) &
399
- (historical_data['marca_id_encoded'] == selected_manufacturer)
400
- ] if selected_manufacturer else historical_data[historical_data['cliente_id'] == customer_code]
401
-
402
  # Define the cutoff date for the last 12 months
403
  fecha_inicio = pd.to_datetime("2023-01-01")
404
  fecha_corte = pd.to_datetime("2024-09-01")
 
284
  )}
285
  )
286
  # Customer Analysis Page
287
+ # Customer Analysis Page
288
  elif page == "Customer Analysis":
289
  st.markdown("""
290
  <h2 style='text-align: center; font-size: 2.5rem;'>Customer Analysis</h2>
 
298
  customer_code = st.selectbox(
299
  "Search and Select Customer Code",
300
  df['CLIENTE'].unique(), # All customer codes
301
+
302
  format_func=lambda x: str(x), # Ensures the values are displayed as strings
303
  help="Start typing to search for a specific customer code"
304
  )
 
325
  # Convert cliente_id to string
326
  predict_data['cliente_id'] = predict_data['cliente_id'].astype(str)
327
 
 
 
 
 
328
  with st.spinner("Filtering data..."):
329
+ # Filter for the specific customer
330
+ customer_code_str = str(customer_code)
331
+ customer_data = predict_data[predict_data['cliente_id'] == customer_code_str]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
332
 
333
  with st.spinner("Generating sales predictions..."):
334
  if not customer_data.empty:
 
352
  results['ventas_predichas'] = y_pred
353
 
354
  # Load actual data from df_agg_2024
355
+ actual_sales = df_agg_2024[df_agg_2024['cliente_id'] == customer_code_str]
 
 
 
356
 
357
  if not actual_sales.empty:
358
  # Merge predictions with actual sales
 
367
  # Ensure any missing sales data is filled with 0
368
  results['ventas_reales'].fillna(0, inplace=True)
369
 
 
 
 
 
 
 
370
  # Define the cutoff date for the last 12 months
371
  fecha_inicio = pd.to_datetime("2023-01-01")
372
  fecha_corte = pd.to_datetime("2024-09-01")