Repository navigation
import: let a longer noop export finish a partial day #1001
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6825,7 +6825,9 @@ class DerivationEngine { | |
| // so importing a file that overlaps real history destroyed it | ||
| // silently and permanently. Same guard the WHOOP importer has always | ||
| // had; it just was not shared. | ||
| if (await LocalDb.isMeasuredDay(day.date)) { | ||
| final existing = await LocalDb.dayResult(day.date); | ||
| if (LocalDb.isMeasuredDayRow(existing) && | ||
| !importReachesFurther(existing, dataNowSec)) { | ||
| _log('import day ${day.date} kept (already measured on this device)'); | ||
| continue; | ||
| } | ||
|
|
@@ -7891,7 +7893,14 @@ class DerivationEngine { | |
| // test compares the row's wake with THIS edge, not a fresher one read | ||
| // later: ingest keeps committing during a pass, and a newer edge would | ||
| // call a night settled whose wake came from a truncated substrate. | ||
| payloadJson: jsonEncode({...bundle, 'data_edge_sec': dataNowSec}), | ||
| payloadJson: jsonEncode({ | ||
| ...bundle, | ||
| 'data_edge_sec': dataNowSec, | ||
| // An import's snapshot of however much its file held: a later import | ||
| // reaching further into the day may replace it | ||
| // ([importReachesFurther]). Only deriveImportedDays force-finalizes. | ||
| if (forceFinalize && suppliedSubstrate) 'import_snapshot': true, | ||
|
Comment on lines
+7897
to
+7902
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Stop carrying When a band derive's second half fails, Treat Suggested fix
|
||
| }), | ||
| windowJson: jsonEncode( | ||
| ((day.sleepJson['window'] as Map?) ?? const {}).cast<String, dynamic>(), | ||
| ), | ||
|
|
@@ -8991,6 +9000,21 @@ class DerivationEngine { | |
| static Map<String, dynamic>? _decodeBundle(Object? json) => | ||
| SeriesCodec.decodePayloadJson(json); | ||
|
|
||
| /// True when [row] was written by an earlier [deriveImportedDays] and the | ||
| /// new import's [edgeSec] reaches past the edge that row was derived | ||
| /// against. An export taken mid-day force-finalizes that day from the | ||
| /// morning only; a later, longer export of the same range must be able to | ||
| /// finish it. The same file again, or an older shorter one, reaches no | ||
| /// further and keeps the row. A band-derived row never carries the marker. | ||
| @visibleForTesting | ||
| static bool importReachesFurther(Map<String, dynamic>? row, int edgeSec) { | ||
| if (row == null) return false; | ||
| final p = _decodeBundle(row['payload_json']); | ||
| if (p == null || p['import_snapshot'] != true) return false; | ||
| final prevEdge = (p['data_edge_sec'] as num?)?.toInt(); | ||
| return prevEdge != null && edgeSec > prevEdge; | ||
| } | ||
|
|
||
| /// One `day_result` row as a cross-day input record, with the per-day | ||
| /// masks the rollup needs. Static and pure so it runs in the isolate. | ||
| @visibleForTesting | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bump the analytics version for the changed output.
A longer import can now replace a result that the previous code kept, but the new result still uses
kAlgoVersion = 133. Add a version bump and changelog entry. As per coding guidelines, “BumpkAlgoVersionwhenever any analytics output changes” and “Add a changelog entry above the constant.”Source: Coding guidelines