import React, { Component } from 'react'; import path from 'pathe'; import { Link } from 'react-router-dom'; import { isNil, isString } from 'lodash'; import { Button } from '../ui/button'; import { EXPERIMENTS, DEVICES } from '../../constants/constants'; import { readWorkspaceRawEEGData } from '../../utils/filesystem/storage'; import CleanSidebar from './CleanSidebar'; import { PyodideActions, ExperimentActions } from '../../actions'; export interface Props { type?: EXPERIMENTS; title: string; deviceType: DEVICES; epochsInfo: Array<{ [key: string]: number | string; }>; PyodideActions: typeof PyodideActions; ExperimentActions: typeof ExperimentActions; subject: string; session: number; } interface DropdownOption { key: string; text: string; value: string; } interface State { subjects: Array; eegFilePaths: Array; selectedSubject: string; selectedFilePaths: Array; isSidebarVisible: boolean; } export default class Clean extends Component { icons: string[]; constructor(props: Props) { super(props); this.state = { subjects: [], eegFilePaths: [{ key: '', text: '', value: '' }], selectedFilePaths: [], selectedSubject: props.subject, isSidebarVisible: false, }; this.handleRecordingChange = this.handleRecordingChange.bind(this); this.handleLoadData = this.handleLoadData.bind(this); this.handleSidebarToggle = this.handleSidebarToggle.bind(this); this.handleSubjectChange = this.handleSubjectChange.bind(this); this.icons = props.type === EXPERIMENTS.N170 ? ['😊', '🏠', '✕', '📖'] : ['★', '☆', '✕', '📖']; } async componentDidMount() { const workspaceRawData = await readWorkspaceRawEEGData(this.props.title); this.setState({ subjects: workspaceRawData .map( (filepath) => filepath.path.split(path.sep)[ filepath.path.split(path.sep).length - 3 ] ) .reduce((acc, curr) => { if (acc.find((subject) => subject.key === curr)) { return acc; } return acc.concat({ key: curr, text: curr, value: curr }); }, []), eegFilePaths: workspaceRawData.map((filepath) => ({ key: filepath.name, text: filepath.name, value: filepath.path, })), }); } handleRecordingChange(e: React.ChangeEvent) { const filePaths = Array.from(e.target.selectedOptions, (o) => o.value); this.setState({ selectedFilePaths: filePaths }); } handleSubjectChange(e: React.ChangeEvent) { const { value } = e.target; if (!isNil(value) && isString(value)) { this.setState({ selectedSubject: value, selectedFilePaths: [] }); } } handleLoadData() { this.props.ExperimentActions.SetSubject(this.state.selectedSubject); this.props.PyodideActions.LoadEpochs(this.state.selectedFilePaths); } handleSidebarToggle() { this.setState({ isSidebarVisible: !this.state.isSidebarVisible }); } renderEpochLabels() { if ( !isNil(this.props.epochsInfo) && this.state.selectedFilePaths.length >= 1 ) { return (
{this.props.epochsInfo.map((infoObj, index) => (
{this.icons[index]} {infoObj.name}

{infoObj.value}

))}
); } return
; } renderAnalyzeButton() { const { epochsInfo } = this.props; if (!isNil(epochsInfo)) { const drop = epochsInfo.find( (infoObj) => infoObj.name === 'Drop Percentage' )?.value; if (drop && typeof drop === 'number' && drop >= 2) { return ( ); } } return null; } render() { const filteredFilePaths = this.state.eegFilePaths.filter((filepath) => { const strVal = filepath.value; const subjectFromFilepath = strVal.split(path.sep)[ strVal.split(path.sep).length - 3 ]; return this.state.selectedSubject === subjectFromFilepath; }); return (
{this.state.isSidebarVisible && (
)}

Clean

Select & Clean

Ready to clean some data? Select a subject and one or more EEG recordings, then launch the editor

Select Subject

Select Recordings

{this.renderEpochLabels()} {this.renderAnalyzeButton()}
); } }