feat: Zuordnen ohne Freeze und zuerst die letzten Wochen
Katalogsuche und Bestätigen blockieren die UI nicht mehr; offene Namen starten bei den aktuellen Tagebucheinträgen, alter Ballast bleibt unter Alle. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
c1873a47b1
commit
132a364a3a
17 files changed
+745
-163
No files matched your search
@@ -3,6 +3,7 @@ from __future__ import annotations
|
||||
|
||||
import re
|
||||
import unicodedata
|
||||
from datetime import date, timedelta
|
||||
from typing import Any
|
||||
|
||||
LEADING_QTY_RE = re.compile(
|
||||
@@ -64,6 +65,44 @@ def merge_unmapped_rows(rows: list[dict]) -> list[dict]:
|
||||
return list(merged.values())
|
||||
|
||||
|
||||
def as_iso_date(value: Any) -> str | None:
|
||||
if value is None or value == "":
|
||||
return None
|
||||
if hasattr(value, "isoformat"):
|
||||
return str(value.isoformat())[:10]
|
||||
text = str(value).strip()
|
||||
return text[:10] if len(text) >= 10 else None
|
||||
|
||||
|
||||
def filter_unmapped_since(rows: list[dict], since_days: int, today: date | None = None) -> list[dict]:
|
||||
"""Keep names last eaten in the window. Rows without last_date drop out (old recipe leftovers)."""
|
||||
days = int(since_days or 0)
|
||||
if days <= 0:
|
||||
return list(rows)
|
||||
cutoff = ((today or date.today()) - timedelta(days=days)).isoformat()
|
||||
out = []
|
||||
for row in rows:
|
||||
last = as_iso_date(row.get("last_date"))
|
||||
if last and last >= cutoff:
|
||||
out.append(row)
|
||||
return out
|
||||
|
||||
|
||||
def sort_unmapped_rows(rows: list[dict], since_days: int = 0) -> list[dict]:
|
||||
rows = list(rows)
|
||||
if int(since_days or 0) > 0:
|
||||
rows.sort(
|
||||
key=lambda x: (
|
||||
as_iso_date(x.get("last_date")) or "",
|
||||
int(x.get("count") or 0),
|
||||
),
|
||||
reverse=True,
|
||||
)
|
||||
else:
|
||||
rows.sort(key=lambda x: (-int(x.get("count") or 0), x.get("source_name_normalized") or ""))
|
||||
return rows
|
||||
|
||||
|
||||
UNIT_ALIASES = {
|
||||
"g": "g", "gr": "g", "gramm": "g",
|
||||
"kg": "kg",
|
||||
|
||||
Reference in new issue
Block a user