demo seed change 3
This commit is contained in:
@@ -23,7 +23,7 @@ from app.models.production import (
|
||||
EquipmentStatus, EquipmentType
|
||||
)
|
||||
from shared.utils.demo_dates import (
|
||||
adjust_date_for_demo, resolve_time_marker, calculate_edge_case_times
|
||||
adjust_date_for_demo, resolve_time_marker
|
||||
)
|
||||
|
||||
from app.core.config import settings
|
||||
@@ -625,142 +625,17 @@ async def clone_demo_data(
|
||||
db.add(new_capacity)
|
||||
stats["production_capacity"] += 1
|
||||
|
||||
# Add deterministic edge case batches
|
||||
edge_times = calculate_edge_case_times(session_time)
|
||||
|
||||
# Get a sample product_id from existing batches for edge cases
|
||||
sample_product_id = None
|
||||
if seed_data.get('batches'):
|
||||
sample_product_id = seed_data['batches'][0].get('product_id')
|
||||
|
||||
if sample_product_id:
|
||||
# Edge Case 1: Overdue Batch (should have started 2 hours ago)
|
||||
overdue_batch = ProductionBatch(
|
||||
id=str(uuid.uuid4()),
|
||||
tenant_id=virtual_uuid,
|
||||
batch_number=f"{session_id[:8]}-EDGE-OVERDUE",
|
||||
product_id=sample_product_id,
|
||||
product_name="Pan Integral (Edge Case)",
|
||||
planned_start_time=edge_times["overdue_batch_planned_start"],
|
||||
planned_end_time=edge_times["overdue_batch_planned_start"] + timedelta(hours=3),
|
||||
planned_quantity=50.0,
|
||||
planned_duration_minutes=180,
|
||||
actual_start_time=None,
|
||||
actual_end_time=None,
|
||||
actual_quantity=None,
|
||||
status=ProductionStatus.PENDING,
|
||||
priority=ProductionPriority.URGENT,
|
||||
current_process_stage=None,
|
||||
production_notes="⚠️ EDGE CASE: Should have started 2 hours ago - triggers yellow alert for delayed production",
|
||||
created_at=session_time,
|
||||
updated_at=session_time
|
||||
)
|
||||
db.add(overdue_batch)
|
||||
stats["batches"] += 1
|
||||
|
||||
# Edge Case 2: In-Progress Batch (started 1h45m ago)
|
||||
in_progress_batch = ProductionBatch(
|
||||
id=str(uuid.uuid4()),
|
||||
tenant_id=virtual_uuid,
|
||||
batch_number=f"{session_id[:8]}-EDGE-INPROGRESS",
|
||||
product_id=sample_product_id,
|
||||
product_name="Croissant de Mantequilla (Edge Case)",
|
||||
planned_start_time=edge_times["in_progress_batch_actual_start"],
|
||||
planned_end_time=edge_times["upcoming_batch_planned_start"],
|
||||
planned_quantity=100.0,
|
||||
planned_duration_minutes=195,
|
||||
actual_start_time=edge_times["in_progress_batch_actual_start"],
|
||||
actual_end_time=None,
|
||||
actual_quantity=None,
|
||||
status=ProductionStatus.IN_PROGRESS,
|
||||
priority=ProductionPriority.HIGH,
|
||||
current_process_stage=ProcessStage.BAKING,
|
||||
production_notes="⚠️ EDGE CASE: Currently in progress - visible in active production dashboard",
|
||||
created_at=session_time,
|
||||
updated_at=session_time
|
||||
)
|
||||
db.add(in_progress_batch)
|
||||
stats["batches"] += 1
|
||||
|
||||
# Edge Case 3: Upcoming Batch (starts in 1.5 hours)
|
||||
upcoming_batch = ProductionBatch(
|
||||
id=str(uuid.uuid4()),
|
||||
tenant_id=virtual_uuid,
|
||||
batch_number=f"{session_id[:8]}-EDGE-UPCOMING",
|
||||
product_id=sample_product_id,
|
||||
product_name="Baguette Tradicional (Edge Case)",
|
||||
planned_start_time=edge_times["upcoming_batch_planned_start"],
|
||||
planned_end_time=edge_times["upcoming_batch_planned_start"] + timedelta(hours=2),
|
||||
planned_quantity=75.0,
|
||||
planned_duration_minutes=120,
|
||||
actual_start_time=None,
|
||||
actual_end_time=None,
|
||||
actual_quantity=None,
|
||||
status=ProductionStatus.PENDING,
|
||||
priority=ProductionPriority.MEDIUM,
|
||||
current_process_stage=None,
|
||||
production_notes="⚠️ EDGE CASE: Starting in 1.5 hours - visible in upcoming production schedule",
|
||||
created_at=session_time,
|
||||
updated_at=session_time
|
||||
)
|
||||
db.add(upcoming_batch)
|
||||
stats["batches"] += 1
|
||||
|
||||
# Edge Case 4: Evening Batch (starts at 17:00 today)
|
||||
evening_batch = ProductionBatch(
|
||||
id=str(uuid.uuid4()),
|
||||
tenant_id=virtual_uuid,
|
||||
batch_number=f"{session_id[:8]}-EDGE-EVENING",
|
||||
product_id=sample_product_id,
|
||||
product_name="Pan de Molde (Edge Case)",
|
||||
planned_start_time=edge_times["evening_batch_planned_start"],
|
||||
planned_end_time=edge_times["evening_batch_planned_start"] + timedelta(hours=2, minutes=30),
|
||||
planned_quantity=60.0,
|
||||
planned_duration_minutes=150,
|
||||
actual_start_time=None,
|
||||
actual_end_time=None,
|
||||
actual_quantity=None,
|
||||
status=ProductionStatus.PENDING,
|
||||
priority=ProductionPriority.MEDIUM,
|
||||
current_process_stage=None,
|
||||
production_notes="⚠️ EDGE CASE: Evening shift production - scheduled for 17:00",
|
||||
created_at=session_time,
|
||||
updated_at=session_time
|
||||
)
|
||||
db.add(evening_batch)
|
||||
stats["batches"] += 1
|
||||
|
||||
# Edge Case 5: Tomorrow Morning Batch (starts at 05:00 tomorrow)
|
||||
tomorrow_batch = ProductionBatch(
|
||||
id=str(uuid.uuid4()),
|
||||
tenant_id=virtual_uuid,
|
||||
batch_number=f"{session_id[:8]}-EDGE-TOMORROW",
|
||||
product_id=sample_product_id,
|
||||
product_name="Bollería Variada (Edge Case)",
|
||||
planned_start_time=edge_times["tomorrow_morning_planned_start"],
|
||||
planned_end_time=edge_times["tomorrow_morning_planned_start"] + timedelta(hours=4),
|
||||
planned_quantity=120.0,
|
||||
planned_duration_minutes=240,
|
||||
actual_start_time=None,
|
||||
actual_end_time=None,
|
||||
actual_quantity=None,
|
||||
status=ProductionStatus.PENDING,
|
||||
priority=ProductionPriority.MEDIUM,
|
||||
current_process_stage=None,
|
||||
production_notes="⚠️ EDGE CASE: Tomorrow morning production - scheduled for 05:00",
|
||||
created_at=session_time,
|
||||
updated_at=session_time
|
||||
)
|
||||
db.add(tomorrow_batch)
|
||||
stats["batches"] += 1
|
||||
|
||||
logger.info(
|
||||
"Added deterministic edge case batches",
|
||||
edge_cases_added=5,
|
||||
overdue=edge_times["overdue_batch_planned_start"].isoformat(),
|
||||
in_progress=edge_times["in_progress_batch_actual_start"].isoformat(),
|
||||
upcoming=edge_times["upcoming_batch_planned_start"].isoformat()
|
||||
)
|
||||
# Note: Edge cases are now handled exclusively through JSON seed data
|
||||
# The seed data files already contain comprehensive edge cases including:
|
||||
# - Overdue batches (should have started 2 hours ago)
|
||||
# - In-progress batches (currently being processed)
|
||||
# - Upcoming batches (scheduled for later today/tomorrow)
|
||||
# This ensures standardization and single source of truth for demo data
|
||||
|
||||
logger.info(
|
||||
"Edge cases handled by JSON seed data - no manual creation needed",
|
||||
seed_data_edge_cases="overdue_batches, in_progress_batches, upcoming_batches"
|
||||
)
|
||||
|
||||
# Commit cloned data
|
||||
await db.commit()
|
||||
|
||||
Reference in New Issue
Block a user