Files

67 lines
2.2 KiB
Python
Raw Permalink Normal View History

"""Change C1 (Gitea issue 1): "over target" is decided by the VISUAL ticket hours against the work-order target, not
by the station timer. A packet with no ticket hours is not over target. No database: a stub report feeds the PM
hours tables."""
from __future__ import annotations
from typing import Any
from packetstation.domain import pm
class StubReport:
def __init__(self, hours: dict[int, dict[str, float]]) -> None:
self._h = hours
self.cards = [
{"id": pid, "status": "station", "dept": {"code": "WP"}, "unit": {"number": f"L1-00{pid}"}, "op": "10"}
for pid in hours
]
def hours(self) -> dict[int, dict[str, float]]:
return self._h
def dept_short(self, code: str) -> str:
return code
def h(timer: float, ticket: float, target: float) -> dict[str, float]:
return {"timer_h": timer, "ticket_h": ticket, "target_h": target}
WORLD = {
1: h(9.0, 0.0, 4.0), # timer over, no tickets: not over
2: h(1.0, 5.5, 4.0), # tickets over, timer under: over
3: h(9.0, 3.0, 4.0), # timer over, tickets under: not over
4: h(0.0, 2.0, 0.0), # no target: never over
}
def tables() -> dict[str, dict[str, Any]]:
rep: Any = StubReport(WORLD)
return {t["key"]: t for t in pm.hours_tables(rep)}
def test_is_over_reads_the_tickets() -> None:
assert [pid for pid, x in WORLD.items() if pm.is_over(x)] == [2]
def test_over_table_lists_ticket_overs_only() -> None:
over = tables()["hours_over"]
assert over["head"][-1] == "Over by (tickets)"
assert [r["pid"] for r in over["rows"]] == [2]
assert over["rows"][0]["cells"][-1] == "+1.5 h"
def test_group_counts_and_heads() -> None:
dept = tables()["hours_dept"]
assert dept["head"][-3:] == ["Ticket variance h", "Ticket h / target", "Over target (tickets)"]
cells = dept["rows"][0]["cells"]
assert cells[-1] == "1" # one packet over on its tickets
# ticket 8.5 against target 12: under, so the group is not flagged and the ratio is the tickets'
assert cells[-2] == "71%" and not dept["rows"][0]["flag"]
def test_over_target_count() -> None:
rep: Any = StubReport(WORLD)
assert pm.over_target_count(rep) == 1