Compare commits

..

3 Commits

Author SHA1 Message Date
833fbe46b9 Merge pull request 'worktree-citti-arkiver-tur' (#14) from worktree-citti-arkiver-tur into main
All checks were successful
Build and Deploy citti / build-and-deploy (push) Successful in 42s
Reviewed-on: #14
2026-10-31 06:54:23 +01:00
Henrik Jess Nielsen
298f90812d feat(mobile): show estimate + ½kg price per item on phones
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.
2026-10-30 16:17:57 +01:00
Henrik Jess Nielsen
925174d80e fix(match): prefer standard/cheapest variant, not premium, for truthful estimates
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.
2026-10-30 14:51:18 +01:00
2 changed files with 38 additions and 11 deletions

12
app.py
View File

@@ -423,9 +423,12 @@ def match_offers_ai():
# Skip the (daily) match call when the offer set hasn't changed since the # 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 # 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( 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() .encode('utf-8')).hexdigest()
with get_db() as c: with get_db() as c:
if _meta_get(c, 'last_match_sig') == sig and \ 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 " "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 " "(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 " "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, ' 'JSON-array [{"item_key":"...","offer_id":"..."}] med de sikre match, '
"intet andet.") "intet andet.")
client = anthropic.Anthropic(max_retries=CLAUDE_MAX_RETRIES) client = anthropic.Anthropic(max_retries=CLAUDE_MAX_RETRIES)

View File

@@ -71,6 +71,7 @@
.item-name { padding: 0.7rem 0.5rem; font-size: 14px; } .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 .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 .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 { 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-card { background: var(--blue-light); color: var(--blue); }
.badge-kasse { background: var(--amber-light); color: var(--amber); } .badge-kasse { background: var(--amber-light); color: var(--amber); }
@@ -169,6 +170,7 @@
.header-actions { flex-direction: row; align-items: center; } .header-actions { flex-direction: row; align-items: center; }
.item-row { grid-template-columns: 28px 1fr 64px 78px; } .item-row { grid-template-columns: 28px 1fr 64px 78px; }
.item-est { display: none; } .item-est { display: none; }
.item-name .row-est-m { display: block; }
.col-headers { grid-template-columns: 28px 1fr 64px 78px; } .col-headers { grid-template-columns: 28px 1fr 64px 78px; }
.col-h:nth-child(4) { display: none; } .col-h:nth-child(4) { display: none; }
.extra-item-row { grid-template-columns: 28px 1fr auto auto; } .extra-item-row { grid-template-columns: 28px 1fr auto auto; }
@@ -266,6 +268,7 @@
{% if item.get('note') %}<span class="note">{{ item.note }}</span>{% endif %} {% if item.get('note') %}<span class="note">{{ item.note }}</span>{% endif %}
{% set d = deals.get(item.key) %} {% set d = deals.get(item.key) %}
{% if d %}<a class="deal" href="/tilbud" title="{{ d.heading }} ({{ d.catalog }})">🏷 på tilbud: {{ "{:.2f}".format(d.price_eur).replace(".",",") }} € ≈ {{ "{:.0f}".format(d.price_eur * eur_dkk) }} kr. · {{ d.heading_da or d.heading }}</a>{% endif %} {% if d %}<a class="deal" href="/tilbud" title="{{ d.heading }} ({{ d.catalog }})">🏷 på tilbud: {{ "{:.2f}".format(d.price_eur).replace(".",",") }} € ≈ {{ "{:.0f}".format(d.price_eur * eur_dkk) }} kr. · {{ d.heading_da or d.heading }}</a>{% endif %}
<span class="row-est-m"></span>
</div> </div>
<div class="item-qty"> <div class="item-qty">
<input type="text" value="{{ s.get('qty') or item.qty }}" placeholder="{{ item.qty }}" <input type="text" value="{{ s.get('qty') or item.qty }}" placeholder="{{ item.qty }}"
@@ -709,16 +712,34 @@ function recalcAll() {
// picked offers), live from each row's data-est. Reflects add/remove/pick. // picked offers), live from each row's data-est. Reflects add/remove/pick.
let est = 0; let est = 0;
document.querySelectorAll('[data-est]').forEach(r => { document.querySelectorAll('[data-est]').forEach(r => {
const qi = r.querySelector('.item-qty input');
const offer = offerLineDkk(r); // real offer price if matched const offer = offerLineDkk(r); // real offer price if matched
if (offer != null) { est += offer; return; } let line;
let base = parseFloat(r.dataset.est) || 0; if (offer != null) {
const qi = r.querySelector('.item-qty input'); // scale estimate with quantity line = offer;
if (qi) { } else {
line = parseFloat(r.dataset.est) || 0;
if (qi) { // scale estimate with quantity
const cur = qtyNum(qi.value.trim() || qi.placeholder); const cur = qtyNum(qi.value.trim() || qi.placeholder);
const def = qtyNum(qi.placeholder); const def = qtyNum(qi.placeholder);
if (cur != null && def != null && def > 0) base = base * (cur / def); 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') : '—'; document.getElementById('stat-est').textContent = est > 0 ? Math.round(est).toLocaleString('da-DK') : '—';