Fix new services implementation 5

This commit is contained in:
Urtzi Alfaro
2025-08-15 17:53:59 +02:00
parent 03b4d4185d
commit f7de9115d1
43 changed files with 1714 additions and 891 deletions

View File

@@ -92,9 +92,27 @@ class EnhancedBakeryMLTrainer:
# Get unique products from the sales data
products = sales_df['inventory_product_id'].unique().tolist()
logger.info("Training enhanced models",
# Debug: Log sales data details to understand why only one product is found
total_sales_records = len(sales_df)
sales_by_product = sales_df.groupby('inventory_product_id').size().to_dict()
logger.info("Enhanced training pipeline - Sales data analysis",
total_sales_records=total_sales_records,
products_count=len(products),
products=products)
products=products,
sales_by_product=sales_by_product)
if len(products) == 1:
logger.warning("Only ONE product found in sales data - this may indicate a data fetching issue",
tenant_id=tenant_id,
single_product_id=products[0],
total_sales_records=total_sales_records)
elif len(products) == 0:
raise ValueError("No products found in sales data")
else:
logger.info("Multiple products detected for training",
products_count=len(products))
self.status_publisher.products_total = len(products)
@@ -512,7 +530,7 @@ class EnhancedBakeryMLTrainer:
from_column='quantity_sold',
to_column='quantity')
required_columns = ['date', 'product_name', 'quantity']
required_columns = ['date', 'inventory_product_id', 'quantity']
missing_columns = [col for col in required_columns if col not in sales_df.columns]
if missing_columns:
raise ValueError(f"Missing required columns: {missing_columns}")
@@ -541,7 +559,7 @@ class EnhancedBakeryMLTrainer:
try:
logger.info("Enhanced model evaluation starting",
tenant_id=tenant_id,
product_name=product_name)
inventory_product_id=inventory_product_id)
# Get database session and repositories
async with self.database_manager.get_session() as db_session: