Make the Sud forecast piecewise, computed once per segment
Previously, the dynamic forecast's projected remainder was fully
recomputed on every step change, and a step requiring user
confirmation was simulated with zero added delay ("count it as
instant for estimation purposes"). Both undercut the actual goal of
the forecast: an honest comparison between real control behavior and
a simulation-based prediction. A forecast that keeps re-anchoring
itself to match reality isn't a useful baseline to compare reality
against, and assuming zero confirmation delay quietly understates the
schedule.
components/sud_forecast.py: SudForecastEstimator.estimate() now stops
simulating at the first step requiring user confirmation instead of
auto-confirming, returning the final SudState alongside the data so
the caller knows whether it stopped there or actually finished.
tasks/sud.py: SudTask now accumulates the forecast across piecewise
segments (forecast_t/forecast_theta). send_forecast() computes only
the first segment, at Load/Save. The real Confirm handler triggers
_continue_forecast_after_confirm(), which computes the next segment
anchored at the real elapsed time and real current temperature -
bridging the unforecastable wait with a flat segment rather than
guessing at its length - and sends the updated, stitched Forecast
(now carrying a Finished flag). The old per-step-change
RemainingForecast recompute is gone entirely, along with
remaining_schedule()/send_remaining_forecast().
client/brewpi_gui.py: SudForecastPlot redesigned around this - the
dashed line is the fixed, piecewise forecast (locked axes, untouched
except when a genuinely new segment arrives via show_forecast());
the solid line is purely the actual measured trace
(show_dynamic(), now only touching that). extend_forecast_while_
waiting() repeats the forecast's last value while the real Sud sits
in WAIT_USER, so the dashed line doesn't just stop, then snaps to the
new segment the moment the real confirmation appends one.
Verified via a raw-protocol test (segment boundaries, the Finished
flag, and real-time stitching across a confirm delay) and visually in
the GUI (locked dashed forecast, "X min so far total" title while
incomplete, solid/dashed comparison rendering with realistic
convergence/divergence).
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LhiQe64F74uHV8jzuoSa5K
This commit is contained in:
+18
-12
@@ -34,17 +34,27 @@ class SudForecastEstimator:
|
||||
self.theta_amb = theta_amb
|
||||
|
||||
def estimate(self, doc, start_theta=None):
|
||||
"""Returns (t, theta): parallel lists of elapsed simulated seconds
|
||||
and temperature, one point per tick, for the given sud.json
|
||||
document. start_theta defaults to the configured ambient
|
||||
temperature - i.e. a cold start, same as the GUI's static
|
||||
estimate."""
|
||||
"""Returns (t, theta, final_state): t/theta are parallel lists of
|
||||
elapsed simulated seconds and temperature for one piecewise
|
||||
segment of the schedule, starting from doc['steps'][0] - either
|
||||
all the way to the end (final_state is SudState.DONE), or, if a
|
||||
step requires user confirmation, only up to and including that
|
||||
step's hold (final_state is SudState.WAIT_USER). A real user's
|
||||
confirm time can't be forecast, so the simulation simply stops
|
||||
there instead of guessing zero delay or otherwise - the caller is
|
||||
expected to compute the next segment for real once the user
|
||||
actually confirms (see tasks/sud.py's SudTask), anchored at
|
||||
whatever the real elapsed time and temperature are by then,
|
||||
rather than this estimate continuing to guess at it.
|
||||
|
||||
start_theta defaults to the configured ambient temperature - i.e.
|
||||
a cold start, same as the GUI's static estimate."""
|
||||
if start_theta is None:
|
||||
start_theta = self.theta_amb
|
||||
|
||||
sud = Sud()
|
||||
if not sud.load(doc) or not sud.schedule:
|
||||
return [0.0], [start_theta]
|
||||
return [0.0], [start_theta], SudState.DONE
|
||||
|
||||
pot = Pot(self.dt, self.plant_params, self.theta_amb)
|
||||
pot.initial(start_theta)
|
||||
@@ -80,7 +90,7 @@ class SudForecastEstimator:
|
||||
|
||||
sud.start()
|
||||
ticks = 0
|
||||
while sud.state != SudState.DONE and ticks < MAX_TICKS:
|
||||
while sud.state not in (SudState.DONE, SudState.WAIT_USER) and ticks < MAX_TICKS:
|
||||
pot.process()
|
||||
tc.set_theta_ist(pot.get_temperature())
|
||||
tc.process()
|
||||
@@ -89,14 +99,10 @@ class SudForecastEstimator:
|
||||
if sud.state == SudState.RAMPING:
|
||||
if tc.is_holding():
|
||||
sud.temp_reached()
|
||||
elif sud.state == SudState.WAIT_USER:
|
||||
# A real user's confirm time isn't predictable - count it
|
||||
# as instant for estimation purposes.
|
||||
sud.confirm()
|
||||
sud.tick(self.dt)
|
||||
|
||||
t.append(t[-1] + self.dt)
|
||||
theta.append(pot.get_temperature())
|
||||
ticks += 1
|
||||
|
||||
return t, theta
|
||||
return t, theta, sud.state
|
||||
|
||||
Reference in New Issue
Block a user