Skip to content

Commit 4337ba1

Browse files
authored
refactor(operator-trend): collapse refresh-recovery hotspot selectors onto a parametrized base (T3-2 phase 7b) (#92)
Collapse the 3 reset-reentry refresh-recovery hotspot selectors (rebuild / restore / rerestore) in operator_resolution_trend.py onto one `_refresh_hotspots_base` + `_RefreshHotspotsSpec` + 3 specs. They were exact structural clones differing only in the per-tier score/status/path keys and the confirmation / clearance status sets. Proven byte-identical by an exhaustive branch differential (real vs base+spec over a 9-class grouping/filter/sort/cap corpus across both modes per tier); full suite is the integration backstop (no composer golden covers this file). Net -114 lines. pytest 2539 passed / 2 skipped; mypy clean; ruff clean.
1 parent 4dfe9e2 commit 4337ba1

1 file changed

Lines changed: 76 additions & 190 deletions

File tree

src/operator_resolution_trend.py

Lines changed: 76 additions & 190 deletions
Original file line numberDiff line numberDiff line change
@@ -8831,9 +8831,27 @@ def _apply_reset_reentry_rebuild_refresh_reentry_control(
88318831
}
88328832

88338833

8834-
def _closure_forecast_reset_reentry_rebuild_refresh_hotspots(
8834+
class _RefreshHotspotsSpec(NamedTuple):
8835+
"""Tier-specific literals for the reset-reentry refresh-recovery hotspot selector.
8836+
8837+
The rebuild / restore / rerestore refresh hotspot selectors share one
8838+
group-by-class / max-abs-score / status-filter / sort algorithm and differ
8839+
only in the per-tier score, status, and path keys and the confirmation /
8840+
clearance status sets. Proven byte-identical by an exhaustive branch
8841+
differential.
8842+
"""
8843+
8844+
score_key: str
8845+
status_key: str
8846+
path_key: str
8847+
confirmation_statuses: frozenset[str]
8848+
clearance_statuses: frozenset[str]
8849+
8850+
8851+
def _refresh_hotspots_base(
88358852
resolution_targets: list[dict],
88368853
*,
8854+
spec: _RefreshHotspotsSpec,
88378855
mode: str,
88388856
) -> list[dict]:
88398857
grouped: dict[str, dict] = {}
@@ -8844,66 +8862,74 @@ def _closure_forecast_reset_reentry_rebuild_refresh_hotspots(
88448862
current = {
88458863
"scope": "class",
88468864
"label": class_key,
8847-
"closure_forecast_reset_reentry_rebuild_refresh_recovery_score": target.get(
8848-
"closure_forecast_reset_reentry_rebuild_refresh_recovery_score",
8849-
0.0,
8850-
),
8851-
"closure_forecast_reset_reentry_rebuild_refresh_recovery_status": target.get(
8852-
"closure_forecast_reset_reentry_rebuild_refresh_recovery_status",
8853-
"none",
8854-
),
8855-
"recent_reset_reentry_rebuild_refresh_path": target.get(
8856-
"recent_reset_reentry_rebuild_refresh_path",
8857-
"",
8858-
),
8865+
spec.score_key: target.get(spec.score_key, 0.0),
8866+
spec.status_key: target.get(spec.status_key, "none"),
8867+
spec.path_key: target.get(spec.path_key, ""),
88598868
}
88608869
existing = grouped.get(class_key)
8861-
if existing is None or abs(
8862-
current["closure_forecast_reset_reentry_rebuild_refresh_recovery_score"]
8863-
) > abs(existing["closure_forecast_reset_reentry_rebuild_refresh_recovery_score"]):
8870+
if existing is None or abs(current[spec.score_key]) > abs(
8871+
existing[spec.score_key]
8872+
):
88648873
grouped[class_key] = current
88658874
hotspots = list(grouped.values())
88668875
if mode == "confirmation":
88678876
hotspots = [
88688877
item
88698878
for item in hotspots
8870-
if item.get("closure_forecast_reset_reentry_rebuild_refresh_recovery_status")
8871-
in {
8872-
"recovering-confirmation-rebuild-reset",
8873-
"reentering-confirmation-rebuild",
8874-
}
8879+
if item.get(spec.status_key) in spec.confirmation_statuses
88758880
]
88768881
hotspots.sort(
8877-
key=lambda item: (
8878-
-item.get(
8879-
"closure_forecast_reset_reentry_rebuild_refresh_recovery_score",
8880-
0.0,
8881-
),
8882-
item.get("label", ""),
8883-
)
8882+
key=lambda item: (-item.get(spec.score_key, 0.0), item.get("label", ""))
88848883
)
88858884
else:
88868885
hotspots = [
88878886
item
88888887
for item in hotspots
8889-
if item.get("closure_forecast_reset_reentry_rebuild_refresh_recovery_status")
8890-
in {
8891-
"recovering-clearance-rebuild-reset",
8892-
"reentering-clearance-rebuild",
8893-
}
8888+
if item.get(spec.status_key) in spec.clearance_statuses
88948889
]
88958890
hotspots.sort(
8896-
key=lambda item: (
8897-
item.get(
8898-
"closure_forecast_reset_reentry_rebuild_refresh_recovery_score",
8899-
0.0,
8900-
),
8901-
item.get("label", ""),
8902-
)
8891+
key=lambda item: (item.get(spec.score_key, 0.0), item.get("label", ""))
89038892
)
89048893
return hotspots[:5]
89058894

89068895

8896+
_REBUILD_REFRESH_HOTSPOTS_SPEC = _RefreshHotspotsSpec(
8897+
score_key='closure_forecast_reset_reentry_rebuild_refresh_recovery_score',
8898+
status_key='closure_forecast_reset_reentry_rebuild_refresh_recovery_status',
8899+
path_key='recent_reset_reentry_rebuild_refresh_path',
8900+
confirmation_statuses=frozenset({'recovering-confirmation-rebuild-reset', 'reentering-confirmation-rebuild'}),
8901+
clearance_statuses=frozenset({'recovering-clearance-rebuild-reset', 'reentering-clearance-rebuild'}),
8902+
)
8903+
8904+
_RESTORE_REFRESH_HOTSPOTS_SPEC = _RefreshHotspotsSpec(
8905+
score_key='closure_forecast_reset_reentry_rebuild_reentry_restore_refresh_recovery_score',
8906+
status_key='closure_forecast_reset_reentry_rebuild_reentry_restore_refresh_recovery_status',
8907+
path_key='recent_reset_reentry_rebuild_reentry_restore_refresh_path',
8908+
confirmation_statuses=frozenset({'recovering-confirmation-rebuild-reentry-restore-reset', 'rerestoring-confirmation-rebuild-reentry'}),
8909+
clearance_statuses=frozenset({'recovering-clearance-rebuild-reentry-restore-reset', 'rerestoring-clearance-rebuild-reentry'}),
8910+
)
8911+
8912+
_RERESTORE_REFRESH_HOTSPOTS_SPEC = _RefreshHotspotsSpec(
8913+
score_key='closure_forecast_reset_reentry_rebuild_reentry_restore_rerestore_refresh_recovery_score',
8914+
status_key='closure_forecast_reset_reentry_rebuild_reentry_restore_rerestore_refresh_recovery_status',
8915+
path_key='recent_reset_reentry_rebuild_reentry_restore_rerestore_refresh_path',
8916+
confirmation_statuses=frozenset({'recovering-confirmation-rebuild-reentry-rerestore-reset', 'rererestoring-confirmation-rebuild-reentry'}),
8917+
clearance_statuses=frozenset({'recovering-clearance-rebuild-reentry-rerestore-reset', 'rererestoring-clearance-rebuild-reentry'}),
8918+
)
8919+
8920+
8921+
def _closure_forecast_reset_reentry_rebuild_refresh_hotspots(
8922+
resolution_targets: list[dict],
8923+
*,
8924+
mode: str,
8925+
) -> list[dict]:
8926+
return _refresh_hotspots_base(
8927+
resolution_targets,
8928+
spec=_REBUILD_REFRESH_HOTSPOTS_SPEC,
8929+
mode=mode,
8930+
)
8931+
8932+
89078933
def _closure_forecast_reset_reentry_rebuild_refresh_recovery_summary(
89088934
primary_target: dict,
89098935
recovering_confirmation_hotspots: list[dict],
@@ -13437,80 +13463,11 @@ def _closure_forecast_reset_reentry_rebuild_reentry_restore_refresh_hotspots(
1343713463
*,
1343813464
mode: str,
1343913465
) -> list[dict]:
13440-
grouped: dict[str, dict] = {}
13441-
for target in resolution_targets:
13442-
class_key = _target_class_key(target)
13443-
if not class_key:
13444-
continue
13445-
current = {
13446-
"scope": "class",
13447-
"label": class_key,
13448-
"closure_forecast_reset_reentry_rebuild_reentry_restore_refresh_recovery_score": target.get(
13449-
"closure_forecast_reset_reentry_rebuild_reentry_restore_refresh_recovery_score",
13450-
0.0,
13451-
),
13452-
"closure_forecast_reset_reentry_rebuild_reentry_restore_refresh_recovery_status": target.get(
13453-
"closure_forecast_reset_reentry_rebuild_reentry_restore_refresh_recovery_status",
13454-
"none",
13455-
),
13456-
"recent_reset_reentry_rebuild_reentry_restore_refresh_path": target.get(
13457-
"recent_reset_reentry_rebuild_reentry_restore_refresh_path",
13458-
"",
13459-
),
13460-
}
13461-
existing = grouped.get(class_key)
13462-
if existing is None or abs(
13463-
current["closure_forecast_reset_reentry_rebuild_reentry_restore_refresh_recovery_score"]
13464-
) > abs(
13465-
existing[
13466-
"closure_forecast_reset_reentry_rebuild_reentry_restore_refresh_recovery_score"
13467-
]
13468-
):
13469-
grouped[class_key] = current
13470-
hotspots = list(grouped.values())
13471-
if mode == "confirmation":
13472-
hotspots = [
13473-
item
13474-
for item in hotspots
13475-
if item.get(
13476-
"closure_forecast_reset_reentry_rebuild_reentry_restore_refresh_recovery_status"
13477-
)
13478-
in {
13479-
"recovering-confirmation-rebuild-reentry-restore-reset",
13480-
"rerestoring-confirmation-rebuild-reentry",
13481-
}
13482-
]
13483-
hotspots.sort(
13484-
key=lambda item: (
13485-
-item.get(
13486-
"closure_forecast_reset_reentry_rebuild_reentry_restore_refresh_recovery_score",
13487-
0.0,
13488-
),
13489-
item.get("label", ""),
13490-
)
13491-
)
13492-
else:
13493-
hotspots = [
13494-
item
13495-
for item in hotspots
13496-
if item.get(
13497-
"closure_forecast_reset_reentry_rebuild_reentry_restore_refresh_recovery_status"
13498-
)
13499-
in {
13500-
"recovering-clearance-rebuild-reentry-restore-reset",
13501-
"rerestoring-clearance-rebuild-reentry",
13502-
}
13503-
]
13504-
hotspots.sort(
13505-
key=lambda item: (
13506-
item.get(
13507-
"closure_forecast_reset_reentry_rebuild_reentry_restore_refresh_recovery_score",
13508-
0.0,
13509-
),
13510-
item.get("label", ""),
13511-
)
13512-
)
13513-
return hotspots[:5]
13466+
return _refresh_hotspots_base(
13467+
resolution_targets,
13468+
spec=_RESTORE_REFRESH_HOTSPOTS_SPEC,
13469+
mode=mode,
13470+
)
1351413471

1351513472

1351613473
def _closure_forecast_reset_reentry_rebuild_reentry_restore_refresh_recovery_summary(
@@ -16403,82 +16360,11 @@ def _closure_forecast_reset_reentry_rebuild_reentry_restore_rerestore_refresh_ho
1640316360
*,
1640416361
mode: str,
1640516362
) -> list[dict]:
16406-
grouped: dict[str, dict] = {}
16407-
for target in resolution_targets:
16408-
class_key = _target_class_key(target)
16409-
if not class_key:
16410-
continue
16411-
current = {
16412-
"scope": "class",
16413-
"label": class_key,
16414-
"closure_forecast_reset_reentry_rebuild_reentry_restore_rerestore_refresh_recovery_score": target.get(
16415-
"closure_forecast_reset_reentry_rebuild_reentry_restore_rerestore_refresh_recovery_score",
16416-
0.0,
16417-
),
16418-
"closure_forecast_reset_reentry_rebuild_reentry_restore_rerestore_refresh_recovery_status": target.get(
16419-
"closure_forecast_reset_reentry_rebuild_reentry_restore_rerestore_refresh_recovery_status",
16420-
"none",
16421-
),
16422-
"recent_reset_reentry_rebuild_reentry_restore_rerestore_refresh_path": target.get(
16423-
"recent_reset_reentry_rebuild_reentry_restore_rerestore_refresh_path",
16424-
"",
16425-
),
16426-
}
16427-
existing = grouped.get(class_key)
16428-
if existing is None or abs(
16429-
current[
16430-
"closure_forecast_reset_reentry_rebuild_reentry_restore_rerestore_refresh_recovery_score"
16431-
]
16432-
) > abs(
16433-
existing[
16434-
"closure_forecast_reset_reentry_rebuild_reentry_restore_rerestore_refresh_recovery_score"
16435-
]
16436-
):
16437-
grouped[class_key] = current
16438-
hotspots = list(grouped.values())
16439-
if mode == "confirmation":
16440-
hotspots = [
16441-
item
16442-
for item in hotspots
16443-
if item.get(
16444-
"closure_forecast_reset_reentry_rebuild_reentry_restore_rerestore_refresh_recovery_status"
16445-
)
16446-
in {
16447-
"recovering-confirmation-rebuild-reentry-rerestore-reset",
16448-
"rererestoring-confirmation-rebuild-reentry",
16449-
}
16450-
]
16451-
hotspots.sort(
16452-
key=lambda item: (
16453-
-item.get(
16454-
"closure_forecast_reset_reentry_rebuild_reentry_restore_rerestore_refresh_recovery_score",
16455-
0.0,
16456-
),
16457-
item.get("label", ""),
16458-
)
16459-
)
16460-
else:
16461-
hotspots = [
16462-
item
16463-
for item in hotspots
16464-
if item.get(
16465-
"closure_forecast_reset_reentry_rebuild_reentry_restore_rerestore_refresh_recovery_status"
16466-
)
16467-
in {
16468-
"recovering-clearance-rebuild-reentry-rerestore-reset",
16469-
"rererestoring-clearance-rebuild-reentry",
16470-
}
16471-
]
16472-
hotspots.sort(
16473-
key=lambda item: (
16474-
item.get(
16475-
"closure_forecast_reset_reentry_rebuild_reentry_restore_rerestore_refresh_recovery_score",
16476-
0.0,
16477-
),
16478-
item.get("label", ""),
16479-
)
16480-
)
16481-
return hotspots[:5]
16363+
return _refresh_hotspots_base(
16364+
resolution_targets,
16365+
spec=_RERESTORE_REFRESH_HOTSPOTS_SPEC,
16366+
mode=mode,
16367+
)
1648216368

1648316369

1648416370
def _closure_forecast_reset_reentry_rebuild_reentry_restore_rerestore_refresh_recovery_summary(

0 commit comments

Comments
 (0)