feat(nfdrs): add Driver state persistence - #26
Merged
Conversation
Add the DriverState type and the State and SetState methods. DriverState holds the state of the four Nelson sticks, the two live fuel moisture models, the drought index, and the driver's daily accumulators and last outputs. It marshals to JSON and back with an exact round trip. A caller can now snapshot a warm driver and restore it, so a restart does not repeat the spin-up that the 1000-hour stick needs from a cold start. The caller constructs the driver with the same Config, then restores the state. SetState checks the schema version and that every sub-model is present. Add JSON tags to the Indices type, so the stored state has stable keys. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Add
Driver.State()andDriver.SetState(), so a caller can persist a warmdriver and resume without the spin-up. This is the piece an ingest service
needs: the 1000-hour stick has a long time lag, so a cold start needs about six
weeks of history before the energy release component is right. With a saved
state, a restart resumes at once.
What it adds
DriverStateholds the state of the four Nelson sticks, the two live fuelmoisture models, the drought index, and the driver's daily accumulators and
last outputs.
Driver.State()returns the state.Driver.SetState()restores it. Thecaller constructs the driver with the same
Configfirst.SetStatechecks the schema version and that every sub-model is present.Indicestype gets JSON tags, so the stored state has stable keys.Validation
TestDriverStateRoundTripruns a driver across two daily boundaries, marshalsthe state to JSON, restores it into a second driver, and confirms:
further weather.
TestDriverSetStateErrorschecks thatSetStaterejects a wrong schema versionand an absent sub-model. Passes in the workspace and in isolation.
Why now
This unblocks the backfill: a year of history streams through the driver in one
pass, then
State()snapshots the warm driver for a live ingest service. Seethe storage schema proposed in lfprocks/timescale-migrations#6.
🤖 Generated with Claude Code