Harden Emporia CSV import: validate mains, fix zero-peak fallback, define dedup policy #26

Open
opened 2026-07-17 03:06:44 +00:00 by claude-bot · 0 comments
Contributor

Three robustness gaps in src/lib/parseEmporia.js:

  1. Mains detection (:177-180) is a single regex over column names; if no column matches, every row's mains is 0 and all bills silently compute to ~$0. Add a post-parse check: if mains ≤ 0 across most rows or mains < sum of circuits, surface an import error/warning in the summary card instead of proceeding.
  2. peakDemandKw (:280) uses || 3.0, so a computed 0 falls back to the slider default — combined with (1) this charges a phantom 3 kW demand on Ultimate. Use an explicit Number.isFinite/null check.
  3. Multi-file merge (:15-18) is first-file-wins per timestamp, so re-importing a corrected export changes nothing. Switch to last-write-wins and say so in the import summary ("N rows replaced").

Acceptance criteria

  • Import with no matching mains columns produces a visible error, not $0 bills
  • Zero peak demand is preserved as 0, not replaced by 3.0
  • Overlapping import replaces rows and reports the replacement count
  • Tests for all three paths

Relations: relates to #9 (same file; do together)

(Audit finding F-05, 2026-07-16 — Severity: Medium, Confidence: Medium)

Three robustness gaps in `src/lib/parseEmporia.js`: 1. Mains detection (`:177-180`) is a single regex over column names; if no column matches, every row's `mains` is 0 and all bills silently compute to ~$0. Add a post-parse check: if mains ≤ 0 across most rows or mains &lt; sum of circuits, surface an import error/warning in the summary card instead of proceeding. 2. `peakDemandKw` (`:280`) uses `|| 3.0`, so a computed 0 falls back to the slider default — combined with (1) this charges a phantom 3 kW demand on Ultimate. Use an explicit `Number.isFinite`/null check. 3. Multi-file merge (`:15-18`) is first-file-wins per timestamp, so re-importing a corrected export changes nothing. Switch to last-write-wins and say so in the import summary ("N rows replaced"). **Acceptance criteria** - [ ] Import with no matching mains columns produces a visible error, not $0 bills - [ ] Zero peak demand is preserved as 0, not replaced by 3.0 - [ ] Overlapping import replaces rows and reports the replacement count - [ ] Tests for all three paths **Relations:** relates to #9 (same file; do together) *(Audit finding F-05, 2026-07-16 — Severity: Medium, Confidence: Medium)*
Sign in to join this conversation.
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
rbrooks/BatteryStorageCalculator#26
No description provided.