Skip to content

Commit fcb0907

Browse files
committed
Some reorganization
1 parent 0b7f747 commit fcb0907

4 files changed

Lines changed: 22 additions & 15 deletions

File tree

client/src/api/experiment.js

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
// API functions for the Experiment tab
22

33
import { fetchData } from './api';
4+
import { dateToRFC } from './utils';
45

56
const NUMBER_OF_WELLS = 16;
67

78
// Queries all wells for either temperature or luminosity
89
const queryAllWells = async (start, end, key) => {
910
let endpoint = `/payload/wells`
1011

11-
if (key == 'temperature') endpoint += `/temp`
12-
else if (key == 'luminosity') endpoint += `/lumin`
12+
if (key === 'temperature') endpoint += `/temp`
13+
else if (key === 'luminosity') endpoint += `/lumin`
1314

1415
const params = new URLSearchParams({start: dateToRFC(start), end: dateToRFC(end)})
1516

@@ -32,8 +33,3 @@ export const fetchExperiment = async (start, end) => {
3233
]);
3334
return { temperature, luminosity };
3435
};
35-
36-
const dateToRFC = (d) => {
37-
// removes the fractional seconds from the ISO string
38-
return d.toISOString().replace(/\.\d{3}Z$/, 'Z');
39-
}
Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
1+
/*
2+
* Contains randomly generated datasets, useful
3+
* for testing data display components without
4+
* connecting to the database.
5+
*/
6+
17
let hour = 1000 * 60 * 60;
28

9+
/* Payload datasets */
310
export const testTemperatureData = Array.from({ length: 4 }, () =>
411
Array.from({ length: 720 }, (_, i) => [
512
Date.now() - i * hour,
@@ -14,11 +21,9 @@ export const testLuminosityData = Array.from({ length: 4 }, () =>
1421
])
1522
);
1623

17-
export const wellActivity = [
24+
export const testWellActivity = [
1825
1, 1, 0, 1,
1926
1, 1, 0, 1,
2027
1, 1, 0, 1,
2128
1, 1, 0, 1
2229
]
23-
24-
export const labels = Array.from({length: 16}, (_, i) => `Well ${i + 1}`)

client/src/api/utils.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// General API utility functions
2+
3+
export const dateToRFC = (d) => {
4+
// removes the fractional seconds from the ISO string
5+
return d.toISOString().replace(/\.\d{3}Z$/, 'Z');
6+
}

client/src/pages/ExperimentTab.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
import React, { useState, useEffect } from 'react';
2-
import {
3-
labels, wellActivity
4-
} from '../components/ExperimentData.jsx';
52
import { useQuery } from '@tanstack/react-query';
63
import { fetchExperiment } from '../api/experiment.js';
74
import Box from '@mui/material/Box';
85
import FormControlLabel from '@mui/material/FormControlLabel';
96
import Switch from '@mui/material/Switch';
107
import TimeseriesChart from '../components/TimeseriesChart.jsx';
118
import { useTimeContext } from "../components/TimeRangeContext.jsx";
9+
import { testTemperatureData, testLuminosityData, testWellActivity } from '../api/testData.js';
1210

1311
const CHART_WIDTH = 800;
1412

@@ -17,6 +15,8 @@ const chartSize = {
1715
height: 400
1816
}
1917

18+
const chartLabels = Array.from({length: 16}, (_, i) => `Well ${i + 1}`)
19+
2020
export default function ExperimentTab() {
2121
const { timeRange } = useTimeContext();
2222

@@ -44,8 +44,8 @@ export default function ExperimentTab() {
4444
}, [data]);
4545

4646
const chartProps = {
47-
labels: labels,
48-
seriesActivity: !showInactiveWells ? wellActivity : undefined,
47+
labels: chartLabels,
48+
seriesActivity: !showInactiveWells ? testWellActivity : undefined,
4949
xmin: timeRange.start,
5050
xmax: timeRange.end,
5151
style: {...chartSize}

0 commit comments

Comments
 (0)