Skip to content

Commit

Permalink
Merge pull request #66 from lnccbrown/develop
Browse files Browse the repository at this point in the history
Develop merge to master -- ver v0.1.0
  • Loading branch information
wasita authored Dec 17, 2019
2 parents d81382a + ff4eaf3 commit 848b132
Show file tree
Hide file tree
Showing 41 changed files with 3,237 additions and 1,678 deletions.
4 changes: 0 additions & 4 deletions .github/workflows/build_at_home.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
name: Build at home version (Windows)

on:
push:
branches:
- master
- develop
pull_request:
paths:
- 'src/**'
Expand Down
4 changes: 0 additions & 4 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
name: CI Tests

on:
push:
branches:
- master
- develop
pull_request:
paths:
- 'src/**'
Expand Down
3,074 changes: 1,570 additions & 1,504 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"electron-devtools-installer": "^2.2.4",
"electron-log": "^3.0.9",
"electron-squirrel-startup": "^1.0.0",
"event-marker": "git+https://github.com/brown-ccv/event-marker.git#bump-version",
"event-marker": "git+https://github.com/brown-ccv/event-marker.git#feat-comname",
"jquery": "^3.4.1",
"jspsych-react": "^0.2.2",
"lodash": "^4.17.11",
Expand Down
2 changes: 1 addition & 1 deletion psiturkit/psiturk-it
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ else
psiturk-setup-example
cp -R ../build/static/* psiturk-example/static/
cp ../build/*.js* psiturk-example/static/
cp ../build/lib/*.js psiturk-example/static/lib
cp ../build/lib/*.js psiturk-example/static/lib/
cp ../build/index.html psiturk-example/templates/exp.html
mv psiturk-example ${PSI_PATH}
fi
2 changes: 1 addition & 1 deletion public/config/saveData.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// dataDir will be created on Desktop and used as root folder for saving data
// data save format is ~/Desktop/<dataDir>/<patientID>/<date>/<filename>.json
// it is also incrementally saved to the user's app data folder (logged to console)
const dataDir = 'OCD-Project-Data'
const dataDir = 'Effort-Data'

// this is module.exports isntead of just exports as it is also imported into the electron app
module.exports = {
Expand Down
36 changes: 24 additions & 12 deletions public/config/trigger.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,33 @@
// Event trigger settings - used in both the react app (renderer) and the electron app (main)
const manufacturer = 'Teensyduino'
const vendorId = '16c0'
const productId = '0487'
const comName = 'COM7'

// NOTE - these event codes must match what is in public/config/trigger.js
// NOTE - these event codes must match what is in src/config/trigger.js
const eventCodes = {
fixation: 1,
evidence: 5,
show_earnings: 7,
test_connect: 32,
open_task: 18
fixationStart: 1,
fixationEnd: 2,
rewardProbabilityStart: 10,
rewardProbabilityEnd: 11,
frameSpikeStart: 20,
frameSpikeEnd: 21,
costBenefitsStart: 30,
costBenefitsEnd: 31,
choiceStart: 40,
choiceEnd: 41,
pressBalloonStart: 50,
pressBalloonEnd: 51,
cumulativeRewardsStart: 60,
cumulativeRewardsEnd: 61,
rewardFeedbackStart: 70,
rewardFeedbackEnd: 71,
showPaymentStart: 80,
showPaymendEnd: 81,
trialFinish: 3,
test_connect: 4,
open_task: 5
}

// this is module.exports isntead of just exports as it is also imported into the electron app
module.exports = {
manufacturer,
vendorId,
productId,
comName,
eventCodes
}
93 changes: 48 additions & 45 deletions public/electron.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ const log = require('electron-log');

const AT_HOME = (process.env.REACT_APP_AT_HOME === 'true')
// Event Trigger
const { eventCodes, manufacturer, vendorId, productId } = require('./config/trigger')
const { eventCodes, comName } = require('./config/trigger')
const { isPort, getPort, sendToPort } = require('event-marker')

// Override product ID if environment variable set
const activeProductId = process.env.EVENT_MARKER_PRODUCT_ID || productId
log.info("Active product ID", activeProductId)
// Override comName if environment variable set
const activeComName = process.env.COMNAME || comName
log.info("Trigger Box comName", activeComName)

// Data Saving
const { dataDir } = require('./config/saveData')
Expand Down Expand Up @@ -83,7 +83,7 @@ let portAvailable
let SKIP_SENDING_DEV = false

const setUpPort = async () => {
p = await getPort(vendorId, activeProductId)
p = await getPort(activeComName)
if (p) {
triggerPort = p
portAvailable = true
Expand Down Expand Up @@ -112,30 +112,30 @@ const setUpPort = async () => {
}

const handleEventSend = (code) => {
if (!portAvailable && !SKIP_SENDING_DEV) {
let message = "Event Marker not connected"
log.warn(message)

let buttons = ["Quit", "Retry"]
if (process.env.ELECTRON_START_URL) {
buttons.push("Continue Anyway")
}
dialog.showMessageBox(mainWindow, {type: "error", message: message, title: "Task Error", buttons: buttons, defaultId: 0})
.then((resp) => {
let opt = resp.response
if (opt == 0) { // quit
app.exit()
} else if (opt == 1) { // retry
setUpPort()
.then(() => handleEventSend(code))
} else if (opt == 2) {
// if (!portAvailable && !SKIP_SENDING_DEV) {
// let message = "Event Marker not connected"
// log.warn(message)
//
// let buttons = ["Quit", "Retry"]
// if (process.env.ELECTRON_START_URL) {
// buttons.push("Continue Anyway")
// }
// dialog.showMessageBox(mainWindow, {type: "error", message: message, title: "Task Error", buttons: buttons, defaultId: 0})
// .then((resp) => {
// let opt = resp.response
// if (opt == 0) { // quit
// app.exit()
// } else if (opt == 1) { // retry
// setUpPort()
// .then(() => handleEventSend(code))
// } else if (opt == 2) {
SKIP_SENDING_DEV = true
}
})

} else if (!SKIP_SENDING_DEV) {
sendToPort(triggerPort, code)
}
// }
// })
//
// } else if (!SKIP_SENDING_DEV) {
// sendToPort(triggerPort, code)
// }
}

// EVENT TRIGGER
Expand Down Expand Up @@ -190,23 +190,6 @@ ipc.on('data', (event, args) => {

// EXPERIMENT END
ipc.on('end', (event, args) => {
// finish writing file
stream.write(']')
stream.end()
stream = false

// copy file to config location
const desktop = app.getPath('desktop')
const name = app.getName()
const today = new Date(Date.now())
const date = today.toISOString().slice(0,10)
const copyPath = path.join(desktop, dataDir, `${patientID}`, date, name)
fs.mkdir(copyPath, { recursive: true }, (err) => {
log.error(err)
fs.copyFileSync(filePath, path.join(copyPath, fileName))

})

// quit app
app.quit()
})
Expand Down Expand Up @@ -261,3 +244,23 @@ app.on('activate', function () {

// In this file you can include the rest of your app's specific main process
// code. You can also put them in separate files and require them here.

// EXPERIMENT END
app.on('will-quit', () => {
// finish writing file
stream.write(']')
stream.end()
stream = false

// copy file to config location
const desktop = app.getPath('desktop')
const name = app.getName()
const today = new Date(Date.now())
const date = today.toISOString().slice(0,10)
const copyPath = path.join(desktop, dataDir, `${patientID}`, date, name)
fs.mkdir(copyPath, { recursive: true }, (err) => {
log.error(err)
fs.copyFileSync(filePath, path.join(copyPath, fileName))

})
})
4 changes: 3 additions & 1 deletion public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@
<script src="%PUBLIC_URL%/static/lib/backbone-min.js" type="text/javascript"> </script>
<script src="%PUBLIC_URL%/static/lib/psiturk.js" type="text/javascript"> </script>

<title>Neuro Task</title>
<title>Effort Task</title>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>

<div id="root"></div>
<!--
This HTML file is a template.
Expand All @@ -39,5 +40,6 @@
To begin the development, run `npm start` or `yarn start`.
To create a production bundle, use `npm run build` or `yarn build`.
-->

</body>
</html>
86 changes: 80 additions & 6 deletions src/App.css
Original file line number Diff line number Diff line change
@@ -1,8 +1,23 @@
p, li {
font-size: 1.5rem;
}
.App {

.nocursor {
cursor: none;
}

html, body, #root, .App {
text-align: center;
background-color: black;
color: white;
margin: 0;
min-height: 100vh;
height: 100% !important;
width: 100vw !important;
display: flex;
flex-direction: row;
justify-content: space-around;
align-items: center !important;
}

.photodiode-box {
Expand All @@ -22,33 +37,92 @@ p, li {
background-color: black;
border-radius: 50%;
position: absolute;
display: visible;
}

.main-prompt, .beads_container {

.main-prompt, .effort-container {
height: 100vh;
width: 85vw;
margin: auto;
display: flex;
flex-direction: row;
justify-content: space-around;
align-items: center !important;
}

.main-prompt {
margin-top: -10%;
margin-bottom: -5%;
margin-bottom: -20%;
}

.quiz_container {
padding-top: 5rem;
}
.quiz_container > div >.effort-container {
height: 25rem !important;
}
.jspsych-survey-multi-choice-question {
padding-left: 8rem;
}

.image {
display: block;
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}

.text-blue {
color: #00FFFF;
}

.text-green {
color: #7FFF00;
}

.color-green {
background-color: #7FFF00;
}

.color-blue {
background-color: #00FFFF;
}


.color-white {
background-color: white;
}

#fixation-dot {
background-color: black;
position: absolute;
background-color: white;
height: 15px;
width: 15px;
border-radius: 50%;
margin: auto;
}

.instructions {
padding: 0 10rem;
display: flex;
flex-direction: column;
align-items: center;
}

.text-large {
font-size: 24pt;
}

.earnings h1 {
font-size: 3rem;
font-weight: bold;
}

.jspsych-btn {
padding: 0.5rem 1rem;
font-weight: bold;
border-radius: 5px;
box-shadow: 5px 5px 5px #efefef;
background-color: #d3d3d3;
margin: 1rem;
width: 10rem !important;
Expand Down
22 changes: 14 additions & 8 deletions src/config/experiment.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,23 @@ import { deepCopy } from '../lib/utils'
// create copy of default settings
let exptBlock1 = deepCopy(defaultBlockSettings)

exptBlock1.repeats_per_condition = 2
exptBlock1.probs = ["100%", "100%", "50%", "50%"]
exptBlock1.counterbalance = true
exptBlock1.value = [3, 5, 7]
exptBlock1.effort = [100, 120, 150]
exptBlock1.keys = ['q', 'p', 'm']
exptBlock1.get_reward = [true, true, true, false]

// SECOND EXPERIMENT BLOCK SETTINGS
// debug settings where there are only 2 trials in main task block
// exptBlock1.probs = ["100%"]
// exptBlock1.counterbalance = true
// exptBlock1.value = [3]
// exptBlock1.effort = [5]
// exptBlock1.keys = ['q', 'p', 'm']
// exptBlock1.get_reward = [true]

// create copy of default settings
let exptBlock2 = deepCopy(defaultBlockSettings)

exptBlock2.conditions = ["e", "f"]
exptBlock2.repeats_per_condition = 2

export {
exptBlock1,
exptBlock2,
exptBlock1
}
Loading

0 comments on commit 848b132

Please sign in to comment.