Skip to content

Commit

Permalink
Merge pull request #184 from QuantumPhysique/issue183
Browse files Browse the repository at this point in the history
Fix estimation of streak
  • Loading branch information
braniii authored Jan 5, 2025
2 parents 5caa8dc + 5acd374 commit c91c548
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 16 deletions.
22 changes: 10 additions & 12 deletions app/lib/core/measurementStats.dart
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,10 @@ class MeasurementStats {
int get nMeasurements => ip.NMeasurements;

/// get current streak
Duration get currentStreak => Duration(days: streakList.last.round());
Duration get currentStreak =>
db.lastDate.sameDay(DateTime.now())
? Duration(days: streakList.last.round())
: Duration.zero;

/// get max streak
Duration get maxStreak => Duration(days: streakList.max().round());
Expand All @@ -73,18 +76,13 @@ class MeasurementStats {
Vector get streakList => _streakList ??= _estimateStreakList();
Vector _estimateStreakList() {
int streak = 0;
final List<int> streakList = <int>[0];
for (int i = 0; i < ip.isMeasurement.length; i++) {
if (DateTime.fromMillisecondsSinceEpoch(ip.times[i].toInt()).day
<= DateTime.now().day + 1) {
final bool isMS = ip.isMeasurement[i].round() == 1;
final List<int> streakList = <int>[0]; // catch for no measurements
for (final double isMS in ip.isMeasurement) {
if (isMS.round() == 1) {
streak++;
if (!isMS) {
if ((streakList.last > 0) | (streak >= 2)) {
streakList.add(streak - 1);
}
streak = 0;
}
} else if (streak > 0) {
streakList.add(streak);
streak = 0;
}
}
return Vector.fromList(streakList);
Expand Down
1 change: 0 additions & 1 deletion app/lib/pages/settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -833,7 +833,6 @@ class _Settings extends State<Settings> {
),
const LanguageListTile(),
const UnitsListTile(),
const InterpolationListTile(),
const FirstDayListTile(),
const DatePrintListTile(),
Divider(
Expand Down
6 changes: 3 additions & 3 deletions app/lib/widget/addWeightDialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,9 @@ Future<bool> showAddWeightDialog({
return;
}
currentDate = DateTime(
date.year,
date.month,
date.day,
currentDate.year,
currentDate.month,
currentDate.day,
time.hour,
time.minute,
);
Expand Down

0 comments on commit c91c548

Please sign in to comment.