File size: 1,066 Bytes
1f5f31a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
"""
Default relevance windows per category (ADR-0015). These are starting points,
not final — day counts picked before any real classified history existed, to
be revisited once there's enough data to see how fast each category actually
goes stale.

An opportunity with an explicit deadline in the source text uses that deadline
instead of its category's default window — see classify.py.
"""

from datetime import datetime, timedelta, timezone, date

CATEGORY_WINDOW_DAYS = {
    "weather":         7,
    "infrastructure":  14,
    "security":        14,
    "policy":          90,
    "funding":         30,
    "other":           21,
}

DEFAULT_WINDOW_DAYS = 21


def compute_expiry(category: str | None, scraped_at: datetime, deadline: date | None) -> datetime:
    """The point at which an item stops being shown to users."""
    if deadline is not None:
        return datetime.combine(deadline, datetime.min.time(), tzinfo=timezone.utc)
    days = CATEGORY_WINDOW_DAYS.get(category or "", DEFAULT_WINDOW_DAYS)
    return scraped_at + timedelta(days=days)