Skip to content
This repository has been archived by the owner on Jul 9, 2021. It is now read-only.

Commit

Permalink
feat: add env user id, change data save
Browse files Browse the repository at this point in the history
  • Loading branch information
fernandogelin committed Nov 12, 2019
1 parent de0c3bd commit b15e09f
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 26 deletions.
57 changes: 32 additions & 25 deletions public/electron.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@ 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 { isPort, getPort, sendToPort } = require('event-marker')
log.info(AT_HOME)

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

const { isPort, getPort, sendToPort } = require('event-marker')
log.info(AT_HOME)

// Data Saving
const { dataDir } = require('./config/saveData')

Expand All @@ -39,7 +40,6 @@ function createWindow () {
mainWindow = new BrowserWindow({
width: 1500,
height: 900,
icon: './favicon.ico',
webPreferences: {
nodeIntegration: true,
webSecurity: false
Expand All @@ -48,8 +48,7 @@ function createWindow () {
} else {
mainWindow = new BrowserWindow({
fullscreen: true,
icon: './favicon.ico',
frame: false,
frame: AT_HOME,
webPreferences: {
nodeIntegration: true,
webSecurity: true
Expand Down Expand Up @@ -157,6 +156,7 @@ let fileName = ''
let filePath = ''
let patientID = ''
let images = []
let startTrial = -1

// listener for new data
ipc.on('data', (event, args) => {
Expand All @@ -167,6 +167,7 @@ ipc.on('data', (event, args) => {
patientID = args.patient_id
fileName = `pid_${patientID}_${Date.now()}.json`
filePath = path.resolve(dir, fileName)
startTrial = args.trial_index
log.warn(filePath)
stream = fs.createWriteStream(filePath, {flags:'ax+'});
stream.write('[')
Expand All @@ -175,7 +176,7 @@ ipc.on('data', (event, args) => {
// we have a set up stream to write to, write to it!
if (stream) {
// write intermediate commas
if (args.trial_index > 1) {
if (args.trial_index > startTrial) {
stream.write(',')
}

Expand All @@ -187,25 +188,9 @@ 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))

})

// EXPERMENT END
ipc.on('end', (event, args) => {
// quit app
app.quit()
})
Expand Down Expand Up @@ -245,7 +230,6 @@ app.on('ready', () => {
.then(() => handleEventSend(eventCodes.test_connect))
}
})

// Quit when all windows are closed.
app.on('window-all-closed', function () {
// On macOS it is common for applications and their menu bar
Expand All @@ -261,3 +245,26 @@ 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.


// Before quitting, finish writing file and copy it over
app.on('will-quit', () => {
if (fileName) {
// 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))

})
}
})
2 changes: 1 addition & 1 deletion src/trials/userId.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const userId = () => {
else {
return {
type: 'survey_text',
questions: [{ prompt: baseStimulus(`<h1>${lang.userid.set}</h1>`, true) }],
questions: [{ prompt: baseStimulus(`<h1>${lang.userid.set}</h1>`, true), value: process.env.REACT_APP_PATIENT_ID }],
on_finish: (data) => {
getUserId(data)
}
Expand Down

0 comments on commit b15e09f

Please sign in to comment.