fix(rectification): narrate the credible range and stop scoring periods by length (BUG-569–570)
Choice copy was comparing the search window, so every answer said the range had not changed. Block-scan summed raw scores, so longer afternoon windows won before any evidence difference. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -908,6 +908,46 @@ class RectificationV5ServicesTest(unittest.TestCase):
|
||||
self.assertEqual(result["candidate_count"], 144)
|
||||
self.assertLessEqual(elapsed, 15, f"block_scan took {elapsed:.1f}s")
|
||||
|
||||
def test_block_scan_equal_scores_share_evenly_and_length_does_not_win(self):
|
||||
from scripts.rectification.api_service import block_scan
|
||||
|
||||
def grid(score_for):
|
||||
return [
|
||||
{"time": f"{hour:02d}:{minute:02d}", "score": score_for(hour), "supporting_event_ids": []}
|
||||
for hour in range(24)
|
||||
for minute in range(0, 60, 10)
|
||||
]
|
||||
|
||||
equal_rows = grid(lambda _hour: 12.0)
|
||||
morning_rows = grid(lambda hour: 20.0 if 4 <= hour <= 7 else 10.0)
|
||||
dummy = {
|
||||
"result_id": "00000000-0000-4000-8000-000000000099",
|
||||
"algorithm_version": "test",
|
||||
"calculation_spec": {},
|
||||
"calculation_spec_hash": "abc",
|
||||
"decision_receipt": {},
|
||||
}
|
||||
request_body = {
|
||||
"birth_date": "1998-03-15",
|
||||
"start_time": "00:00",
|
||||
"end_time": "23:59",
|
||||
"lat": 39.9042,
|
||||
"lon": 116.4074,
|
||||
"tz": 8.0,
|
||||
"minute_step": 10,
|
||||
"events": [],
|
||||
}
|
||||
with patch("scripts.rectification.api_service.score_candidates", return_value={**dummy, "candidate_scores": equal_rows}):
|
||||
equal = block_scan(request_body)
|
||||
self.assertEqual([row["relative_support"] for row in equal["blocks"]], [20.0, 20.0, 20.0, 20.0, 20.0])
|
||||
self.assertEqual([row["candidate_count"] for row in equal["blocks"]], [24, 24, 36, 30, 30])
|
||||
with patch("scripts.rectification.api_service.score_candidates", return_value={**dummy, "candidate_scores": morning_rows}):
|
||||
morning = block_scan(request_body)
|
||||
shares = {row["period"]: row["relative_support"] for row in morning["blocks"]}
|
||||
self.assertEqual(max(shares, key=shares.get), "early_morning")
|
||||
self.assertGreater(shares["early_morning"], shares["afternoon"])
|
||||
self.assertEqual(shares["afternoon"], 0.0)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
||||
Reference in New Issue
Block a user