Skip to content

Commit

Permalink
ref: rename CONFIG as ENV
Browse files Browse the repository at this point in the history
  • Loading branch information
YUUU23 committed Jul 30, 2024
1 parent 3d12e53 commit 12a5561
Show file tree
Hide file tree
Showing 12 changed files with 36 additions and 36 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/index";
import { ENV, SETTINGS } from "../config/index";
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": ENV,
"Task Settings": SETTINGS,
});

// If on desktop
if (CONFIG.USE_ELECTRON) {
if (ENV.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(ENV); // 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 (ENV.USE_PROLIFIC) {
const pID = getProlificId();
if (CONFIG.USE_FIREBASE && pID) {
if (ENV.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 (ENV.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, taskVersion } from "../../config/index";
import { ENV, taskVersion } from "../../config/index";
import { buildTimeline, jsPsychOptions } from "../../experiment";
import { initParticipant } from "../deployments/firebase";

Expand All @@ -25,7 +25,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 (ENV.USE_FIREBASE) initParticipant(studyID, participantID, startDate);

const jsPsych = initJsPsych({
// Combine necessary Honeycomb options with custom ones (src/timelines/main.js)
Expand Down
4 changes: 2 additions & 2 deletions src/config/env.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const USE_EEG = import.meta.env.VITE_USE_EEG === "true" && USE_ELECTRON; // Whet
const USE_PHOTODIODE = import.meta.env.VITE_USE_PHOTODIODE === "true" && USE_ELECTRON; // whether or not the photodiode is in use

// Configuration object for Honeycomb
const config = {
const env = {
// Deployments
USE_ELECTRON,
USE_PROLIFIC,
Expand All @@ -18,4 +18,4 @@ const config = {
USE_EEG,
USE_CAMERA,
};
export default config;
export default env;
4 changes: 2 additions & 2 deletions src/config/index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import packageInfo from "../../package.json";
import language from "./language.json";
import settings from "./settings.json";
import config from "./env.js";
import env from "./env.js";

export const taskName = packageInfo.name;
export const taskVersion = packageInfo.version;
export const LANGUAGE = language;
export const SETTINGS = settings;
export const CONFIG = config;
export const ENV = env;
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/index";
import { ENV } from "../../config/index";
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 (ENV.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/index";
import { ENV, SETTINGS } from "../../config/index";
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 (ENV.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 (ENV.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/index";
import { ENV } from "../../config/index";

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 (ENV.USE_PHOTODIODE) {
procedure.push(holdUpMarkerTrial);
procedure.push(initPhotodiodeTrial);
}

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

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/index";
import { LANGUAGE, ENV } from "../../config/index";
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 (!ENV.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 (!ENV.USE_ELECTRON) {
throw new Error("video recording is only available when running inside Electron");
}

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/index";
import { SETTINGS, ENV } from "../../config/index";
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 (ENV.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 (ENV.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/index";
import { ENV, LANGUAGE } from "../../config/index";
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 (ENV.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 (ENV.USE_PHOTODIODE) pdSpotEncode(eventCodes.test_connect);
},
};
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/index";
import { ENV } from "../../config/index";
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 (!ENV.USE_ELECTRON) {
throw new Error("photodiode recording is only available when running inside Electron");
}
if (!CONFIG.USE_PHOTODIODE) {
if (!ENV.USE_PHOTODIODE) {
console.warn("photodiode trial was run but USE_PHOTODIODE is set to false ");
}

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/index";
import { ENV } from "../../config/index";
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 (!ENV.USE_ELECTRON) {
throw new Error("photodiodeSpot trial is only available when running inside Electron");
}

if (CONFIG.USE_PHOTODIODE) {
if (ENV.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 12a5561

Please sign in to comment.