GMARTINEZMILLA commited on
Commit
a431e22
1 Parent(s): 145c4e5

feat: updated website

Browse files
Files changed (1) hide show
  1. app.py +16 -2
app.py CHANGED
@@ -88,6 +88,7 @@ fieles_df = pd.read_csv("clientes_relevantes.csv")
88
  cestas = pd.read_csv("cestas.csv")
89
  productos = pd.read_csv("productos.csv")
90
  df_agg_2024['cliente_id'] = df_agg_2024['cliente_id'].astype(str)
 
91
 
92
  # Convert all columns except 'CLIENTE' to float in euros_proveedor
93
  for col in euros_proveedor.columns:
@@ -107,6 +108,19 @@ def get_supplier_name(code):
107
  name = nombres_proveedores[nombres_proveedores['codigo'] == code]['nombre'].values
108
  return name[0] if len(name) > 0 else code
109
 
 
 
 
 
 
 
 
 
 
 
 
 
 
110
  # Custom Donut Chart with Plotly for Inbound/Outbound Percentage
111
  def create_donut_chart(values, labels, color_scheme, title):
112
  fig = px.pie(
@@ -345,7 +359,7 @@ elif page == "Customer Analysis":
345
  top_overperformers = overperforming_manufacturers.head(10)
346
 
347
  for index, row in top_overperformers.iterrows():
348
- manufacturer_name = get_supplier_name(row['marca_id_encoded'])
349
  predicted = row['ventas_predichas']
350
  actual = row['ventas_reales']
351
  extra = row['extra_amount']
@@ -422,7 +436,7 @@ elif page == "Customer Analysis":
422
  top_misses = underperforming_manufacturers.head(10)
423
 
424
  for index, row in top_misses.iterrows():
425
- manufacturer_name = get_supplier_name(row['marca_id_encoded'])
426
  predicted = row['ventas_predichas']
427
  actual = row['ventas_reales']
428
  missed = row['missed_amount']
 
88
  cestas = pd.read_csv("cestas.csv")
89
  productos = pd.read_csv("productos.csv")
90
  df_agg_2024['cliente_id'] = df_agg_2024['cliente_id'].astype(str)
91
+ marca_id_mapping = load('path_to_file/marca_id_mapping.joblib')
92
 
93
  # Convert all columns except 'CLIENTE' to float in euros_proveedor
94
  for col in euros_proveedor.columns:
 
108
  name = nombres_proveedores[nombres_proveedores['codigo'] == code]['nombre'].values
109
  return name[0] if len(name) > 0 else code
110
 
111
+ def get_supplier_name_encoded(encoded_code):
112
+ encoded_code = str(encoded_code) # Ensure the encoded code is a string
113
+
114
+ # First, use the label encoder to get the original manufacturer code
115
+ if encoded_code in marca_id_mapping.classes_:
116
+ real_code = marca_id_mapping.inverse_transform([encoded_code])[0]
117
+ else:
118
+ return f"Unknown code: {encoded_code}" # Handle case where encoded code is not found
119
+
120
+ # Now, use the real_code to find the manufacturer name in nombres_proveedores
121
+ name = nombres_proveedores[nombres_proveedores['codigo'] == real_code]['nombre'].values
122
+ return name[0] if len(name) > 0 else real_code # Return real_code if name not found
123
+
124
  # Custom Donut Chart with Plotly for Inbound/Outbound Percentage
125
  def create_donut_chart(values, labels, color_scheme, title):
126
  fig = px.pie(
 
359
  top_overperformers = overperforming_manufacturers.head(10)
360
 
361
  for index, row in top_overperformers.iterrows():
362
+ manufacturer_name = get_supplier_name_encoded(row['marca_id_encoded'])
363
  predicted = row['ventas_predichas']
364
  actual = row['ventas_reales']
365
  extra = row['extra_amount']
 
436
  top_misses = underperforming_manufacturers.head(10)
437
 
438
  for index, row in top_misses.iterrows():
439
+ manufacturer_name = get_supplier_name_encoded(row['marca_id_encoded'])
440
  predicted = row['ventas_predichas']
441
  actual = row['ventas_reales']
442
  missed = row['missed_amount']