Commit f746899
Refresh prices every price point, not once a day (#1257)
* Refresh prices every price point, not once a day
The price plot labels every bar from the live browser clock, refreshed
every 15 minutes, but reads the array starting at the cursor in the last
importprice.json payload. Those two clocks drift apart, because the
prices are only refetched when the current price changes, or once a day:
priceFetchTimeout = setTimeout(getPrices, ((24-date.getHours())*3600000)+10)
For an hour of staleness every bar shows the price of the hour before
its label, so a modifier configured to start at 23 appears to start at
00. Users on a spot price never see it, since the hourly change of the
current price refetches the payload for them. On a fixed price the
current price only changes when a modifier does, so the plot drifts a
bar per hour for as long as the page stays open, and keeps showing
yesterday's array for up to 59 minutes past midnight.
Rearm on the next price point instead, the way getDayPlot() already
rearms on the next hour.
Reported in #1255
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
* Advance the price cursor by the points passed since the fetch
Refreshing on every price point keeps the cursor current, but only while
the device answers. A failed or delayed fetch puts the plot back to
labelling from the live clock while indexing from an old cursor, and it
mislabels silently.
Stamp the payload when it arrives and skip the points that have passed
since, so a stale payload draws the bars it still has under the right
labels and then runs out, rather than drawing the wrong ones.
Price points start on the whole hour in the price zone, which is a whole
number of hours from UTC, so counting them off epoch boundaries needs no
timezone handling.
Reported in #1255
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>1 parent 4d5c80c commit f746899
3 files changed
Lines changed: 19 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
123 | 123 | | |
124 | 124 | | |
125 | 125 | | |
| 126 | + | |
126 | 127 | | |
127 | 128 | | |
128 | 129 | | |
129 | 130 | | |
130 | 131 | | |
131 | 132 | | |
| 133 | + | |
132 | 134 | | |
133 | 135 | | |
134 | 136 | | |
| 137 | + | |
| 138 | + | |
135 | 139 | | |
136 | | - | |
| 140 | + | |
| 141 | + | |
137 | 142 | | |
138 | 143 | | |
139 | 144 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
42 | 42 | | |
43 | 43 | | |
44 | 44 | | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
45 | 53 | | |
46 | 54 | | |
47 | 55 | | |
| |||
0 commit comments