Spaces:
Running
Running
Add CSV and JSON uploads for additional provider tariff histories
Browse filesExpose the existing dated provider_history API through a compact CSV/JSON upload form and template link. Preserve tariff/VAT separation, import review and bulk scenario behavior. Production frontend build passed.
26 unmodified lines27282930303126 unmodified lines {profiles.length>0&&<section className="panel"><div className="section-title"><div><h2>Imported electricity profiles</h2><p>Annualized historical scenarios; no missing latest-year bills are invented.</p></div><button className="secondary" onClick={()=>run(async()=>setHistory(await api('/api/provider_history',{import_job_id:importJob.job_id})))}>Inspect observed tariff evolution</button></div><SmallTable rows={profiles} fields={[["profile_id","Anonymous meter"],["provider","Provider"],["contracted_power_kva","Power · kVA"],["period_start","Start"],["period_end","End"],["observed_kwh","Observed · kWh"],["observed_electricity_charges","Electricity charges"],["annual_kwh","Annualized · kWh"],["current_annual_bill","Annualized cost"]]}/><div className="button-row">{profiles.map(p=><button className="text-button" key={p.profile_id} disabled={!reviewed||p.annual_kwh==null} onClick={()=>onProfile(p)}>Use {p.profile_id.slice(-6)} in Quote explorer <ArrowRight size={13}/></button>)}</div><details><summary>Allocated months and source checksums</summary><pre className="json">{JSON.stringify(profiles,null,2)}</pre></details></section>} {history&&<section className="panel"><h2>Observed provider price evolution</h2>{history.groups.map(g=><div key={g.tariff_id} className="history-group"><h3>{g.provider} · {g.tariff_id.slice(-8)}</h3><p>{g.tax_included?'VAT included':'Before VAT'} · {g.unit} · historical observations</p><SmallTable rows={g.observations} fields={[["effective_from","Effective from"],["observed_at","Bill period end"],["rate_per_kwh","Unit price"],["date_basis","Date precision"]]}/></div>)}<Note>{history.limits}</Note></section>} {result&&<section className="panel"><div className="section-title"><div><h2>Completed analysis</h2><p>{result.status}</p></div><a className="secondary" href={job.export_path} download><Download size={15}/>Private result audit ZIP</a></div>{plans.length>0&&<><SmallTable rows={plans} fields={[["profile_id","Profile"],["scenario","Price scenario"],["horizon_months","Months"],["planned_cost","Planned cost"],["stay_cost","Stay cost"],["saving_vs_stay_scenario","Scenario saving"],["currency","Currency"],["switch_count","Swaps"]]}/><Note>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.</Note></>}<details open={!plans.length}><summary>Full results, schedules and model diagnostics</summary><pre className="json">{JSON.stringify(result,null,2)}</pre></details></section>} <AuditDatasets/></>; <section className="panel"><h2>Additional provider tariff history</h2><p>Import dated observations for other providers. Tariff IDs and VAT bases remain separate.</p><a className="text-button" href="/downloads/provider_history_template.csv" download>History CSV template <Download size={13}/></a><label className="upload"><Upload size={18}/><b>Inspect provider history CSV / JSON</b><input aria-label="Upload provider tariff history" type="file" accept=".csv,.json" onChange={e=>{const f=e.target.files[0];if(!f)return;if(f.size>2000000){onError('History limit is 2 MB.');return;}run(async()=>{const text=await f.text();let records;if(f.name.endsWith('.json')){const data=JSON.parse(text);records=Array.isArray(data)?data:data.records;}else{const parsed=Papa.parse(text,{header:true,skipEmptyLines:true});if(parsed.errors.length)throw Error(parsed.errors[0].message);records=parsed.data;}setHistory(await api('/api/provider_history',{records}));});e.target.value='';}}/></label></section><AuditDatasets/></>;}AnalysisPanel.jsx+1-1