Skip to content

Commit

Permalink
Merge branch 'feat-v4' into ci-fix-make
Browse files Browse the repository at this point in the history
  • Loading branch information
RobertGemmaJr committed Aug 5, 2024
2 parents 41b351b + 02a5521 commit 0cc6d0a
Show file tree
Hide file tree
Showing 18 changed files with 52 additions and 53 deletions.
14 changes: 7 additions & 7 deletions src/App/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import "@fortawesome/fontawesome-free/css/all.css";
import "./index.css";

// Import configurations and utilities
import { config, SETTINGS } from "../config/main";
import { CONFIG, SETTINGS } from "../config/";
import { trigger } from "../config/trigger";
import { getProlificId, getSearchParam } from "../lib/utils";

Expand Down Expand Up @@ -48,14 +48,14 @@ export default function App() {
async function setUpHoneycomb() {
// For testing and debugging purposes
console.log({
"Honeycomb Configuration": config,
"Honeycomb Configuration": CONFIG,
"Task Settings": SETTINGS,
});

// If on desktop
if (config.USE_ELECTRON) {
if (CONFIG.USE_ELECTRON) {
// TODO @brown-ccv #443 : Pass NODE_ENV here as well
await window.electronAPI.setConfig(config); // Pass config to Electron ipcMain
await window.electronAPI.setConfig(CONFIG); // Pass config to Electron ipcMain
await window.electronAPI.setTrigger(trigger); // Pass trigger to Electron ipcMain

// Fill in login fields based on environment variables (may still be blank)
Expand All @@ -66,16 +66,16 @@ export default function App() {
} else {
// TODO @brown-ccv #227: Deprecate USE_PROLIFIC, always get URL
// TODO @brown-ccv #416: Match USE_PROLIFIC variable names, include session
if (config.USE_PROLIFIC) {
if (CONFIG.USE_PROLIFIC) {
const pID = getProlificId();
if (config.USE_FIREBASE && pID) {
if (CONFIG.USE_FIREBASE && pID) {
setMethod("firebase");
handleLogin("prolific", pID);
} else {
// Error - Prolific must be used with Firebase
setIsError(true);
}
} else if (config.USE_FIREBASE) {
} else if (CONFIG.USE_FIREBASE) {
// Fill in login fields based on query parameters (may still be blank)
const maybeStudyID = getSearchParam("studyID");
const maybeParticipantID = getSearchParam("participantID");
Expand Down
4 changes: 2 additions & 2 deletions src/App/components/JsPsychExperiment.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { initJsPsych } from "jspsych";
import PropTypes from "prop-types";
import React from "react";

import { config } from "../../config/main";
import { CONFIG } from "../../config/";
import { buildTimeline, jsPsychOptions } from "../../experiment";
import { initParticipant } from "../deployments/firebase";

Expand Down Expand Up @@ -31,7 +31,7 @@ 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 tempJsPsych = initJsPsych({
// Combine necessary Honeycomb options with custom ones (src/timelines/main.js)
Expand Down
17 changes: 2 additions & 15 deletions src/config/main.js → src/config/env.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,14 @@
import { getProlificId } from "../lib/utils";

import language from "./language.json";
import settings from "./settings.json";

// TODO @brown-ccv #363: Separate into index.js (for exporting) and env.js

// Re-export the language object
// TODO @brown-ccv #373: Save language in Firebase
export const LANGUAGE = language;
// Re-export the settings object
// TODO @brown-ccv #374: Save settings in Firebase
export const SETTINGS = settings;

const USE_ELECTRON = window.electronAPI !== undefined; // Whether or not the experiment is running in Electron (local app)
const USE_PROLIFIC = getProlificId() !== null; // Whether or not the experiment is running with Prolific
const USE_FIREBASE = import.meta.env.VITE_FIREBASE === "true"; // Whether or not the experiment is running in Firebase (web app)

const USE_CAMERA = import.meta.env.VITE_VIDEO === "true" && USE_ELECTRON; // Whether or not to use video recording
// TODO @brown-ccv #341: Remove USE_EEG - separate variables for USE_PHOTODIODE and USE_EVENT_MARKER
const USE_EEG = import.meta.env.VITE_USE_EEG === "true" && USE_ELECTRON; // Whether or not the EEG/event marker is available (TODO @brown-ccv: This is only used for sending event codes)
const USE_PHOTODIODE = import.meta.env.VITE_USE_PHOTODIODE === "true" && USE_ELECTRON; // whether or not the photodiode is in use

// Configuration object for Honeycomb
export const config = {
const config = {
// Deployments
USE_ELECTRON,
USE_PROLIFIC,
Expand All @@ -32,3 +18,4 @@ export const config = {
USE_EEG,
USE_CAMERA,
};
export default config;
12 changes: 12 additions & 0 deletions src/config/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Re-export the language object
// TODO @brown-ccv #373: Save language in Firebase
import language from "./language.json";
// Re-export the settings object
// TODO @brown-ccv #374: Save settings in Firebase
import settings from "./settings.json";
import config from "./env.js";

export const LANGUAGE = language;
export const SETTINGS = settings;
// Configuration object for Honeycomb
export const CONFIG = config;
4 changes: 2 additions & 2 deletions src/experiment/procedures/endProcedure.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { config } from "../../config/main";
import { CONFIG } from "../../config/";
import { buildCameraEndTrial } from "../trials/camera";
import { conclusionTrial } from "../trials/conclusion";
import { exitFullscreenTrial } from "../trials/fullscreen";
Expand All @@ -15,7 +15,7 @@ export function buildEndProcedure(jsPsych) {
const procedure = [];

// Conditionally add the camera breakdown trials
if (config.USE_CAMERA) {
if (CONFIG.USE_CAMERA) {
procedure.push(buildCameraEndTrial(jsPsych));
}

Expand Down
6 changes: 3 additions & 3 deletions src/experiment/procedures/honeycombProcedure.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import imageKeyboardResponse from "@jspsych/plugin-image-keyboard-response";

import { config, SETTINGS } from "../../config/main";
import { CONFIG, SETTINGS } from "../../config/";
import { eventCodes } from "../../config/trigger";
import { pdSpotEncode, photodiodeGhostBox } from "../../lib/markup/photodiode";
import { buildFixationTrial } from "../trials/fixation";
Expand Down Expand Up @@ -34,7 +34,7 @@ export function buildHoneycombProcedure(jsPsych) {
stimulus: jsPsych.timelineVariable("stimulus"),
prompt: function () {
// Conditionally displays the photodiodeGhostBox
if (config.USE_PHOTODIODE) return photodiodeGhostBox;
if (CONFIG.USE_PHOTODIODE) return photodiodeGhostBox;
else return null;
},
// Possible choices are the correct_responses from the task settings
Expand All @@ -46,7 +46,7 @@ export function buildHoneycombProcedure(jsPsych) {
},
on_load: function () {
// Conditionally flashes the photodiode when the trial first loads
if (config.USE_PHOTODIODE) pdSpotEncode(eventCodes.honeycomb);
if (CONFIG.USE_PHOTODIODE) pdSpotEncode(eventCodes.honeycomb);
},
// Add a boolean value ("correct") to the data - if the user responded with the correct key or not
on_finish: function (data) {
Expand Down
6 changes: 3 additions & 3 deletions src/experiment/procedures/startProcedure.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { config } from "../../config/main";
import { CONFIG } from "../../config/";

import { buildCameraStartTrial } from "../trials/camera";
import { enterFullscreenTrial } from "../trials/fullscreen";
Expand All @@ -22,13 +22,13 @@ export function buildStartProcedure(jsPsych) {
const procedure = [nameTrial, enterFullscreenTrial, introductionTrial];

// Conditionally add the photodiode setup trials
if (config.USE_PHOTODIODE) {
if (CONFIG.USE_PHOTODIODE) {
procedure.push(holdUpMarkerTrial);
procedure.push(initPhotodiodeTrial);
}

// Conditionally add the camera setup trials
if (config.USE_CAMERA) {
if (CONFIG.USE_CAMERA) {
procedure.push(buildCameraStartTrial(jsPsych));
}

Expand Down
2 changes: 1 addition & 1 deletion src/experiment/trials/adjustVolume.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import htmlKeyboardResponse from "@jspsych/plugin-html-keyboard-response";
import { LANGUAGE } from "../../config/main";
import { LANGUAGE } from "../../config/";
import { div, h1 } from "../../lib/markup/tags";

/** Trial that prompts the user to adjust the volume on their computer */
Expand Down
6 changes: 3 additions & 3 deletions src/experiment/trials/camera.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import htmlKeyboardResponse from "@jspsych/plugin-html-keyboard-response";
import htmlButtonResponse from "@jspsych/plugin-html-button-response";
import initializeCamera from "@jspsych/plugin-initialize-camera";

import { LANGUAGE, config } from "../../config/main";
import { LANGUAGE, CONFIG } from "../../config/";
import { div, h1, p, tag } from "../../lib/markup/tags";

const WEBCAM_ID = "webcam";
Expand Down Expand Up @@ -44,7 +44,7 @@ export function buildCameraStartTrial(jsPsych) {
response_ends_trial: true,
on_start: function () {
// Initialize and store the camera feed
if (!config.USE_ELECTRON) {
if (!CONFIG.USE_ELECTRON) {
throw new Error("video recording is only available when running inside Electron");
}

Expand Down Expand Up @@ -103,7 +103,7 @@ export function buildCameraEndTrial(jsPsych) {
on_start: function () {
// Complete the camera recording

if (!config.USE_ELECTRON) {
if (!CONFIG.USE_ELECTRON) {
throw new Error("video recording is only available when running inside Electron");
}

Expand Down
2 changes: 1 addition & 1 deletion src/experiment/trials/conclusion.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import htmlKeyboardResponse from "@jspsych/plugin-html-keyboard-response";

import { LANGUAGE } from "../../config/main";
import { LANGUAGE } from "../../config/";
import { h1 } from "../../lib/markup/tags";

/** Trial that displays a completion message for 5 seconds */
Expand Down
6 changes: 3 additions & 3 deletions src/experiment/trials/fixation.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import htmlKeyboardResponse from "@jspsych/plugin-html-keyboard-response";

import { SETTINGS, config } from "../../config/main";
import { SETTINGS, CONFIG } from "../../config/";
import { eventCodes } from "../../config/trigger";
import { pdSpotEncode, photodiodeGhostBox } from "../../lib/markup/photodiode";
import { div } from "../../lib/markup/tags";
Expand All @@ -21,7 +21,7 @@ export function buildFixationTrial(jsPsych) {
stimulus: div("", { id: "fixation-dot" }),
prompt: function () {
// Conditionally display the photodiodeGhostBox
if (config.USE_PHOTODIODE) return photodiodeGhostBox;
if (CONFIG.USE_PHOTODIODE) return photodiodeGhostBox;
else return null;
},
trial_duration: function () {
Expand All @@ -38,7 +38,7 @@ export function buildFixationTrial(jsPsych) {
},
on_load: function () {
// Conditionally flash the photodiode when the trial first loads
if (config.USE_PHOTODIODE) pdSpotEncode(fixationCode);
if (CONFIG.USE_PHOTODIODE) pdSpotEncode(fixationCode);
},
};
}
6 changes: 3 additions & 3 deletions src/experiment/trials/holdUpMarker.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import htmlButtonResponse from "@jspsych/plugin-html-button-response";

import { config, LANGUAGE } from "../../config/main";
import { CONFIG, LANGUAGE } from "../../config/";
import { eventCodes } from "../../config/trigger";
import { pdSpotEncode, photodiodeGhostBox } from "../../lib/markup/photodiode";
import { div, h1, p } from "../../lib/markup/tags";
Expand All @@ -20,13 +20,13 @@ export const holdUpMarkerTrial = {
let holdUpMarkerPrompt = p(LANGUAGE.trials.holdUpMarker);

// Conditionally add the photodiodeGhostBox
if (config.USE_PHOTODIODE) holdUpMarkerPrompt += photodiodeGhostBox;
if (CONFIG.USE_PHOTODIODE) holdUpMarkerPrompt += photodiodeGhostBox;

return holdUpMarkerPrompt;
},
choices: [LANGUAGE.prompts.continue.button],
on_load: function () {
// Conditionally flash the photodiode when the trial first loads
if (config.USE_PHOTODIODE) pdSpotEncode(eventCodes.test_connect);
if (CONFIG.USE_PHOTODIODE) pdSpotEncode(eventCodes.test_connect);
},
};
2 changes: 1 addition & 1 deletion src/experiment/trials/honeycombTrials.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import htmlKeyboardResponse from "@jspsych/plugin-html-keyboard-response";
import instructionsResponse from "@jspsych/plugin-instructions";
import preloadResponse from "@jspsych/plugin-preload";

import { LANGUAGE, SETTINGS } from "../../config/main";
import { LANGUAGE, SETTINGS } from "../../config/";
import { eventCodes } from "../../config/trigger";
import { b, div, image, p } from "../../lib/markup/tags";

Expand Down
6 changes: 3 additions & 3 deletions src/experiment/trials/initPhotodiode.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import htmlKeyboardResponse from "@jspsych/plugin-html-keyboard-response";

import { config } from "../../config/main";
import { CONFIG } from "../../config/";
import { eventCodes } from "../../config/trigger";
import { pdSpotEncode, photodiodeGhostBox } from "../../lib/markup/photodiode";

Expand All @@ -10,10 +10,10 @@ export const initPhotodiodeTrial = {
trial_duration: 1600,
stimulus: photodiodeGhostBox,
on_load: function () {
if (!config.USE_ELECTRON) {
if (!CONFIG.USE_ELECTRON) {
throw new Error("photodiode recording is only available when running inside Electron");
}
if (!config.USE_PHOTODIODE) {
if (!CONFIG.USE_PHOTODIODE) {
console.warn("photodiode trial was run but USE_PHOTODIODE is set to false ");
}

Expand Down
2 changes: 1 addition & 1 deletion src/experiment/trials/introduction.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import htmlKeyboardResponse from "@jspsych/plugin-html-keyboard-response";

import { LANGUAGE } from "../../config/main";
import { LANGUAGE } from "../../config/";
import { div, p, h1 } from "../../lib/markup/tags";

/** Task that displays a introduction message with the photodiode ghost box */
Expand Down
2 changes: 1 addition & 1 deletion src/experiment/trials/name.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import htmlKeyboardResponse from "@jspsych/plugin-html-keyboard-response";

import { LANGUAGE } from "../../config/main";
import { LANGUAGE } from "../../config/";
import { h1 } from "../../lib/markup/tags";

/** Task that displays the name of the experiment */
Expand Down
2 changes: 1 addition & 1 deletion src/experiment/trials/survey.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import jsPsychSurveyPlugin from "@jspsych/plugin-survey";

import { LANGUAGE } from "../../config/main";
import { LANGUAGE } from "../../config/";

// The survey plugin includes additional styling
import "@jspsych/plugin-survey/css/survey.css";
Expand Down
6 changes: 3 additions & 3 deletions src/lib/markup/photodiode.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { config } from "../../config/main";
import { CONFIG } from "../../config/";
import { div, span } from "./tags";

// TODO @brown-ccv #329: Refactor photodiode logic to be a custom jsPsych extension
Expand All @@ -22,11 +22,11 @@ export const photodiodeGhostBox = div(span("", { id: SPOT_ID }), { id: BOX_ID })
* @param {number} taskCode The unique code for the given trial on which this function executes
*/
export function pdSpotEncode(taskCode) {
if (!config.USE_ELECTRON) {
if (!CONFIG.USE_ELECTRON) {
throw new Error("photodiodeSpot trial is only available when running inside Electron");
}

if (config.USE_PHOTODIODE) {
if (CONFIG.USE_PHOTODIODE) {
// TODO @brown-ccv #333: Get blink time from config.json (equipment.trigger_box.event_codes) (40ms is the default)
const blinkTime = 40;
// TODO @brown-ccv #354: Gen numBlinks from config.json (equipment.trigger_box.event_codes) (40ms is the default)
Expand Down

0 comments on commit 0cc6d0a

Please sign in to comment.