diet-guard/app/lib/models/day_status.dart
Krzysztof kuhy Rudnicki 957769ff0e
Some checks are pending
pre-commit / pre-commit (push) Waiting to run
Tests / test (3.10) (push) Waiting to run
Tests / test (3.11) (push) Waiting to run
Tests / test (3.12) (push) Waiting to run
Add budget-adherence calendar, streaks, and freely-editable synced budget
Both platforms gain a calendar tab/screen (green/yellow/red/not-logged
day coloring, logging/adherence streaks, year-to-date tally), and
tapping a day drills into that day's logged entries. This requires the
daily budget to become a normal, freely-editable value synced between
devices like the food log — replaces the previous chattr +i seal
(deliberately, per user decision) with plain last-edit-wins sync via a
new budget.json alongside food_log.json. The budget field defaults to
2200 kcal, starts read-only, and unlocks via an Edit/Save toggle on
both the PC gate's History tab and the phone app's Calendar screen.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016dHac1iYQKTMZEtL7xDJvA
2026-07-13 21:31:45 +02:00

58 lines
1.5 KiB
Dart

/// Per-day budget-adherence status and year-to-date tally value types.
library;
import 'package:flutter/foundation.dart';
/// Qualitative per-day budget-adherence state, worst to best.
///
/// Kept in sync with `diet_guard/_daystatus.py`'s `DayStatus`: not-logged is
/// considered worse than red, since an unlogged day carries no information
/// about whether it went well or badly.
enum DayStatus {
/// No valid, non-tombstoned entries were logged for the day.
notLogged,
/// Logged, and more than 20% over budget.
red,
/// Logged, and up to 20% over budget.
yellow,
/// Logged, and at or under budget.
green,
}
/// Year-to-date logging/adherence counts.
@immutable
class YtdTally {
/// Creates a tally from its three component counts.
const YtdTally({
required this.loggedDays,
required this.elapsedDays,
required this.adherentDays,
});
/// Days this year with at least one valid log entry.
final int loggedDays;
/// Days from Jan 1 through the reference date, inclusive.
final int elapsedDays;
/// Of [loggedDays], how many were green or yellow.
final int adherentDays;
@override
bool operator ==(Object other) =>
other is YtdTally &&
other.loggedDays == loggedDays &&
other.elapsedDays == elapsedDays &&
other.adherentDays == adherentDays;
@override
int get hashCode => Object.hash(loggedDays, elapsedDays, adherentDays);
@override
String toString() =>
'YtdTally(logged: $loggedDays/$elapsedDays, adherent: $adherentDays)';
}