More recent
This commit is contained in:
parent
03bbce079b
commit
d513b17f93
1 changed files with 5 additions and 5 deletions
|
|
@ -185,24 +185,24 @@ def _filter_by_orientation(assets: list[dict], portrait: bool) -> list[dict]:
|
||||||
|
|
||||||
|
|
||||||
def _pick_weighted_random(assets: list[dict]) -> dict:
|
def _pick_weighted_random(assets: list[dict]) -> dict:
|
||||||
"""Pick random asset, slightly biased towards favorites (20%) and recent photos (20%)."""
|
"""Pick random asset, biased towards favorites (20%) and recently added photos (50%)."""
|
||||||
if not assets:
|
if not assets:
|
||||||
raise ValueError("No assets to choose from")
|
raise ValueError("No assets to choose from")
|
||||||
|
|
||||||
one_week_ago = datetime.now(timezone.utc) - timedelta(days=7)
|
cutoff = datetime.now(timezone.utc) - timedelta(days=30)
|
||||||
favorites = [a for a in assets if a.get("isFavorite")]
|
favorites = [a for a in assets if a.get("isFavorite")]
|
||||||
recent = []
|
recent = []
|
||||||
for asset in assets:
|
for asset in assets:
|
||||||
date_str = asset.get("fileCreatedAt") or asset.get("createdAt", "")
|
date_str = asset.get("createdAt", "")
|
||||||
try:
|
try:
|
||||||
if datetime.fromisoformat(date_str.replace("Z", "+00:00")) >= one_week_ago:
|
if datetime.fromisoformat(date_str.replace("Z", "+00:00")) >= cutoff:
|
||||||
recent.append(asset)
|
recent.append(asset)
|
||||||
except (ValueError, AttributeError):
|
except (ValueError, AttributeError):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
if favorites and random.random() < 0.2:
|
if favorites and random.random() < 0.2:
|
||||||
return random.choice(favorites)
|
return random.choice(favorites)
|
||||||
if recent and random.random() < 0.25:
|
if recent and random.random() < 0.5:
|
||||||
return random.choice(recent)
|
return random.choice(recent)
|
||||||
return random.choice(assets)
|
return random.choice(assets)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue