added record models, settings- and db mock

main
Julian Gegner 2023-02-16 01:59:15 +01:00
parent 0792eb1190
commit d14dafe61f
12 changed files with 252 additions and 53 deletions

View File

@ -1,6 +0,0 @@
enum Group {
gruppe1, //HIIT Morgens
gruppe2, //HIIT Abends
gruppe3, //HIIT Morgens + Schach
gruppe4, //HIIT Abends + Schach
}

View File

@ -0,0 +1,3 @@
abstract class DatabaseRecord {
String toCSV();
}

View File

@ -0,0 +1,23 @@
import 'package:smoke_cess_app/interface/db_record.dart';
import 'package:smoke_cess_app/models/mood.dart';
import 'package:smoke_cess_app/models/sleep.dart';
class DatabaseMock {
final List<DatabaseRecord> _moodRecords = [];
final List<DatabaseRecord> _sleepRecords = [];
final List<DatabaseRecord> _workoutRecords = [];
void saveRecord(DatabaseRecord record) {
if (record is Mood) {
_moodRecords.add(record);
} else if (record is Sleep) {
_sleepRecords.add(record);
} else {
_workoutRecords.add(record);
}
}
List<DatabaseRecord> getMoodRecords() => _moodRecords;
List<DatabaseRecord> getSleepRecords() => _sleepRecords;
List<DatabaseRecord> getWorkoutRecords() => _workoutRecords;
}

View File

@ -0,0 +1,15 @@
import 'package:smoke_cess_app/interface/db_record.dart';
class HIITWorkout implements DatabaseRecord {
final Duration _workoutDuration;
final String _commentBefore;
final String _commentAfter;
final DateTime _workoutDate;
HIITWorkout(this._workoutDuration, this._commentBefore, this._commentAfter,
this._workoutDate);
@override
String toCSV() =>
"${_workoutDate.toIso8601String()}, $_workoutDuration, $_commentBefore, $_commentAfter";
}

View File

@ -0,0 +1,14 @@
import 'package:smoke_cess_app/interface/db_record.dart';
class Mood implements DatabaseRecord {
final double _moodValue;
final String _comment;
final DateTime _date;
Mood(this._moodValue, this._comment, this._date);
@override
String toCSV() {
return "${_date.toIso8601String()}, ${_moodValue.round().toString()}, $_comment";
}
}

View File

@ -1,38 +0,0 @@
import 'package:flutter/material.dart';
import 'package:smoke_cess_app/enums/group.dart';
class Settings {
//should use shared preferences package
//https://pub.dev/packages/shared_preferences
Group _group;
TimeOfDay _dailyTrainingStartTime;
late DateTime _experimentStartDate;
Settings(this._group, this._dailyTrainingStartTime) {
_experimentStartDate = DateTime.now();
}
void setGroup(Group group) {
_group = group;
}
void setDailyTrainingStartTime(TimeOfDay time) {
_dailyTrainingStartTime = time;
}
void set(Group group) {
_group = group;
}
Group getGroup() {
return _group;
}
TimeOfDay getDailyTrainingStartTime() {
return _dailyTrainingStartTime;
}
DateTime getExperimentStartDate() {
return _experimentStartDate;
}
}

View File

@ -0,0 +1,18 @@
import 'package:flutter/material.dart';
import 'package:smoke_cess_app/interface/db_record.dart';
class Sleep implements DatabaseRecord {
final double _sleepQualityValue;
final String _comment;
final DateTime _date;
final TimeOfDay _sleepedAt;
final TimeOfDay _wokeUpAt;
Sleep(this._sleepQualityValue, this._comment, this._date, this._sleepedAt,
this._wokeUpAt);
@override
String toCSV() {
return "${_date.toIso8601String()}, ${_sleepQualityValue.round().toString()}, $_sleepedAt, $_wokeUpAt, $_comment";
}
}

View File

@ -1,9 +0,0 @@
import 'package:smoke_cess_app/models/settings.dart';
class Business {
late Settings settings;
void setSettings(Settings settings) {
this.settings = settings;
}
}

View File

@ -0,0 +1,21 @@
import 'package:smoke_cess_app/interface/db_record.dart';
import 'package:smoke_cess_app/mock/db_mock.dart';
class QueryService {
final DatabaseMock _database;
QueryService(this._database);
void addRecord(DatabaseRecord record) => _database.saveRecord(record);
List<DatabaseRecord> getWorkoutRecords() => _database.getWorkoutRecords();
List<DatabaseRecord> getMoodRecords() => _database.getMoodRecords();
List<DatabaseRecord> getSleepRecords() => _database.getSleepRecords();
String recordsToCSV(List<DatabaseRecord> records) {
String csv = "";
for (DatabaseRecord record in records) {
csv += '${record.toCSV()}\n';
}
return csv;
}
}

View File

@ -0,0 +1,25 @@
import 'package:shared_preferences/shared_preferences.dart';
class SettingsService {
final Future<SharedPreferences> _prefs = SharedPreferences.getInstance();
SettingsService() {
setIntSetting('workout_duration_minutes', 5);
}
void setStringSetting(String settingKey, String settingValue) =>
_prefs.then((pref) => pref.setString(settingKey, settingValue));
Future<String?> getStringSetting(String settingKey) =>
_prefs.then((pref) => pref.getString(settingKey));
void setIntSetting(String settingKey, int settingValue) =>
_prefs.then((pref) => pref.setInt(settingKey, settingValue));
Future<int?> getIntSetting(String settingKey) =>
_prefs.then((pref) => pref.getInt(settingKey));
//Add other setters and getters if needed
//other possible SharedPreferences Types: Int, Bool, Double, StringList
//see https://pub.dev/packages/shared_preferences
}

View File

@ -50,6 +50,20 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.3.1"
ffi:
dependency: transitive
description:
name: ffi
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.1"
file:
dependency: transitive
description:
name: file
url: "https://pub.dartlang.org"
source: hosted
version: "6.1.4"
flutter:
dependency: "direct main"
description: flutter
@ -67,6 +81,18 @@ packages:
description: flutter
source: sdk
version: "0.0.0"
flutter_web_plugins:
dependency: transitive
description: flutter
source: sdk
version: "0.0.0"
js:
dependency: transitive
description:
name: js
url: "https://pub.dartlang.org"
source: hosted
version: "0.6.4"
lints:
dependency: transitive
description:
@ -102,6 +128,97 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.8.2"
path_provider_linux:
dependency: transitive
description:
name: path_provider_linux
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.8"
path_provider_platform_interface:
dependency: transitive
description:
name: path_provider_platform_interface
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.5"
path_provider_windows:
dependency: transitive
description:
name: path_provider_windows
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.3"
platform:
dependency: transitive
description:
name: platform
url: "https://pub.dartlang.org"
source: hosted
version: "3.1.0"
plugin_platform_interface:
dependency: transitive
description:
name: plugin_platform_interface
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.3"
process:
dependency: transitive
description:
name: process
url: "https://pub.dartlang.org"
source: hosted
version: "4.2.4"
shared_preferences:
dependency: "direct main"
description:
name: shared_preferences
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.17"
shared_preferences_android:
dependency: transitive
description:
name: shared_preferences_android
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.15"
shared_preferences_foundation:
dependency: transitive
description:
name: shared_preferences_foundation
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.3"
shared_preferences_linux:
dependency: transitive
description:
name: shared_preferences_linux
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.3"
shared_preferences_platform_interface:
dependency: transitive
description:
name: shared_preferences_platform_interface
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.0"
shared_preferences_web:
dependency: transitive
description:
name: shared_preferences_web
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.4"
shared_preferences_windows:
dependency: transitive
description:
name: shared_preferences_windows
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.3"
sky_engine:
dependency: transitive
description: flutter
@ -156,5 +273,20 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.2"
win32:
dependency: transitive
description:
name: win32
url: "https://pub.dartlang.org"
source: hosted
version: "3.1.3"
xdg_directories:
dependency: transitive
description:
name: xdg_directories
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.0"
sdks:
dart: ">=2.18.2 <3.0.0"
flutter: ">=3.0.0"

View File

@ -35,6 +35,7 @@ dependencies:
# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^1.0.2
shared_preferences: ^2.0.17
dev_dependencies:
flutter_test: