From 65fe0f4f23be42e8d5085cd776e88e63cd6207af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mario=20E=2E=20Bermonti-P=C3=A9rez?= Date: Tue, 26 Mar 2024 09:17:26 -0400 Subject: [PATCH 1/4] improve: Impl FirebaseDB.addTrial --- lib/databases/firebase_db/firebase_db.dart | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/lib/databases/firebase_db/firebase_db.dart b/lib/databases/firebase_db/firebase_db.dart index 811a144..3247bc5 100644 --- a/lib/databases/firebase_db/firebase_db.dart +++ b/lib/databases/firebase_db/firebase_db.dart @@ -81,8 +81,19 @@ class FirebaseDB implements DB { } @override - void addTrial({required Trial trial}) { - // TODO: implement addTrial + Future addTrial({required Trial trial}) async { + final Map trialMap = { + 'participantID': trial.participantID, + 'sessionID': trial.sessionID, + 'trialType': trial.trialType, + 'stim': trial.stim, + 'response': trial.response, + }; + + final CollectionReference trialsRef = _db.collection( + 'participants/$participantID/cognitive_tasks/$taskName/sessions/$sessionID/trials'); + + await trialsRef.add(trialMap); } @override From 042f808a8262ae9883f5e3e701ea5ccb4cafe519 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mario=20E=2E=20Bermonti-P=C3=A9rez?= Date: Tue, 26 Mar 2024 09:18:15 -0400 Subject: [PATCH 2/4] maint(example): Fix example participantID --- example/lib/main.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/example/lib/main.dart b/example/lib/main.dart index a31dfb7..58c7bd1 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -34,7 +34,7 @@ class MyHomePage extends StatelessWidget { final String title; final _db = FirebaseDB( FirebaseFirestore.instance, - participantID: '101,', + participantID: '101', sessionID: '001', taskName: 'dsb', ); From 08663731d8464473b2340032a208f0219fd635f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mario=20E=2E=20Bermonti-P=C3=A9rez?= Date: Tue, 26 Mar 2024 09:18:51 -0400 Subject: [PATCH 3/4] improve(example): Use FirebaseDB.addTrial --- example/lib/main.dart | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/example/lib/main.dart b/example/lib/main.dart index 58c7bd1..944b74c 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -2,6 +2,8 @@ import 'package:cloud_firestore/cloud_firestore.dart'; import 'package:cognitive_data/databases/firebase_db/firebase_db.dart'; import 'package:cognitive_data/models/device.dart'; import 'package:cognitive_data/models/session.dart'; +import 'package:cognitive_data/models/trial.dart'; +import 'package:cognitive_data/models/trial_type.dart'; import 'package:flutter/material.dart'; import 'package:firebase_core/firebase_core.dart'; @@ -74,7 +76,17 @@ class MyHomePage extends StatelessWidget { child: const Text("Save Device metadata to firebase"), ), ElevatedButton( - onPressed: () {}, + onPressed: () async { + final Trial trial = Trial( + participantID: _db.participantID, + sessionID: _db.sessionID, + trialType: TrialType.practice, + stim: '123', + response: '321', + ); + + await _db.addTrial(trial: trial); + }, child: const Text("Save trial to firebase"), ), ElevatedButton( From 51c207e42bb9bedcf85fa582918824be41de97ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mario=20E=2E=20Bermonti-P=C3=A9rez?= Date: Tue, 26 Mar 2024 09:26:38 -0400 Subject: [PATCH 4/4] doc: Add docstring to FirebaseDB.addTrial --- lib/databases/firebase_db/firebase_db.dart | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/databases/firebase_db/firebase_db.dart b/lib/databases/firebase_db/firebase_db.dart index 3247bc5..8575bf1 100644 --- a/lib/databases/firebase_db/firebase_db.dart +++ b/lib/databases/firebase_db/firebase_db.dart @@ -80,6 +80,9 @@ class FirebaseDB implements DB { await sessionRef.doc('sessionMetadata').set(sessionData); } + /// Adds a single [trial] to [FirebaseFirestore]. + /// Stores each [trial] data in an independent doc inside a collection + /// named `trials`. @override Future addTrial({required Trial trial}) async { final Map trialMap = {