Skip to content

Commit

Permalink
fix: update firebase build flow, update psiturk build flow; fix: remo…
Browse files Browse the repository at this point in the history
…ve online var in userid

set REACT_APP_AT_HOME to true for both firebase & psiturk
  • Loading branch information
wasita mahaphanit committed Aug 10, 2020
1 parent 949ab1c commit f773d14
Show file tree
Hide file tree
Showing 10 changed files with 75 additions and 52 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/build_firebase.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ jobs:
run: npm test
env:
CI: true
REACT_APP_FIREBASE: true
REACT_APP_AT_HOME: true

# deploy
- name: deploy to firebase
Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,12 @@ jobs:
- name: Install PsiTurk
if: startsWith(matrix.os, 'ubuntu')
run: pip install psiturk
- name: PsiTurk Build
if: startswith(matrix.os, 'ubuntu')
run: npm run build:turk
env:
CI: true
REACT_APP_AT_HOME: true
- name: Create Psiturk Build
if: startsWith(matrix.os, 'ubuntu')
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/make-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ jobs:
run: npm run build:turk
env:
CI: true
REACT_APP_AT_HOME: false
REACT_APP_AT_HOME: true
REACT_APP_FIREBASE: false
REACT_APP_TURK: true
- name: Create Psiturk Build
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@
"build:win:home": "cross-env REACT_APP_AT_HOME=\"true\" npm run build",
"build:win:clinic": "cross-env REACT_APP_AT_HOME=\"true\" npm run build",
"build:home": "REACT_APP_AT_HOME=\"true\" npm run build",
"build:turk": "REACT_APP_FIREBASE=\"false\" REACT_APP_AT_HOME=\"false\" REACT_APP_TURK=\"true\" npm run build",
"build:firebase": "REACT_APP_FIREBASE=\"true\" REACT_APP_AT_HOME=\"false\" npm run build"
"build:turk": "REACT_APP_FIREBASE=\"false\" REACT_APP_AT_HOME=\"true\" REACT_APP_TURK=\"true\" npm run build",
"build:firebase": "REACT_APP_FIREBASE=\"true\" REACT_APP_AT_HOME=\"true\" npm run build"
},
"eslintConfig": {
"extends": "react-app"
Expand Down
11 changes: 10 additions & 1 deletion src/App.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
import React from "react";
import { Experiment } from "jspsych-react";
import { tl } from "./timelines/main";
import { MTURK, IS_ELECTRON, FIREBASE, PROLIFIC, AT_HOME } from "./config/main";
import {
ONLINE,
MTURK,
IS_ELECTRON,
FIREBASE,
PROLIFIC,
AT_HOME,
} from "./config/main";
import "./App.css";
import "bootstrap/dist/css/bootstrap.css";
import "@fortawesome/fontawesome-free/css/all.css";
Expand All @@ -23,6 +30,7 @@ if (IS_ELECTRON) {

class App extends React.Component {
render() {
console.log("Online:", ONLINE);
console.log("MTurk:", MTURK);
console.log("Firebase:", FIREBASE);
console.log("Prolific:", PROLIFIC);
Expand All @@ -44,6 +52,7 @@ class App extends React.Component {
addToFirebase(data);
}
}
// electron
if (ipcRenderer) {
ipcRenderer.send("data", data);
} else if (psiturk) {
Expand Down
26 changes: 16 additions & 10 deletions src/config/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// This is the main configuration file where universal and default settings should be placed.
// These settings can then be imported anywhere in the app as they are exported at the botom of the file.

// import { jsPsych } from "jspsych-react";
import _ from "lodash";
import { eventCodes } from "./trigger";

Expand Down Expand Up @@ -52,6 +53,7 @@ const keys = {
// all the possible environments for the task:
const AT_HOME = process.env.REACT_APP_AT_HOME === "true";
const MTURK = process.env.REACT_APP_TURK === "true";
// const MTURK = !jsPsych.turk.turkInfo().outsideTurk;
let IS_ELECTRON = true;
let ONLINE = false;
let FIREBASE = process.env.REACT_APP_FIREBASE === "true";
Expand All @@ -61,17 +63,20 @@ try {
window.require("electron");
} catch {
IS_ELECTRON = false;
}

// if AT_HOME and not in-lab/in-clinic EEG electron version,
// then assume it's online in the browser
// with MTurk or Prolific
ONLINE = AT_HOME && !IS_ELECTRON ? true : false;
console.log("ONLINE:", ONLINE);

// if !AT_HOME and not in-lab/in-clinic EEG electron version,
// then assume it's online in the browser
// with MTurk or Prolific
ONLINE = !AT_HOME && !IS_ELECTRON ? true : false;
console.log("ONLINE:", ONLINE);
if (ONLINE) {
PROLIFIC = !MTURK;
if (PROLIFIC) {
FIREBASE = true;
}
// note: it _is_ possible to do both firebase & mturk if desired
// but for now assumine if not mturk then it's prolific and firebase:
if (ONLINE) {
PROLIFIC = !MTURK;
if (PROLIFIC) {
FIREBASE = true;
}
}

Expand All @@ -80,6 +85,7 @@ const PHOTODIODE_ON = false;

// get language file
const lang = require("../language/en_us.json");
// note: prolific lang is lumped in with en_us.json
if (MTURK) {
// if this is mturk, merge in the mturk specific language
const mlang = require("../language/en_us.mturk.json");
Expand Down
3 changes: 0 additions & 3 deletions src/language/en_us.mturk.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
{
"welcome": {
"message": "Welcome to the NEURO experiment."
},
"userid": {
"set": "Setting up user ID."
}
Expand Down
1 change: 1 addition & 0 deletions src/timelines/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ const inLabTimeline = [
experimentEnd(5000),
];

// online just means not using electron aka in-browser
const onlineTimeline = MTURK
? [
experimentStart(),
Expand Down
4 changes: 4 additions & 0 deletions src/trials/showPayment.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const showPayment = (duration, blockSettings) => {
const value = jsPsych.data.get().select("value").values;
const last = value[value.length - 1];
const total_cumulative = last.trial_cumulative_earnings;

total_earnings += total_cumulative / 20; // $1 for every 20 pts

trial.stimulus =
Expand Down Expand Up @@ -58,6 +59,9 @@ const showPayment = (duration, blockSettings) => {
const value = jsPsych.data.get().select("value").values;
const last = value[value.length - 1];
const total_cumulative = last.trial_cumulative_earnings;
// NOTE TO FUTURE SELF: likely to be changing payment scheme for online
// version, divisor likely to change from 20 to 450
// to match prev mturk samples
total_earnings += total_cumulative / 20; // $1 for every 20 pts

trial.stimulus =
Expand Down
68 changes: 33 additions & 35 deletions src/trials/userId.js
Original file line number Diff line number Diff line change
@@ -1,42 +1,40 @@
import { lang, ONLINE, MTURK, PROLIFIC } from "../config/main";
import { lang, MTURK, PROLIFIC } from "../config/main";
import { getUserId, getTurkUniqueId, getProlificId } from "../lib/utils";
import { baseStimulus } from "../lib/markup/stimuli";

const userId = () => {
if (ONLINE) {
if (MTURK) {
return {
type: "html_keyboard_response",
stimulus: baseStimulus(`<h1>${lang.userid.set}</h1>`, true),
response_ends_trial: false,
trial_duration: 800,
on_finish: (data) => {
const uniqueId = getTurkUniqueId();
console.log(uniqueId);
},
};
} else if (PROLIFIC) {
return {
type: "html_keyboard_response",
stimulus: baseStimulus(`<h1>${lang.userid.get_prolific}</h1>`, true),
response_ends_trial: false,
trial_duration: 1000,
on_finish: (data) => {
getProlificId(data);
// console.log(uniqueId);
},
// previously: manual input of ID
// type: "survey_text",
// questions: [
// {
// prompt: baseStimulus(`<h1>${lang.userid.set_prolific}</h1>`, true),
// },
// ],
// on_finish: (data) => {
// getUserId(data);
// },
};
} // end prolific else if
if (MTURK) {
return {
type: "html_keyboard_response",
stimulus: baseStimulus(`<h1>${lang.userid.set}</h1>`, true),
response_ends_trial: false,
trial_duration: 800,
on_finish: (data) => {
const uniqueId = getTurkUniqueId();
console.log(uniqueId);
},
};
} else if (PROLIFIC) {
return {
type: "html_keyboard_response",
stimulus: baseStimulus(`<h1>${lang.userid.get_prolific}</h1>`, true),
response_ends_trial: false,
trial_duration: 1000,
on_finish: (data) => {
getProlificId(data);
// console.log(uniqueId);
},
// previously: manual input of ID
// type: "survey_text",
// questions: [
// {
// prompt: baseStimulus(`<h1>${lang.userid.set_prolific}</h1>`, true),
// },
// ],
// on_finish: (data) => {
// getUserId(data);
// },
};
} else {
return {
type: "survey_text",
Expand Down

0 comments on commit f773d14

Please sign in to comment.