Skip to content

Commit

Permalink
Merge pull request #75 from teonbrooks/python_overhaul
Browse files Browse the repository at this point in the history
[VWIP] Python overhaul
  • Loading branch information
jdpigeon authored May 10, 2020
2 parents 4527962 + 8a46c12 commit b6a87aa
Show file tree
Hide file tree
Showing 32 changed files with 1,306 additions and 1,420 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,5 @@ main.js.map
.idea
npm-debug.log.*
keys.js

app/utils/pyodide/src
26 changes: 12 additions & 14 deletions app/actions/jupyterActions.js → app/actions/pyodideActions.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
// -------------------------------------------------------------------------
// Action Types

export const LAUNCH_KERNEL = 'LAUNCH_KERNEL';
export const REQUEST_KERNEL_INFO = 'REQUEST_KERNEL_INFO';
export const SEND_EXECUTE_REQUEST = 'SEND_EXECUTE_REQUEST';
export const LOAD_EPOCHS = 'LOAD_EPOCHS';
export const LOAD_CLEANED_EPOCHS = 'LOAD_CLEANED_EPOCHS';
export const LOAD_PSD = 'LOAD_PSD';
export const LOAD_ERP = 'LOAD_ERP';
export const LOAD_TOPO = 'LOAD_TOPO';
export const CLEAN_EPOCHS = 'CLEAN_EPOCHS';
export const CLOSE_KERNEL = 'CLOSE_KERNEL';
export const LAUNCH = "LAUNCH";
export const SEND_EXECUTE_REQUEST = "SEND_EXECUTE_REQUEST";
export const LOAD_EPOCHS = "LOAD_EPOCHS";
export const LOAD_CLEANED_EPOCHS = "LOAD_CLEANED_EPOCHS";
export const LOAD_PSD = "LOAD_PSD";
export const LOAD_ERP = "LOAD_ERP";
export const LOAD_TOPO = "LOAD_TOPO";
export const CLEAN_EPOCHS = "CLEAN_EPOCHS";

// -------------------------------------------------------------------------
// Actions

export const launchKernel = () => ({ type: LAUNCH_KERNEL });

export const requestKernelInfo = () => ({ type: REQUEST_KERNEL_INFO });
export const launch = () => ({
type: LAUNCH
});


export const sendExecuteRequest = (payload: string) => ({
payload,
Expand Down Expand Up @@ -48,5 +48,3 @@ export const loadTopo = () => ({
});

export const cleanEpochs = () => ({ type: CLEAN_EPOCHS });

export const closeKernel = () => ({ type: CLOSE_KERNEL });
16 changes: 4 additions & 12 deletions app/components/CleanComponent/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ import {
import { Link } from 'react-router-dom';
import { isNil } from 'lodash';
import styles from './../styles/collect.css';
import { EXPERIMENTS, DEVICES, KERNEL_STATUS } from '../../constants/constants';
import { Kernel } from '../../constants/interfaces';
import { EXPERIMENTS, DEVICES } from '../../constants/constants';
import { readWorkspaceRawEEGData } from '../../utils/filesystem/storage';
import CleanSidebar from './CleanSidebar';
import * as path from 'path';
Expand All @@ -25,10 +24,8 @@ interface Props {
title: string;
deviceType: DEVICES;
mainChannel: ?any;
kernel: ?Kernel;
kernelStatus: KERNEL_STATUS;
epochsInfo: ?Array<{ [string]: number | string }>;
jupyterActions: Object;
pyodideActions: Object;
experimentActions: Object;
subject: string;
session: number;
Expand Down Expand Up @@ -107,7 +104,7 @@ export default class Clean extends Component<Props, State> {

handleLoadData() {
this.props.experimentActions.setSubject(this.state.selectedSubject);
this.props.jupyterActions.loadEpochs(this.state.selectedFilePaths);
this.props.pyodideActions.loadEpochs(this.state.selectedFilePaths);
}

handleSidebarToggle() {
Expand Down Expand Up @@ -200,11 +197,6 @@ export default class Clean extends Component<Props, State> {
<Grid.Column>
<Button
secondary
disabled={this.props.kernelStatus !== KERNEL_STATUS.IDLE}
loading={
this.props.kernelStatus === KERNEL_STATUS.STARTING ||
this.props.kernelStatus === KERNEL_STATUS.BUSY
}
onClick={this.handleLoadData}
>
Load Dataset
Expand All @@ -214,7 +206,7 @@ export default class Clean extends Component<Props, State> {
<Button
primary
disabled={isNil(this.props.epochsInfo)}
onClick={this.props.jupyterActions.cleanEpochs}
onClick={this.props.pyodideActions.cleanEpochs}
>
Clean Data
</Button>
Expand Down
23 changes: 3 additions & 20 deletions app/components/HomeComponent/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,7 @@ import { toast } from 'react-toastify';
import * as moment from 'moment';

import styles from '../styles/common.css';
import {
EXPERIMENTS,
SCREENS,
KERNEL_STATUS,
CONNECTION_STATUS,
DEVICE_AVAILABILITY,
} from '../../constants/constants';
import { EXPERIMENTS, SCREENS } from '../../constants/constants';
import faceHouseIcon from '../../assets/common/FacesHouses.png';
import stroopIcon from '../../assets/common/Stroop.png';
import multitaskingIcon from '../../assets/common/Multitasking.png';
Expand All @@ -30,12 +24,6 @@ import {
import InputModal from '../InputModal';
import SecondaryNavComponent from '../SecondaryNavComponent';
import OverviewComponent from './OverviewComponent';
import { loadProtocol } from '../../utils/labjs/functions';
import EEGExplorationComponent from '../EEGExplorationComponent';

import { remote } from 'electron';

const { dialog } = remote;

const HOME_STEPS = {
// TODO: maybe change the recent and new labels, but not necessary right now
Expand All @@ -45,17 +33,11 @@ const HOME_STEPS = {
};

interface Props {
kernelStatus: KERNEL_STATUS;
history: Object;
jupyterActions: Object;
connectedDevice: Object;
signalQualityObservable: ?any;
deviceType: DEVICES;
deviceAvailability: DEVICE_AVAILABILITY;
connectionStatus: CONNECTION_STATUS;
deviceActions: Object;
availableDevices: Array<any>;
experimentActions: Object;
pyodideActions: Object;
}

interface State {
Expand Down Expand Up @@ -94,6 +76,7 @@ export default class Home extends Component<Props, State> {
}

componentDidMount() {
this.props.pyodideActions.launch();
this.setState({ recentWorkspaces: readWorkspaces() });
}

Expand Down
15 changes: 7 additions & 8 deletions app/components/JupyterPlotWidget.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
// @flow
import React, { Component } from 'react';
import { Segment, Button } from 'semantic-ui-react';
import { richestMimetype, standardDisplayOrder, standardTransforms } from '@nteract/transforms';
import { isNil } from 'lodash';
import { storeJupyterImage } from '../utils/filesystem/storage';
import React, { Component } from "react";
import { Segment, Button } from "semantic-ui-react";
import { isNil } from "lodash";
import { storePyodideImage } from "../utils/filesystem/storage";

interface Props {
title: string;
Expand All @@ -16,7 +15,7 @@ interface State {
mimeType: string;
}

export default class JupyterPlotWidget extends Component<Props, State> {
export default class PyodidePlotWidget extends Component<Props, State> {
props: Props;
state: State;
constructor(props: Props) {
Expand All @@ -42,8 +41,8 @@ export default class JupyterPlotWidget extends Component<Props, State> {
}

handleSave() {
const buf = Buffer.from(this.state.rawData, 'base64');
storeJupyterImage(this.props.title, this.props.imageTitle, buf);
const buf = Buffer.from(this.state.rawData, "base64");
storePyodideImage(this.props.title, this.props.imageTitle, buf);
}

renderResults() {
Expand Down
131 changes: 66 additions & 65 deletions app/constants/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,39 +20,32 @@ export const SCREENS = {
};

export const DEVICES = {
NONE: 'NONE',
MUSE: 'MUSE',
EMOTIV: 'EMOTIV',
GANGLION: 'GANGLION', // One day ;)
NONE: "NONE",
MUSE: "MUSE",
EMOTIV: "EMOTIV",
GANGLION: "GANGLION" // One day ;)
};

export const CONNECTION_STATUS = {
CONNECTED: 'CONNECTED',
CONNECTING: 'CONNECTING',
DISCONNECTED: 'DISCONNECTED',
NO_DEVICES: 'NO_DEVICES',
NOT_YET_CONNECTED: 'NOT_YET_CONNECTED',
SEARCHING: 'SEARCHING',
BLUETOOTH_DISABLED: 'BLUETOOTH_DISABLED',
};

export const KERNEL_STATUS = {
OFFLINE: 'Offline',
BUSY: 'Busy',
IDLE: 'Idle',
STARTING: 'Starting',
CONNECTED: "CONNECTED",
CONNECTING: "CONNECTING",
DISCONNECTED: "DISCONNECTED",
NO_DEVICES: "NO_DEVICES",
NOT_YET_CONNECTED: "NOT_YET_CONNECTED",
SEARCHING: "SEARCHING",
BLUETOOTH_DISABLED: "BLUETOOTH_DISABLED"
};

export const DEVICE_AVAILABILITY = {
NONE: 'NONE',
SEARCHING: 'SEARCHING',
AVAILABLE: 'AVAILABLE',
NONE: "NONE",
SEARCHING: "SEARCHING",
AVAILABLE: "AVAILABLE"
};

// Names of variables in the jupyter kernel
export const JUPYTER_VARIABLE_NAMES = {
RAW_EPOCHS: 'raw_epochs',
CLEAN_EPOCHS: 'clean_epochs',
// Names of variables in pyodide
export const PYODIDE_VARIABLE_NAMES = {
RAW_EPOCHS: "raw_epochs",
CLEAN_EPOCHS: "clean_epochs"
};

export const SEARCH_TIMER = 3000;
Expand All @@ -67,46 +60,46 @@ export const EVENTS = {

export const CHANNELS = {
// Epoc channels
AF3: { index: 0, color: '#9B6ABC' },
F7: { index: 1, color: '#7EA0C5' },
F3: { index: 2, color: '#8BD6E9' },
FC5: { index: 3, color: '#66B0A9' },
T7: { index: 4, color: '#E7789E' },
P7: { index: 5, color: '#F1A766' },
O1: { index: 6, color: '#FFDA6A' },
O2: { index: 7, color: '#F8F8F8' },
P8: { index: 8, color: '#F8F8F8' },
T8: { index: 9, color: '#F8F8F8' },
FC6: { index: 10, color: '#F8F8F8' },
F4: { index: 11, color: '#F8F8F8' },
F8: { index: 12, color: '#F8F8F8' },
AF4: { index: 13, color: '#F8F8F8' },
AF3: { index: 0, color: "#9B6ABC" },
F7: { index: 1, color: "#7EA0C5" },
F3: { index: 2, color: "#8BD6E9" },
FC5: { index: 3, color: "#66B0A9" },
T7: { index: 4, color: "#E7789E" },
P7: { index: 5, color: "#F1A766" },
O1: { index: 6, color: "#FFDA6A" },
O2: { index: 7, color: "#F8F8F8" },
P8: { index: 8, color: "#F8F8F8" },
T8: { index: 9, color: "#F8F8F8" },
FC6: { index: 10, color: "#F8F8F8" },
F4: { index: 11, color: "#F8F8F8" },
F8: { index: 12, color: "#F8F8F8" },
AF4: { index: 13, color: "#F8F8F8" },
// Muse channels
TP9: { index: 0, color: '#9B6ABC' },
AF7: { index: 1, color: '#7EA0C5' },
AF8: { index: 2, color: '#8BD6E9' },
TP10: { index: 3, color: '#66B0A9' },
AUX: { index: 4, color: '#E7789E' },
TP9: { index: 0, color: "#9B6ABC" },
AF7: { index: 1, color: "#7EA0C5" },
AF8: { index: 2, color: "#8BD6E9" },
TP10: { index: 3, color: "#66B0A9" },
AUX: { index: 4, color: "#E7789E" }
};

export const EMOTIV_CHANNELS = [
'AF3',
'F7',
'F3',
'FC5',
'T7',
'P7',
'O1',
'O2',
'P8',
'T8',
'FC6',
'F4',
'F8',
'AF4',
"AF3",
"F7",
"F3",
"FC5",
"T7",
"P7",
"O1",
"O2",
"P8",
"T8",
"FC6",
"F4",
"F8",
"AF4"
];

export const MUSE_CHANNELS = ['TP9', 'AF7', 'AF8', 'TP10', 'AUX'];
export const MUSE_CHANNELS = ["TP9", "AF7", "AF8", "TP10", "AUX"];

export const ZOOM_SCALAR = 1.5;
export const MUSE_SAMPLING_RATE = 256;
Expand All @@ -120,10 +113,10 @@ export const VIEWER_DEFAULTS = {
};

export const SIGNAL_QUALITY = {
BAD: '#ed5a5a',
OK: '#FFCD39',
GREAT: '#66B0A9',
DISCONNECTED: '#BFBFBF',
BAD: "#ed5a5a",
OK: "#FFCD39",
GREAT: "#66B0A9",
DISCONNECTED: "#BFBFBF"
};

export const SIGNAL_QUALITY_THRESHOLDS = {
Expand All @@ -133,6 +126,14 @@ export const SIGNAL_QUALITY_THRESHOLDS = {
};

export const FILE_TYPES = {
STIMULUS_DIR: 'STIMULUS_DIR',
TIMELINE: 'TIMELINE',
STIMULUS_DIR: "STIMULUS_DIR",
TIMELINE: "TIMELINE"
};

// -----------------------------------------------
// Pyodide

export const PYODIDE_STATUS = {
LOADED: "LOADED",
NOT_LOADED: "NOT_LOADED"
};
10 changes: 0 additions & 10 deletions app/constants/interfaces.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,6 @@ export interface SampleParameter {

export type StimulusVariable = () => any;

// --------------------------------------------------------------------
// Jupyter

export interface Kernel {
config: Object;
connectionFile: string;
kernelSpec: Object;
spawn: ChildProcess;
}

// --------------------------------------------------------------------
// Device

Expand Down
Loading

0 comments on commit b6a87aa

Please sign in to comment.