fix: correct hourly index calculation for 25-year data
Some checks are pending
CI / Engine — lint / typecheck / test (push) Waiting to run
CI / API — lint / typecheck / test (push) Waiting to run
CI / Web — typecheck / lint / build (push) Waiting to run

- Reset index per year caused out-of-bounds error
- Simplified loop using sequential hour_idx 0-8759 per year

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
Manohar Gupta 2026-05-16 12:56:31 +05:30
parent 5e49926289
commit 38797736a4

View file

@ -508,26 +508,37 @@ def run_scenario(inputs: ScenarioInput) -> ScenarioResult:
fy_start = cod_year + year fy_start = cod_year + year
fy_label = f"{fy_start}-{str(fy_start + 1)[-2:]}" fy_label = f"{fy_start}-{str(fy_start + 1)[-2:]}"
# Generate timestamps for this year # Run through each hour sequentially (0 to 8759)
hour_idx = 0 for hour_idx in range(8760):
for month in range(12): # Map hour_idx to month/day/hour
month_len = month_lengths[month] hour_of_year = hour_idx
for day in range(1, month_len + 1): # Find month by cumulative hours
for hour in range(24): cum_hours = 0
for m in range(12):
month_len = month_lengths[m]
if hour_of_year < cum_hours + month_len * 24:
month = m
day_of_month = (hour_of_year - cum_hours) // 24 + 1
hour_of_day = (hour_of_year - cum_hours) % 24
break
cum_hours += month_len * 24
# ISO timestamp # ISO timestamp
month_num = month + 4 if month < 8 else month - 8 month_num = month + 4 if month < 8 else month - 8
year_adj = fy_start + 1 if month >= 8 else fy_start year_adj = fy_start + 1 if month >= 8 else fy_start
dt = f"{year_adj:04d}-{month_num:02d}-{day:02d}T{hour:02d}:00:00" dt = f"{year_adj:04d}-{month_num:02d}-{day_of_month:02d}T{hour_of_day:02d}:00:00"
hourly_timestamps.append(dt) hourly_timestamps.append(dt)
hourly_fy.append(fy_label) hourly_fy.append(fy_label)
hourly_proj_year.append(proj_year) hourly_proj_year.append(proj_year)
# Use full index into hourly arrays
idx = year * 8760 + hour_idx idx = year * 8760 + hour_idx
total_re = pipe.solar_hourly[idx] + pipe.wind_hourly[idx] solar_val = pipe.solar_hourly[idx] if pipe.solar_hourly and idx < len(pipe.solar_hourly) else 0.0
wind_val = pipe.wind_hourly[idx] if pipe.wind_hourly and idx < len(pipe.wind_hourly) else 0.0
total_re = solar_val + wind_val
hourly_total_re.append(total_re) hourly_total_re.append(total_re)
hourly_client_end.append(total_re * loss_factor) hourly_client_end.append(total_re * loss_factor)
hourly_load.append(client_load_mw) hourly_load.append(client_load_mw)
hour_idx += 1
return ScenarioResult( return ScenarioResult(
inputs=inputs, inputs=inputs,