Skip to content

Commit

Permalink
Updated central resources path to be flexible for both prod and dev
Browse files Browse the repository at this point in the history
  • Loading branch information
jdpigeon committed Jul 4, 2021
1 parent 3f154ae commit 07d1045
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 57 deletions.
3 changes: 2 additions & 1 deletion app/components/ViewerComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
EMOTIV_CHANNELS,
DEVICES,
VIEWER_DEFAULTS,
RESOURCE_PATH,
} from '../constants/constants';
import { PipesEpoch, SignalQualityData } from '../constants/interfaces';

Expand Down Expand Up @@ -117,7 +118,7 @@ class ViewerComponent extends Component<Props, State> {
return (
<webview
id="eegView"
src={`file://${__dirname}/viewer.html`}
src={`file://${RESOURCE_PATH}/app/viewer.html`}
autosize={trueAsString}
nodeintegration={trueAsString}
plugins={trueAsString}
Expand Down
5 changes: 5 additions & 0 deletions app/constants/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,3 +139,8 @@ export enum FILE_TYPES {
STIMULUS_DIR = 'STIMULUS_DIR',
TIMELINE = 'TIMELINE',
}

export const RESOURCE_PATH =
!process.env.NODE_ENV || process.env.NODE_ENV === 'production'
? process.resourcesPath // Live Mode
: __dirname; // Dev Mode
7 changes: 5 additions & 2 deletions app/experiments/faces_houses/params.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@ import * as path from 'path';
import { EVENTS } from '../../constants/constants';

// Default directories containing stimuli
const rootFolder = __dirname; // Note: there's a weird issue where the fs readdir function reads from BrainWaves dir
const resourcePath =
!process.env.NODE_ENV || process.env.NODE_ENV === 'production'
? process.resourcesPath // Live Mode
: __dirname; // Dev Mode

const parentDir = path.join(
rootFolder,
resourcePath,
'experiments',
'faces_houses',
'stimuli'
Expand Down
4 changes: 2 additions & 2 deletions app/experiments/multitasking/experiment.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
/* eslint-disable no-template-curly-in-string */

import * as path from 'path';
import { RESOURCE_PATH } from '../../constants/constants';
import {
initMultitaskingResponseHandlers,
initTasks,
initTaskScreen,
triggerEEGCallback,
} from './utils';

const rootFolder = __dirname;
const assetsDirectory = path.join(
rootFolder,
RESOURCE_PATH,
'experiments',
'multitasking',
'stimuli'
Expand Down
2 changes: 2 additions & 0 deletions app/main.dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ app.commandLine.appendSwitch(
);
app.commandLine.appendSwitch('user-activation-v2', 'true');

app.allowRendererProcessReuse = false;

export default class AppUpdater {
constructor() {
log.transports.file.level = 'info';
Expand Down
62 changes: 23 additions & 39 deletions app/menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,45 +178,29 @@ export default class MenuBuilder {
const templateDefault = [
{
label: '&View',
submenu:
process.env.NODE_ENV === 'development' ||
process.env.DEBUG_PROD === 'true'
? [
{
label: '&Reload',
accelerator: 'Ctrl+R',
click: () => {
this.mainWindow.webContents.reload();
},
},
{
label: 'Toggle &Full Screen',
accelerator: 'F11',
click: () => {
this.mainWindow.setFullScreen(
!this.mainWindow.isFullScreen()
);
},
},
{
label: 'Toggle &Developer Tools',
accelerator: 'Alt+Ctrl+I',
click: () => {
this.mainWindow.webContents.toggleDevTools();
},
},
]
: [
{
label: 'Toggle &Full Screen',
accelerator: 'F11',
click: () => {
this.mainWindow.setFullScreen(
!this.mainWindow.isFullScreen()
);
},
},
],
submenu: [
{
label: '&Reload',
accelerator: 'Ctrl+R',
click: () => {
this.mainWindow.webContents.reload();
},
},
{
label: 'Toggle &Full Screen',
accelerator: 'F11',
click: () => {
this.mainWindow.setFullScreen(!this.mainWindow.isFullScreen());
},
},
{
label: 'Toggle &Developer Tools',
accelerator: 'Alt+Ctrl+I',
click: () => {
this.mainWindow.webContents.toggleDevTools();
},
},
],
},
{
label: 'Help',
Expand Down
21 changes: 11 additions & 10 deletions app/utils/jupyter/cells.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// File we be replaced by pyodide update
import * as path from 'path';
import { readFileSync } from 'fs';
import { RESOURCE_PATH } from '../../constants/constants';

export const imports = () =>
[
Expand All @@ -18,24 +19,24 @@ export const imports = () =>
'import numpy as np',
'import seaborn as sns',
'from matplotlib import pyplot as plt',
"plt.style.use('fivethirtyeight')"
"plt.style.use('fivethirtyeight')",
].join('\n');

export const utils = () =>
readFileSync(path.join(__dirname, '/utils/jupyter/utils.py'), 'utf8');
readFileSync(path.join(RESOURCE_PATH, '/utils/jupyter/utils.py'), 'utf8');

export const loadCSV = (filePathArray: Array<string>) =>
[
`files = [${filePathArray.map(filePath => formatFilePath(filePath))}]`,
`files = [${filePathArray.map((filePath) => formatFilePath(filePath))}]`,
`replace_ch_names = None`,
`raw = load_data(files, replace_ch_names)`
`raw = load_data(files, replace_ch_names)`,
].join('\n');

export const loadCleanedEpochs = (filePathArray: Array<string>) =>
[
`files = [${filePathArray.map(filePath => formatFilePath(filePath))}]`,
`files = [${filePathArray.map((filePath) => formatFilePath(filePath))}]`,
`clean_epochs = concatenate_epochs([read_epochs(file) for file in files])`,
`conditions = OrderedDict({key: [value] for (key, value) in clean_epochs.event_id.items()})`
`conditions = OrderedDict({key: [value] for (key, value) in clean_epochs.event_id.items()})`,
].join('\n');

// NOTE: this command includes a ';' to prevent returning data
Expand All @@ -54,7 +55,7 @@ export const epochEvents = (
reject: Array<string> | string = 'None'
) => {
const IDs = Object.keys(eventIDs)
.filter(k => k !== '')
.filter((k) => k !== '')
.reduce((res, key) => ((res[key] = eventIDs[key]), res), {});
const command = [
`event_id = ${JSON.stringify(IDs)}`,
Expand All @@ -67,7 +68,7 @@ export const epochEvents = (
`raw_epochs = Epochs(raw, events=events, event_id=event_id,
tmin=tmin, tmax=tmax, baseline=baseline, reject=reject, preload=True,
verbose=False, picks=picks)`,
`conditions = OrderedDict({key: [value] for (key, value) in raw_epochs.event_id.items()})`
`conditions = OrderedDict({key: [value] for (key, value) in raw_epochs.event_id.items()})`,
].join('\n');
return command;
};
Expand All @@ -81,7 +82,7 @@ export const requestChannelInfo = () =>
export const cleanEpochsPlot = () =>
[
`%matplotlib`,
`raw_epochs.plot(scalings='auto', n_epochs=6, title="Clean Data", events=None)`
`raw_epochs.plot(scalings='auto', n_epochs=6, title="Clean Data", events=None)`,
].join('\n');

export const plotTopoMap = () =>
Expand All @@ -91,7 +92,7 @@ export const plotERP = (channelIndex: number | string) =>
[
`%matplotlib inline`,
`X, y = plot_conditions(clean_epochs, ch_ind=${channelIndex}, conditions=conditions,
ci=97.5, n_boot=1000, title='', diff_waveform=None)`
ci=97.5, n_boot=1000, title='', diff_waveform=None)`,
].join('\n');

export const saveEpochs = (workspaceDir: string, subject: string) =>
Expand Down
12 changes: 9 additions & 3 deletions app/utils/labjs/protocols/custom.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
import * as path from 'path';
import { EVENTS } from '../../../constants/constants';
import { EVENTS, RESOURCE_PATH } from '../../../constants/constants';

// Default directories containing stimuli
const rootFolder = __dirname; // Note: there's a weird issue where the fs readdir function reads from BrainWaves dir

const fixation = path.join(rootFolder, 'assets', 'common', 'fixationcross.png');
const fixation = path.join(
RESOURCE_PATH,
'experiments',
'custom',
'assets',
'common',
'fixationcross.png'
);

export const buildCustomTimeline = () => ({
overview_title: `Custom Experiment`,
Expand Down

0 comments on commit 07d1045

Please sign in to comment.