cpd_2022_zi/lib/models/sleep.dart

48 lines
1.5 KiB
Dart
Raw Normal View History

import 'package:flutter/material.dart';
import 'package:smoke_cess_app/interface/db_record.dart';
import 'package:smoke_cess_app/utils/timer_util.dart';
class Sleep implements DatabaseRecord {
final int _sleepQualityValue;
final String _comment;
final DateTime _date;
2023-02-26 17:07:38 +01:00
final TimeOfDay _sleptAt;
final TimeOfDay _wokeUpAt;
2023-02-26 17:07:38 +01:00
Sleep(this._sleepQualityValue, this._comment, this._date, this._sleptAt,
this._wokeUpAt);
2023-03-02 18:35:03 +01:00
DateTime get date => _date;
2023-03-06 14:53:50 +01:00
String get comment => _comment;
2023-03-03 12:47:54 +01:00
int get sleepQualitiyValue => _sleepQualityValue;
TimeOfDay get sleepDuration => _sleptAt.durationBetween(_wokeUpAt);
2023-03-02 18:35:03 +01:00
@override
factory Sleep.fromDatabase(Map<String, dynamic> map) {
DateTime date = DateTime.parse(map['date']);
2023-02-26 17:07:38 +01:00
TimeOfDay sleptAt =
TimeOfDay(hour: map['sleptAtHour'], minute: map['sleptAtMinute']);
TimeOfDay wokeUpAt =
TimeOfDay(hour: map['wokeUpAtHour'], minute: map['wokeUpAtMinute']);
2023-02-26 17:07:38 +01:00
return Sleep(map['value'], map['comment'], date, sleptAt, wokeUpAt);
}
@override
String toCSV() {
2023-02-26 17:07:38 +01:00
return "${_date.toIso8601String()}, $_sleepQualityValue, ${_sleptAt.hour}:${_sleptAt.minute}, ${_wokeUpAt.hour}:${_wokeUpAt.minute}, $_comment";
}
2023-02-22 01:28:01 +01:00
@override
Map<String, dynamic> toMap() {
return {
'value': _sleepQualityValue,
2023-02-22 01:28:01 +01:00
'comment': _comment,
'date': _date.toIso8601String(),
2023-02-26 17:07:38 +01:00
'sleptAtHour': _sleptAt.hour,
'sleptAtMinute': _sleptAt.minute,
'wokeUpAtHour': _wokeUpAt.hour,
'wokeUpAtMinute': _wokeUpAt.minute,
2023-02-22 01:28:01 +01:00
};
}
}