Energy Utilization Shows 0% Because the Ratio Is Truncated Too Early
Level 2 · node · Correctness · Integer truncation before percentage conversion
Scenario
A fictional building energy dashboard aggregates electricity consumption and generation in Wh for each site and displays utilization as a percentage. Some sites consume less than they generate, but their utilization is not actually zero. The current calculation truncates the division result to an integer before converting it to a percentage, displaying 0%. Trace the aggregation path from repository to report controller.
Requirements
Divide each site's total consumption by its total generation and then multiply by 100 to compute the percentage. Return zero when generation is zero; allow values above 100% when consumption exceeds generation. Do not mix sites or mutate stored measurements. Add no external packages.
Acceptance criteria
- Sum consumption and generation for each site.
- Compute percentage accurately even when the ratio is below one.
- Preserve utilization above 100% when consumption exceeds generation.
- Return zero utilization when generation is zero.
- Never mix readings from different sites.
- Reading the report does not mutate stored measurements.