Skip to content

Commit 6561b9b

Browse files
fix(prediction): bound import/export kWh to end_record, not the full forecast horizon
run_prediction() returned the raw, whole-loop import_kwh_battery/house and export_kwh accumulators instead of the already-computed final_* variants that are correctly gated to end_record (matching final_metric/final_soc). Any caller planning a longer horizon than it bills (e.g. the annual tool's 48h lookahead billed as one day, or Compare's 48h plan billed as 24h) reported import/export inflated by the unbilled spillover period - roughly double for a flat load. Mirrored the same fix into the C++ kernel and bumped the parity revision. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
1 parent 400171d commit 6561b9b

9 files changed

Lines changed: 17 additions & 11 deletions

apps/predbat/prediction.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1288,9 +1288,9 @@ def run_prediction(self, charge_limit, charge_window, export_window, export_limi
12881288
if not save and cache:
12891289
self.prediction_cache[sim_hash] = (
12901290
round(final_metric, 4),
1291-
round(import_kwh_battery, 4),
1292-
round(import_kwh_house, 4),
1293-
round(export_kwh, 4),
1291+
round(final_import_kwh_battery, 4),
1292+
round(final_import_kwh_house, 4),
1293+
round(final_export_kwh, 4),
12941294
round(soc_min, 4),
12951295
round(final_soc, 4),
12961296
soc_min_minute,
@@ -1308,9 +1308,9 @@ def run_prediction(self, charge_limit, charge_window, export_window, export_limi
13081308

13091309
return (
13101310
round(final_metric, 4),
1311-
round(import_kwh_battery, 4),
1312-
round(import_kwh_house, 4),
1313-
round(export_kwh, 4),
1311+
round(final_import_kwh_battery, 4),
1312+
round(final_import_kwh_house, 4),
1313+
round(final_export_kwh, 4),
13141314
round(soc_min, 4),
13151315
round(final_soc, 4),
13161316
soc_min_minute,

apps/predbat/prediction_kernel.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
#include <vector>
2828

2929
#define PK_ABI_VERSION 2
30-
#define PK_PARITY_REVISION 2
30+
#define PK_PARITY_REVISION 3
3131
#define PK_MAX_CARS 4
3232
#define PK_RUN_EVERY 5 // const.py RUN_EVERY
3333

@@ -375,6 +375,9 @@ int32_t pk_run(int64_t handle, const PkScenario *s, PkResult *out)
375375
double final_metric_keep = metric_keep;
376376
double final_iboost_kwh = iboost_today_kwh;
377377
double final_carbon_g = carbon_g;
378+
double final_import_kwh_battery = import_kwh_battery;
379+
double final_import_kwh_house = import_kwh_house;
380+
double final_export_kwh = export_kwh;
378381
double charge_rate_now = c->charge_rate_now;
379382
double discharge_rate_now = c->discharge_rate_now;
380383
const bool car_enable = c->num_cars > 0;
@@ -938,6 +941,9 @@ int32_t pk_run(int64_t handle, const PkScenario *s, PkResult *out)
938941
final_metric_keep = metric_keep;
939942
final_iboost_kwh += iboost_amount;
940943
final_carbon_g = carbon_g;
944+
final_import_kwh_battery = import_kwh_battery;
945+
final_import_kwh_house = import_kwh_house;
946+
final_export_kwh = export_kwh;
941947

942948
// Record soc min - prediction.py:1183-1186
943949
if (soc < soc_min) {
@@ -948,9 +954,9 @@ int32_t pk_run(int64_t handle, const PkScenario *s, PkResult *out)
948954
}
949955

950956
out->final_metric = final_metric;
951-
out->import_kwh_battery = import_kwh_battery;
952-
out->import_kwh_house = import_kwh_house;
953-
out->export_kwh = export_kwh;
957+
out->import_kwh_battery = final_import_kwh_battery;
958+
out->import_kwh_house = final_import_kwh_house;
959+
out->export_kwh = final_export_kwh;
954960
out->soc_min = soc_min;
955961
out->final_soc = final_soc;
956962
out->battery_cycle = final_battery_cycle;

apps/predbat/prediction_kernel.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131

3232
# Expected ABI/parity revisions of the shared library (see prediction_kernel.cpp)
3333
KERNEL_ABI_VERSION = 2
34-
KERNEL_PARITY_REVISION = 2
34+
KERNEL_PARITY_REVISION = 3
3535

3636
# Maximum number of cars supported by the kernel (PK_MAX_CARS in prediction_kernel.cpp)
3737
KERNEL_MAX_CARS = 4
48 Bytes
Binary file not shown.
144 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.
372 Bytes
Binary file not shown.
112 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)