2021-11-07 20:13:28 +00:00
|
|
|
import 'package:diameter/main.dart';
|
2021-10-22 23:08:09 +00:00
|
|
|
import 'package:diameter/models/log_event.dart';
|
2021-11-07 20:13:28 +00:00
|
|
|
import 'package:diameter/models/log_meal.dart';
|
|
|
|
import 'package:diameter/objectbox.g.dart';
|
2021-10-22 23:08:09 +00:00
|
|
|
|
2021-11-09 00:17:35 +00:00
|
|
|
@Entity(uid: 752131069307970560)
|
2021-10-22 23:08:09 +00:00
|
|
|
class LogEntry {
|
2021-11-07 20:13:28 +00:00
|
|
|
static final Box<LogEntry> box = objectBox.store.box<LogEntry>();
|
|
|
|
|
|
|
|
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<LogEvent>();
|
|
|
|
|
|
|
|
@Backlink('endLogEntry')
|
|
|
|
final endedEvents = ToMany<LogEvent>();
|
|
|
|
|
|
|
|
@Backlink('logEntry')
|
|
|
|
final meals = ToMany<LogMeal>();
|
|
|
|
|
|
|
|
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<LogEntry> getAll() => box.getAll();
|
|
|
|
static void put(LogEntry logEntry) => box.put(logEntry);
|
|
|
|
static void remove(int id) => box.remove(id);
|
|
|
|
|
|
|
|
static Map<DateTime, List<LogEntry>> getDailyEntryMap() {
|
2021-10-23 20:57:37 +00:00
|
|
|
Map<DateTime, List<LogEntry>> dateMap = <DateTime, List<LogEntry>>{};
|
2021-11-07 20:13:28 +00:00
|
|
|
|
|
|
|
QueryBuilder<LogEntry> allByDate = box.query()..order(LogEntry_.time, flags: Order.descending);
|
|
|
|
List<LogEntry> entries = allByDate.build().find();
|
2021-10-23 20:57:37 +00:00
|
|
|
DateTime? date;
|
|
|
|
|
|
|
|
for (LogEntry entry in entries) {
|
|
|
|
date = DateTime.utc(entry.time.year, entry.time.month, entry.time.day);
|
|
|
|
dateMap.putIfAbsent(date, () => <LogEntry>[]).add(entry);
|
|
|
|
}
|
|
|
|
|
|
|
|
return dateMap;
|
|
|
|
}
|
2021-10-22 23:08:09 +00:00
|
|
|
}
|