GMARTINEZMILLA commited on
Commit
01bbb5b
1 Parent(s): 3d8a22e

feat: updated website

Browse files
Files changed (1) hide show
  1. app.py +53 -9
app.py CHANGED
@@ -430,22 +430,66 @@ elif page == "Customer Analysis":
430
  sales_columns = ['VENTA_2021', 'VENTA_2022', 'VENTA_2023']
431
  if all(col in ventas_clientes.columns for col in sales_columns):
432
  customer_sales_data = ventas_clientes[ventas_clientes['codigo_cliente'] == customer_code]
433
-
434
  if not customer_sales_data.empty:
435
  customer_sales = customer_sales_data[sales_columns].values[0]
436
  years = ['2021', '2022', '2023']
437
-
438
- fig_sales = px.line(x=years, y=customer_sales, markers=True, title=f'Sales Over the Years for Customer {customer_code}')
439
- fig_sales.update_layout(xaxis_title="Year", yaxis_title="Sales")
440
- st.plotly_chart(fig_sales)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
441
  else:
442
  st.warning(f"No historical sales data found for customer {customer_code}")
 
443
  else:
444
  st.warning("Sales data for 2021-2023 not available in the dataset.")
445
- else:
446
- st.warning(f"No data found for customer {customer_code}. Please check the code.")
447
- else:
448
- st.warning("Please select a customer.")
449
 
450
 
451
  # Customer Recommendations Page
 
430
  sales_columns = ['VENTA_2021', 'VENTA_2022', 'VENTA_2023']
431
  if all(col in ventas_clientes.columns for col in sales_columns):
432
  customer_sales_data = ventas_clientes[ventas_clientes['codigo_cliente'] == customer_code]
433
+
434
  if not customer_sales_data.empty:
435
  customer_sales = customer_sales_data[sales_columns].values[0]
436
  years = ['2021', '2022', '2023']
437
+
438
+ # Add the 2024 actual and predicted data
439
+ if 'ventas_predichas' in results.columns and 'ventas_reales' in results.columns:
440
+ # Get the actual and predicted sales for 2024
441
+ actual_sales_2024 = results[results['fecha_mes'].str.startswith('2024')]['ventas_reales'].sum()
442
+ predicted_sales_2024 = results[results['fecha_mes'].str.startswith('2024')]['ventas_predichas'].sum()
443
+
444
+ # Estimate full-year predicted sales (assuming predictions available until September)
445
+ months_available = 9 # Data available until September
446
+ predicted_sales_2024_annual = (predicted_sales_2024 / months_available) * 12
447
+
448
+ # Add 2024 actual and predicted sales
449
+ sales_values = list(customer_sales) + [actual_sales_2024] # Actual sales
450
+ predicted_values = list(customer_sales) + [predicted_sales_2024_annual] # Predicted sales
451
+
452
+ # Add 2024 to the years list
453
+ years.append('2024')
454
+
455
+ # Create an interactive bar chart using Plotly
456
+ fig_sales_bar = px.bar(
457
+ x=years,
458
+ y=[sales_values, predicted_values],
459
+ labels={"x": "Year", "y": "Sales (€)"},
460
+ barmode='group',
461
+ title=f"Sales Over the Years for Customer {customer_code} (Actual vs Predicted)"
462
+ )
463
+
464
+ # Update the layout to make the bar chart interactive
465
+ fig_sales_bar.update_layout(
466
+ yaxis_title="Sales (€)",
467
+ xaxis_title="Year",
468
+ hovermode="x unified",
469
+ height=600,
470
+ legend_title_text="Sales Type"
471
+ )
472
+
473
+ # Add traces for actual and predicted sales
474
+ fig_sales_bar.add_trace(
475
+ px.bar(x=years, y=sales_values, name="Actual Sales", marker_color='blue').data[0]
476
+ )
477
+
478
+ fig_sales_bar.add_trace(
479
+ px.bar(x=years, y=predicted_values, name="Predicted Sales (Annualized for 2024)", marker_color='orange').data[0]
480
+ )
481
+
482
+ # Show the interactive bar chart in Streamlit
483
+ st.plotly_chart(fig_sales_bar, use_container_width=True)
484
+
485
+ else:
486
+ st.warning(f"No predicted or actual data found for customer {customer_code} for 2024.")
487
+
488
  else:
489
  st.warning(f"No historical sales data found for customer {customer_code}")
490
+
491
  else:
492
  st.warning("Sales data for 2021-2023 not available in the dataset.")
 
 
 
 
493
 
494
 
495
  # Customer Recommendations Page