From a37e40e640e49aa46b32c5948025961e62e42bca Mon Sep 17 00:00:00 2001 From: Hermes Agent Date: Sat, 12 Sep 2026 19:57:27 +0200 Subject: [PATCH] Afficher la distribution locale des prix --- app.py | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/app.py b/app.py index ec118a3..693632d 100755 --- a/app.py +++ b/app.py @@ -83,7 +83,10 @@ function render(d){ const stations=(d.stations||[]).map(s=>`
${s.name}${s.city||''} · ${s.distance_km} km · màj ${s.updated||'N/A'}${s.price.toFixed(3)} €/L${s.address||''}
`).join(''); const reasons=(d.reasons||[]).map(x=>`${x}`).join(''); const news=(d.news||[]).map(n=>`
  • ${n}
  • `).join(''); - document.getElementById('result').innerHTML=`
    Recommandation

    ${d.label}

    ${d.summary}

    ${reasons}

    Stations les moins chères

    ${stations||'Aucune station locale trouvée.'}

    Signaux externes

    Marché: ${d.market?.summary||'indisponible'} · IA: ${d.ai_used?'utilisée':'non utilisée'}

    ${news?``:''}`; + const stats=d.local_stats||{}; + const buckets=(stats.price_buckets||[]).map(b=>`${b.price.toFixed(3)} €/L · ${b.count}`).join(''); + const tie=stats.best_tie_count>1?`

    ${stats.best_tie_count} stations sont à égalité au meilleur prix affiché (${stats.best.toFixed(3)} €/L). Les stations ci-dessous sont les moins chères, pas toutes les stations du rayon.

    `:''; + document.getElementById('result').innerHTML=`
    Recommandation

    ${d.label}

    ${d.summary}

    ${reasons}

    Résumé local

    ${stats.count||0} stations comparées · min ${stats.min?.toFixed(3)||'N/A'} €/L · médiane ${stats.median?.toFixed(3)||'N/A'} €/L · max ${stats.max?.toFixed(3)||'N/A'} €/L

    ${buckets}
    ${tie}

    Stations les moins chères

    ${stations||'Aucune station locale trouvée.'}

    Signaux externes

    Marché: ${d.market?.summary||'indisponible'} · IA: ${d.ai_used?'utilisée':'non utilisée'}

    ${news?``:''}`; } async function geocode(){ const q=document.getElementById('place').value.trim(); @@ -342,6 +345,11 @@ def advice(lat: float, lon: float, fuel: str, radius_km: float) -> dict[str, Any f"Moyenne locale: {local_avg:.3f} €/L sur {len(stations)} stations." ) ai_text, ai_used = ollama_summary({"label": label, "best": best.price, "avg": local_avg, "spread": spread, "market": market, "reasons": reasons}) + price_counts: dict[str, int] = {} + for p in prices: + key = f"{p:.3f}" + price_counts[key] = price_counts.get(key, 0) + 1 + best_tie_count = sum(1 for s in stations if round(s.price, 3) == round(best.price, 3)) return { "generated_at": now_iso(), "fuel": fuel, @@ -353,6 +361,19 @@ def advice(lat: float, lon: float, fuel: str, radius_km: float) -> dict[str, Any "market": market, "news": news[:4], "ai_used": ai_used, + "local_stats": { + "count": len(stations), + "best": round(best.price, 3), + "best_tie_count": best_tie_count, + "average": round(local_avg, 3), + "median": round(median, 3), + "min": round(min(prices), 3), + "max": round(max(prices), 3), + "price_buckets": [ + {"price": float(price), "count": count} + for price, count in sorted(price_counts.items(), key=lambda item: float(item[0]))[:12] + ], + }, "stations": [s.__dict__ for s in stations[:8]], }