More memories
This commit is contained in:
parent
8081a4c738
commit
9a009f0b4c
2 changed files with 12 additions and 8 deletions
|
|
@ -151,8 +151,12 @@ def _filter_by_orientation(assets: list[dict], portrait: bool) -> list[dict]:
|
||||||
return out
|
return out
|
||||||
|
|
||||||
|
|
||||||
def _on_this_day_candidates(assets: list[dict]) -> list[dict]:
|
def _on_this_day_candidates(assets: list[dict]) -> tuple[list[dict], bool]:
|
||||||
"""Photos taken on today's month-day in past years, with a ±3-day fallback."""
|
"""Photos taken on today's month-day in past years, with a ±3-day fallback.
|
||||||
|
|
||||||
|
Returns (candidates, is_exact). `is_exact` is True when same-month-day matches
|
||||||
|
exist; callers use it to weight the pool higher than the looser ±3-day fallback.
|
||||||
|
"""
|
||||||
today = datetime.now(timezone.utc).date()
|
today = datetime.now(timezone.utc).date()
|
||||||
dated = []
|
dated = []
|
||||||
for a in assets:
|
for a in assets:
|
||||||
|
|
@ -169,13 +173,13 @@ def _on_this_day_candidates(assets: list[dict]) -> list[dict]:
|
||||||
|
|
||||||
exact = [a for a, dt in dated if (dt.month, dt.day) == (today.month, today.day)]
|
exact = [a for a, dt in dated if (dt.month, dt.day) == (today.month, today.day)]
|
||||||
if exact:
|
if exact:
|
||||||
return exact
|
return exact, True
|
||||||
|
|
||||||
nearby_md = set()
|
nearby_md = set()
|
||||||
for offset in range(-3, 4):
|
for offset in range(-3, 4):
|
||||||
d = today + timedelta(days=offset)
|
d = today + timedelta(days=offset)
|
||||||
nearby_md.add((d.month, d.day))
|
nearby_md.add((d.month, d.day))
|
||||||
return [a for a, dt in dated if (dt.month, dt.day) in nearby_md]
|
return [a for a, dt in dated if (dt.month, dt.day) in nearby_md], False
|
||||||
|
|
||||||
|
|
||||||
def _pick_weighted_random(assets: list[dict]) -> dict:
|
def _pick_weighted_random(assets: list[dict]) -> dict:
|
||||||
|
|
@ -189,10 +193,10 @@ def _pick_weighted_random(assets: list[dict]) -> dict:
|
||||||
recent.append(a)
|
recent.append(a)
|
||||||
except (ValueError, AttributeError):
|
except (ValueError, AttributeError):
|
||||||
pass
|
pass
|
||||||
on_this_day = _on_this_day_candidates(assets)
|
on_this_day, on_this_day_exact = _on_this_day_candidates(assets)
|
||||||
|
|
||||||
candidates = [
|
candidates = [
|
||||||
("on this day", on_this_day, 0.10),
|
("on this day", on_this_day, 0.30 if on_this_day_exact else 0.10),
|
||||||
("favorites", favorites, 0.18),
|
("favorites", favorites, 0.18),
|
||||||
("recent", recent, 0.36),
|
("recent", recent, 0.36),
|
||||||
("all", assets, 0.36),
|
("all", assets, 0.36),
|
||||||
|
|
|
||||||
|
|
@ -49,11 +49,11 @@ def format_age(asset: dict) -> str | None:
|
||||||
return "Yesterday"
|
return "Yesterday"
|
||||||
if days < 7:
|
if days < 7:
|
||||||
return f"{days} days ago"
|
return f"{days} days ago"
|
||||||
for n, unit in ((365, "year"), (30, "month"), (7, "week")):
|
for n, unit in ((12 * 30, "year"), (30, "month"), (7, "week")):
|
||||||
if days >= n:
|
if days >= n:
|
||||||
count = max(1, days // n)
|
count = max(1, days // n)
|
||||||
if count == 1:
|
if count == 1:
|
||||||
return f"Last {unit}"
|
return f"A {unit} ago"
|
||||||
return f"{count} {unit}s ago"
|
return f"{count} {unit}s ago"
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue