Add unified shift reporting

This commit is contained in:
admin committed 2026-10-07 21:58:18 +02:00
1 parent 1b060377aa
commit 41a5ae7a63
30 files changed
+3751 -9

No files matched your search

@@ -0,0 +1,54 @@
"""Sequential composition of validated services; mandatory failures propagate."""
from collections.abc import Mapping
from datetime import datetime
from types import MappingProxyType
from production_analytics.calculations.shift_report import SHIFT_TIMEZONE, ShiftReport
from production_analytics.calculations.shift_speed import validate_speed_window
from production_analytics.service.shift_downtime import ShiftDowntimeService
from production_analytics.service.shift_material import (
ShiftChannelMaterialService,
ShiftMaterialService,
)
from production_analytics.service.shift_production import ShiftProductionService
from production_analytics.service.shift_report_config import ShiftReportMachineConfig
from production_analytics.service.shift_speed import ShiftSpeedService
class ShiftReportService:
def __init__(
self, *, machines: Mapping[str, ShiftReportMachineConfig],
production: ShiftProductionService, downtime: ShiftDowntimeService,
materials: ShiftMaterialService, channel_materials: ShiftChannelMaterialService,
speed: ShiftSpeedService,
) -> None:
self.machines = MappingProxyType(dict(machines))
self.production = production
self.downtime = downtime
self.materials = materials
self.channel_materials = channel_materials
self.speed = speed
def build(self, *, machine_name: str, start: datetime, end: datetime) -> ShiftReport:
validate_speed_window(start, end)
if not isinstance(machine_name, str) or machine_name not in self.machines:
raise ValueError("Unknown shift-report machine")
config = self.machines[machine_name]
start, end = start.astimezone(SHIFT_TIMEZONE), end.astimezone(SHIFT_TIMEZONE)
production = self.production.summarize(
workplace=config.erp_workplace, start=start, end=end,
)
downtime = self.downtime.summarize(machine_id=config.machine_id, start=start, end=end)
material_service = (
self.channel_materials if config.material.mode == "channel" else self.materials
)
materials = material_service.summarize(
machine_id=config.machine_id, calculation_ids=config.material.calculation_ids,
start=start, end=end,
)
speed = self.speed.summarize(config=config.speed, start=start, end=end)
return ShiftReport(
machine_name=machine_name, machine_id=config.machine_id, start=start, end=end,
production=production, downtime=downtime, materials=materials, speed=speed,
)