Identite Fuel Advisor, assets locaux et audit economique corrige
Renommage Fuel Advisor (titre, header, favicon SVG/PNG, apple-touch-icon, logo SVG servis localement). Oracle: contrainte de penalty corrigee (portee inversee), quantites non entieres ecartees avant rejeu, double comptage de penalite supprime. Audit economique regenerer: plafonds omniscients coherents et positifs; deux lignes non resolues conservees telles quelles.
This commit is contained in:
41
research/economic_audit/export_economic.py
Normal file
41
research/economic_audit/export_economic.py
Normal file
@@ -0,0 +1,41 @@
|
||||
"""Export prix et routage observés pour audit offline, aucun secret."""
|
||||
|
||||
import json
|
||||
import sqlite3
|
||||
from pathlib import Path
|
||||
|
||||
from clean_backtest import states_for
|
||||
from validation import VEHICLE_PROFILES
|
||||
|
||||
c = sqlite3.connect("/var/lib/fuel-advisor/fuel.sqlite3")
|
||||
c.row_factory = sqlite3.Row
|
||||
routes = [
|
||||
dict(r)
|
||||
for r in c.execute(
|
||||
"SELECT * FROM route_cache WHERE origin_lat=? AND origin_lon=? AND provider=?",
|
||||
(44.7737872, -0.5595029, "osrm"),
|
||||
)
|
||||
]
|
||||
stations = [dict(r) for r in c.execute("SELECT id,lat,lon FROM stations")]
|
||||
by_id = {}
|
||||
for s in stations:
|
||||
if s["lat"] is None:
|
||||
continue
|
||||
candidates = [
|
||||
r
|
||||
for r in routes
|
||||
if abs(r["target_lat"] - s["lat"]) < 0.0001 and abs(r["target_lon"] - s["lon"]) < 0.0001
|
||||
]
|
||||
if candidates:
|
||||
r = max(candidates, key=lambda r: r["computed_at"])
|
||||
by_id[s["id"]] = dict(roundtrip_km=2 * r["distance_m"] / 1000, computed_at=r["computed_at"])
|
||||
out = dict(profiles=VEHICLE_PROFILES, routes=by_id, origin="fav:1", fuels={})
|
||||
for fuel in ("Gazole", "SP95"):
|
||||
states = states_for(fuel)
|
||||
out["fuels"][fuel] = [
|
||||
dict(day=k, prices=v["prices"])
|
||||
for k, v in sorted(states.items())
|
||||
if "2024-01-01" <= k <= "2026-09-13"
|
||||
]
|
||||
Path("reports/economic-inputs.json").write_text(json.dumps(out))
|
||||
print("routes", len(by_id), "days", {f: len(v) for f, v in out["fuels"].items()})
|
||||
Reference in New Issue
Block a user