From 925174d80e6c791af60ae1519b71d12f9323917f Mon Sep 17 00:00:00 2001 From: Henrik Jess Nielsen Date: Fri, 30 Oct 2026 14:51:18 +0100 Subject: [PATCH 1/2] fix(match): prefer standard/cheapest variant, not premium, for truthful estimates MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A generic catalog item (e.g. 'Entrecote ½ kg') could match a premium offer (Wagyu 250 €/kg, US-Beef), inflating the estimate — correct math, wrong product. Tell the matcher to pick the ordinary/standard variant at the lowest price and avoid premium/luxury (Wagyu, Dry-Aged, US-Beef, øko-premium) unless the item names it. No price caps (that would be guesswork) — the estimate stays raw offer price × quantity. Version marker in the match signature forces a re-match so the new logic takes effect. --- app.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/app.py b/app.py index a9444f4..2e932b7 100644 --- a/app.py +++ b/app.py @@ -423,9 +423,12 @@ def match_offers_ai(): # Skip the (daily) match call when the offer set hasn't changed since the # last successful match — the avis only turns over weekly, so this avoids a - # pointless Claude call most days. + # pointless Claude call most days. The leading version forces a re-match + # whenever the matching logic/prompt changes (bump it when editing them). + MATCH_VERSION = "v2-standard-not-premium" sig = hashlib.md5( - "\n".join(sorted(o['id'] + '|' + (o.get('heading') or '') for o in offers)) + (MATCH_VERSION + "\n" + "\n".join( + sorted(o['id'] + '|' + (o.get('heading') or '') for o in offers))) .encode('utf-8')).hexdigest() with get_db() as c: if _meta_get(c, 'last_match_sig') == sig and \ @@ -452,7 +455,10 @@ def match_offers_ai(): "findes. Vær striks: match kun når det tydeligt er samme varetype " "(fx entrecôte↔entrecôte-tilbud). Match IKKE blot på mærke eller løst " "beslægtede varer (fx 'Nutella 1kg glas' må IKKE matche 'Nutella " - "julekalender'). Vælg det billigste ved flere ens. Returnér KUN et " + "julekalender'). Når varen er generisk (fx 'Entrecote ½ kg'), vælg den " + "ALMINDELIGE/standard variant til den LAVESTE pris — undgå premium-/" + "luksus-varianter (Wagyu, Dry-Aged, US-Beef, øko-premium) medmindre varen " + "selv nævner det, da de giver et urealistisk højt estimat. Returnér KUN et " 'JSON-array [{"item_key":"...","offer_id":"..."}] med de sikre match, ' "intet andet.") client = anthropic.Anthropic(max_retries=CLAUDE_MAX_RETRIES) From 298f90812dab3f3ace051a2bfb0e489b972801f8 Mon Sep 17 00:00:00 2001 From: Henrik Jess Nielsen Date: Fri, 30 Oct 2026 16:17:57 +0100 Subject: [PATCH 2/2] =?UTF-8?q?feat(mobile):=20show=20estimate=20+=20?= =?UTF-8?q?=C2=BDkg=20price=20per=20item=20on=20phones?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The estimate column is hidden on phones, so add a small 'est X kr · ½kg Y kr' line under each item name, shown only on mobile. The ½kg (per-500g) price is computed for weight items (line price ÷ kg × 0.5). The est column (desktop) and this line now show the *computed* per-row price (offer price × quantity, or quantity-scaled estimate), so each row matches what the total adds up. --- templates/index.html | 37 +++++++++++++++++++++++++++++-------- 1 file changed, 29 insertions(+), 8 deletions(-) diff --git a/templates/index.html b/templates/index.html index 3ed0492..4783ec7 100644 --- a/templates/index.html +++ b/templates/index.html @@ -71,6 +71,7 @@ .item-name { padding: 0.7rem 0.5rem; font-size: 14px; } .item-name .note { font-size: 11px; color: var(--muted); display: block; margin-top: 1px; } .item-name .de { font-size: 10px; color: #b0aba3; display: block; margin-top: 0; font-style: italic; } + .item-name .row-est-m { display: none; font-size: 10px; color: var(--muted); font-family: var(--mono); margin-top: 2px; } .badge { display: inline-block; font-size: 9px; padding: 1px 5px; border-radius: 3px; margin-left: 5px; vertical-align: middle; font-weight: 500; } .badge-card { background: var(--blue-light); color: var(--blue); } .badge-kasse { background: var(--amber-light); color: var(--amber); } @@ -169,6 +170,7 @@ .header-actions { flex-direction: row; align-items: center; } .item-row { grid-template-columns: 28px 1fr 64px 78px; } .item-est { display: none; } + .item-name .row-est-m { display: block; } .col-headers { grid-template-columns: 28px 1fr 64px 78px; } .col-h:nth-child(4) { display: none; } .extra-item-row { grid-template-columns: 28px 1fr auto auto; } @@ -266,6 +268,7 @@ {% if item.get('note') %}{{ item.note }}{% endif %} {% set d = deals.get(item.key) %} {% if d %}🏷 på tilbud: {{ "{:.2f}".format(d.price_eur).replace(".",",") }} € ≈ {{ "{:.0f}".format(d.price_eur * eur_dkk) }} kr. · {{ d.heading_da or d.heading }}{% endif %} +
{ + const qi = r.querySelector('.item-qty input'); const offer = offerLineDkk(r); // real offer price if matched - if (offer != null) { est += offer; return; } - let base = parseFloat(r.dataset.est) || 0; - const qi = r.querySelector('.item-qty input'); // scale estimate with quantity - if (qi) { - const cur = qtyNum(qi.value.trim() || qi.placeholder); - const def = qtyNum(qi.placeholder); - if (cur != null && def != null && def > 0) base = base * (cur / def); + let line; + if (offer != null) { + line = offer; + } else { + line = parseFloat(r.dataset.est) || 0; + if (qi) { // scale estimate with quantity + const cur = qtyNum(qi.value.trim() || qi.placeholder); + const def = qtyNum(qi.placeholder); + if (cur != null && def != null && def > 0) line = line * (cur / def); + } + } + est += line; + + // Per-row display: computed estimate + ½kg price (for weight items). The + // est column is hidden on phones, so also fill the mobile sub-line. + if (qi) { + const col = r.querySelector('.item-est'); + if (col) col.textContent = line > 0 ? Math.round(line).toLocaleString('da-DK') : '—'; + const sub = r.querySelector('.row-est-m'); + if (sub) { + const kg = qtyToKg(qi.value.trim() || qi.placeholder); + const per500 = (kg > 0 && line > 0) ? Math.round(line / kg * 0.5) : null; + sub.textContent = (line > 0 ? 'est ' + Math.round(line).toLocaleString('da-DK') + ' kr' : '') + + (per500 ? ' · ½kg ' + per500 + ' kr' : ''); + } } - est += base; }); document.getElementById('stat-est').textContent = est > 0 ? Math.round(est).toLocaleString('da-DK') : '—';