feat: VIN-specific data — recall check, safety ratings, full VPIC specs

This commit is contained in:
2026-07-03 13:12:11 -04:00
parent 3eee5b0acf
commit 078128f7b1
4 changed files with 315 additions and 46 deletions
+17 -5
View File
@@ -19,7 +19,10 @@ from fastapi.templating import Jinja2Templates
from src.ai.ollama_analyzer import analyze_vehicle
from src.api.epa import fetch_epa_data
from src.api.nhtsa import decode_vin, fetch_complaints, fetch_investigations, fetch_recalls
from src.api.nhtsa import (
decode_vin, fetch_complaints, fetch_investigations, fetch_recalls,
fetch_vin_recalls, fetch_safety_ratings,
)
from src.report.pdf import generate_pdf
from src.utils.risk import calculate_risk, compute_extended_fields
from src.utils.validator import validate_vin
@@ -114,15 +117,20 @@ async def fetch(
yield evt(f"✅ Vehículo: {year} {make} {model}", "success")
await asyncio.sleep(0.05)
# 3 — Recalls + Complaints + Investigations (paralelo)
yield evt("⏳ Consultando recalls, quejas e investigaciones...", "progress")
recalls, complaints, invests = await asyncio.gather(
# 3 — Recalls + Complaints + Investigations + VIN check + Safety (paralelo)
yield evt("⏳ Consultando NHTSA: recalls, quejas, VIN check, seguridad...", "progress")
recalls, complaints, invests, vin_recalls, safety_ratings = await asyncio.gather(
fetch_recalls(make, model, year),
fetch_complaints(make, model, year),
fetch_investigations(make, model, year),
fetch_vin_recalls(vin_clean),
fetch_safety_ratings(year, make, model),
)
open_count = len(vin_recalls)
stars = safety_ratings.get("overall", "")
stars_txt = f" · {stars}★ seguridad" if stars and stars != "NR" else ""
yield evt(
f"{len(recalls)} recalls · {len(complaints)} quejas · {len(invests)} investigaciones",
f"{len(recalls)} recalls · {len(complaints)} quejas · {open_count} VIN-recalls{stars_txt}",
"success",
)
await asyncio.sleep(0.05)
@@ -185,6 +193,8 @@ async def fetch(
"risk": risk,
"recalls": recalls,
"complaints": complaints,
"vin_recalls": vin_recalls,
"safety_ratings": safety_ratings,
"critical_recall_count": extended["critical_recall_count"],
"engine_complaints": extended["engine_complaints"],
"transmission_complaints": extended["transmission_complaints"],
@@ -212,6 +222,8 @@ async def fetch(
"recalls": recalls,
"complaints": complaints,
"investigations": invests,
"vin_recalls": vin_recalls,
"safety_ratings": safety_ratings,
"epa": epa,
"risk": risk,
"ai_analysis": ai_analysis,