Skip to content

Commit

Permalink
add series type
Browse files Browse the repository at this point in the history
  • Loading branch information
hillalex committed Dec 11, 2024
1 parent 302074d commit 5f819ae
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 8 deletions.
14 changes: 11 additions & 3 deletions src/components/ChoosePlot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,14 @@ import React from "react";
interface Props {
selectedPlot: string;
selectPlot: (name: string) => void
seriesType: "surveillance" | "post-exposure"
}

export default function ChoosePlot({selectedPlot, selectPlot}: Props) {
export default function ChoosePlot({
selectedPlot,
selectPlot,
seriesType
}: Props) {

const onSelectPlot = (event: any) => {
selectPlot(event.target.value);
Expand All @@ -17,8 +22,11 @@ export default function ChoosePlot({selectedPlot, selectPlot}: Props) {
plot</Form.Label>
<Form.Select id="plot" onChange={onSelectPlot}
value={selectedPlot}>
<option value={"population"}>Population</option>
<option value={"individual"}>Individual</option>
<option value={"population"}>Population trajectories</option>
{seriesType === "post-exposure" &&
<option value={"histogram"}>Population histogram</option>

Check warning on line 27 in src/components/ChoosePlot.tsx

View check run for this annotation

Codecov / codecov/patch

src/components/ChoosePlot.tsx#L27

Added line #L27 was not covered by tests
}
<option value={"individual"}>Individual trajectories</option>
</Form.Select>
</Form.Group>
}
24 changes: 24 additions & 0 deletions src/components/ChooseSeriesType.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import Form from "react-bootstrap/Form";

Check warning on line 1 in src/components/ChooseSeriesType.tsx

View check run for this annotation

Codecov / codecov/patch

src/components/ChooseSeriesType.tsx#L1

Added line #L1 was not covered by tests
import React from "react";

interface Props {
selectedType: "surveillance" | "post-exposure";
selectType: (name: "surveillance" | "post-exposure") => void
}

export default function ChooseSeriesType({selectedType, selectType}: Props) {

Check warning on line 9 in src/components/ChooseSeriesType.tsx

View check run for this annotation

Codecov / codecov/patch

src/components/ChooseSeriesType.tsx#L9

Added line #L9 was not covered by tests

const onSelectType = (event: any) => {
selectType(event.target.value);

Check warning on line 12 in src/components/ChooseSeriesType.tsx

View check run for this annotation

Codecov / codecov/patch

src/components/ChooseSeriesType.tsx#L11-L12

Added lines #L11 - L12 were not covered by tests
}

return <Form.Group key="choose-dataset" className={"mb-3"}>

Check warning on line 15 in src/components/ChooseSeriesType.tsx

View check run for this annotation

Codecov / codecov/patch

src/components/ChooseSeriesType.tsx#L15

Added line #L15 was not covered by tests
<Form.Label htmlFor="data">Choose
dataset</Form.Label>
<Form.Select id="data" onChange={onSelectType}
value={selectedType}>
<option value={"surveillance"}>Surveillance</option>
<option value={"post-exposure"}>Post-exposure</option>
</Form.Select>
</Form.Group>
}
11 changes: 9 additions & 2 deletions src/components/SideBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,21 @@ export default function SideBar() {
<fieldset>
<ChooseDataset selectedDataset={state.selectedDataset}
selectDataset={selectDataset}/>
<ChoosePlot selectedPlot={state.selectedPlot}
selectPlot={selectPlot}/>
<Row className={"mb-3"}>
<Col>
Time series type <br/><span
className={"text-secondary"}>{state.datasetMetadata?.type}</span>
</Col>
</Row>
<Row className={"mb-3"}>
<Col>
Detected biomarkers <br/><span
className={"text-secondary"}>{state.datasetMetadata?.biomarkers.join(", ")}</span>
</Col>
</Row>
<ChoosePlot selectedPlot={state.selectedPlot}
selectPlot={selectPlot}
seriesType={state.datasetMetadata?.type || "surveillance"}/>
<ChooseScale/>
<hr/>
<PopulationOptions/>
Expand Down
17 changes: 17 additions & 0 deletions src/components/UploadDataset.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@ export default function UploadDataset() {
const apiService = api(state.language, dispatch);

const [timeColumnHeader, setTimeColumnHeader] = useState("day");
const [dataType, setDataType] = useState("surveillance");
const [datasetName, setDatasetName] = useState("");
const [validName, setValidName] = useState(true);
const [selectedFile, selectFile] = useState("");
const [isUploading, setIsUploading] = useState(false);

const onSelectTimeColumnHeader = (e: any) => setTimeColumnHeader(e.target.value);
const onSelectDataType = (e: any) => setDataType(e.target.value);
const onSelectDatasetName = (e: any) => {
setDatasetName(e.target.value);
setValidName(isAlphaNumeric(e.target.value));
Expand Down Expand Up @@ -52,6 +54,7 @@ export default function UploadDataset() {
formData.append('file', selectedFile);
formData.append('xcol', timeColumnHeader);
formData.append('name', datasetName);
formData.append('series_type', dataType);

const dataService = new DataService(apiService);

Expand Down Expand Up @@ -118,6 +121,20 @@ export default function UploadDataset() {
</Form.Text>
</Col>
</Form.Group>
<Form.Group className={"row mb-3"}>
<Form.Label column sm={3}>Time series type</Form.Label>
<Col sm={6}>
<Form.Select onChange={onSelectDataType}
value={dataType}>
<option value={"surveillance"}>Surveillance</option>
<option value={"post-exposure"}>Post-exposure</option>
</Form.Select>
<Form.Text>
Is this an absolute (surveillance) or a relative
(post-exposure) time series?
</Form.Text>
</Col>
</Form.Group>
<div
className={state.uploadError ? "invalid-feedback d-block" : "d-none"}>
{state.uploadError && state.uploadError.detail}
Expand Down
4 changes: 1 addition & 3 deletions src/generated.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export interface DatasetMetadata {
variables: VariableSchema[];
biomarkers: string[];
xcol: string;
type: "surveillance" | "post-exposure";
}
export interface VariableSchema {
name: string;
Expand All @@ -29,7 +30,6 @@ export type DatasetNames = string[];
export interface ErrorDetail {
error: string;
detail: string | null;
[k: string]: unknown;
}
export interface Plotly {
data: {
Expand All @@ -48,12 +48,10 @@ export interface ResponseFailure {
status: "failure";
data: null;
errors: ErrorDetailSchema[];
[k: string]: unknown;
}
export interface ErrorDetailSchema {
error: string;
detail: string | null;
[k: string]: unknown;
}
export interface ResponseSuccess {
status: "success";
Expand Down
1 change: 1 addition & 0 deletions test/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export function mockDatasetMetadata(datasetMetadata: Partial<DatasetMetadata> =
variables: [mockVariable()],
xcol: "day",
biomarkers: ["ab"],
type: "surveillance",
...datasetMetadata
}
}
Expand Down

0 comments on commit 5f819ae

Please sign in to comment.