Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use the cognitive_data package to manage the data #104

Merged
merged 79 commits into from
Mar 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
79 commits
Select commit Hold shift + click to select a range
b93e358
deps: Add cognitive_data package
mario-bermonti Feb 23, 2024
526e5fa
deps: Add autom updated files after updating deps
mario-bermonti Feb 23, 2024
3fab055
Merge pull request #90 from mario-bermonti:add-cognitive_package
mario-bermonti Feb 23, 2024
ba94e9d
improve: Require sessionID in UserConfig
mario-bermonti Feb 23, 2024
fc246de
improve: Require participantID in UserConfig
mario-bermonti Feb 23, 2024
c90663a
Merge pull request #91 from mario-bermonti:require-participant-sessio…
mario-bermonti Feb 23, 2024
7f70fc1
improve: Add autogenerated changes by flutter
mario-bermonti Feb 23, 2024
9b4500c
improve: Instantiate InMemoryDB in manager
mario-bermonti Feb 24, 2024
2d7b1b5
Merge pull request #92 from mario-bermonti:use-instance-InMemoryDB
mario-bermonti Feb 24, 2024
5bfe9c4
improve: Define SessionType enum
mario-bermonti Feb 24, 2024
4ca4d30
improve: Implement sessionType in ds_config
mario-bermonti Feb 24, 2024
75b799c
improve: Instantiate DSConfig in DataManager
mario-bermonti Feb 24, 2024
b085236
doc: Add docstring to sessionType in DSConfig
mario-bermonti Feb 24, 2024
d2dbfec
Merge pull request #94 from mario-bermonti:session-type
mario-bermonti Feb 24, 2024
bac1a72
maint: Add files autom generated by flutter
mario-bermonti Feb 25, 2024
865179b
refactor: Define participantID in example
mario-bermonti Feb 24, 2024
f8c63d9
refactor: Define sessionID in example
mario-bermonti Feb 25, 2024
3198046
refactor(forward): Use participantID to run task
mario-bermonti Feb 24, 2024
79456a3
refactor(forward): Use sessionID to run task
mario-bermonti Feb 25, 2024
50d18f2
refactor(backwards): Use participantID to run task
mario-bermonti Feb 25, 2024
fda607d
refactor(backwards): Use sessionID to run task
mario-bermonti Feb 25, 2024
b7d2404
Merge pull request #95 from mario-bermonti:fix-issues-session-partici…
mario-bermonti Feb 25, 2024
cffd715
refactor: Implement startTime as field in manager
mario-bermonti Feb 25, 2024
750329a
refactor: Remove addStartTime method
mario-bermonti Feb 25, 2024
fe5bc45
refactor: Implement setter for startTime
mario-bermonti Feb 25, 2024
6c71045
doc: Add docstring to startTime setter
mario-bermonti Feb 25, 2024
33e5fa9
improve: Implement endTime as field in manager
mario-bermonti Feb 25, 2024
6621b6e
refactor: Remove addEndTime method
mario-bermonti Feb 25, 2024
276bf23
refactor: Implement setter for endTime
mario-bermonti Feb 25, 2024
4c7ef88
doc: Add docstring to endTime setter
mario-bermonti Feb 25, 2024
b3f200f
Merge pull request #96 from mario-bermonti:refactor-start-end-time
mario-bermonti Feb 25, 2024
1fb9f7c
refactor: Remove isPractice flag definition
mario-bermonti Feb 26, 2024
1f36cbb
refactor: Remove unneeded refs to isPractice
mario-bermonti Feb 26, 2024
0e98a71
refactor: Use SessionType when resetting task
mario-bermonti Feb 26, 2024
074c177
refactor: Use SessionType in startTime setter
mario-bermonti Feb 26, 2024
b9e4f13
refactor: Use SessionType in endTime setter
mario-bermonti Feb 26, 2024
7c62d56
refactor: Use SessionType in general activity
mario-bermonti Feb 26, 2024
864aea2
refactor: Use SessionType to get stim
mario-bermonti Feb 26, 2024
b4911b9
refactor: Remove getData(), not needed
mario-bermonti Feb 26, 2024
2414e04
refactor: Rename exceptions dir
mario-bermonti Feb 26, 2024
7a80412
improve: Define sessiontype_conversion_exception
mario-bermonti Feb 26, 2024
bcf4754
improve: Define a Session to Trial type map
mario-bermonti Feb 26, 2024
f35ab0d
improve: Impl fun to convert session to trial type
mario-bermonti Feb 27, 2024
dfa2c2e
refactor: Update addTrial impl to use InMemoryDB
mario-bermonti Feb 27, 2024
8ff6f08
doc: Add docstring to session to trial type map
mario-bermonti Feb 27, 2024
a52369e
doc: Add docstring to convertSessionToTrialType()
mario-bermonti Feb 27, 2024
2d6f9b3
doc: Update DataManager.addTrials docstring
mario-bermonti Feb 27, 2024
649a390
maint(example): Remove test for example
mario-bermonti Feb 27, 2024
9fd3899
test: Add test for convertSessionToTrialType()
mario-bermonti Feb 27, 2024
9f8dcb3
test: Add test for convertSessionToTrialType()
mario-bermonti Feb 27, 2024
cb67c2d
refactor: Rename DataManager.addTrial()
mario-bermonti Feb 27, 2024
46eeaf6
Merge pull request #97 from mario-bermonti:integrate-practice-experim…
mario-bermonti Feb 27, 2024
9a0bf3a
improve: Define data model to return to user
mario-bermonti Feb 28, 2024
cf79018
test: Add test for DigitSpanTaskData.toString()
mario-bermonti Feb 28, 2024
423344e
improve: Impl DigitSpanTaskData.toString()
mario-bermonti Feb 28, 2024
a3e2f90
doc: Update docstring DigitSpanTaskData.trials
mario-bermonti Feb 28, 2024
be8157e
doc: Add docstring to DigitSpanTaskData
mario-bermonti Feb 28, 2024
3f86b92
test: Add test DataManager.collectMetadata()
mario-bermonti Feb 29, 2024
2d99644
test: Define setup fun DataManager.collectMetadata
mario-bermonti Mar 1, 2024
e057d7d
test: Add teardown DataManager.collectMetadata test
mario-bermonti Mar 1, 2024
f2cf9a3
improve: Impl DataManager.collect_metadata()
mario-bermonti Feb 29, 2024
ff09e39
doc: Add docstring to DataManager.collectMetadata()
mario-bermonti Mar 1, 2024
15d9f7a
Merge pull request #99 from mario-bermonti:collect-metadata
mario-bermonti Mar 1, 2024
233fe2e
doc: Update DataManager.export docstring
mario-bermonti Mar 1, 2024
15c382e
test: Add test DataManager.export()
mario-bermonti Mar 1, 2024
1baaa69
test: Define participantID in main()
mario-bermonti Mar 2, 2024
a6ff6c1
improve: Impl DataManager.export()
mario-bermonti Mar 1, 2024
6892990
refactor: Fix usage of DataManager.export()
mario-bermonti Mar 2, 2024
f168972
Merge pull request #100 from mario-bermonti:refactor-export-data
mario-bermonti Mar 2, 2024
5392ad2
refactor: Delete DataModel, unused old code
mario-bermonti Mar 2, 2024
5b0d7ad
refactor: Remove refs to DataModel, old code
mario-bermonti Mar 2, 2024
89b7502
refactor: Delete digit_span_tasks_data, old code
mario-bermonti Mar 2, 2024
fa028be
refactor: Fix refs to DigitSpanTaskData
mario-bermonti Mar 2, 2024
c91a734
refactor: Delete TrialData model, old code
mario-bermonti Mar 2, 2024
78fe487
refactor: Delete SessionData model, old code
mario-bermonti Mar 2, 2024
37bed22
Merge pull request #101 from mario-bermonti:clean-old-models-code
mario-bermonti Mar 2, 2024
eb9618b
fix: Remove late from DigitSpanTaskData fields
mario-bermonti Mar 2, 2024
e202fda
Merge pull request #102 from mario-bermonti:fix-late-vars
mario-bermonti Mar 2, 2024
a649a3c
Merge pull request #103 from mario-bermonti/refactor-datamodel-digits…
mario-bermonti Mar 2, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
208 changes: 125 additions & 83 deletions .dart_tool/package_config.json

Large diffs are not rendered by default.

360 changes: 194 additions & 166 deletions .dart_tool/package_config_subset

Large diffs are not rendered by default.

31 changes: 25 additions & 6 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ class MyApp extends StatelessWidget {
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key});

final String participantID = '101';
final String sessionID = '001';

@override
State<MyHomePage> createState() => _MyHomePageState();
}
Expand All @@ -36,15 +39,21 @@ class _MyHomePageState extends State<MyHomePage> {
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
ElevatedButton(
onPressed: runDigitSpanForward,
onPressed: () => runDigitSpanForward(
participantID: widget.participantID,
sessionID: widget.sessionID,
),
child: Text(
'Digit Span Forward',
style: Theme.of(context).textTheme.titleLarge,
),
),
const SizedBox(height: 10),
ElevatedButton(
onPressed: runDigitSpanBackwards,
onPressed: () => runDigitSpanBackwards(
participantID: widget.participantID,
sessionID: widget.sessionID,
),
child: Text(
'Digit Span Backwards',
style: Theme.of(context).textTheme.titleLarge,
Expand All @@ -57,24 +66,34 @@ class _MyHomePageState extends State<MyHomePage> {
);
}

void runDigitSpanForward() async {
void runDigitSpanForward({
required String participantID,
required String sessionID,
}) async {
UserConfig config = UserConfig(
stimListPractice: ['01', '234'],
stimListExperimental: ['5678', '01567', '987654'],
participantID: participantID,
sessionID: sessionID,
);
DigitSpanTasksData data = await Get.to(() => DigitSpanForward(
DigitSpanTaskData data = await Get.to(() => DigitSpanForward(
config: config,
));
// ignore: avoid_print
print('\n\n\nFORWARD data \n $data');
}

void runDigitSpanBackwards() async {
void runDigitSpanBackwards({
required String participantID,
required String sessionID,
}) async {
UserConfig config = UserConfig(
stimListPractice: ['23', '567'],
stimListExperimental: ['0123', '45678', '901234'],
participantID: participantID,
sessionID: sessionID,
);
DigitSpanTasksData data = await Get.to(() => DigitSpanBackwards(
DigitSpanTaskData data = await Get.to(() => DigitSpanBackwards(
config: config,
));
// ignore: avoid_print
Expand Down
4 changes: 4 additions & 0 deletions example/linux/flutter/generated_plugin_registrant.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@

#include "generated_plugin_registrant.h"

#include <sqlite3_flutter_libs/sqlite3_flutter_libs_plugin.h>

void fl_register_plugins(FlPluginRegistry* registry) {
g_autoptr(FlPluginRegistrar) sqlite3_flutter_libs_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "Sqlite3FlutterLibsPlugin");
sqlite3_flutter_libs_plugin_register_with_registrar(sqlite3_flutter_libs_registrar);
}
1 change: 1 addition & 0 deletions example/linux/flutter/generated_plugins.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#

list(APPEND FLUTTER_PLUGIN_LIST
sqlite3_flutter_libs
)

list(APPEND FLUTTER_FFI_PLUGIN_LIST
Expand Down
4 changes: 4 additions & 0 deletions example/macos/Flutter/GeneratedPluginRegistrant.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@
import FlutterMacOS
import Foundation

import path_provider_foundation
import shared_preferences_foundation
import sqlite3_flutter_libs

func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin"))
SharedPreferencesPlugin.register(with: registry.registrar(forPlugin: "SharedPreferencesPlugin"))
Sqlite3FlutterLibsPlugin.register(with: registry.registrar(forPlugin: "Sqlite3FlutterLibsPlugin"))
}
65 changes: 65 additions & 0 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,29 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.1"
cognitive_data:
dependency: transitive
description:
path: "."
ref: HEAD
resolved-ref: "1ccab9a918c15db74a7b8b35aa7bc5d0079a31ae"
url: "https://github.com/mario-bermonti/cognitive_data.git"
source: git
version: "0.0.1"
collection:
dependency: transitive
description:
name: collection
url: "https://pub.dartlang.org"
source: hosted
version: "1.16.0"
convert:
dependency: transitive
description:
name: convert
url: "https://pub.dartlang.org"
source: hosted
version: "3.1.0"
cupertino_icons:
dependency: "direct main"
description:
Expand All @@ -50,6 +66,13 @@ packages:
relative: true
source: path
version: "0.0.1"
drift:
dependency: transitive
description:
name: drift
url: "https://pub.dartlang.org"
source: hosted
version: "1.7.1"
fake_async:
dependency: transitive
description:
Expand Down Expand Up @@ -156,6 +179,27 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.8.2"
path_provider:
dependency: transitive
description:
name: path_provider
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.15"
path_provider_android:
dependency: transitive
description:
name: path_provider_android
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.27"
path_provider_foundation:
dependency: transitive
description:
name: path_provider_foundation
url: "https://pub.dartlang.org"
source: hosted
version: "2.2.1"
path_provider_linux:
dependency: transitive
description:
Expand Down Expand Up @@ -294,6 +338,20 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.9.0"
sqlite3:
dependency: transitive
description:
name: sqlite3
url: "https://pub.dartlang.org"
source: hosted
version: "1.8.0"
sqlite3_flutter_libs:
dependency: transitive
description:
name: sqlite3_flutter_libs
url: "https://pub.dartlang.org"
source: hosted
version: "0.5.20"
stack_trace:
dependency: transitive
description:
Expand Down Expand Up @@ -338,6 +396,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "0.4.9"
typed_data:
dependency: transitive
description:
name: typed_data
url: "https://pub.dartlang.org"
source: hosted
version: "1.3.2"
vector_math:
dependency: transitive
description:
Expand Down
30 changes: 0 additions & 30 deletions example/test/widget_test.dart

This file was deleted.

3 changes: 3 additions & 0 deletions example/windows/flutter/generated_plugin_registrant.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@
#include "generated_plugin_registrant.h"

#include <permission_handler_windows/permission_handler_windows_plugin.h>
#include <sqlite3_flutter_libs/sqlite3_flutter_libs_plugin.h>

void RegisterPlugins(flutter::PluginRegistry* registry) {
PermissionHandlerWindowsPluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("PermissionHandlerWindowsPlugin"));
Sqlite3FlutterLibsPluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("Sqlite3FlutterLibsPlugin"));
}
1 change: 1 addition & 0 deletions example/windows/flutter/generated_plugins.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

list(APPEND FLUTTER_PLUGIN_LIST
permission_handler_windows
sqlite3_flutter_libs
)

list(APPEND FLUTTER_FFI_PLUGIN_LIST
Expand Down
2 changes: 1 addition & 1 deletion lib/digit_span_tasks.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ library digit_span_tasks;

export 'src/digit_span_forward.dart';
export 'src/digit_span_backwards.dart';
export 'src/digit_span_task/components/data/digit_span_tasks_data.dart';
export 'src/digit_span_task/components/data/digit_span_task_data.dart';
export 'src/digit_span_task/components/config/user_config.dart';
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:digit_span_tasks/src/digit_span_task/components/config/session_type.dart';
import 'package:get/get.dart';
import 'package:digit_span_tasks/src/digit_span_task/components/data/data_manager.dart';
import 'package:digit_span_tasks/src/digit_span_task/components/activity/task_step.dart';
Expand Down Expand Up @@ -47,14 +48,14 @@ class ActivityController extends GetxController {
}

Future<void> endSession() async {
_data.addEndTime(_config.isPractice);
_data.endTime = DateTime.now();
await reset();
Get.back();
}

/// Resets the important settings so another session can be run.
Future<void> reset() async {
taskStep(TaskStep.instructions);
_config.isPractice = true;
_config.sessionType = SessionType.practice;
}
}
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
7 changes: 4 additions & 3 deletions lib/src/digit_span_task/components/config/ds_config.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:digit_span_tasks/src/digit_span_task/components/config/session_type.dart';
import 'package:get/get.dart';
import 'package:digit_span_tasks/src/digit_span_task/components/config/user_config.dart';

Expand All @@ -6,9 +7,9 @@ import 'package:digit_span_tasks/src/digit_span_task/components/config/user_conf
class DSConfig extends GetxController {
final UserConfig userConfig;

/// The [isPractice] flag controls whether the practice or experimental should
/// be presented and how to store the data.
bool isPractice = true;
/// Controls whether the practice or experimental should be presented and
/// how to manage the data.
SessionType sessionType = SessionType.practice;

DSConfig({required this.userConfig});
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import 'package:cognitive_data/models/trial_type.dart';
import 'package:digit_span_tasks/src/digit_span_task/components/config/session_type.dart';
import 'package:digit_span_tasks/src/digit_span_task/components/exceptions/sessiontype_conversion_exception.dart';

/// Maps from a [SessionType] to the corresponding [TrialType].
/// This mapping is essential because creating a [Trial] object requires a
/// [TrialType], and this conversion provides a straightforward way to obtain
/// the required [TrialType] based on the given [SessionType].
const Map<SessionType, TrialType> sessionToTrialTypeMap = {
SessionType.practice: TrialType.practice,
SessionType.experimental: TrialType.experimental,
};

/// Converts a [SessionType] to the corresponding [TrialType].
///
/// Given a [SessionType], this function looks up the corresponding
/// [TrialType] using the [sessionToTrialTypeMap]. If a match is found,
/// it returns the associated [TrialType]. If no match is found, a
/// [DSTSessionTypeConversionException] is thrown.
TrialType convertSessionToTrialType(SessionType sessionType) {
final TrialType? trialType = sessionToTrialTypeMap[sessionType];
if (trialType == null) {
throw DSTSessionTypeConversionException();
}
return trialType;
}
2 changes: 2 additions & 0 deletions lib/src/digit_span_task/components/config/session_type.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/// Identifies whether it is a practice or experimental session
enum SessionType { practice, experimental }
15 changes: 15 additions & 0 deletions lib/src/digit_span_task/components/config/user_config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,24 @@ class UserConfig extends GetxController {
/// are randomized (e.g., "123" may be turned into "213").
late final List<String> stimListExperimental;

/// ID that uniquely identifies this participant's session.
/// It will be used to pair the different data collected by [digit_span_tasks]
/// for the participant's particular session. So it is essential that
/// the [sessionID] is an unique identifier across all the sessions for this
/// participant.
final String sessionID;

/// ID that uniquely identifies this participant.
/// It will be used to pair the different data collected by [digit_span_tasks]
/// for the participant. So it is essential that the [participantID] is an
/// unique identifier across all participant.
final String participantID;

UserConfig({
required stimListPractice,
required stimListExperimental,
required this.sessionID,
required this.participantID,
}) {
this.stimListPractice = randomizeDigitsInSets(stimListPractice);
this.stimListExperimental = randomizeDigitsInSets(stimListExperimental);
Expand Down
Loading
Loading