Repository navigation
06: Day metrics and app integration on retained calculation state - #108
Draft
mikenrafter wants to merge 19 commits into
Draft
mikenrafter wants to merge 19 commits into
mikenrafter wants to merge 19 commits into
Conversation
Apply the batch clock refusal before touching retained state for regressions and supplied length mismatches. Keep the replacement and force fixture monotonic by shifting its suffix, and cover invalid clocks separately.
There was a problem hiding this comment.
Sorry @mikenrafter, this pull request is too large to review
It changes 47,344 lines. Sourcery can review pull requests with up to 20,000 changed lines.
|
Important Draft PR not reviewedDraft PRs are not automatically reviewed by default.
To automatically review draft PRs, update your CodeRabbit configuration: reviews:
auto_review:
drafts: true
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. |
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.
Depends on 05 / #107.
Depends on 04 / #106.
Depends on 03 / #105.
Depends on 02 / #104.
Depends on 01 / #103.
This is part 06 of the split of #99. It targets
main, so its diff also contains the earlier parts until they merge. Its own changes are the commits listed under "Suggested review order". After each earlier part merges, I'll mergemaininto this branch so the diff shrinks to this part alone.The per-area states cannot support application adoption without keyed day consumers, dependency rules and end-to-end parity checks. This finishes the stack with incremental HRV/motion/minute consumers, energy contributions, the calculation-group registry and cross-area research/benchmark tools.
What changes
incremental.dartlibrary and its HRV, motion, minute and checkpoint parts, keeping their shared compilation unit intact.No runtime dependency is added. The source retains Task Force 1996 HRV, Banister/Morton TRIMP, Keytel 2005, Mifflin-St Jeor 1990 and Tudor-Locke 2019 energy citations. Internal policy remains explicitly ESTIMATE. Missing coverage, cadence, profile or reference evidence keeps its existing absence/provenance rules. The parent owns changed batch arithmetic and its Edge
kAlgoVersionrequirement; the final frozen checks pin this stack to those outputs. The area 2 gap-aware screen change remains part of adoption.Algebraic breakdown
CalculationModecalculation_cache_test.dartchecks every mode's bypass/reuse behavior and exact invocation counters.CalculationCacheadoptionIncrementalHrvTimesyncvalidates prefix and parameters, adds new data or rebuilds; finish constructs HRV and invokes batch on documented jitter/refusal paths. Checkpointed ordered prefix fold.hrv_time_test.dart, drift, checkpoint andincremental_laws_test.dart: chunk/restart/detour invariance, empty/idempotent sync, conservation, refusal atomicity, malformed checkpoint checks. Valuesmax(1e-9, abs(expected)*1e-8), presence/counts/metadata exact. Checkpoint text equal after removing work counters as specified by laws._MotionBin,IncrementalEnmoSeriesmax(1e-9, abs(expected)*1e-8), counts/absence/provenance exact. Magnitudes are retained because exact deviation depends on a moving center.MinuteEnergyPricer,Calories._bill, source/abstention enumsIncrementalMinuteMetrics.sync(includeMinuteSeries: false)minute_summary_test.dartcompares summary and batch results through append/restore/edit cases, numericmax(1e-9, abs(expected)*1e-8), exact null minute artifacts and metadata. Walking is included once in active total.MinuteEnergy,MinuteEnergySeries,HourlyEnergy,Calories.assembleMinuteEnergySeries, minute/hourly/daily energy viewsminute_energy_test.dart, minute summary and metric tests check totals, keys, counts, sources, abstention and hourly grouping under the existing numeric comparisons._MinuteBill,MinuteMetrics,IncrementalMinuteMetricssyncreplaces changed key contributions, removes missing keys, reprices on profile/anchor changes and finishes TRIMP/strain/energy/views. Keyed edit-aware fold, not a monoid: duplicate keys are refused and replacement order matters.max(1e-9, abs(expected)*1e-8), chunk/restart/detour consistency, idempotence and invalid-input atomicity.IncrementalLombScargleintegration andRunningMoments/IntHistogramproperty lawsincremental_laws_test.dartadds all sync laws and explicit associative/commutative/identity merge tests for moments/histogram. Histogram exact; moments/PSD use the file's numeric helper and independent moment/histogram references. Batch spectral comparisons share production helpers and establish path parity.GroupKind,InputScope,InputDecl,GroupDecl,GroupRegistry, declarations and validationregistry_closure_test.dartverifies required declarations, public symbols, dependency cycles and actual import/export/part closure; not a scientific estimator test.adopted_aggregators_test.dartrequires batch versus one-slice bit identity; original per-area reference/law tests retain chunk tolerances.phase0_parity_test.dartand parenttool/reproduce_outputs.dartpin the frozen parent outputs. Persistence tests preserve NaN-aware per-element comparisons for matcher 0.12.17.bench_*, probes, benchmark driversday_curves_test.darttests the research consumers with full shared inputs. Benchmark timing output is not treated as a correctness test.incremental.dartuses Dartpartfiles and private helpers shared by HRV, motion, minutes and codecs. Keeping that compilation unit together avoids temporary duplicate state/codec APIs. Empty sync identity and idempotent same-prefix sync are transition laws; they do not imply these objects have an associative state merge.Where the speedup comes from
The app reprices old minutes at every sync, so this PR adds keyed daily-energy state and the integration support needed to keep it. This PR: 0.000 of the 109.065 s saved per night (0.00%). Overall after the full stack: 13.98×.
See the sync-work explanation in #103 for the timeline, overall table and Edge adoption requirement; these are AOT medians from at least five full schedules on generated data, with this PR credited only beyond #102 and its inherited gains included in the overall saving.
How each structure saves work
HRV and fixed-grid spectral arithmetic append only new points on eligible paths. Motion reuses trailing gravity and per-minute contributions. Keyed minute metrics reprice affected minutes and keep aggregate bills; dependency changes trigger exact rebuilds. Dependency memoization returns already-computed results when inputs are unchanged. Whole calls still validate/copy prefixes, motion sorts the supplied valid input, minute sync visits supplied keys and result/checkpoint rendering scales with retained output. Therefore these full APIs are not uniformly O(new data), even when expensive estimator arithmetic is.
Fresh timings are in "Where the speedup comes from" above. Older numbers in the docs predate this split. Historical evidence is retained with its input and limitations in
docs/AGGREGATOR_DESIGN.md,docs/COMBINED_BUMP_STATUS.mdand the preceding localPR-aggregators.md.tool/bench_aggregate.dartuses 30,000 synthetic beats;tool/bench_night_nn.dartdefaults to seeds 1/2/3 and 32 overnight prefixes;tool/incremental_benchmark.dartreports elapsed time and processed-work counters on its deterministic fixture.tool/bench_phase0.dartandtool/bench_night_bins.dartuse the frozen phase-0 source.tool/combined_bump_probe.dartoptionally reads the original capture, so old real-night timings are not reproducible from the replacement fixture. The original docs' earlier failure/status narratives are historical snapshots, not the validation result for this stack.Tests
Full suite on this branch with Dart 3.13.0: 2,805 passed, 7 skipped, 0 failed.
dart analyze(Dart 3.11.4) reports no issues. Counts include the earlier parts' tests. The 7 skips are existing checks that need data outside the repo: six need a localwhoop_hist.jsonlcapture, and one wall-clock agreement test needs the DREAMT corpus.The first full run after merging part 05 had one failure:
IncrementalHrvTime.syncaccepted a regressing clock that the batch HRV path refuses since #102.9b23985makes it hand regressing or length-mismatched clocks to the batch path before touching its retained state. It adds two tests that failed before the fix. The existing replacement test moved one timestamp so that the next one regressed. It now shifts the whole suffix, so its original assertions still run on valid input.Suggested review order
b3237d6Day metrics and integration tools need reusable calculation state. Read the state and append transitions first, then the finish rules, then the joint law, persistence and adoption tests.d608d98merges part 05. OnlyCHANGELOG.mdconflicted; both sides are kept.9b23985Refuse invalid clocks in incremental HRV.Change size
This part's own changes, measured against part 05:
lib/+1,781/-35 in 8 files; tests, tools and docs +10,817/-74 in 33 files. The tests are large because this part carries the 3,172-line joint incremental law suite and the 986-line cross-metric persistence suite, which need every earlier part.Questions for the reviewer
MAX(timestamp):COUNT(*)?