fix(summarizer): ignore future-dated rows; require a score floor for the fallback
Two leaks let low-value items reach the operator brief: - get_recent_news() only bounded the window from below, so event listings dated days ahead (wiseye.org, +3d/+6d) were re-fetched, re-graded and re-billed every interval for a week. The window is now (now - N, now]; NULL timestamps stay excluded as before. - select_graded() returned ordered[:fallback_top] with no floor, so a 15/100 event listing entered the brief as 'low'. New SUMMARY_FALLBACK_MIN_SCORE (default 40, clamped 0-100) filters the fallback set; when nothing clears it the reduce phase gets empty DATA and writes the empty-brief response. The fallback WARNING now logs the floor. Docs: .env.example and docs/news.md document the new knob and window.
This commit is contained in:
parent
2c41737d42
commit
57c0444a69
7 changed files with 311 additions and 23 deletions
|
|
@ -210,13 +210,20 @@ def parse_map_scores(
|
|||
|
||||
|
||||
def select_graded(
|
||||
blocks: list[dict], *, min_score: int, top_n: int, fallback_top: int
|
||||
blocks: list[dict],
|
||||
*,
|
||||
min_score: int,
|
||||
top_n: int,
|
||||
fallback_top: int,
|
||||
fallback_min_score: int = 0,
|
||||
) -> tuple[list[dict], bool]:
|
||||
"""Rank blocks best-first and return the ones the reduce phase should see.
|
||||
|
||||
Keeps ``score >= min_score`` capped at ``top_n`` (stable on ties: original
|
||||
order). When nothing clears the bar, returns the top ``fallback_top`` blocks
|
||||
and True; ``fallback_top == 0`` yields an empty selection.
|
||||
order). When nothing clears the bar, returns up to ``fallback_top`` blocks
|
||||
that also clear ``fallback_min_score`` and True; ``fallback_top == 0``, a
|
||||
floor that excludes every block, or no blocks at all yield an empty
|
||||
selection and False.
|
||||
"""
|
||||
ordered = sorted(blocks, key=lambda b: -int(b.get("score") or 0))
|
||||
limit = max(0, int(top_n))
|
||||
|
|
@ -226,7 +233,11 @@ def select_graded(
|
|||
fallback_limit = max(0, int(fallback_top))
|
||||
if fallback_limit <= 0:
|
||||
return [], False
|
||||
return ordered[:fallback_limit], bool(ordered)
|
||||
floor = int(fallback_min_score)
|
||||
floor_clearing = [b for b in ordered if int(b.get("score") or 0) >= floor]
|
||||
if not floor_clearing:
|
||||
return [], False
|
||||
return floor_clearing[:fallback_limit], True
|
||||
|
||||
|
||||
def join_blocks(blocks: list[dict]) -> str:
|
||||
|
|
|
|||
Loading…
Reference in a new issue