Repository navigation
Faster, more robust processes: shared feed I/O, base classes, tests and bug fixes - #39
Open
TrystanLea wants to merge 5 commits into
Open
TrystanLea wants to merge 5 commits into
TrystanLea wants to merge 5 commits into
Conversation
- tests/run.php runs process tests against synthetic feeds, no database or redis required, with tests for existing processes and common code - FeedReader/FeedWriter in common.php read and write feeds in blocks, check writes, resample to a common timeline and update redis - resolve_start_time() implements recent/from/all in one place - Runner reports exceptions thrown by a process as a failed process - Fix interval setting validation using $processitem->key - backfillfeed uses FeedReader/FeedWriter, rejects an empty target Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Simple value by value processes now only implement value($value): - MapProcess: scalefeed, offsetfeed, allowpositive, allownegative - InPlaceProcess: to_signed, limit_morethan_lessthan, remove_morethan_lessthan, removenan_lastvalue Fixes: - from mode past the end of the output left a 0.0 gap - reprocess all left stale data beyond the end of the input - redis time is the last datapoint, NAN is never set as last value - to_signed always reported 0 datapoints modified - remove_morethan_lessthan setting label typos Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Converted: addfeeds, mergefeeds, importcalc, exportcalc, solardirectcalc, powertokwh, accumulator, constantflow_tokwh, liquidorairflow_tokwh and basic_formula. Inputs are read in blocks, 11-17x faster for two and three input processes. Inputs with a shorter interval are averaged into each output interval and only complete output intervals are written. Fixes: - powertokwh/accumulator: filtered values shifted later output data - basic_formula: feed ids that are prefixes of others (f1, f12) not read - basic_formula: from mode appended a duplicate copy of the output - solardirectcalc: redis update used a non existent setting - constantflow/liquidorairflow ignored the process mode - combine processes overwrote output meta in recent mode Reprocess all now replaces an output feed with a different start time or interval. Removes unused compute_meta, bfo takes values rather than file handles. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ModelHelper reads inputs and writes outputs in 8192 datapoint blocks rather than one at a time and keeping all output in memory. On a year of 10s data: carnot_cop_simulator 7.8s to 2.6s, 51MB to 3MB; batterysimulator 6.2s to 4.5s, 228MB to 8MB; solarbatterykwh unchanged at 3MB and slightly faster. Fixes, tested by processing in several runs giving the same output as a single run: - carnot_cop_simulator: first run shifted outputs one interval later, each run counted the step it continued from twice - batterysimulator: each run counted the step it continued from twice in state of charge and kWh totals, off-peak charging stopped at run boundaries (now restored from the stored state of charge) - solarbatterykwh: the 12 hour backcast counted one step twice - runs starting in a gap hold the last valid value from before the run batterysimulator works out the local hour only when it changes. Tests add snapshots of single runs from the previous code, which the new code matches exactly. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The parsed formula is evaluated one operation at a time over a block of datapoints rather than for each datapoint separately, 5-7x faster on 1M datapoints. A test compares the output byte for byte with a per datapoint reference evaluation on random data with gaps and zeros. Fixes: - division by zero gives a missing value rather than 0 - a literal 0 is kept, f1*0 was evaluated as f1*1 - result message no longer converts a NAN last value to a string Parsing is split out into parse_formula(), ftoa() moves from common.php to basic_formula.php and bfo() is replaced by the block evaluator. Co-Authored-By: Claude Opus 5.5 <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.
Reworks how post processes read and write feeds. Most processes now share block-based feed access and a few base classes, so each one is only its calculation. Adds a test suite that needs no database or redis, and fixes a number of bugs the tests found, several of which silently corrupted output data.
Speed and memory
Measured on synthetic data, old vs new; outputs are identical apart from the bug fixes listed below.
f1-0.5*f2+max(f3-21,0))Memory no longer grows with the amount of data processed. Previously batterysimulator held all 18 outputs in memory until the end, which would need over 1 GB to recalculate several years of data.
Structure
FeedReader/FeedWriter(common.php): block reads and writes, resampling onto a common timeline, checked writes (a full disk is an error rather than silent truncation), meta written with the data, redis last time/value set to the last datapoint.resolve_start_time(): one implementation of recent / from / all.MapProcess(input → output) andInPlaceProcess(modify a feed in place): implementvalue($x).CombineProcess(several inputs → output, optionally accumulating): implementrow($a, $b, ...).ModelHelperkeeps the same API, rebuilt on the reader/writer.backfillfeed. Extends a feed that has stopped recording from another feed recording the same quantity. It only ever appends after the target's current end.Bug fixes
f1andf12never read feed 12;f1*0was evaluated asf1*1.0.0gap. "Reprocess all" left stale data beyond the end of the input.Behaviour changes to be aware of
Testing
php tests/run.phpruns 86 tests against synthetic feeds in a temporary directory:Not yet converted: removenan, average, downsample, upsample.
🤖 Generated with Claude Code