Skip to content

Commit

Permalink
Merge pull request #18 from mario-bermonti:process-data
Browse files Browse the repository at this point in the history
[improvement] Accept function that processes data
  • Loading branch information
mario-bermonti committed Sep 1, 2023
2 parents b784d6c + e001037 commit d2a91bd
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 16 deletions.
6 changes: 5 additions & 1 deletion example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@ class _MyHomePageState extends State<MyHomePage> {
ElevatedButton(
onPressed: () {
List<String> stimList = ['012', '9876', '567890'];
Get.put(MDigits(stimList: stimList));
MDigits mDigits = Get.put(MDigits(
stimList: stimList,
participantID: '000',
processData: print,
));
},
child: Text(
'Comenzar mDigits',
Expand Down
4 changes: 1 addition & 3 deletions lib/activity/trial_response/trial_response_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,9 @@ class TrialResponseController extends GetxController {
}

void submit() {
// spaces are meaningless as in paper and pencil measures
String response = textController.text.trim();

_mDigits.addTrialData(resp: response);
textController.clear();
// _mDigits.addTrialData(result: response);
}

void toNextScreen() {
Expand Down
38 changes: 26 additions & 12 deletions lib/mdigits.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'package:mdigits/activity/trial_stim/stim_controller.dart';
import 'package:mdigits/activity/trial_response/trial_response_view.dart';
import 'package:mdigits/activity/trial_stim/trial_stim_view.dart';
import 'package:mdigits/end/end_view.dart';
import 'package:mdigits/models/trial_data.dart';
import 'package:mdigits/rest/rest_view.dart';

import 'activity/begin_view.dart';
Expand All @@ -14,6 +15,10 @@ class MDigits extends GetxController {
/// Provides access and manages the stimuli
late final StimController _stimuli;

/// Data for all trials
/// Used to provide data to app
final List<TrialData> data = <TrialData>[];

/// Global task start time
final DateTime _timeStart = DateTime.now();

Expand All @@ -26,29 +31,34 @@ class MDigits extends GetxController {
Step _status = Step.stim;

final List<String> stimList;

MDigits({required this.stimList});

final String participantID;
@override
onInit() async {
await _setup();
super.onInit();
}

Function(List<TrialData> value)? processData;

MDigits({
required this.stimList,
required this.participantID,
this.processData,
});

@override
onReady() {
Get.to(() => BeginView(beginFunction: run));
}

/// Add trial data to the db
// void addTrialData({required String result}) {
// _database.addTrialData(
// participantId: _participantId,
// stim: _stimuli.stim.currentStim,
// resp: result,
// sessionNumber: _sessionNumber,
// );
// }
void addTrialData({required String resp}) {
TrialData trialData = TrialData(
participantID: participantID,
stim: _stimuli.stim.currentStim,
response: resp,
);
data.add(trialData);
}

// TODO improve name of conditions checks?
/// TODO can presenting stim next be improved? Current implementation seems
Expand Down Expand Up @@ -115,6 +125,10 @@ class MDigits extends GetxController {
case Step.completed:
// _saveData();
Get.off(const EndView());
if (processData != null) {
processData!(data);
}
;
Get.back();
return;
default:
Expand Down
16 changes: 16 additions & 0 deletions lib/models/trial_data.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
class TrialData {
final String participantID;
final String stim;
final String response;

TrialData({
required this.participantID,
required this.stim,
required this.response,
});

@override
String toString() {
return "Participant $participantID, stim: $stim, resp: $response";
}
}

0 comments on commit d2a91bd

Please sign in to comment.