The dashboard (Raspberry Pi 3.5" screen + web pages), the end-to-end encrypted sync mailbox (PHP + SQLite) and the Android companion app (Flutter), with docs, clean-install checks and screenshots made from demo data. Built mostly with an AI coding assistant; not yet reviewed line by line by a human (see README and SECURITY.md). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
34 lines
1.5 KiB
Dart
34 lines
1.5 KiB
Dart
// The Pi's Health summaries (dashboard plugins/health/summary.py), synced one way as "health.summary"
|
|
// rows: day:<date>, night:<date>, wk:<id>, meta:energy, meta:person — each {k, kind, day, data (JSON)}.
|
|
// Read-only here: what the band measured, worked out on the Pi with the Health pages' own functions.
|
|
import 'dart:convert';
|
|
|
|
import '../sync/store.dart';
|
|
|
|
class Summaries {
|
|
Summaries(this.store);
|
|
final SyncStore store;
|
|
|
|
Map<String, dynamic>? _get(String k) {
|
|
final r = store.row('health.summary', k);
|
|
return r == null ? null : jsonDecode(r['data'] as String) as Map<String, dynamic>;
|
|
}
|
|
|
|
Map<String, dynamic>? day(String iso) => _get('day:$iso');
|
|
Map<String, dynamic>? night(String iso) => _get('night:$iso');
|
|
Map<String, dynamic>? meta(String name) => _get('meta:$name');
|
|
|
|
/// Every row of a kind (day / night / workout) in [a, z] (ISO days; null = all), by day.
|
|
List<Map<String, dynamic>> all(String kind, {String? a, String? z}) {
|
|
final rs = store.rows('health.summary', where: "json_extract(data, '\$.kind') = ?", args: [kind]);
|
|
final out = <Map<String, dynamic>>[];
|
|
for (final r in rs) {
|
|
final d = r['day'] as String?;
|
|
if (a != null && d != null && d.compareTo(a) < 0) continue;
|
|
if (z != null && d != null && d.compareTo(z) > 0) continue;
|
|
out.add({'_day': d, ...jsonDecode(r['data'] as String) as Map<String, dynamic>});
|
|
}
|
|
out.sort((x, y) => ((x['_day'] as String?) ?? '').compareTo((y['_day'] as String?) ?? ''));
|
|
return out;
|
|
}
|
|
}
|