Spaces:
Sleeping
Sleeping
GMARTINEZMILLA
commited on
Commit
•
416d73b
1
Parent(s):
bf91a9d
feat: generated files
Browse files
app.py
CHANGED
@@ -59,66 +59,54 @@ elif page == "Customer Analysis":
|
|
59 |
if not customer_data.empty:
|
60 |
st.write(f"### Analysis for Customer {customer_code}")
|
61 |
|
62 |
-
# Generar el spider chart con los top 6 fabricantes
|
63 |
-
fig_spider = go.Figure()
|
64 |
-
|
65 |
# Obtener las 6 columnas con los valores más altos (ignorar la columna de cliente)
|
66 |
top_6_manufacturers = customer_data.iloc[:, 1:].T.nlargest(6, customer_data.index[0])
|
67 |
|
68 |
# Ordenar los fabricantes por valor descendente para mejor visualización
|
69 |
top_6_manufacturers = top_6_manufacturers.sort_values(by=customer_data.index[0], ascending=False)
|
70 |
|
71 |
-
# Preparar los valores y fabricantes
|
72 |
values = top_6_manufacturers[customer_data.index[0]].values.tolist()
|
73 |
manufacturers = top_6_manufacturers.index.tolist()
|
74 |
|
75 |
-
#
|
76 |
st.write("### Resultados porcentaje fabricante (ordenados):")
|
77 |
-
for
|
78 |
-
st.write(f"{manufacturer} = {
|
79 |
-
|
80 |
-
#
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
fig_spider.add_trace(go.Scatterpolar(
|
92 |
-
r=values, # Los valores del cliente
|
93 |
-
theta=manufacturers, # Los nombres de los fabricantes
|
94 |
-
fill='toself', # Rellenar el gráfico
|
95 |
name=f'Customer {customer_code}',
|
96 |
-
line_color='blue',
|
97 |
-
fillcolor='rgba(0, 0, 255, 0.3)',
|
98 |
-
mode='lines+markers',
|
99 |
-
marker=dict(size=8, color='red')
|
100 |
))
|
101 |
|
102 |
-
|
103 |
-
fig_spider.update_layout(
|
104 |
polar=dict(
|
105 |
radialaxis=dict(
|
106 |
visible=True,
|
107 |
-
range=[0, 1] # Ajustar el rango para
|
108 |
-
),
|
109 |
-
angularaxis=dict(
|
110 |
-
tickmode='array',
|
111 |
-
tickvals=[i * (360 / 6) for i in range(6)], # Distribuir los puntos de los fabricantes de manera uniforme
|
112 |
)
|
113 |
),
|
114 |
-
title=f'
|
115 |
-
showlegend=False,
|
116 |
height=600,
|
117 |
width=600
|
118 |
)
|
119 |
|
120 |
-
# Mostrar el gráfico
|
121 |
-
st.plotly_chart(
|
122 |
|
123 |
# Ventas del cliente 2021-2024 (si los datos existen)
|
124 |
if 'VENTA_2021' in df.columns and 'VENTA_2022' in df.columns and 'VENTA_2023' in df.columns and 'VENTA_2024' in df.columns:
|
@@ -133,7 +121,7 @@ elif page == "Customer Analysis":
|
|
133 |
st.warning("Sales data for 2021-2024 not available.")
|
134 |
else:
|
135 |
st.warning(f"No data found for customer {customer_code}. Please check the code.")
|
136 |
-
|
137 |
# Página Customer Recommendations
|
138 |
elif page == "Customer Recommendations":
|
139 |
st.title("Customer Recommendations")
|
|
|
59 |
if not customer_data.empty:
|
60 |
st.write(f"### Analysis for Customer {customer_code}")
|
61 |
|
|
|
|
|
|
|
62 |
# Obtener las 6 columnas con los valores más altos (ignorar la columna de cliente)
|
63 |
top_6_manufacturers = customer_data.iloc[:, 1:].T.nlargest(6, customer_data.index[0])
|
64 |
|
65 |
# Ordenar los fabricantes por valor descendente para mejor visualización
|
66 |
top_6_manufacturers = top_6_manufacturers.sort_values(by=customer_data.index[0], ascending=False)
|
67 |
|
68 |
+
# Preparar los valores y fabricantes
|
69 |
values = top_6_manufacturers[customer_data.index[0]].values.tolist()
|
70 |
manufacturers = top_6_manufacturers.index.tolist()
|
71 |
|
72 |
+
# Mostrar los resultados de cada fabricante
|
73 |
st.write("### Resultados porcentaje fabricante (ordenados):")
|
74 |
+
for manufacturer, value in zip(manufacturers, values):
|
75 |
+
st.write(f"{manufacturer} = {value:.4f}")
|
76 |
+
|
77 |
+
# Normalizar los valores para que sumen 1
|
78 |
+
total = sum(values)
|
79 |
+
values = [v / total for v in values]
|
80 |
+
|
81 |
+
# Crear el gráfico de radar
|
82 |
+
fig = go.Figure()
|
83 |
+
|
84 |
+
fig.add_trace(go.Scatterpolar(
|
85 |
+
r=values + [values[0]], # Añadir el primer valor al final para cerrar el polígono
|
86 |
+
theta=manufacturers + [manufacturers[0]], # Añadir el primer fabricante al final
|
87 |
+
fill='toself',
|
|
|
|
|
|
|
|
|
88 |
name=f'Customer {customer_code}',
|
89 |
+
line_color='blue',
|
90 |
+
fillcolor='rgba(0, 0, 255, 0.3)',
|
91 |
+
mode='lines+markers',
|
92 |
+
marker=dict(size=8, color='red')
|
93 |
))
|
94 |
|
95 |
+
fig.update_layout(
|
|
|
96 |
polar=dict(
|
97 |
radialaxis=dict(
|
98 |
visible=True,
|
99 |
+
range=[0, max(values) * 1.1] # Ajustar el rango para que sea un poco mayor que el valor máximo
|
|
|
|
|
|
|
|
|
100 |
)
|
101 |
),
|
102 |
+
title=f'Radar Chart for Top 6 Manufacturers of Customer {customer_code}',
|
103 |
+
showlegend=False,
|
104 |
height=600,
|
105 |
width=600
|
106 |
)
|
107 |
|
108 |
+
# Mostrar el gráfico
|
109 |
+
st.plotly_chart(fig)
|
110 |
|
111 |
# Ventas del cliente 2021-2024 (si los datos existen)
|
112 |
if 'VENTA_2021' in df.columns and 'VENTA_2022' in df.columns and 'VENTA_2023' in df.columns and 'VENTA_2024' in df.columns:
|
|
|
121 |
st.warning("Sales data for 2021-2024 not available.")
|
122 |
else:
|
123 |
st.warning(f"No data found for customer {customer_code}. Please check the code.")
|
124 |
+
|
125 |
# Página Customer Recommendations
|
126 |
elif page == "Customer Recommendations":
|
127 |
st.title("Customer Recommendations")
|