Improve the frontend and repository layer

This commit is contained in:
Urtzi Alfaro
2025-10-23 07:44:54 +02:00
parent 8d30172483
commit 07c33fa578
112 changed files with 14726 additions and 2733 deletions

View File

@@ -274,6 +274,76 @@ class ProductionServiceClient(BaseServiceClient):
error=str(e), alert_id=alert_id, tenant_id=tenant_id)
return None
# ================================================================
# WASTE AND SUSTAINABILITY ANALYTICS
# ================================================================
async def get_waste_analytics(
self,
tenant_id: str,
start_date: str,
end_date: str
) -> Optional[Dict[str, Any]]:
"""
Get production waste analytics for sustainability reporting
Args:
tenant_id: Tenant ID
start_date: Start date (ISO format)
end_date: End date (ISO format)
Returns:
Dictionary with waste analytics data:
- total_production_waste: Total waste in kg
- total_defects: Total defect waste in kg
- total_planned: Total planned production in kg
- total_actual: Total actual production in kg
- ai_assisted_batches: Number of AI-assisted batches
"""
try:
params = {
"start_date": start_date,
"end_date": end_date
}
result = await self.get("production/waste-analytics", tenant_id=tenant_id, params=params)
if result:
logger.info("Retrieved production waste analytics",
tenant_id=tenant_id,
start_date=start_date,
end_date=end_date)
return result
except Exception as e:
logger.error("Error getting production waste analytics",
error=str(e), tenant_id=tenant_id)
return None
async def get_baseline(self, tenant_id: str) -> Optional[Dict[str, Any]]:
"""
Get baseline waste percentage for SDG compliance calculations
Args:
tenant_id: Tenant ID
Returns:
Dictionary with baseline data:
- waste_percentage: Baseline waste percentage
- period: Information about the baseline period
- data_available: Whether real data is available
- total_production_kg: Total production during baseline
- total_waste_kg: Total waste during baseline
"""
try:
result = await self.get("production/baseline", tenant_id=tenant_id)
if result:
logger.info("Retrieved production baseline data",
tenant_id=tenant_id,
data_available=result.get('data_available', False))
return result
except Exception as e:
logger.error("Error getting production baseline",
error=str(e), tenant_id=tenant_id)
return None
# ================================================================
# UTILITY METHODS
# ================================================================