import 'package:diameter/main.dart'; import 'package:diameter/models/log_bolus.dart'; import 'package:diameter/models/log_event.dart'; import 'package:diameter/models/log_meal.dart'; import 'package:diameter/objectbox.g.dart'; @Entity(uid: 752131069307970560) class LogEntry { static final Box box = objectBox.store.box(); int id; @Property(type: PropertyType.date) DateTime time; int? mgPerDl; double? mmolPerL; double? bolusGlucose; int? delayedBolusDuration; double? delayedBolusRate; String? notes; @Backlink('logEntry') final events = ToMany(); @Backlink('endLogEntry') final endedEvents = ToMany(); @Backlink('logEntry') final meals = ToMany(); @Backlink('logEntry') final boli = ToMany(); LogEntry({ this.id = 0, required this.time, this.mgPerDl, this.mmolPerL, this.bolusGlucose, this.delayedBolusDuration, this.delayedBolusRate, this.notes, }); static LogEntry? get(int id) => box.get(id); static List getAll() => box.getAll(); static void put(LogEntry logEntry) => box.put(logEntry); static void remove(int id) => box.remove(id); static Map> getDailyEntryMap() { Map> dateMap = >{}; QueryBuilder allByDate = box.query() ..order(LogEntry_.time, flags: Order.descending); List entries = allByDate.build().find(); DateTime? date; for (LogEntry entry in entries) { date = DateTime.utc(entry.time.year, entry.time.month, entry.time.day); dateMap.putIfAbsent(date, () => []).add(entry); } return dateMap; } }