Skip to content

Commit

Permalink
Merge pull request #96 from mario-bermonti:refactor-start-end-time
Browse files Browse the repository at this point in the history
Make startTime and endTime fields in the data manager
  • Loading branch information
mario-bermonti committed Feb 25, 2024
2 parents b7d2404 + 4c7ef88 commit b3f200f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class ActivityController extends GetxController {
}

Future<void> endSession() async {
_data.addEndTime(_config.isPractice);
_data.endTime = DateTime.now();
await reset();
Get.back();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class ActivityView extends StatelessWidget {

@override
Widget build(BuildContext context) {
data.addStartTime(_config.isPractice);
data.startTime = DateTime.now();
return Obx(() {
switch (mDigits.taskStep.value) {
case TaskStep.instructions:
Expand Down
28 changes: 18 additions & 10 deletions lib/src/digit_span_task/components/data/data_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import 'package:digit_span_tasks/src/digit_span_task/components/data/data_model.
class DataManager extends GetxController {
final InMemoryDB db = InMemoryDB();
final DSConfig _config = Get.find();
late final DateTime _startTime;
late final DateTime _endTime;
DataModel practiceData = DataModel();
DataModel experimentalData = DataModel();

Expand All @@ -29,18 +31,24 @@ class DataManager extends GetxController {
data.trialData.add(trialData);
}

/// Adds the time at which the session started for the current
/// phase (practice or experimental) based on the [isPractice] flag.
void addStartTime(bool isPractice) {
DataModel data = getData(isPractice);
data.sessionData.startTime = DateTime.now();
/// Sets the start time for the session, but only if this is a practice phase.
/// Practice and experimental phases are considered part of the same session
/// so the start time for the practice phase is considered the beginning of
/// the session.
set startTime(DateTime time) {
if (_config.isPractice) {
_startTime = time;
}
}

/// Adds the time at which the session ended for the current
/// phase (practice or experimental) based on the [isPractice] flag.
void addEndTime(bool isPractice) {
DataModel data = getData(isPractice);
data.sessionData.endTime = DateTime.now();
/// Sets the end time for the session, but only if this is a experimental
/// phase. Practice and experimental phases are considered part of the same
/// session so the end time for the experimental phase is considered the
/// end of the session.
set endTime(DateTime time) {
if (!_config.isPractice) {
_endTime = DateTime.now();
}
}

/// Exports the data collected during the session.
Expand Down

0 comments on commit b3f200f

Please sign in to comment.