Skip to content

Commit 6eae202

Browse files
committed
Copy the split logic from HTML to JSON generation
1 parent beceff8 commit 6eae202

File tree

1 file changed

+39
-5
lines changed

1 file changed

+39
-5
lines changed

apps/predbat/predbat.py

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4235,8 +4235,23 @@ def publish_json_plan(self, pv_forecast_minute_step, pv_forecast_minute_step10,
42354235
metric_end = self.predict_metric_best.get(minute_relative_slot_end, metric_start)
42364236
metric_change = metric_end - metric_start
42374237

4238+
soc_sym = ""
4239+
if abs(soc_change) < 0.05:
4240+
soc_sym = "(hold)"
4241+
elif soc_change >= 0:
4242+
soc_sym = "(increasing)"
4243+
else:
4244+
soc_sym = "(decreasing)"
4245+
42384246
slot["state"] = {}
42394247

4248+
slot['state']['mode'] = soc_sym
4249+
if minute in self.manual_idle_times:
4250+
slot['state']['mode'] += " Idle"
4251+
slot['state']['override'] = True
4252+
split = False
4253+
4254+
42404255
slot["state"]["soc"] = {}
42414256
slot["state"]["soc"]["percent"] = soc_percent
42424257
slot["state"]["soc"]["percent_end"] = soc_percent_end
@@ -4289,25 +4304,44 @@ def publish_json_plan(self, pv_forecast_minute_step, pv_forecast_minute_step10,
42894304
if start > minute:
42904305
soc_change_this = self.predict_soc_best.get(max(start - self.minutes_now, 0), 0.0) - self.predict_soc_best.get(minute_relative_start, 0.0)
42914306
slot["state"]["soc"]["change"] = self.dp2(soc_change_this)
4307+
if soc_change_this >= 0:
4308+
slot['state']['mode'] = " (increasing)"
4309+
elif soc_change_this < 0:
4310+
slot['state']['mode'] = " (decreasing)"
4311+
else:
4312+
slot['state']['mode'] = " (hold)"
42924313

42934314
if discharge_window_n >= 0:
42944315
limit = self.discharge_limits_best[discharge_window_n]
42954316
if limit == 99:
4296-
# TODO: figure out the split state logic, and how to reflect it here
4297-
slot["state"]["mode"] = "Freeze discharge"
4317+
if state == soc_sym:
4318+
state = ""
4319+
if state:
4320+
split = True
4321+
slot["state"]["mode"] += " - "
4322+
slot["state"]["mode"] += "Freeze discharge"
42984323
slot["state"]["limit"] = limit
4324+
42994325
elif limit < 100:
4300-
# TODO: figure out the split state logic, and how to reflect it here
4326+
if state == soc_sym:
4327+
state = ""
4328+
if state:
4329+
slot["state"]["mode"] += " - "
4330+
split = True
43014331
if limit > soc_percent_max:
4302-
slot["state"]["mode"] = "Hold discharge"
4332+
slot["state"]["mode"] += "Hold discharge"
43034333
else:
4304-
slot["state"]["mode"] = "Discharge"
4334+
slot["state"]["mode"] += "Discharge"
43054335
slot["state"]["limit"] = limit
43064336

43074337
if self.discharge_window_best[discharge_window_n]["start"] in self.manual_discharge_times:
43084338
slot["state"]["override"] = True
4339+
slot["state"]["mode"] += "Manual discharge"
43094340
elif self.discharge_window_best[discharge_window_n]["start"] in self.manual_freeze_discharge_times:
43104341
slot["state"]["override"] = True
4342+
slot["state"]["mode"] += "Freeze discharge"
4343+
4344+
slot["state"]["split"] = split
43114345

43124346
slot["rate"] = {}
43134347
slot["rate"]["start"] = rate_start.strftime("%a %H:%M")

0 commit comments

Comments
 (0)