feat: Listen-Tab und sichtbare Zutatenlisten-Verwaltung
Listen anlegen, bearbeiten und importieren liegt unter Ernährung. Tagebuchzeilen werden auch mit Mengen-Prefix verknüpft. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
3b46630a37
commit
b37005be01
12 files changed
+307
-73
No files matched your search
@@ -31,6 +31,28 @@ def normalize_food_name(raw: str | None) -> str:
|
||||
return s.lower()
|
||||
|
||||
|
||||
def item_name_keys(raw: str | None, stored_norm: str | None = None) -> set[str]:
|
||||
"""Compare diary names to list names despite stored quantity prefixes."""
|
||||
keys: set[str] = set()
|
||||
for v in (raw, stored_norm):
|
||||
if not v:
|
||||
continue
|
||||
text = str(v).strip()
|
||||
if text:
|
||||
keys.add(text.lower())
|
||||
norm = normalize_food_name(text)
|
||||
if norm:
|
||||
keys.add(norm)
|
||||
return keys
|
||||
|
||||
|
||||
def names_match_list(raw: str | None, stored_norm: str | None, list_norm: str | None) -> bool:
|
||||
target = normalize_food_name(list_norm) if list_norm else ""
|
||||
if not target:
|
||||
return False
|
||||
return target in item_name_keys(raw, stored_norm)
|
||||
|
||||
|
||||
_LIST_COMMA_RE = re.compile(r",(?!\s*\d)")
|
||||
|
||||
|
||||
@@ -130,6 +152,29 @@ def fetch_unmapped_rows(cur, profile_id: str) -> list[dict[str, Any]]:
|
||||
(profile_id,),
|
||||
)
|
||||
diary = [dict(r) | {"kind": "diary"} for r in cur.fetchall()]
|
||||
cur.execute(
|
||||
"""
|
||||
SELECT id, name_raw, name_normalized
|
||||
FROM food_recipes
|
||||
WHERE profile_id = %s
|
||||
""",
|
||||
(profile_id,),
|
||||
)
|
||||
lists = [dict(r) for r in cur.fetchall()]
|
||||
for row in diary:
|
||||
keys = item_name_keys(row.get("source_name_raw"), row.get("source_name_normalized"))
|
||||
hit = next(
|
||||
(
|
||||
rec
|
||||
for rec in lists
|
||||
if rec.get("name_normalized") in keys
|
||||
or normalize_food_name(rec.get("name_raw")) in keys
|
||||
),
|
||||
None,
|
||||
)
|
||||
if hit:
|
||||
row["matching_recipe_id"] = str(hit["id"])
|
||||
row["matching_recipe_name"] = hit["name_raw"]
|
||||
cur.execute(
|
||||
"""
|
||||
SELECT i.source_name_raw, i.source_name_normalized,
|
||||
|
||||
Reference in new issue
Block a user