[Developer] #204 Phase 1 MVP — Flutter app skeleton complete
- Drift 21 tables (8 catalog + 11 user + habit_dose_variants + meta_kv) with R1~R10 CHECK constraints and 19 indexes - 8 hand-crafted seed JSON catalogs in app/assets/seed/ (refs 84, protocols 34, methodologies 21, frame_patterns 30, reward_menu_items 30, break_protocols 8, common_frames 5, diet_patterns 5) - 6 domain functions: recommend_variant, compute_streak, validate_frame_level, active_habit_quota, weekly_minimum_ratio, seed_importer (transactional, idempotent) - 4 vertical-slice Riverpod screens: HabitList, HabitCreate, CheckIn, Streak - 31 unit tests passing; flutter analyze clean - OQ-5 streak semantics: missing entry ≠ explicit blank (missing = end of history; only TrackerValue.blank triggers Never-miss-twice) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
42
app/lib/domain/rules/active_habit_quota.dart
Normal file
42
app/lib/domain/rules/active_habit_quota.dart
Normal file
@@ -0,0 +1,42 @@
|
||||
import '../models/habit.dart';
|
||||
|
||||
/// R1/R2: max active habits per type.
|
||||
/// - build: ≤ 3
|
||||
/// - break: ≤ 1
|
||||
const int kMaxActiveBuild = 3;
|
||||
const int kMaxActiveBreak = 1;
|
||||
|
||||
class QuotaResult {
|
||||
final HabitType type;
|
||||
final int currentCount;
|
||||
final int limit;
|
||||
final bool allowed;
|
||||
|
||||
const QuotaResult({
|
||||
required this.type,
|
||||
required this.currentCount,
|
||||
required this.limit,
|
||||
required this.allowed,
|
||||
});
|
||||
|
||||
String get reason {
|
||||
if (allowed) return 'ok';
|
||||
return type == HabitType.build
|
||||
? 'build habit quota reached (≤ $kMaxActiveBuild active)'
|
||||
: 'break habit quota reached (≤ $kMaxActiveBreak active)';
|
||||
}
|
||||
}
|
||||
|
||||
/// Pure judgment: caller passes in the current active count.
|
||||
QuotaResult judgeActiveHabitQuota({
|
||||
required HabitType type,
|
||||
required int currentActiveCount,
|
||||
}) {
|
||||
final limit = type == HabitType.build ? kMaxActiveBuild : kMaxActiveBreak;
|
||||
return QuotaResult(
|
||||
type: type,
|
||||
currentCount: currentActiveCount,
|
||||
limit: limit,
|
||||
allowed: currentActiveCount < limit,
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user