diff --git a/lib/ui2/screens/day_timeline.dart b/lib/ui2/screens/day_timeline.dart index 65e0c4b5d..32fcfea52 100644 --- a/lib/ui2/screens/day_timeline.dart +++ b/lib/ui2/screens/day_timeline.dart @@ -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'; @@ -96,7 +97,7 @@ class DayNote { Map _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), @@ -104,6 +105,9 @@ Map _events(AppLocalizations? l) => { 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. @@ -244,11 +248,16 @@ List dayMoments({ // times, and a day with the charger on it should not read as four chargers. final seen = {}; final events = _events(l); + final taps = []; 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); + continue; + } out.add(Moment( at: t, title: def.$1, @@ -256,6 +265,29 @@ List dayMoments({ 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( + at: taps[i], + until: n > 1 ? taps[j] : null, + title: tap.$1, + detail: n > 1 + ? '${clockOfTs(taps[i])}–${clockOfTs(taps[j])} · $n×' + : clockOfTs(taps[i]), + icon: tap.$2, + )); + i = j + 1; + } for (final m in meals) { final t = m.atTs; diff --git a/test/day_timeline_test.dart b/test/day_timeline_test.dart index 3ce9c72ae..f4d10125e 100644 --- a/test/day_timeline_test.dart +++ b/test/day_timeline_test.dart @@ -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);