Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[wip] Move to Pyodide #157

Open
wants to merge 40 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
e673fde
direct copy from pyodide-0.10 build
teonbrooks Apr 1, 2019
d4f7883
Rebased with makebrainwaves/master
jdpigeon Apr 26, 2020
40b08b3
Update pyodide.js
teonbrooks Apr 3, 2019
4a3abfe
rewriting the python dependency within brainwaves
teonbrooks Apr 7, 2019
ff76465
fixed package script conflict
jdpigeon Apr 26, 2020
147326d
fixed package script conflict
jdpigeon Apr 26, 2020
9a03113
rename files from jupyter to pyodide
teonbrooks Apr 7, 2019
6be006b
WIP cleanup and overhaul
teonbrooks Apr 9, 2019
3a02731
overhaul continues
teonbrooks Apr 12, 2019
7c2c30b
Switched Cortex wrapper to debug verbosity
jdpigeon May 26, 2019
73459a0
Speculatively updated epics for pyodide
jdpigeon May 26, 2019
83418cf
Added node pyodide install script
jdpigeon Jun 17, 2019
ffd5fab
Added loading of pyodide within app epics
jdpigeon Jun 18, 2019
d5145e1
moving files
teonbrooks Jun 19, 2019
9783e7a
Reverted inadvertent logging change
jdpigeon Jul 8, 2019
6773440
updates and rebase
teonbrooks Aug 3, 2019
5f416ea
massive overhaul of pyodide in the app
teonbrooks Aug 3, 2019
473b711
Tidyed up pyodide files and removed some jupyter dependencies
jdpigeon Mar 7, 2020
4092c58
Updated pyodide version
jdpigeon Mar 7, 2020
465a79d
fixed rebase bug
jdpigeon Apr 26, 2020
4961fa8
Switched to web worker with different epic pattern
jdpigeon May 11, 2020
4523001
Tidied up dependency bugs related to pyodide rebase
jdpigeon May 11, 2020
446bfa4
additional cleanup from rebase
teonbrooks Oct 15, 2020
b2b687b
wip
teonbrooks Jun 29, 2021
fd76cd5
Delete index.js
teonbrooks Jul 2, 2021
a65f242
Delete pyodideActions.js
teonbrooks Jul 2, 2021
28246d2
Converted js epics to ts
jdpigeon Jul 2, 2021
523251d
Updated pyodide actions
jdpigeon Jul 2, 2021
d442c5c
Updated utils to typescript
jdpigeon Jul 2, 2021
74cf703
fix the postinstall script
teonbrooks Jul 2, 2021
ec4782a
fix the reducer to remove the SetMainChannel action
teonbrooks Jul 2, 2021
e8399c6
code cleanup
teonbrooks Jul 3, 2021
ea960fd
updated the webworker code to rely on pyodide loader
teonbrooks Jul 3, 2021
2e4339e
updates to package.json
teonbrooks Jul 3, 2021
b152ed6
debugging
teonbrooks Jul 3, 2021
a459369
Fixed issues with pyodide not loading;
jdpigeon Aug 1, 2021
6b5f79f
Debug screen added; blocked by pyodide error
jdpigeon Aug 1, 2021
987a5ea
fixed error related to the field
teonbrooks Aug 2, 2021
62173fc
patch pyodide
teonbrooks Sep 17, 2021
6222cb1
Update InstallPyodide.js
teonbrooks Aug 23, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,5 @@ npm-debug.log.*
*.sass.d.ts
*.scss.d.ts
keys.js

app/utils/pyodide/src
2 changes: 1 addition & 1 deletion app/actions/index.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export * from './experimentActions';
export * from './jupyterActions';
export * from './pyodideActions';
export * from './deviceActions';
50 changes: 0 additions & 50 deletions app/actions/jupyterActions.ts

This file was deleted.

36 changes: 36 additions & 0 deletions app/actions/pyodideActions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { createAction } from '@reduxjs/toolkit';
import { ActionType } from 'typesafe-actions';
import { PYODIDE_VARIABLE_NAMES } from '../constants/constants';

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

export const PyodideActions = {
Launch: createAction('LAUNCH'),
SetPyodideWorker: createAction<Worker, 'SET_PYODIDE_WORKER'>(
'SET_PYODIDE_WORKER'
),
LoadEpochs: createAction<string[], 'LOAD_EPOCHS'>('LOAD_EPOCHS'),
LoadCleanedEpochs: createAction<string[], 'LOAD_CLEANED_EPOCHS'>(
'LOAD_CLEANED_EPOCHS'
),
LoadPSD: createAction('LOAD_PSD'),
LoadERP: createAction<string, 'LOAD_ERP'>('LOAD_ERP'),
LoadTopo: createAction('LOAD_TOPO'),
CleanEpochs: createAction('CLEAN_EPOCHS'),
GetEpochsInfo: createAction<PYODIDE_VARIABLE_NAMES, 'GET_EPOCHS_INFO'>(
'GET_EPOCHS_INFO'
),
GetChannelInfo: createAction('GET_CHANNEL_INFO'),
SetEpochInfo: createAction<any, 'SET_EPOCH_INFO'>('SET_EPOCH_INFO'),
SetChannelInfo: createAction<any, 'SET_CHANNEL_INFO'>('SET_CHANNEL_INFO'),
SetPSDPlot: createAction<any, 'SET_PSD_PLOT'>('SET_PSD_PLOT'),
SetTopoPlot: createAction<any, 'SET_TOPO_PLOT'>('SET_TOPO_PLOT'),
SetERPPlot: createAction<any, 'SET_ERP_PLOT'>('SET_ERP_PLOT'),
ReceiveMessage: createAction<any, 'RECEIVE_MESSAGE'>('RECEIVE_MESSAGE'),
ReceiveError: createAction<any, 'RECEIVE_ERROR'>('RECEIVE_ERROR'),
} as const;

export type PyodideActionType = ActionType<
typeof PyodideActions[keyof typeof PyodideActions]
>;
22 changes: 7 additions & 15 deletions app/components/AnalyzeComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import {
DEVICES,
MUSE_CHANNELS,
EMOTIV_CHANNELS,
KERNEL_STATUS,
EXPERIMENTS,
} from '../constants/constants';
import {
Expand All @@ -34,10 +33,9 @@ import {
} from '../utils/behavior/compute';
import SecondaryNavComponent from './SecondaryNavComponent';
import ClickableHeadDiagramSVG from './svgs/ClickableHeadDiagramSVG';
import JupyterPlotWidget from './JupyterPlotWidget';
import PyodidePlotWidget from './PyodidePlotWidget';
import { HelpButton } from './CollectComponent/HelpSidebar';
import { Kernel } from '../constants/interfaces';
import { JupyterActions } from '../actions/jupyterActions';
import { PyodideActions } from '../actions/pyodideActions';

const ANALYZE_STEPS = {
OVERVIEW: 'OVERVIEW',
Expand All @@ -54,9 +52,6 @@ interface Props {
type: EXPERIMENTS;
deviceType: DEVICES;
isEEGEnabled: boolean;
kernel: Kernel;
kernelStatus: KERNEL_STATUS;
mainChannel: any;
epochsInfo: Array<{
[key: string]: number | string;
}>;
Expand All @@ -74,7 +69,7 @@ interface Props {
[key: string]: string;
};

JupyterActions: typeof JupyterActions;
PyodideActions: typeof PyodideActions;
}

interface State {
Expand Down Expand Up @@ -163,9 +158,6 @@ export default class Analyze extends Component<Props, State> {
const workspaceCleanData = await readWorkspaceCleanedEEGData(
this.props.title
);
if (this.props.kernelStatus === KERNEL_STATUS.OFFLINE) {
this.props.JupyterActions.LaunchKernel();
}
const behavioralData = await readWorkspaceBehaviorData(this.props.title);
this.setState({
eegFilePaths: workspaceCleanData.map((filepath) => ({
Expand Down Expand Up @@ -200,7 +192,7 @@ export default class Analyze extends Component<Props, State> {
selectedFilePaths: data.value,
selectedSubjects: getSubjectNamesFromFiles(data.value),
});
this.props.JupyterActions.LoadCleanedEpochs(data.value);
this.props.PyodideActions.LoadCleanedEpochs(data.value);
}
}

Expand Down Expand Up @@ -343,7 +335,7 @@ export default class Analyze extends Component<Props, State> {

handleChannelSelect(channelName: string) {
this.setState({ selectedChannel: channelName });
this.props.JupyterActions.LoadERP(channelName);
this.props.PyodideActions.LoadERP(channelName);
}

handleStepClick(step: string) {
Expand Down Expand Up @@ -480,7 +472,7 @@ export default class Analyze extends Component<Props, State> {
</Segment>
</Grid.Column>
<Grid.Column width={8}>
<JupyterPlotWidget
<PyodidePlotWidget
title={this.props.title}
imageTitle={`${this.concatSubjectNames(
this.state.selectedSubjects
Expand Down Expand Up @@ -509,7 +501,7 @@ export default class Analyze extends Component<Props, State> {
</Segment>
</Grid.Column>
<Grid.Column width={8}>
<JupyterPlotWidget
<PyodidePlotWidget
title={this.props.title}
imageTitle={`${this.concatSubjectNames(
this.state.selectedSubjects
Expand Down
29 changes: 6 additions & 23 deletions app/components/CleanComponent/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,19 @@ import { Link } from 'react-router-dom';
import { isNil, isArray, isString } from 'lodash';
import styles from '../styles/collect.css';
import commonStyles from '../styles/common.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 { JupyterActions, ExperimentActions } from '../../actions';
import { PyodideActions, ExperimentActions } from '../../actions';

export interface Props {
type?: EXPERIMENTS;
title: string;
deviceType: DEVICES;
mainChannel?: any;
kernel?: Kernel;
kernelStatus: KERNEL_STATUS;
epochsInfo: Array<{
[key: string]: number | string;
}>;
JupyterActions: typeof JupyterActions;
PyodideActions: typeof PyodideActions;
ExperimentActions: typeof ExperimentActions;
subject: string;
session: number;
Expand Down Expand Up @@ -72,9 +68,6 @@ export default class Clean extends Component<Props, State> {

async componentDidMount() {
const workspaceRawData = await readWorkspaceRawEEGData(this.props.title);
if (this.props.kernelStatus === KERNEL_STATUS.OFFLINE) {
this.props.JupyterActions.LaunchKernel();
}
this.setState({
subjects: workspaceRawData
.map(
Expand Down Expand Up @@ -116,7 +109,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 @@ -230,25 +223,15 @@ export default class Clean extends Component<Props, State> {
<Divider hidden section />
<Grid textAlign="center" columns="equal">
<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}
>
<Button secondary onClick={this.handleLoadData}>
Load Dataset
</Button>
</Grid.Column>
<Grid.Column>
<Button
primary
disabled={isNil(this.props.epochsInfo)}
onClick={this.props.JupyterActions.CleanEpochs}
onClick={this.props.PyodideActions.CleanEpochs}
>
Clean Data
</Button>
Expand Down
37 changes: 30 additions & 7 deletions app/components/HomeComponent/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { Component } from 'react';
import { isNil } from 'lodash';
import { Grid, Button, Header, Segment, Image, Table } from 'semantic-ui-react';
import { Grid, Button, Header, Image, Table } from 'semantic-ui-react';
import { toast } from 'react-toastify';
import * as moment from 'moment';
import { History } from 'history';
Expand All @@ -10,7 +10,6 @@ import styles from '../styles/common.css';
import {
EXPERIMENTS,
SCREENS,
KERNEL_STATUS,
CONNECTION_STATUS,
DEVICE_AVAILABILITY,
DEVICES,
Expand All @@ -19,7 +18,7 @@ import faceHouseIcon from '../../experiments/faces_houses/icon.png';
import stroopIcon from '../../experiments/stroop/icon.png';
import multitaskingIcon from '../../experiments/multitasking/icon.png';
import searchIcon from '../../experiments/search/icon.png';
import customIcon from '../../experiments/custom/icon.png';
// import customIcon from '../../experiments/custom/icon.png';
import appLogo from '../../assets/common/app_logo.png';
import divingMan from '../../assets/common/divingMan.svg';
import {
Expand All @@ -29,7 +28,7 @@ import {
deleteWorkspaceDir,
} from '../../utils/filesystem/storage';
import {
JupyterActions,
PyodideActions,
DeviceActions,
ExperimentActions,
} from '../../actions';
Expand All @@ -40,6 +39,7 @@ import OverviewComponent from './OverviewComponent';
import EEGExplorationComponent from '../EEGExplorationComponent';
import { SignalQualityData } from '../../constants/interfaces';
import { getExperimentFromType } from '../../utils/labjs/functions';
import PyodidePlotWidget from '../PyodidePlotWidget';

const { dialog } = remote;

Expand All @@ -48,6 +48,7 @@ const HOME_STEPS = {
RECENT: 'MY EXPERIMENTS',
NEW: 'EXPERIMENT BANK',
EXPLORE: 'EXPLORE EEG DATA',
PYODIDE_TEST: 'PYODIDE_TEST',
};

export interface Props {
Expand All @@ -60,9 +61,11 @@ export interface Props {
deviceType: DEVICES;
ExperimentActions: typeof ExperimentActions;
history: History;
JupyterActions: typeof JupyterActions;
kernelStatus: KERNEL_STATUS;
PyodideActions: typeof PyodideActions;
signalQualityObservable?: Observable<SignalQualityData>;
topoPlot: {
[key: string]: string;
};
}

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

componentDidMount() {
this.props.PyodideActions.Launch();
this.setState({ recentWorkspaces: readWorkspaces() });
}

Expand Down Expand Up @@ -226,7 +230,7 @@ export default class Home extends Component<Props, State> {
if (!workspaceState) {
return undefined;
}
const dateModified = workspaceState.dateModified;
const { dateModified } = workspaceState;
return (
<Table.Row key={dir} className={styles.experimentRow}>
<Table.Cell className={styles.experimentRowName}>
Expand Down Expand Up @@ -361,6 +365,25 @@ export default class Home extends Component<Props, State> {
DeviceActions={this.props.DeviceActions}
/>
);
case HOME_STEPS.PYODIDE_TEST:
return (
<Grid columns="two" relaxed padded>
<Grid.Row>
<Grid.Column>
<Button onClick={this.props.PyodideActions.LoadTopo}>
Generate Plot
</Button>
</Grid.Column>
<Grid.Column>
<PyodidePlotWidget
title={"Test Plot"}
imageTitle={`Test-Topoplot`}
plotMIMEBundle={this.props.topoPlot}
/>
</Grid.Column>
</Grid.Row>
</Grid>
);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
standardTransforms,
} from '@nteract/transforms';
import { isNil } from 'lodash';
import { storeJupyterImage } from '../utils/filesystem/storage';
import { storePyodideImage } from '../utils/filesystem/storage';

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

export default class JupyterPlotWidget extends Component<Props, State> {
export default class PyodidePlotWidget extends Component<Props, State> {
// state: State;
constructor(props: Props) {
super(props);
Expand Down Expand Up @@ -56,7 +56,7 @@ 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);
storePyodideImage(this.props.title, this.props.imageTitle, buf);
}

renderResults() {
Expand Down
Loading