|
1 | 1 | from __future__ import annotations |
2 | 2 |
|
| 3 | +from functools import lru_cache |
| 4 | + |
3 | 5 | from src.operator_trend_apply_chain import ( |
4 | 6 | run_resolution_trend_apply_chain as _run_resolution_trend_apply_chain_helper, |
5 | 7 | ) |
@@ -5857,20 +5859,42 @@ def _apply_reacquisition_reset_refresh_recovery_and_reentry( |
5857 | 5859 | } |
5858 | 5860 |
|
5859 | 5861 |
|
5860 | | -def _closure_forecast_reset_reentry_side_from_status(status: str) -> str: |
5861 | | - if status in {"pending-confirmation-reentry", "reentered-confirmation"}: |
| 5862 | +@lru_cache(maxsize=None) |
| 5863 | +def _side_sets(confirmation_members: tuple[str, ...]) -> tuple[frozenset[str], frozenset[str]]: |
| 5864 | + return ( |
| 5865 | + frozenset(confirmation_members), |
| 5866 | + frozenset(member.replace("confirmation", "clearance") for member in confirmation_members), |
| 5867 | + ) |
| 5868 | + |
| 5869 | + |
| 5870 | +def _resolve_side(status: str, *confirmation_members: str) -> str: |
| 5871 | + # Shared side classifier for the reset/reentry/rebuild/restore status families. The |
| 5872 | + # clearance-side set is the confirmation-side set with "confirmation" swapped for |
| 5873 | + # "clearance"; confirmation membership wins, so a confirmation-only token (e.g. |
| 5874 | + # "just-rererestored") resolves to confirmation even though the swap also lands it |
| 5875 | + # in clearance. Returns "none" for anything unrecognized. |
| 5876 | + confirmation, clearance = _side_sets(confirmation_members) |
| 5877 | + if status in confirmation: |
5862 | 5878 | return "confirmation" |
5863 | | - if status in {"pending-clearance-reentry", "reentered-clearance"}: |
| 5879 | + if status in clearance: |
5864 | 5880 | return "clearance" |
5865 | 5881 | return "none" |
5866 | 5882 |
|
5867 | 5883 |
|
| 5884 | +def _closure_forecast_reset_reentry_side_from_status(status: str) -> str: |
| 5885 | + return _resolve_side( |
| 5886 | + status, |
| 5887 | + "pending-confirmation-reentry", |
| 5888 | + "reentered-confirmation", |
| 5889 | + ) |
| 5890 | + |
| 5891 | + |
5868 | 5892 | def _closure_forecast_reset_reentry_side_from_recovery_status(status: str) -> str: |
5869 | | - if status in {"recovering-confirmation-reset", "reentering-confirmation"}: |
5870 | | - return "confirmation" |
5871 | | - if status in {"recovering-clearance-reset", "reentering-clearance"}: |
5872 | | - return "clearance" |
5873 | | - return "none" |
| 5893 | + return _resolve_side( |
| 5894 | + status, |
| 5895 | + "recovering-confirmation-reset", |
| 5896 | + "reentering-confirmation", |
| 5897 | + ) |
5874 | 5898 |
|
5875 | 5899 |
|
5876 | 5900 | def _closure_forecast_reset_reentry_side_from_event(event: dict) -> str: |
@@ -6993,17 +7017,11 @@ def _apply_reset_reentry_persistence_and_churn( |
6993 | 7017 |
|
6994 | 7018 |
|
6995 | 7019 | def _closure_forecast_reset_reentry_side_from_persistence_status(status: str) -> str: |
6996 | | - if status in { |
| 7020 | + return _resolve_side( |
| 7021 | + status, |
6997 | 7022 | "holding-confirmation-reentry", |
6998 | 7023 | "sustained-confirmation-reentry", |
6999 | | - }: |
7000 | | - return "confirmation" |
7001 | | - if status in { |
7002 | | - "holding-clearance-reentry", |
7003 | | - "sustained-clearance-reentry", |
7004 | | - }: |
7005 | | - return "clearance" |
7006 | | - return "none" |
| 7024 | + ) |
7007 | 7025 |
|
7008 | 7026 |
|
7009 | 7027 | def _closure_forecast_reset_reentry_memory_side_from_event(event: dict) -> str: |
@@ -7424,25 +7442,19 @@ def _apply_reset_reentry_freshness_and_reset( |
7424 | 7442 |
|
7425 | 7443 |
|
7426 | 7444 | def _closure_forecast_reset_reentry_rebuild_side_from_status(status: str) -> str: |
7427 | | - if status in {"pending-confirmation-rebuild", "rebuilt-confirmation-reentry"}: |
7428 | | - return "confirmation" |
7429 | | - if status in {"pending-clearance-rebuild", "rebuilt-clearance-reentry"}: |
7430 | | - return "clearance" |
7431 | | - return "none" |
| 7445 | + return _resolve_side( |
| 7446 | + status, |
| 7447 | + "pending-confirmation-rebuild", |
| 7448 | + "rebuilt-confirmation-reentry", |
| 7449 | + ) |
7432 | 7450 |
|
7433 | 7451 |
|
7434 | 7452 | def _closure_forecast_reset_reentry_rebuild_side_from_recovery_status(status: str) -> str: |
7435 | | - if status in { |
| 7453 | + return _resolve_side( |
| 7454 | + status, |
7436 | 7455 | "recovering-confirmation-reentry-reset", |
7437 | 7456 | "rebuilding-confirmation-reentry", |
7438 | | - }: |
7439 | | - return "confirmation" |
7440 | | - if status in { |
7441 | | - "recovering-clearance-reentry-reset", |
7442 | | - "rebuilding-clearance-reentry", |
7443 | | - }: |
7444 | | - return "clearance" |
7445 | | - return "none" |
| 7457 | + ) |
7446 | 7458 |
|
7447 | 7459 |
|
7448 | 7460 | def _closure_forecast_reset_reentry_refresh_path_label(event: dict) -> str: |
@@ -7754,17 +7766,11 @@ def _apply_reset_reentry_refresh_recovery_and_rebuild( |
7754 | 7766 |
|
7755 | 7767 |
|
7756 | 7768 | def _closure_forecast_reset_reentry_rebuild_side_from_persistence_status(status: str) -> str: |
7757 | | - if status in { |
| 7769 | + return _resolve_side( |
| 7770 | + status, |
7758 | 7771 | "holding-confirmation-rebuild", |
7759 | 7772 | "sustained-confirmation-rebuild", |
7760 | | - }: |
7761 | | - return "confirmation" |
7762 | | - if status in { |
7763 | | - "holding-clearance-rebuild", |
7764 | | - "sustained-clearance-rebuild", |
7765 | | - }: |
7766 | | - return "clearance" |
7767 | | - return "none" |
| 7773 | + ) |
7768 | 7774 |
|
7769 | 7775 |
|
7770 | 7776 | def _closure_forecast_reset_reentry_rebuild_side_from_event(event: dict) -> str: |
@@ -8272,31 +8278,19 @@ def _apply_reset_reentry_rebuild_freshness_and_reset( |
8272 | 8278 | def _closure_forecast_reset_reentry_rebuild_side_from_refresh_recovery_status( |
8273 | 8279 | status: str, |
8274 | 8280 | ) -> str: |
8275 | | - if status in { |
| 8281 | + return _resolve_side( |
| 8282 | + status, |
8276 | 8283 | "recovering-confirmation-rebuild-reset", |
8277 | 8284 | "reentering-confirmation-rebuild", |
8278 | | - }: |
8279 | | - return "confirmation" |
8280 | | - if status in { |
8281 | | - "recovering-clearance-rebuild-reset", |
8282 | | - "reentering-clearance-rebuild", |
8283 | | - }: |
8284 | | - return "clearance" |
8285 | | - return "none" |
| 8285 | + ) |
8286 | 8286 |
|
8287 | 8287 |
|
8288 | 8288 | def _closure_forecast_reset_reentry_rebuild_side_from_reentry_status(status: str) -> str: |
8289 | | - if status in { |
| 8289 | + return _resolve_side( |
| 8290 | + status, |
8290 | 8291 | "pending-confirmation-rebuild-reentry", |
8291 | 8292 | "reentered-confirmation-rebuild", |
8292 | | - }: |
8293 | | - return "confirmation" |
8294 | | - if status in { |
8295 | | - "pending-clearance-rebuild-reentry", |
8296 | | - "reentered-clearance-rebuild", |
8297 | | - }: |
8298 | | - return "clearance" |
8299 | | - return "none" |
| 8293 | + ) |
8300 | 8294 |
|
8301 | 8295 |
|
8302 | 8296 | def _closure_forecast_reset_reentry_rebuild_refresh_path_label(event: dict) -> str: |
@@ -9139,17 +9133,11 @@ def _apply_reset_reentry_rebuild_refresh_recovery_and_reentry( |
9139 | 9133 | def _closure_forecast_reset_reentry_rebuild_reentry_side_from_persistence_status( |
9140 | 9134 | status: str, |
9141 | 9135 | ) -> str: |
9142 | | - if status in { |
| 9136 | + return _resolve_side( |
| 9137 | + status, |
9143 | 9138 | "holding-confirmation-rebuild-reentry", |
9144 | 9139 | "sustained-confirmation-rebuild-reentry", |
9145 | | - }: |
9146 | | - return "confirmation" |
9147 | | - if status in { |
9148 | | - "holding-clearance-rebuild-reentry", |
9149 | | - "sustained-clearance-rebuild-reentry", |
9150 | | - }: |
9151 | | - return "clearance" |
9152 | | - return "none" |
| 9140 | + ) |
9153 | 9141 |
|
9154 | 9142 |
|
9155 | 9143 | def _closure_forecast_reset_reentry_rebuild_reentry_side_from_event(event: dict) -> str: |
@@ -10934,49 +10922,31 @@ def _apply_reset_reentry_rebuild_reentry_freshness_and_reset( |
10934 | 10922 | def _closure_forecast_reset_reentry_rebuild_reentry_side_from_refresh_recovery_status( |
10935 | 10923 | status: str, |
10936 | 10924 | ) -> str: |
10937 | | - if status in { |
| 10925 | + return _resolve_side( |
| 10926 | + status, |
10938 | 10927 | "recovering-confirmation-rebuild-reentry-reset", |
10939 | 10928 | "restoring-confirmation-rebuild-reentry", |
10940 | | - }: |
10941 | | - return "confirmation" |
10942 | | - if status in { |
10943 | | - "recovering-clearance-rebuild-reentry-reset", |
10944 | | - "restoring-clearance-rebuild-reentry", |
10945 | | - }: |
10946 | | - return "clearance" |
10947 | | - return "none" |
| 10929 | + ) |
10948 | 10930 |
|
10949 | 10931 |
|
10950 | 10932 | def _closure_forecast_reset_reentry_rebuild_reentry_side_from_restore_status( |
10951 | 10933 | status: str, |
10952 | 10934 | ) -> str: |
10953 | | - if status in { |
| 10935 | + return _resolve_side( |
| 10936 | + status, |
10954 | 10937 | "pending-confirmation-rebuild-reentry-restore", |
10955 | 10938 | "restored-confirmation-rebuild-reentry", |
10956 | | - }: |
10957 | | - return "confirmation" |
10958 | | - if status in { |
10959 | | - "pending-clearance-rebuild-reentry-restore", |
10960 | | - "restored-clearance-rebuild-reentry", |
10961 | | - }: |
10962 | | - return "clearance" |
10963 | | - return "none" |
| 10939 | + ) |
10964 | 10940 |
|
10965 | 10941 |
|
10966 | 10942 | def _closure_forecast_reset_reentry_rebuild_reentry_side_from_restore_persistence_status( |
10967 | 10943 | status: str, |
10968 | 10944 | ) -> str: |
10969 | | - if status in { |
| 10945 | + return _resolve_side( |
| 10946 | + status, |
10970 | 10947 | "holding-confirmation-rebuild-reentry-restore", |
10971 | 10948 | "sustained-confirmation-rebuild-reentry-restore", |
10972 | | - }: |
10973 | | - return "confirmation" |
10974 | | - if status in { |
10975 | | - "holding-clearance-rebuild-reentry-restore", |
10976 | | - "sustained-clearance-rebuild-reentry-restore", |
10977 | | - }: |
10978 | | - return "clearance" |
10979 | | - return "none" |
| 10949 | + ) |
10980 | 10950 |
|
10981 | 10951 |
|
10982 | 10952 | def _closure_forecast_reset_reentry_rebuild_reentry_refresh_path_label(event: dict) -> str: |
@@ -14039,33 +14009,21 @@ def _apply_reset_reentry_rebuild_reentry_restore_refresh_recovery_and_rerestore( |
14039 | 14009 | def _closure_forecast_reset_reentry_rebuild_reentry_restore_rerestore_side_from_status( |
14040 | 14010 | status: str, |
14041 | 14011 | ) -> str: |
14042 | | - if status in { |
| 14012 | + return _resolve_side( |
| 14013 | + status, |
14043 | 14014 | "pending-confirmation-rebuild-reentry-rerestore", |
14044 | 14015 | "rerestored-confirmation-rebuild-reentry", |
14045 | | - }: |
14046 | | - return "confirmation" |
14047 | | - if status in { |
14048 | | - "pending-clearance-rebuild-reentry-rerestore", |
14049 | | - "rerestored-clearance-rebuild-reentry", |
14050 | | - }: |
14051 | | - return "clearance" |
14052 | | - return "none" |
| 14016 | + ) |
14053 | 14017 |
|
14054 | 14018 |
|
14055 | 14019 | def _closure_forecast_reset_reentry_rebuild_reentry_restore_rerestore_side_from_persistence_status( |
14056 | 14020 | status: str, |
14057 | 14021 | ) -> str: |
14058 | | - if status in { |
| 14022 | + return _resolve_side( |
| 14023 | + status, |
14059 | 14024 | "holding-confirmation-rebuild-reentry-rerestore", |
14060 | 14025 | "sustained-confirmation-rebuild-reentry-rerestore", |
14061 | | - }: |
14062 | | - return "confirmation" |
14063 | | - if status in { |
14064 | | - "holding-clearance-rebuild-reentry-rerestore", |
14065 | | - "sustained-clearance-rebuild-reentry-rerestore", |
14066 | | - }: |
14067 | | - return "clearance" |
14068 | | - return "none" |
| 14026 | + ) |
14069 | 14027 |
|
14070 | 14028 |
|
14071 | 14029 | def _closure_forecast_reset_reentry_rebuild_reentry_restore_rerestore_side_from_event( |
@@ -16140,33 +16098,21 @@ def _apply_reset_reentry_rebuild_reentry_restore_rerestore_freshness_and_reset( |
16140 | 16098 | def _closure_forecast_reset_reentry_rebuild_reentry_restore_rererestore_side_from_status( |
16141 | 16099 | status: str, |
16142 | 16100 | ) -> str: |
16143 | | - if status in { |
| 16101 | + return _resolve_side( |
| 16102 | + status, |
16144 | 16103 | "pending-confirmation-rebuild-reentry-rererestore", |
16145 | 16104 | "rererestored-confirmation-rebuild-reentry", |
16146 | | - }: |
16147 | | - return "confirmation" |
16148 | | - if status in { |
16149 | | - "pending-clearance-rebuild-reentry-rererestore", |
16150 | | - "rererestored-clearance-rebuild-reentry", |
16151 | | - }: |
16152 | | - return "clearance" |
16153 | | - return "none" |
| 16105 | + ) |
16154 | 16106 |
|
16155 | 16107 |
|
16156 | 16108 | def _closure_forecast_reset_reentry_rebuild_reentry_restore_rerestore_side_from_refresh_recovery_status( |
16157 | 16109 | status: str, |
16158 | 16110 | ) -> str: |
16159 | | - if status in { |
| 16111 | + return _resolve_side( |
| 16112 | + status, |
16160 | 16113 | "recovering-confirmation-rebuild-reentry-rerestore-reset", |
16161 | 16114 | "rererestoring-confirmation-rebuild-reentry", |
16162 | | - }: |
16163 | | - return "confirmation" |
16164 | | - if status in { |
16165 | | - "recovering-clearance-rebuild-reentry-rerestore-reset", |
16166 | | - "rererestoring-clearance-rebuild-reentry", |
16167 | | - }: |
16168 | | - return "clearance" |
16169 | | - return "none" |
| 16115 | + ) |
16170 | 16116 |
|
16171 | 16117 |
|
16172 | 16118 | def _closure_forecast_reset_reentry_rebuild_reentry_restore_rerestore_refresh_path_label( |
@@ -17169,18 +17115,12 @@ def _apply_reset_reentry_rebuild_reentry_restore_rerestore_refresh_recovery_and_ |
17169 | 17115 | def _closure_forecast_reset_reentry_rebuild_reentry_restore_rererestore_side_from_persistence_status( |
17170 | 17116 | status: str, |
17171 | 17117 | ) -> str: |
17172 | | - if status in { |
| 17118 | + return _resolve_side( |
| 17119 | + status, |
17173 | 17120 | "just-rererestored", |
17174 | 17121 | "holding-confirmation-rebuild-reentry-rererestore", |
17175 | 17122 | "sustained-confirmation-rebuild-reentry-rererestore", |
17176 | | - }: |
17177 | | - return "confirmation" |
17178 | | - if status in { |
17179 | | - "holding-clearance-rebuild-reentry-rererestore", |
17180 | | - "sustained-clearance-rebuild-reentry-rererestore", |
17181 | | - }: |
17182 | | - return "clearance" |
17183 | | - return "none" |
| 17123 | + ) |
17184 | 17124 |
|
17185 | 17125 |
|
17186 | 17126 | def _closure_forecast_reset_reentry_rebuild_reentry_restore_rererestore_side_from_event( |
|
0 commit comments