30 lines
1.0 KiB
Python
30 lines
1.0 KiB
Python
"""Compose historical ERP reads with pure shift-production aggregation."""
|
|
|
|
from datetime import datetime
|
|
from typing import Protocol
|
|
|
|
from production_analytics.calculations.shift_production import (
|
|
ShiftProductionSummary,
|
|
aggregate_shift_production,
|
|
validate_shift_window,
|
|
)
|
|
from production_analytics.erp import ProductionConfirmation
|
|
|
|
|
|
class ProductionConfirmationReader(Protocol):
|
|
def get_confirmations(
|
|
self, *, workplace: str, start: datetime, end: datetime
|
|
) -> list[ProductionConfirmation]: ...
|
|
|
|
|
|
class ShiftProductionService:
|
|
def __init__(self, gateway: ProductionConfirmationReader) -> None:
|
|
self.gateway = gateway
|
|
|
|
def summarize(
|
|
self, *, workplace: str, start: datetime, end: datetime
|
|
) -> ShiftProductionSummary:
|
|
workplace = validate_shift_window(workplace=workplace, start=start, end=end)
|
|
confirmations = self.gateway.get_confirmations(workplace=workplace, start=start, end=end)
|
|
return aggregate_shift_production(confirmations, workplace=workplace, start=start, end=end)
|