Skip to content

Commit 4d5d9a0

Browse files
author
=
committed
Fixed missing plan events
Octopus Power Up and Power down events were missing from plan view. Resolved horizontal scroll issue on Config page in mobile view.
1 parent 1787591 commit 4d5d9a0

12 files changed

Lines changed: 53 additions & 12 deletions

File tree

‎apps/predbat/frontend.zip‎

97 Bytes
Binary file not shown.

‎apps/predbat/octopus.py‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4185,10 +4185,16 @@ def fetch_octopus_sessions(self, axle_sessions=None):
41854185
octopus_free_slot["start"] = start
41864186
octopus_free_slot["end"] = end
41874187
octopus_free_slot["rate"] = 0
4188+
if event.get("event_type", None):
4189+
octopus_free_slot["event_type"] = event["event_type"]
41884190
octopus_free_slots.append(octopus_free_slot)
41894191
# Direct Octopus URL
41904192
if "octopus_free_url" in self.args:
41914193
free_online = self.download_octopus_free(self.get_arg("octopus_free_url", indirect=False))
4194+
for slot in free_online:
4195+
# The public website feed exposes only times and a zero rate. Keep
4196+
# that provenance so the UI does not guess Power Up or Happy Hour.
4197+
slot.setdefault("event_type", "FREE_ELECTRICITY")
41924198
octopus_free_slots.extend(free_online)
41934199

41944200
# Load free electricity events from Octopus flexibility API
@@ -4205,6 +4211,8 @@ def fetch_octopus_sessions(self, axle_sessions=None):
42054211
octopus_free_slot["start"] = start
42064212
octopus_free_slot["end"] = end
42074213
octopus_free_slot["rate"] = 0
4214+
if event.get("event_type", None):
4215+
octopus_free_slot["event_type"] = event["event_type"]
42084216
octopus_free_slots.append(octopus_free_slot)
42094217

42104218
# Octopus saving session
@@ -4364,7 +4372,7 @@ def fetch_octopus_sessions(self, axle_sessions=None):
43644372
continue
43654373
if abs((start_time - self.now_utc).days) <= 3:
43664374
self.log("Octopus: Joined Octopus Weekend Happy Hour {}-{} - treating as a free electricity session".format(start_time.strftime("%a %d/%m %H:%M"), end_time.strftime("%H:%M")))
4367-
octopus_free_slots.append({"start": start, "end": end, "rate": 0})
4375+
octopus_free_slots.append({"start": start, "end": end, "rate": 0, "event_type": "WEEKEND_HAPPY_HOUR"})
43684376
continue
43694377

43704378
# Skip events with no rate info unless default is configured

‎apps/predbat/output.py‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,12 @@ def event_slot_contains_minute(slot, minute, midnight_utc, start_key="start", en
7373

7474
def plan_rate_event_type(base, minute):
7575
"""Return the programme that produced a plan row's generic ``saving`` rate tag."""
76-
if any(event_slot_contains_minute(slot, minute, base.midnight_utc) for slot in base.octopus_free_slots):
76+
matching_free_slots = [slot for slot in base.octopus_free_slots if event_slot_contains_minute(slot, minute, base.midnight_utc)]
77+
if any(slot.get("event_type") == "WEEKEND_HAPPY_HOUR" for slot in matching_free_slots):
78+
return "octopus_happy_hour"
79+
if any(slot.get("event_type") == "FREE_ELECTRICITY" for slot in matching_free_slots):
80+
return "octopus_free_electricity"
81+
if matching_free_slots:
7782
return "octopus_power_up"
7883
for slot in base.octopus_saving_slots:
7984
active_undated_slot = slot.get("state") and not slot.get("start") and not slot.get("end") and (base.minutes_now // 30) * 30 <= minute < (base.minutes_now // 30) * 30 + 30

‎apps/predbat/tests/test_plan_json_rate_adjust.py‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,14 @@ def run_test_plan_json_rate_adjust(my_predbat):
152152
event_cases = [
153153
("octopus_power_down", [{"start": event_start, "end": event_end}], [], []),
154154
("octopus_power_up", [], [{"start": event_start, "end": event_end}], []),
155+
("octopus_free_electricity", [], [{"start": event_start, "end": event_end, "event_type": "FREE_ELECTRICITY"}], []),
156+
("octopus_happy_hour", [], [{"start": event_start, "end": event_end, "event_type": "WEEKEND_HAPPY_HOUR"}], []),
157+
(
158+
"octopus_happy_hour",
159+
[],
160+
[{"start": event_start, "end": event_end}, {"start": event_start, "end": event_end, "event_type": "WEEKEND_HAPPY_HOUR"}],
161+
[],
162+
),
155163
("axle_export", [], [], [{"start_time": event_start, "end_time": event_end, "import_export": "export"}]),
156164
]
157165
try:

‎apps/predbat/tests/test_saving_session.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1547,7 +1547,7 @@ def run(joined_yaml):
15471547
print(" Test 1: WEEKEND_HAPPY_HOUR is free, TURN_DOWN is a saving slot")
15481548
octopus_free_slots, octopus_saving_slots = run(happy_hour + "\n" + turn_down_rewarded)
15491549

1550-
expected_free = [{"start": "{}T11:00:00+{}:00".format(date_today, tz_offset), "end": "{}T12:00:00+{}:00".format(date_today, tz_offset), "rate": 0}]
1550+
expected_free = [{"start": "{}T11:00:00+{}:00".format(date_today, tz_offset), "end": "{}T12:00:00+{}:00".format(date_today, tz_offset), "rate": 0, "event_type": "WEEKEND_HAPPY_HOUR"}]
15511551
expected_saving = [{"start": "{}T17:00:00+{}:00".format(date_today, tz_offset), "end": "{}T18:00:00+{}:00".format(date_today, tz_offset), "rate": 50.0, "state": False}]
15521552
if json.dumps(octopus_free_slots) != json.dumps(expected_free):
15531553
print("ERROR: Expecting free slots {} got {}".format(expected_free, octopus_free_slots))

‎frontend/src/components/PlanSummary.css‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,10 @@
355355
grid-column: 4;
356356
}
357357

358+
.plan-summary-next-label-compact {
359+
display: none;
360+
}
361+
358362
.plan-summary-context-now,
359363
.plan-summary-context-next {
360364
position: relative;
@@ -375,3 +379,14 @@
375379
.plan-summary-context-next::after {
376380
right: 0;
377381
}
382+
383+
@media (max-width: 900px) {
384+
.plan-summary-context,
385+
.plan-summary-next-label-desktop {
386+
display: none;
387+
}
388+
389+
.plan-summary-next-label-compact {
390+
display: block;
391+
}
392+
}

‎frontend/src/components/PlanSummary.tsx‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -613,7 +613,9 @@ function PlanSummary({ plan, showPlanLink = true }: PlanSummaryProps) {
613613
Next action family, its window and final planned limit.
614614
-------------------------------------------------------- */}
615615
<div className="plan-summary-metric">
616-
<span className="metric-label">Action</span>
616+
<span className="metric-label plan-summary-next-label-desktop">Action</span>
617+
618+
<span className="metric-label plan-summary-next-label-compact">Next action</span>
617619

618620
<strong className={`metric-value action-value ${getActionClass(nextActionType)}`}>
619621
{nextActionType && getActionIcon(nextActionType)}

‎frontend/src/components/PlanTable.css‎

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,13 @@
3333
}
3434

3535
.plan-table {
36-
width: 100%;
37-
min-width: 1120px;
38-
table-layout: fixed;
36+
width: max-content;
37+
min-width: 100%;
38+
table-layout: auto;
3939
border-collapse: collapse;
4040
font-size: 0.72rem;
4141
}
4242

43-
.plan-table.is-debug {
44-
min-width: 1420px;
45-
}
46-
4743
.plan-debug-notice {
4844
display: flex;
4945
flex-wrap: wrap;

‎frontend/src/components/PlanTable.tsx‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,11 @@ const RATE_EVENT_DETAILS: Record<string, { label: string; description: string; c
5757
description: 'Octopus Weekend Happy Hour: Predbat has applied the free electricity rate to this slot.',
5858
colour: 'power-up'
5959
},
60+
octopus_free_electricity: {
61+
label: 'Free electricity',
62+
description: 'Free electricity session from an untyped public feed: Predbat has applied the zero rate to this slot.',
63+
colour: 'power-up'
64+
},
6065
axle_import: {
6166
label: 'Axle import',
6267
description: 'Axle import event: Predbat has applied the event reward to this slot.',

‎frontend/src/components/PlanVisual.tsx‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ const RATE_EVENT_DETAILS: Record<NonNullable<PlanRow['rate_event_type']>, { labe
8080
octopus_power_down: { label: 'Power Down', colour: 'power-down' },
8181
octopus_power_up: { label: 'Power Up', colour: 'power-up' },
8282
octopus_happy_hour: { label: 'Happy Hour', colour: 'power-up' },
83+
octopus_free_electricity: { label: 'Free electricity', colour: 'power-up' },
8384
axle_import: { label: 'Axle import', colour: 'axle-import' },
8485
axle_export: { label: 'Axle export', colour: 'axle-export' },
8586
axle_event: { label: 'Axle event', colour: 'axle-event' },

0 commit comments

Comments
 (0)