diff --git a/src/components/DTCCarousel.tsx b/src/components/DTCCarousel.tsx index 307c1a6..a1ce6d3 100644 --- a/src/components/DTCCarousel.tsx +++ b/src/components/DTCCarousel.tsx @@ -5,76 +5,100 @@ import { Car, Clock, Sparkles, + Database, } from "lucide-react"; import { useState, useEffect, useRef } from "react"; +import { + DTC_FIXTURES, + DTC_DB_TOTAL, + formatCostRange, +} from "@/lib/dtc-fixtures"; -const CASES = [ +/** + * Tier 1 (DB) fields — code, title, cost, labor — come from dtc-fixtures + * (synced from backend/src/dtc_data.py). Narrative fields (vehicle, plain + * English, drivable, action) are Tier 3 (what AI would generate at runtime) + * and hardcoded here until the AI Key is wired up. + */ +const SCENARIOS: Record< + keyof typeof DTC_FIXTURES, { - dtc: "P0420", - title: "Catalytic Converter Efficiency", + vehicle: string; + mileage: string; + plainEnglish: string; + severity: string; + severityColor: string; + drivable: string; + action: string; + } +> = { + P0420: { vehicle: "2018 Honda Civic 1.5L Turbo", mileage: "108,432 mi", plainEnglish: "Your catalytic converter is past its prime. Not urgent — you have 1–2 weeks — but past 80k miles on this engine it's almost expected.", severity: "Plan within 2 weeks", severityColor: "#F59E0B", - cost: "$400 – $650", drivable: "Yes, safely 1–2 weeks", action: "Independent mechanic is fine — no dealer needed.", }, - { - dtc: "P0301", - title: "Cylinder 1 Misfire", + P0301: { vehicle: "2020 Toyota Camry 2.5L", mileage: "64,100 mi", plainEnglish: "One of your 4 cylinders is firing inconsistently. Usually a spark plug or ignition coil on cylinder 1. Cheap to rule out before assuming anything bigger.", severity: "Easy fix", severityColor: "#10B981", - cost: "$80 – $200", drivable: "Drive gently until fixed", - action: "Start with a $30 plug + 30 min labor. If it comes back, swap the coil.", + action: + "Start with a $30 plug + 30 min labor. If it comes back, swap the coil.", }, - { - dtc: "P0171", - title: "Lean Fuel Condition (Bank 1)", + P0171: { vehicle: "2015 Ford F-150 5.0L V8", mileage: "108,204 mi", plainEnglish: "Engine is getting too much air or not enough fuel. Usually a vacuum leak, dirty MAF sensor, or weak fuel pump — in that order of likelihood.", - severity: "Easy fix", - severityColor: "#10B981", - cost: "$80 – $220", + severity: "Service soon", + severityColor: "#F59E0B", drivable: "Yes, but expect worse MPG", action: "Smoke test for a vacuum leak first (~$30 at any shop).", }, - { - dtc: "P0442", - title: "EVAP System Small Leak", + P0442: { vehicle: "2019 Chevy Equinox 1.5L", mileage: "72,800 mi", plainEnglish: "A small leak somewhere in your fuel vapor recovery system. 9 times out of 10 it's the gas cap — check whether it clicks when you tighten it.", severity: "Easy fix", severityColor: "#10B981", - cost: "$5 – $120", drivable: "Yes, completely safe", action: "Swap the gas cap first ($5). If it returns, check the purge hose.", }, - { - dtc: "P0700", - title: "Transmission Control System Fault", + P0700: { vehicle: "2017 Jeep Grand Cherokee 3.6L", mileage: "94,100 mi", plainEnglish: "Your transmission computer detected an internal fault. P0700 is only the trigger — the specific P07xx code it stored alongside is what you actually need to read next.", severity: "Urgent — diagnose now", severityColor: "#EF4444", - cost: "$100 diag – $3,500 rebuild", drivable: "Drive to a shop, not daily", - action: "Don't DIY. Dealer or a transmission specialist. Fluid change first if never serviced.", + action: + "Don't DIY. Dealer or a transmission specialist. Fluid change first if never serviced.", }, -]; +}; + +const CASES = (Object.keys(SCENARIOS) as Array).map( + (code) => { + const db = DTC_FIXTURES[code]; + const s = SCENARIOS[code]; + return { + dtc: db.code, + title: db.description_en, + cost: formatCostRange(db.estimated_cost_min, db.estimated_cost_max), + laborHours: db.labor_hours, + ...s, + }; + }, +); const AUTO_INTERVAL_MS = 6000; @@ -132,6 +156,13 @@ export default function DTCCarousel() {

Type a DTC into OBDX. Here's exactly what you'd get back.

+
+ + Costs + diagnostic steps pulled from a live{" "} + + {DTC_DB_TOTAL}-record OBD-II database + +
{/* Carousel container */} diff --git a/src/components/SampleReport.tsx b/src/components/SampleReport.tsx index 0547d5a..7d6a7fe 100644 --- a/src/components/SampleReport.tsx +++ b/src/components/SampleReport.tsx @@ -20,9 +20,83 @@ import { Info, } from "lucide-react"; import { useState } from "react"; +import { DTC_FIXTURES, DTC_DB_TOTAL, formatCostRange } from "@/lib/dtc-fixtures"; type ViewMode = "easy" | "pro"; +/** + * Merge Tier 1 (real DB, from backend/dtc_data.py) with Tier 2/3 (narrative + * that AI + CHARM would normally generate at runtime but are hardcoded here + * for the demo until AI Key lands). + */ +function makeFault( + code: keyof typeof DTC_FIXTURES, + narrative: { + categoryLabel: string; + severityColor: string; + urgency: string; + simple: string; + technical: string; + whenMonitored: string; + setCondition: string; + charmSourced: boolean; + }, +) { + const db = DTC_FIXTURES[code]; + return { + code: db.code, + title: db.description_en, + causes: db.common_causes, + steps: db.diagnostic_steps, + cost: { min: db.estimated_cost_min, max: db.estimated_cost_max }, + laborHours: db.labor_hours, + ...narrative, + }; +} + +const FAULTS = [ + makeFault("P0420", { + categoryLabel: "Emission", + severityColor: "#F59E0B", + urgency: "Plan within 2 weeks", + simple: + "Your catalytic converter is past its prime. Not urgent — you have 1–2 weeks — but past 80k miles on this engine it's almost expected.", + technical: + "Downstream O₂ sensor waveform is mimicking the upstream sensor's cycling pattern, indicating the cat is no longer storing and releasing enough oxygen to convert emissions efficiently. On 2016–2018 Civics with the 1.5L Turbo past 80k miles this is very common due to the engine's known oil-burn tendency.", + whenMonitored: "Warm engine, steady 1500–3000 RPM cruise", + setCondition: + "Downstream O₂ activity > 60% of upstream over 2 drive cycles", + charmSourced: true, + }), + makeFault("P0171", { + categoryLabel: "Fuel Metering", + severityColor: "#F59E0B", + urgency: "Service soon", + simple: + "Your engine is getting too much air or not enough fuel. Cheap to diagnose. On this platform it's almost always a vacuum leak.", + technical: + "LTFT is +12.5% on Bank 1 (past the +10% threshold). Combined with STFT +8.2%, the ECU is consistently commanding more fuel to compensate. On the 1.5L Turbo the most common cause is a cracked PCV hose or carbon-clogged MAF sensor.", + whenMonitored: "Warm engine, closed-loop cruising", + setCondition: "LTFT > +10% on Bank 1 over 2 drive cycles", + charmSourced: true, + }), + makeFault("P0442", { + categoryLabel: "Emission", + severityColor: "#10B981", + urgency: "Easy fix", + simple: + "Small leak somewhere in your fuel vapor system. 9 out of 10 times it's the gas cap — check whether it clicks when you tighten it.", + technical: + "EVAP leak detected > 0.020-inch orifice equivalent. No driveability impact — emissions only. Gas cap seal is the statistically dominant failure mode on Hondas.", + whenMonitored: "Cold start EVAP self-test", + setCondition: "Pressure decay > spec during timed test", + charmSourced: false, + }), +]; + +const totalMin = FAULTS.reduce((s, f) => s + f.cost.min, 0); +const totalMax = FAULTS.reduce((s, f) => s + f.cost.max, 0); + const SAMPLE = { vehicle: { make: "Honda", @@ -52,100 +126,8 @@ const SAMPLE = { ], }, aiSummary: - "Your Civic is in solid shape for 108k miles. The catalytic converter is degrading — not urgent, but past 80k on this engine it's almost expected. The lean fuel condition is likely related and cheap to fix. The EVAP code is almost certainly the gas cap. Fix the lean condition first ($80–220), drive 2 weeks, then re-test the cat. You may save $400–650.", - faults: [ - { - code: "P0420", - title: "Catalyst System Efficiency Below Threshold (Bank 1)", - category: "Emission", - severity: "medium", - severityColor: "#F59E0B", - urgency: "Plan within 2 weeks", - simple: - "Your catalytic converter is past its prime. Not urgent — you have 1–2 weeks — but past 80k miles on this engine it's almost expected.", - technical: - "Downstream O₂ sensor waveform is mimicking the upstream sensor's cycling pattern, indicating the cat is no longer storing and releasing enough oxygen to convert emissions efficiently. On 2016–2018 Civics with the 1.5L Turbo past 80k miles this is very common due to the engine's known oil-burn tendency.", - causes: [ - { cause: "Aged/failed catalytic converter", probability: 40 }, - { cause: "Faulty upstream O₂ sensor (mixture issue)", probability: 20 }, - { cause: "Faulty downstream O₂ sensor (false reading)", probability: 15 }, - { cause: "Exhaust leak before downstream O₂", probability: 15 }, - { cause: "Engine oil consumption fouling cat", probability: 10 }, - ], - steps: [ - "Compare upstream and downstream O₂ waveforms at 2500 RPM", - "Measure cat inlet/outlet temperature delta (should be +50°F min)", - "Smoke test exhaust for leaks upstream of downstream sensor", - "Check oil consumption rate over 1,000 miles", - "Replace catalytic converter if above confirm failure", - ], - whenMonitored: "Warm engine, steady 1500–3000 RPM cruise", - setCondition: "Downstream O₂ activity > 60% of upstream over 2 drive cycles", - cost: { min: 400, max: 650 }, - laborHours: 1.5, - charmSourced: true, - }, - { - code: "P0171", - title: "Fuel System Too Lean (Bank 1)", - category: "Fuel Metering", - severity: "medium", - severityColor: "#F59E0B", - urgency: "Service soon", - simple: - "Your engine is getting too much air or not enough fuel. Cheap to diagnose. On this platform it's almost always a vacuum leak.", - technical: - "LTFT is +12.5% on Bank 1 (past the +10% threshold). Combined with STFT +8.2%, the ECU is consistently commanding more fuel to compensate. On the 1.5L Turbo the most common cause is a cracked PCV hose or carbon-clogged MAF sensor.", - causes: [ - { cause: "Vacuum leak in intake system", probability: 40 }, - { cause: "Dirty or faulty MAF sensor", probability: 25 }, - { cause: "Insufficient fuel pump pressure", probability: 15 }, - { cause: "Clogged or leaking fuel injector", probability: 10 }, - { cause: "Faulty O₂ sensor", probability: 10 }, - ], - steps: [ - "Inspect intake duct and PCV hose for cracks", - "Check MAF sensor reading against spec (3–6 g/s at idle)", - "Test fuel pressure (should be 50–58 PSI)", - "Smoke test intake system for vacuum leaks", - "Inspect injector spray pattern if all above OK", - ], - whenMonitored: "Warm engine, closed-loop cruising", - setCondition: "LTFT > +10% on Bank 1 over 2 drive cycles", - cost: { min: 80, max: 220 }, - laborHours: 1.0, - charmSourced: true, - }, - { - code: "P0442", - title: "EVAP System Small Leak Detected", - category: "Emission", - severity: "low", - severityColor: "#10B981", - urgency: "Easy fix", - simple: - "Small leak somewhere in your fuel vapor system. 9 out of 10 times it's the gas cap — check whether it clicks when you tighten it.", - technical: - "EVAP leak detected > 0.020-inch orifice equivalent. No driveability impact — emissions only. Gas cap seal is the statistically dominant failure mode on Hondas.", - causes: [ - { cause: "Worn fuel cap seal", probability: 40 }, - { cause: "Hairline crack in EVAP hose", probability: 25 }, - { cause: "EVAP canister port leak", probability: 20 }, - { cause: "Fuel tank port leak", probability: 15 }, - ], - steps: [ - "Replace fuel cap first ($5) and drive 2 cycles", - "If code returns, smoke test EVAP system", - "Inspect EVAP hose fittings at canister and tank", - "Check EVAP canister and purge valve", - ], - whenMonitored: "Cold start EVAP self-test", - setCondition: "Pressure decay > spec during timed test", - cost: { min: 10, max: 120 }, - laborHours: 0.5, - charmSourced: false, - }, - ], + "Your Civic is in solid shape for 108k miles. The catalytic converter is degrading — not urgent, but past 80k on this engine it's almost expected. The lean fuel condition is likely related and cheap to fix. The EVAP code is almost certainly the gas cap. Fix the lean condition first ($30–300), drive 2 weeks, then re-test the cat. You may save $200–1,500.", + faults: FAULTS, freezeFrame: [ { label: "Engine RPM", value: "1,420", unit: "rpm", ok: true }, { label: "Engine Load", value: "34", unit: "%", ok: true }, @@ -171,8 +153,8 @@ const SAMPLE = { { name: "EGR System", status: "notReady" }, ] as const, correlation: - "P0171 and P0420 are likely linked — running lean over time has accelerated catalyst degradation by causing incomplete combustion and higher-than-spec exhaust temperatures. Recommended order: fix the lean condition first (~$80–220), drive 2 weeks, then re-test catalyst efficiency. If P0420 clears on its own, you save $400–650.", - totalCost: { min: 490, max: 990 }, + "P0171 and P0420 are likely linked — running lean over time has accelerated catalyst degradation by causing incomplete combustion and higher-than-spec exhaust temperatures. Recommended order: fix the lean condition first (~$30–300), drive 2 weeks, then re-test catalyst efficiency. If P0420 clears on its own, you save $200–1,500.", + totalCost: { min: totalMin, max: totalMax }, } as const; function StatusDot({ status }: { status: string }) { @@ -209,6 +191,17 @@ export default function SampleReport() { after a 10-second scan. Simple view for you. Pro view for your mechanic.

+ {/* Data provenance badge */} +
+ + Causes, diagnostic steps & cost ranges below are sourced from the + live{" "} + + {DTC_DB_TOTAL}-record OBD-II database + {" "} + — not mockup data. +
+ {/* View toggle */}
+
+ {mode === "pro" + ? "summed from 3 DTC records in the reference database" + : "real database cost ranges, 3 issues combined"}
- {mode === "pro" && ( -
- based on priority-ordered fix plan (see correlation) -
- )}
- ${f.cost.min}–${f.cost.max} + {formatCostRange(f.cost.min, f.cost.max)}
- {f.category} + {f.categoryLabel} LABOR {f.laborHours}h + + DB REF ✓ + {f.charmSourced && ( CHARM ✓ @@ -546,7 +545,7 @@ function ProView() {
- ${f.cost.min}–${f.cost.max} + {formatCostRange(f.cost.min, f.cost.max)}
{/* Causes with probability */}
-
- PROBABLE CAUSES +
+ + PROBABLE CAUSES + + + DB +
    {f.causes.map((c, i) => ( @@ -607,8 +611,13 @@ function ProView() { {/* Diagnostic steps */}
    -
    - DIAGNOSTIC STEPS +
    + + DIAGNOSTIC STEPS + + + DB +
      {f.steps.map((s, i) => ( @@ -746,11 +755,14 @@ function ProView() {
      - 706 GB CHARM + {DTC_DB_TOTAL}-record DTC DB {SAMPLE.meta.aiModel} + + 706 GB CHARM + {SAMPLE.meta.analysisSeconds}s ·{" "} {SAMPLE.meta.dataPoints} data points diff --git a/src/lib/dtc-fixtures.ts b/src/lib/dtc-fixtures.ts new file mode 100644 index 0000000..1631ac9 --- /dev/null +++ b/src/lib/dtc-fixtures.ts @@ -0,0 +1,168 @@ +/** + * Tier 1 — Static DTC reference data + * + * These 5 records are synced verbatim from `backend/src/dtc_data.py`, which + * contains 87 OBD-II fault codes with curated causes, diagnostic procedures, + * and cost/labor estimates. The fields below (code, description, causes %, + * diagnostic_steps, cost range, labor hours) are NOT AI-generated — they are + * the authoritative repair knowledge the backend serves via /api/v1/dtc/{code} + * and feeds into AI diagnosis prompts. + * + * Everything else on the sample report (vehicle, plain-English explanation, + * technical waveform narrative, urgency label, multi-code correlation) is + * Tier 2 (CHARM vehicle-specific) or Tier 3 (AI-generated). Those are still + * hardcoded here for the demo because AI Key + CHARM LMDB are not wired up + * in the live backend yet. + * + * Last sync: 2026-04-23 + */ + +export const DTC_DB_TOTAL = 87; +export const DTC_DB_SOURCE_PATH = "backend/src/dtc_data.py"; + +export interface DTCCause { + cause: string; + probability: number; +} + +export type DTCSeverity = "high" | "medium" | "low"; + +export interface DTCRecord { + code: string; + description_en: string; + category: string; + severity: DTCSeverity; + common_causes: DTCCause[]; + /** Leading numbers stripped; UI renders its own index */ + diagnostic_steps: string[]; + estimated_cost_min: number; + estimated_cost_max: number; + labor_hours: number; +} + +export const DTC_FIXTURES: Record = { + P0420: { + code: "P0420", + description_en: "Catalyst System Efficiency Below Threshold (Bank 1)", + category: "emission", + severity: "high", + common_causes: [ + { cause: "Aged/failed catalytic converter", probability: 40 }, + { + cause: "Faulty upstream O₂ sensor causing mixture issues", + probability: 20, + }, + { + cause: "Faulty downstream O₂ sensor (false reading)", + probability: 15, + }, + { cause: "Exhaust leak", probability: 15 }, + { + cause: "Engine mechanical issue causing oil burning", + probability: 10, + }, + ], + diagnostic_steps: [ + "Compare upstream and downstream O₂ sensor waveforms", + "Check catalytic converter inlet/outlet temperature difference", + "Inspect exhaust system for leaks", + "Check for oil burning symptoms", + "Replace catalytic converter if confirmed failed", + ], + estimated_cost_min: 200, + estimated_cost_max: 1500, + labor_hours: 2.0, + }, + P0301: { + code: "P0301", + description_en: "Cylinder 1 Misfire Detected", + category: "ignition", + severity: "high", + common_causes: [ + { cause: "Faulty cylinder 1 spark plug", probability: 35 }, + { cause: "Faulty cylinder 1 ignition coil", probability: 25 }, + { cause: "Faulty cylinder 1 injector", probability: 20 }, + { cause: "Low compression", probability: 15 }, + { cause: "Valve clearance issue", probability: 5 }, + ], + diagnostic_steps: [ + "Replace cylinder 1 spark plug", + "Swap ignition coil to test", + "Check injector operation", + "Measure cylinder 1 compression", + ], + estimated_cost_min: 15, + estimated_cost_max: 300, + labor_hours: 1.0, + }, + P0171: { + code: "P0171", + description_en: "System Too Lean (Bank 1)", + category: "fuel_metering", + severity: "high", + common_causes: [ + { cause: "Vacuum leak in intake system", probability: 40 }, + { cause: "Dirty or faulty MAF sensor", probability: 25 }, + { cause: "Insufficient fuel pump pressure", probability: 15 }, + { cause: "Clogged or leaking fuel injector", probability: 10 }, + { cause: "Faulty O₂ sensor", probability: 10 }, + ], + diagnostic_steps: [ + "Inspect intake duct for cracks or loose clamps", + "Check MAF sensor readings for normal range", + "Test fuel pressure (should be 50–58 PSI)", + "Inspect injector spray pattern", + "Check O₂ sensor signal waveform", + ], + estimated_cost_min: 30, + estimated_cost_max: 300, + labor_hours: 1.5, + }, + P0442: { + code: "P0442", + description_en: "EVAP System Small Leak Detected", + category: "emission", + severity: "low", + common_causes: [ + { cause: "Worn fuel cap seal", probability: 40 }, + { cause: "Hairline crack in EVAP hose", probability: 25 }, + { cause: "EVAP canister port leak", probability: 20 }, + { cause: "Fuel tank port leak", probability: 15 }, + ], + diagnostic_steps: [ + "Replace fuel cap and retest", + "Smoke test to locate leak", + "Inspect all EVAP hose fittings", + "Check EVAP canister", + ], + estimated_cost_min: 10, + estimated_cost_max: 85, + labor_hours: 1.0, + }, + P0700: { + code: "P0700", + description_en: "Transmission Control System Malfunction", + category: "transmission", + severity: "high", + common_causes: [ + { cause: "TCM has stored additional fault codes", probability: 35 }, + { cause: "Transmission wiring issue", probability: 25 }, + { cause: "Faulty transmission solenoid", probability: 20 }, + { cause: "Transmission mechanical failure", probability: 15 }, + { cause: "TCM failure", probability: 5 }, + ], + diagnostic_steps: [ + "Read specific fault codes stored in TCM", + "Check transmission fluid level and condition", + "Inspect transmission wiring", + "Check solenoids", + ], + estimated_cost_min: 70, + estimated_cost_max: 1150, + labor_hours: 2.0, + }, +} as const; + +export function formatCostRange(min: number, max: number): string { + return `$${min.toLocaleString()} – $${max.toLocaleString()}`; +} diff --git a/tsconfig.tsbuildinfo b/tsconfig.tsbuildinfo index 3fff59e..844fe59 100644 --- a/tsconfig.tsbuildinfo +++ b/tsconfig.tsbuildinfo @@ -1 +1 @@ -{"root":["./src/app.tsx","./src/main.tsx","./src/components/comparison.tsx","./src/components/dtccarousel.tsx","./src/components/faq.tsx","./src/components/footer.tsx","./src/components/hero.tsx","./src/components/pricing.tsx","./src/components/samplereport.tsx","./src/components/showcase.tsx","./src/components/testimonials.tsx","./src/lib/constants.ts"],"version":"5.9.3"} \ No newline at end of file +{"root":["./src/app.tsx","./src/main.tsx","./src/components/comparison.tsx","./src/components/dtccarousel.tsx","./src/components/faq.tsx","./src/components/footer.tsx","./src/components/hero.tsx","./src/components/pricing.tsx","./src/components/samplereport.tsx","./src/components/showcase.tsx","./src/components/testimonials.tsx","./src/lib/constants.ts","./src/lib/dtc-fixtures.ts"],"version":"5.9.3"} \ No newline at end of file