← all branches

fix/gdmth-cap-q

safe
5ee36dd · incrementalPR #312reviewed 2026-07-15 00:29 UTC0H · 0M · 0L · 1I
The branch
Purpose
Fix GDMTH winter under-billing: when a tariff period has no punta demand (Tijuana winter), the capacity charge collapsed to $0. CFE mandates the Q-method fallback (demanda facturable) instead.
Goal
Add Q-method capacity fallback for GDMTH no-punta seasons + carry chargeFactor through the DB schema SSOT and THOR seed
Sub-goals
  • SG-1: Bill-calculator decisions — when resolved kW is 0/absent and charge carries qFallbackFactor, return Q estimate (total_kwh / (24 × days × chargeFactor))
  • SG-2: Tariff adapter — parse chargeFactor and set qFallbackFactor on TOU capacity charge only
  • SG-3: Types — additive chargeFactor on Charge, RateValues, RateComponents (no reshape)
  • SG-4: DB schema SSOT — add chargeFactor to TariffRateComponents
  • SG-5: THOR seed — hardcoded fallback TARIFF_CHARGE_FACTOR['GDMTH THOR'] = '0.57'
The changes (whole branch)
What
Commit 2 of 2: adds chargeFactor to TariffRateComponents (JSONB SSOT in packages/database) and wires TARIFF_CHARGE_FACTOR fallback into seed-thor-rate-values. Commit 1 (4a519ddc) landed the decision + adapter + domain type changes.
Why
The SSOT (TariffRateComponents in Drizzle schema) was missing chargeFactor even though the domain RateComponents type and seed already needed it — keeping the SSOT aligned is required for JSONB introspection and future type-check assertions.
Areas
domains/utility/src/bill-calculator+1502domains/utility/src/tariff-rate+90packages/database/src+160
Blast
8 files, +186/-2 across 3 areas. Data-gated: fallback fires only when chargeFactor is present in rate data — inert until seeded. Zero regression on summer (punta) periods confirmed by A/B vs 33 GDMTH THOR sites × 3 periods.
data-gated-fix billing-critical winter-gdmth-only
typecheck· tsc not available on self-hosted runnerci-checks· statusCheckRollup not accessible via PAT

Findings · 1

tests1

info

Pre-existing: no type-check assertion for TariffRateComponents ↔ RateComponents

packages/database/src/schema/tariff-rates.ts

No tariff-rates.type-check.ts asserting AssertEqual<TariffRateComponents, RateComponents>. Both types now have chargeFactor aligned, but structural drift would go undetected. Pre-existing gap — out of scope for this commit.

History · 2 commits

  1. 5ee36ddsafeincremental0H · 0M · 0L2026-07-15 00:29current
  2. 4a519ddneeds attentionfull1H · 5M · 5L2026-07-15 00:11