Skip to content

Commit

Permalink
Merge pull request #296 from brown-ccv/enchance-build-timeline
Browse files Browse the repository at this point in the history
Enhance build timeline
  • Loading branch information
RobertGemmaJr authored Sep 26, 2023
2 parents 57e67ef + 257de9e commit 86c8e0e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 15 deletions.
4 changes: 2 additions & 2 deletions src/App/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,8 @@ export default function App() {
if (loggedIn) {
return (
<JsPsychExperiment
studyId={studyID}
participantId={participantID}
studyID={studyID}
participantID={participantID}
taskVersion={taskVersion}
dataUpdateFunction={
{
Expand Down
16 changes: 8 additions & 8 deletions src/App/components/JsPsychExperiment.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import { initParticipant } from "../deployments/firebase";
import { buildTimeline, jsPsychOptions } from "../../timelines/main";

export default function JsPsychExperiment({
studyId,
participantId,
studyID,
participantID,
taskVersion,
dataUpdateFunction,
dataFinishFunction,
Expand All @@ -26,7 +26,7 @@ export default function JsPsychExperiment({
};

/**
* Create the instance of JsPsych whenever the studyId, participantId, or taskVersion changes,
* Create the instance of JsPsych whenever the studyID, participantID, or taskVersion changes,
* which occurs then the user logs in.
*
* This instance of jsPsych is passed to any trials that need it when the timeline is built.
Expand All @@ -37,21 +37,21 @@ export default function JsPsychExperiment({
const startDate = new Date().toISOString();

// Write the initial record to Firestore
if (config.USE_FIREBASE) initParticipant(studyId, participantId, startDate);
if (config.USE_FIREBASE) initParticipant(studyID, participantID, startDate);

const jsPsych = initJsPsych(combinedOptions);
// Add experiment properties into jsPsych directly
jsPsych.data.addProperties({
study_id: studyId,
participant_id: participantId,
study_id: studyID,
participant_id: participantID,
start_date: startDate,
task_version: taskVersion,
});
return jsPsych;
}, [studyId, participantId, taskVersion]);
}, [studyID, participantID, taskVersion]);

// Build the experiment timeline
const timeline = buildTimeline(jsPsych);
const timeline = buildTimeline(jsPsych, studyID, participantID);

/**
* Callback function used to set up event and lifecycle callbacks to start and stop jspsych.
Expand Down
11 changes: 6 additions & 5 deletions src/timelines/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,20 @@ import { createHoneycombTimeline } from "./honeycombTimeline";
* Note that Honeycomb combines these with other options required for Honeycomb to operate correctly
*/
const jsPsychOptions = {
on_trial_finish: function (data) {
console.log("A trial just ended, here are the latest data:");
console.log(data);
},
on_trial_finish: (data) => console.log(`Trial ${data.internal_node_id} just finished:`, data),
default_iti: 250,
};

/**
* Builds the experiment's timeline that jsPsych will run
* The instance of jsPsych passed in will include jsPsychOptions from above
* @param {Object} jsPsych The jsPsych instance that is running the experiment
* @param {string} studyID The ID of the study that was just logged into
* @param {string} participantID The ID of the participant that was just logged in
* @returns The timeline for JsPsych to run
*/
function buildTimeline(jsPsych) {
function buildTimeline(jsPsych, studyID, participantID) {
console.log(`Building timeline for participant ${participantID} on study ${studyID}`);
const timeline = createHoneycombTimeline(jsPsych);

// Dynamically adds the camera trials to the experiment if config.USE_CAMERA
Expand Down

0 comments on commit 86c8e0e

Please sign in to comment.