-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
194 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import React from 'react'; | ||
import { Container } from 'reactstrap'; | ||
|
||
import Header from 'components/header'; | ||
import WaitingForServerToBeReady from './waiting-for-server-to-be-ready'; | ||
import UploadForm from './upload-form'; | ||
|
||
import text from './text.json'; | ||
|
||
const isServerReady = true; | ||
|
||
const AnalyzeSleep = () => { | ||
return ( | ||
<div> | ||
<Header | ||
sizeClass={'pb-100'} | ||
shapeQty={7} | ||
title={text['header_title']} | ||
subtitle={text['header_subtitle']} | ||
description={text['header_description']} | ||
/> | ||
<Container className="mt-5 text-justify">{isServerReady ? <UploadForm /> : <WaitingForServerToBeReady />}</Container> | ||
</div> | ||
); | ||
}; | ||
|
||
export default AnalyzeSleep; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"header_title": "Your night", | ||
"header_subtitle": "visualized and compared", | ||
"header_description": "Upload your night of sleep" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
import React from 'react'; | ||
import { Button, Container, CustomInput, Form, FormGroup, Label, Input, InputGroup, Col, Row } from 'reactstrap'; | ||
import { useForm } from 'react-hook-form'; | ||
|
||
const UploadForm = () => { | ||
const { register, handleSubmit } = useForm(); | ||
const onSubmit = (data) => { | ||
const dateFieldSuffix = '-date'; | ||
const timeFieldSuffix = '-time'; | ||
|
||
const dateTimeFields = Object.keys(data) | ||
.filter((field) => field.endsWith(timeFieldSuffix)) | ||
.map((field) => field.replace(timeFieldSuffix, '')); | ||
|
||
const mergedDateTimeFields = dateTimeFields.map((fieldPrefix) => [ | ||
fieldPrefix, | ||
new Date( | ||
Object.entries(data) | ||
.filter(([fieldName, value]) => fieldName.startsWith(fieldPrefix)) | ||
.map(([fieldName, value]) => value) | ||
.join(' '), | ||
), | ||
]); | ||
|
||
const newFormData = Object.fromEntries([ | ||
...Object.entries(data).filter(([fieldName, value]) => !(fieldName.endsWith(dateFieldSuffix) || fieldName.endsWith(timeFieldSuffix))), | ||
...mergedDateTimeFields, | ||
]); | ||
|
||
console.log(newFormData); | ||
}; | ||
|
||
return ( | ||
<Container style={{ padding: '2em 0' }}> | ||
<Row> | ||
<Col sm="12" md={{ size: 8, offset: 2 }}> | ||
<Form onSubmit={handleSubmit(onSubmit)}> | ||
<h3>Please enter your EEG recorded data and the information related to it:</h3> | ||
|
||
<CustomInput | ||
innerRef={register} | ||
required | ||
accept=".csv, text/plain" | ||
bsSize="lg" | ||
type="file" | ||
id="openbci-file" | ||
name="openbci-file" | ||
label="Upload an OpenBCI CSV file" | ||
/> | ||
|
||
<FormGroup> | ||
<Label for="openbci-device">OpenBCI device</Label> | ||
<Row> | ||
<Col md={6}> | ||
<CustomInput innerRef={register} required type="select" id="openbci-device" name="device"> | ||
<option></option> | ||
<option>Cython</option> | ||
<option>Ganglion</option> | ||
</CustomInput> | ||
</Col> | ||
</Row> | ||
</FormGroup> | ||
|
||
<FormGroup inline> | ||
<Label>Name</Label> | ||
<Row form> | ||
<Col md={6}> | ||
<Input innerRef={register} required type="text" name="firstName" id="firstName" placeholder="First name" /> | ||
</Col> | ||
<Col md={6}> | ||
<Input innerRef={register} required type="text" name="lastName" id="lastName" placeholder="Last name" /> | ||
</Col> | ||
</Row> | ||
</FormGroup> | ||
|
||
<Row form> | ||
<Col md={6}> | ||
<FormGroup inline> | ||
<Label for="sex">Sex</Label> | ||
<CustomInput required type="radio" id="male" name="sex" label="Male" /> | ||
<CustomInput required type="radio" id="female" name="sex" label="Female" /> | ||
</FormGroup> | ||
</Col> | ||
<Col md={6}> | ||
<FormGroup> | ||
<Label for="age">Age</Label> | ||
<Input innerRef={register} required type="number" name="age" id="age" min="0" max="125" placeholder="Enter your age" /> | ||
</FormGroup> | ||
</Col> | ||
</Row> | ||
|
||
<div> | ||
<Row form> | ||
<Col md={6}> | ||
<FormGroup> | ||
<Label>Time when OpenBCI stream started</Label> | ||
<InputGroup> | ||
<Input innerRef={register} required type="date" name="stream-start-date" id="stream-start-date" /> | ||
<Input innerRef={register} required type="time" name="stream-start-time" id="stream-start-time" /> | ||
</InputGroup> | ||
</FormGroup> | ||
</Col> | ||
<Col md={6}> | ||
<FormGroup> | ||
<Label>I went to bed at</Label> | ||
<InputGroup> | ||
<Input innerRef={register} required type="date" name="bedtime-date" id="bedtime-date" /> | ||
<Input innerRef={register} required type="time" name="bedtime-time" id="bedtime-time" /> | ||
</InputGroup> | ||
</FormGroup> | ||
</Col> | ||
</Row> | ||
<Row form> | ||
<Col md={6}> | ||
<FormGroup> | ||
<Label>I think I fell asleep at</Label> | ||
<InputGroup> | ||
<Input innerRef={register} required type="date" name="sleeping-date" id="sleeping-date" /> | ||
<Input innerRef={register} required type="time" name="sleeping-time" id="sleeping-time" /> | ||
</InputGroup> | ||
</FormGroup> | ||
</Col> | ||
<Col md={6}> | ||
<FormGroup> | ||
<Label>And woke up at</Label> | ||
<InputGroup> | ||
<Input innerRef={register} required type="date" name="wakeup-date" id="wakeup-date" /> | ||
<Input innerRef={register} required type="time" name="wakeup-time" id="wakeup-time" /> | ||
</InputGroup> | ||
</FormGroup> | ||
</Col> | ||
</Row> | ||
</div> | ||
|
||
<Button size="lg" color="primary"> | ||
Analyze my sleep | ||
</Button> | ||
</Form> | ||
</Col> | ||
</Row> | ||
</Container> | ||
); | ||
}; | ||
|
||
export default UploadForm; |
9 changes: 9 additions & 0 deletions
9
web/src/views/analyze-sleep/waiting-for-server-to-be-ready.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import React from 'react'; | ||
|
||
const WaitingForServerToBeReady = () => ( | ||
<div> | ||
<h1>Waiting for local server to be running...</h1> | ||
</div> | ||
); | ||
|
||
export default WaitingForServerToBeReady; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters