These downloads contain official grid snapshots and recorded benchmark evidence. Uploaded customer bills and private analysis results are separate. Transformer/LLM evidence remains retrospective.;
}
export default function AnalysisPanel({country,quotes,onProfile,onError}){
const [busy,setBusy]=useState(false),[importJob,setImportJob]=useState(null),[imported,setImported]=useState(null),[job,setJob]=useState(null),[result,setResult]=useState(null),[reviewed,setReviewed]=useState(false),[future,setFuture]=useState(false),[growth,setGrowth]=useState(5),[history,setHistory]=useState(null),[mode,setMode]=useState('switching'),[bulkInput,setBulkInput]=useState(''),[selected,setSelected]=useState('');
const run=async(fn)=>{setBusy(true);onError('');try{await fn()}catch(e){onError(e.message)}finally{setBusy(false)}};
const poll=async(jid,type)=>{const r=await api('/api/analysis_result',{job_id:jid,limit:20});if(r.state==='failed')throw Error(r.error);if(type==='import'){setImportJob(r);if(r.state==='completed'){setImported(r.result);setReviewed(false);}}else{setJob(r);if(r.state==='completed')setResult(r.result);}return r;};
useEffect(()=>{let jid=importJob?.job_id;if(!jid||!['queued','running'].includes(importJob.state||'queued'))return;let id=setInterval(()=>poll(jid,'import').catch(e=>{onError(e.message);clearInterval(id);}),2500);return()=>clearInterval(id)},[importJob?.job_id,importJob?.state]);
useEffect(()=>{let jid=job?.job_id;if(!jid||!['queued','running'].includes(job.state||'queued'))return;let id=setInterval(()=>poll(jid,'analysis').catch(e=>{onError(e.message);clearInterval(id);}),2500);return()=>clearInterval(id)},[job?.job_id,job?.state]);
const upload=async(files)=>{if(!files.length)return;if([...files].reduce((s,f)=>s+f.size,0)>25*1024*1024)throw Error('Combined compressed files must be at most 25 MiB.');let form=new FormData();for(const f of files)form.append('files',f);const r=await fetch('/api/billing_import',{method:'POST',body:form});const data=await r.json();if(!r.ok)throw Error(data.detail||'Import failed');setImported(null);setImportJob({...data,state:'queued'});setSelected('');};
const profiles=imported?.profiles||[];
const submit=async()=>{let payload;if(mode==='switching'){const prices={};for(const q of quotes||[])prices[q.provider]=Number(growth);payload={kind:'switching',import_job_id:importJob?.job_id,profiles:selected?profiles.filter(p=>p.profile_id===selected):profiles,offers:quotes||[],horizons:[3,12,36],accept_profile_estimates:reviewed,assume_future_enrolment:future,price_scenarios:[{name:'constant-price',annual_price_change_pct:{}},{name:'declared-price-change',annual_price_change_pct:prices}]};}else{payload=JSON.parse(bulkInput);payload.kind=mode;}const data=await api('/api/analysis_submit',payload);setResult(null);setJob({...data,state:'queued'});};
const plans=result?.profiles?.flatMap(p=>p.plans.map(x=>({profile_id:p.profile_id,...x})))||[];
return <>
Import compressed bills
Keep multiple meters apart. Inspect what was extracted.
ZIP · PDF · CSV · JSON
Text-based EDP Portugal PDFs are supported. Germany/Australia and other PDF layouts need normalized CSV/JSON. Water and unrelated files are excluded; scanned PDFs need OCR elsewhere. Raw files are used for this temporary computation and are not published.{importJob&&
Compare staying with constrained swap schedules over 3, 12 and 36 months, under explicit future-price assumptions.
{mode==='switching'&&}
{mode==='switching'?<>{quotes?.length||0} supplied quotes loaded from Quote explorer. A comparison requires complete, fresh, tax-inclusive quotes matching each meter’s power and contract terms. Without quotes the scenario keeps the historical bill baseline.>:<>Forecasts: 1–10 series, 12 complete months for seasonal naive and 36 for Grokked/SARIMA. Benchmarks: 1–3 grid/wholesale series with 72 complete months. Units, coverage and monthly dates are mandatory. Archived transformer/Astra scores do not run customer inference.>}{job&&
Analysis: {job.state}
}Results use a private unguessable link and expire after one hour or a Space restart. Download the audit ZIP to retain them. One CPU worker; no paid model calls or automatic supplier switching.
{profiles.length>0&&
Imported electricity profiles
Annualized historical scenarios; no missing latest-year bills are invented.
{plans.length>0&&<>Exact minima within supplied monthly assumptions. Future prices and availability are uncertain; the full schedule shows fees, credits, guarantees and assumptions. This does not execute a switch.>}Full results, schedules and model diagnostics
{JSON.stringify(result,null,2)}
}
Additional provider tariff history
Import dated observations for other providers. Tariff IDs and VAT bases remain separate.