Spaces:
Sleeping
Sleeping
Commit
路
8d27cbf
1
Parent(s):
586b580
feat: updated website
Browse files
app.py
CHANGED
@@ -362,21 +362,40 @@ elif page == "Customer Analysis":
|
|
362 |
# Ensure any missing sales data is filled with 0
|
363 |
results['ventas_reales'].fillna(0, inplace=True)
|
364 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
365 |
st.markdown("### Sales History, Predictions, and Real Sales")
|
366 |
-
fechas = pd.to_datetime(results['fecha_mes']) # Extract the date
|
367 |
|
368 |
-
# Extract the actual data for the plot
|
369 |
-
ventas_historicas = customer_data['precio_total'].values[:12] # Historical sales (first 12 months)
|
370 |
-
ventas_predichas = results['ventas_predichas'].values # Predicted sales (next months)
|
371 |
-
ventas_reales = results['ventas_reales'].values # Real sales (next months)
|
372 |
-
|
373 |
# Create the figure using Plotly
|
374 |
fig = go.Figure()
|
375 |
|
376 |
# Plot historical sales
|
377 |
fig.add_trace(go.Scatter(
|
378 |
-
x=
|
379 |
-
y=ventas_historicas,
|
380 |
mode='lines+markers',
|
381 |
name='Ventas Hist贸ricas',
|
382 |
line=dict(color='blue')
|
@@ -384,8 +403,8 @@ elif page == "Customer Analysis":
|
|
384 |
|
385 |
# Plot predicted sales
|
386 |
fig.add_trace(go.Scatter(
|
387 |
-
x=
|
388 |
-
y=ventas_predichas,
|
389 |
mode='lines+markers',
|
390 |
name='Ventas Predichas',
|
391 |
line=dict(color='orange')
|
@@ -393,8 +412,8 @@ elif page == "Customer Analysis":
|
|
393 |
|
394 |
# Plot real sales
|
395 |
fig.add_trace(go.Scatter(
|
396 |
-
x=
|
397 |
-
y=ventas_reales,
|
398 |
mode='lines+markers',
|
399 |
name='Ventas Reales',
|
400 |
line=dict(color='green')
|
|
|
362 |
# Ensure any missing sales data is filled with 0
|
363 |
results['ventas_reales'].fillna(0, inplace=True)
|
364 |
|
365 |
+
# Define the cutoff date for the last 12 months
|
366 |
+
fecha_corte = pd.to_datetime("2024-01-01") # Adjust as needed
|
367 |
+
fecha_inicio = fecha_corte - pd.DateOffset(months=12)
|
368 |
+
|
369 |
+
# Filter historical data for the customer over the last 12 months
|
370 |
+
datos_historicos = historical_data[
|
371 |
+
(historical_data['cliente_id'] == customer_code_str) &
|
372 |
+
(historical_data['fecha_mes'] >= fecha_inicio) &
|
373 |
+
(historical_data['fecha_mes'] < fecha_corte)
|
374 |
+
].groupby('fecha_mes')['precio_total'].sum().reset_index()
|
375 |
+
|
376 |
+
# Rename 'precio_total' column to 'ventas_historicas'
|
377 |
+
datos_historicos.rename(columns={'precio_total': 'ventas_historicas'}, inplace=True)
|
378 |
+
|
379 |
+
# Filter prediction and real sales data and sum by month
|
380 |
+
datos_cliente_total = results.groupby('fecha_mes').agg({
|
381 |
+
'ventas_reales': 'sum',
|
382 |
+
'ventas_predichas': 'sum'
|
383 |
+
}).reset_index()
|
384 |
+
|
385 |
+
# Combine historical data with prediction and real sales data
|
386 |
+
datos_combinados = pd.concat([datos_historicos, datos_cliente_total], sort=False).sort_values('fecha_mes').reset_index(drop=True)
|
387 |
+
|
388 |
+
# **Generate the graph**
|
389 |
+
|
390 |
st.markdown("### Sales History, Predictions, and Real Sales")
|
|
|
391 |
|
|
|
|
|
|
|
|
|
|
|
392 |
# Create the figure using Plotly
|
393 |
fig = go.Figure()
|
394 |
|
395 |
# Plot historical sales
|
396 |
fig.add_trace(go.Scatter(
|
397 |
+
x=datos_combinados['fecha_mes'], # Dates
|
398 |
+
y=datos_combinados['ventas_historicas'],
|
399 |
mode='lines+markers',
|
400 |
name='Ventas Hist贸ricas',
|
401 |
line=dict(color='blue')
|
|
|
403 |
|
404 |
# Plot predicted sales
|
405 |
fig.add_trace(go.Scatter(
|
406 |
+
x=datos_combinados['fecha_mes'], # Dates
|
407 |
+
y=datos_combinados['ventas_predichas'],
|
408 |
mode='lines+markers',
|
409 |
name='Ventas Predichas',
|
410 |
line=dict(color='orange')
|
|
|
412 |
|
413 |
# Plot real sales
|
414 |
fig.add_trace(go.Scatter(
|
415 |
+
x=datos_combinados['fecha_mes'], # Dates
|
416 |
+
y=datos_combinados['ventas_reales'],
|
417 |
mode='lines+markers',
|
418 |
name='Ventas Reales',
|
419 |
line=dict(color='green')
|