feat: implement background LLM pattern analysis on Insights screen

Adds a prompt builder that serialises 7-day mood/activity data, wires
InsightNotifier to call the on-device LLM directly (no user interaction),
caches results by prompt hash, and renders the analysis as a passive card.
Includes loading, empty (<2 entries), and error states with a force-refresh button.
This commit is contained in:
2026-04-26 14:37:37 +10:00
parent d1b18c5296
commit ea412d6fe9
4 changed files with 322 additions and 48 deletions
+16
View File
@@ -84,6 +84,22 @@ class MoodDao extends DatabaseAccessor<AppDatabase> with _$MoodDaoMixin {
.getSingleOrNull()) != null;
}
// Entries with their linked activities — used by LLM prompt builder
Future<List<MoodEntryWithActivities>> getEntriesWithActivitiesInRange(
DateTime start, DateTime end) async {
final entries = await getEntriesInRange(start, end);
return Future.wait(entries.map((e) async {
final links = await (select(entryActivities)
..where((t) => t.entryId.equals(e.id)))
.get();
final actIds = links.map((l) => l.activityId).toList();
final acts = actIds.isEmpty
? <Activity>[]
: await (select(activities)..where((t) => t.id.isIn(actIds))).get();
return MoodEntryWithActivities(entry: e, activities: acts, tags: []);
}));
}
// Average mood per day — used by calendar heatmap
Future<Map<DateTime, double>> getDailyAverages(
DateTime start, DateTime end) async {