Landing imporvement

This commit is contained in:
Urtzi Alfaro
2025-11-08 12:02:18 +01:00
parent a1cd7958ed
commit 4678f96f8f
16 changed files with 475 additions and 393 deletions

View File

@@ -734,44 +734,65 @@ class SustainabilityService:
def _assess_grant_readiness(self, sdg_compliance: Dict[str, Any]) -> Dict[str, Any]:
"""
Assess readiness for EU grant programs accessible to Spanish bakeries and retail.
Based on 2025 research and Spain's Law 1/2025 on food waste prevention.
Based on 2026 verified research. Updated Dec 2025.
"""
reduction = sdg_compliance['sdg_12_3']['reduction_achieved']
grants = {
'life_circular_economy': {
'eligible': reduction >= 15,
'confidence': 'high' if reduction >= 25 else 'medium' if reduction >= 15 else 'low',
'requirements_met': reduction >= 15,
'funding_eur': 73_000_000, # €73M available for circular economy
'deadline': '2025-09-23',
'program_type': 'grant'
},
'horizon_europe_cluster_6': {
'horizon_europe_food_systems': {
'eligible': reduction >= 20,
'confidence': 'high' if reduction >= 35 else 'medium' if reduction >= 20 else 'low',
'requirements_met': reduction >= 20,
'funding_eur': 880_000_000, # €880M+ annually for food systems
'deadline': 'rolling_2025',
'program_type': 'grant'
'funding_eur': 12_000_000, # €3-12M per project
'deadline': '2026-02-18',
'program_type': 'grant',
'category': 'European Union'
},
'fedima_sustainability_grant': {
'horizon_europe_circular_sme': {
'eligible': reduction >= 15,
'confidence': 'high' if reduction >= 20 else 'medium' if reduction >= 15 else 'low',
'confidence': 'high' if reduction >= 25 else 'medium' if reduction >= 15 else 'low',
'requirements_met': reduction >= 15,
'funding_eur': 20_000, # €20k bi-annual
'deadline': '2025-06-30',
'funding_eur': 10_000_000, # €10M total program
'deadline': '2026-02-18',
'program_type': 'grant',
'sector_specific': 'bakery'
'category': 'European Union'
},
'eit_food_retail': {
'eligible': reduction >= 20,
'confidence': 'high' if reduction >= 30 else 'medium' if reduction >= 20 else 'low',
'requirements_met': reduction >= 20,
'funding_eur': 45_000, # €15-45k range
'deadline': 'rolling',
'eit_food_impact_2026': {
'eligible': reduction >= 15,
'confidence': 'high' if reduction >= 25 else 'medium' if reduction >= 15 else 'low',
'requirements_met': reduction >= 15,
'funding_eur': 1_000_000, # €50K-1M range
'deadline': 'rolling_2026',
'program_type': 'grant',
'sector_specific': 'retail'
'category': 'European Union'
},
'eib_circular_economy': {
'eligible': reduction >= 10,
'confidence': 'high' if reduction >= 20 else 'medium' if reduction >= 10 else 'low',
'requirements_met': reduction >= 10,
'funding_eur': 12_500_000, # Up to €12.5M loans
'deadline': 'ongoing_2026',
'program_type': 'loan',
'category': 'European Union'
},
'circular_economy_perte': {
'eligible': reduction >= 15,
'confidence': 'high' if reduction >= 25 else 'medium' if reduction >= 15 else 'low',
'requirements_met': reduction >= 15,
'funding_eur': 10_000_000, # €150K-10M range
'deadline': 'rolling_until_2026',
'program_type': 'grant',
'category': 'Spain'
},
'planes_turismo_2026': {
'eligible': reduction >= 10,
'confidence': 'medium',
'requirements_met': reduction >= 10,
'funding_eur': 500_000, # Variable by region
'deadline': '2026-12-31',
'program_type': 'grant',
'category': 'Spain',
'sector_specific': 'tourism'
},
'un_sdg_certified': {
'eligible': reduction >= 50,
@@ -779,7 +800,8 @@ class SustainabilityService:
'requirements_met': reduction >= 50,
'funding_eur': 0, # Certification, not funding
'deadline': 'ongoing',
'program_type': 'certification'
'program_type': 'certification',
'category': 'International'
}
}

View File

@@ -189,30 +189,46 @@ async def generate_orchestration_for_tenant(
runs_created = 0
steps_created = 0
# Special case: Create at least 1 recent completed run for "today" (for dashboard visibility)
# This ensures the dashboard "Listo Para Planificar Tu Día" shows data
today_run_created = False
for i in range(total_runs):
# Determine temporal distribution
rand_temporal = random.random()
cumulative = 0
temporal_category = None
for category, details in orch_config["temporal_distribution"].items():
cumulative += details["percentage"]
if rand_temporal <= cumulative:
temporal_category = details
break
if not temporal_category:
# For the first run, create it for today with completed status
if i == 0 and not today_run_created:
temporal_category = orch_config["temporal_distribution"]["completed"]
# Use current time instead of BASE_REFERENCE_DATE
now = datetime.now(timezone.utc)
# Set offset to create run that started yesterday and completed today
offset_days = 0 # Today
run_date = now.date()
today_run_created = True
# Force status to completed for dashboard visibility
status = "completed"
else:
# Determine temporal distribution
rand_temporal = random.random()
cumulative = 0
temporal_category = None
# Calculate run date
offset_days = random.randint(
temporal_category["offset_days_min"],
temporal_category["offset_days_max"]
)
run_date = calculate_date_from_offset(offset_days)
for category, details in orch_config["temporal_distribution"].items():
cumulative += details["percentage"]
if rand_temporal <= cumulative:
temporal_category = details
break
# Select status
status = random.choice(temporal_category["statuses"])
if not temporal_category:
temporal_category = orch_config["temporal_distribution"]["completed"]
# Calculate run date
offset_days = random.randint(
temporal_category["offset_days_min"],
temporal_category["offset_days_max"]
)
run_date = calculate_date_from_offset(offset_days)
# Select status
status = random.choice(temporal_category["statuses"])
# Select run type
run_type_choice = weighted_choice(orch_config["run_types"])
@@ -232,19 +248,26 @@ async def generate_orchestration_for_tenant(
run_number = generate_run_number(tenant_id, i + 1, run_type)
# Calculate timing based on status
started_at = calculate_datetime_from_offset(offset_days - 1)
completed_at = None
duration_seconds = None
# For today's run (i==0), use current datetime instead of BASE_REFERENCE_DATE
if i == 0 and today_run_created:
now = datetime.now(timezone.utc)
started_at = now - timedelta(hours=2) # Started 2 hours ago
completed_at = now - timedelta(minutes=30) # Completed 30 minutes ago
duration_seconds = int((completed_at - started_at).total_seconds())
else:
started_at = calculate_datetime_from_offset(offset_days - 1)
completed_at = None
duration_seconds = None
if status in ["completed", "partial_success"]:
completed_at = calculate_datetime_from_offset(offset_days)
duration_seconds = int((completed_at - started_at).total_seconds())
elif status == "failed":
completed_at = calculate_datetime_from_offset(offset_days - 0.5)
duration_seconds = int((completed_at - started_at).total_seconds())
elif status == "cancelled":
completed_at = calculate_datetime_from_offset(offset_days - 0.2)
duration_seconds = int((completed_at - started_at).total_seconds())
if status in ["completed", "partial_success"]:
completed_at = calculate_datetime_from_offset(offset_days)
duration_seconds = int((completed_at - started_at).total_seconds())
elif status == "failed":
completed_at = calculate_datetime_from_offset(offset_days - 0.5)
duration_seconds = int((completed_at - started_at).total_seconds())
elif status == "cancelled":
completed_at = calculate_datetime_from_offset(offset_days - 0.2)
duration_seconds = int((completed_at - started_at).total_seconds())
# Generate step timing
forecasting_started_at = started_at