Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 33 additions & 1 deletion lib/ui2/screens/day_timeline.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import '../../compute/inputs/measurement_inputs.dart'
import '../../compute/profile.dart' show bmiOf;
import '../../data/coverage_resolver.dart' show OwnedSpan, coverageFromJson, spanAt;
import '../../data/day_label.dart' show localDayEndSec;
import '../../data/triathlon_store.dart' show kTriathlonDoubleTapEventId;
import '../../data/db.dart';
import '../../data/journal_fields.dart';
import '../../data/local_repository.dart';
Expand Down Expand Up @@ -96,14 +97,17 @@ class DayNote {
Map<int, (String, IconData)> _events(AppLocalizations? l) => {
7: (l?.dayTimelineChargerOn ?? 'On the charger', LucideIcons.batteryCharging),
8: (l?.dayTimelineChargerOff ?? 'Off the charger', LucideIcons.batteryFull),
14: (l?.dayTimelineDoubleTap ?? 'You double-tapped the band', LucideIcons.hand),
kTriathlonDoubleTapEventId: (l?.dayTimelineDoubleTap ?? 'You double-tapped the band', LucideIcons.hand),
15: (l?.dayTimelineRestarted ?? 'The band restarted', LucideIcons.rotateCw),
21: (l?.dayTimelineBatteryPackAttached ?? 'Battery pack attached',
LucideIcons.batteryCharging),
22: (l?.dayTimelineBatteryPackRemoved ?? 'Battery pack removed', LucideIcons.battery),
57: (l?.dayTimelineAlarmWentOff ?? 'Alarm went off', LucideIcons.alarmClock),
};

/// Double-taps closer together than this are one run on the timeline.
const int kDoubleTapRunGapSec = 10 * 60;

/// An off-wrist gap shorter than this is a dropout, not an event in a day.
/// Listing every one of them would bury the four that mean something under
/// forty that mean the strap moved.
Expand Down Expand Up @@ -244,18 +248,46 @@ List<Moment> dayMoments({
// times, and a day with the charger on it should not read as four chargers.
final seen = <String>{};
final events = _events(l);
final taps = <int>[];
for (final e in (timeline['events'] as List?) ?? const []) {
if (e is! Map) continue;
final id = asInt(e['event_id']), t = asInt(e['ts']);
final def = id == null ? null : events[id];
if (def == null || t == null || !seen.add('$id/$t')) continue;
if (id == kTriathlonDoubleTapEventId) {
taps.add(t);
Comment thread
sourcery-ai[bot] marked this conversation as resolved.
Resolved
continue;
}
out.add(Moment(
at: t,
title: def.$1,
detail: clockOfTs(t),
icon: def.$2,
));
}
// Double-taps in a run (a ball sport sets the firmware's tap detector off on
// every contact) are one span carrying the band's own count, not one line
// per tap burying the rest of the day.
taps.sort();
final tap = events[kTriathlonDoubleTapEventId]!;
for (var i = 0; i < taps.length;) {
var j = i;
while (j + 1 < taps.length &&
taps[j + 1] - taps[j] < kDoubleTapRunGapSec) {
j++;
}
final n = j - i + 1;
out.add(Moment(
Comment thread
sourcery-ai[bot] marked this conversation as resolved.
Resolved
at: taps[i],
until: n > 1 ? taps[j] : null,
title: tap.$1,
detail: n > 1
? '${clockOfTs(taps[i])}–${clockOfTs(taps[j])} · $n×'
Comment thread
sourcery-ai[bot] marked this conversation as resolved.
Resolved
: clockOfTs(taps[i]),
icon: tap.$2,
));
i = j + 1;
}

for (final m in meals) {
final t = m.atTs;
Expand Down
35 changes: 35 additions & 0 deletions test/day_timeline_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,41 @@ void main() {
expect(m, hasLength(2));
});

test('a run of double-taps is one line with its count, not one per tap',
() {
// Volleyball: every ball contact the firmware reads as a double-tap. The
// run stays on the page (it happened, and the count is the band's), but
// as one span instead of forty lines burying the day.
final m = dayMoments(timeline: {
'day_start': _day,
'events': [
for (var i = 0; i < 14; i++) {'event_id': 14, 'ts': _at(18, 2 + i * 4)},
// A tap on its own hours later is still its own line.
{'event_id': 14, 'ts': _at(21)},
],
});
expect(m, hasLength(2));
final run = m.first;
expect(run.at, _at(18, 2));
expect(run.until, _at(18, 54));
expect(run.detail, contains('14×'));
expect(m.last.at, _at(21));
expect(m.last.until, isNull);
expect(m.last.detail, isNot(contains('×')));
});

test('taps exactly 10 minutes apart are two lines', () {
final m = dayMoments(timeline: {
'day_start': _day,
'events': [
{'event_id': 14, 'ts': _at(18)},
{'event_id': 14, 'ts': _at(18, 10)},
],
});
expect(m, hasLength(2));
expect(m.every((x) => x.until == null), isTrue);
});

test('a meal with no time is never placed, and is not lost either', () {
const timed = FoodEntry(
id: 'a', date: '2026-08-14', meal: 'Lunch', label: 'Soup', kcal: 300);
Expand Down