Skip to content

Commit

Permalink
bugfix/cwms-data-plotting (#251)
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinJJackson authored Dec 12, 2024
1 parent 58e9c9c commit 071d793
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 10 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "hhd-ui",
"version": "0.18.6",
"version": "0.18.7",
"private": true,
"dependencies": {
"@ag-grid-community/client-side-row-model": "^30.0.3",
Expand Down
20 changes: 11 additions & 9 deletions src/app-pages/project/batch-plotting/batch-plotting.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,7 @@ const BatchPlotting = connect(
const uri = `/projects/${projectId}/instruments/${id}/timeseries/cwms`;
return apiGet(uri);
},
staleTime: Infinity,
enabled: !!cwmsTimeseries.length,
enabled: !!instrumentIds.length,
})),
combine: (ret) => {
return {
Expand All @@ -72,23 +71,25 @@ const BatchPlotting = connect(

const cwmsTimeseriesIds = midasCwmsTimeseries.map(ts => ts?.cwms_timeseries_id);

const { data: cwmsTimeseriesMeasurements } = useQueries({
queries: cwmsTimeseriesIds.map(ts => ({
queryKey: ['cwmsTimeseriesMeasurementsPlotting', ts, currentDateRange[0]],
const { data: cwmsTimeseriesMeasurements, errors: cwmsMeasurementsErrors } = useQueries({
queries: cwmsTimeseriesIds.map(cwmsId => ({
queryKey: ['cwmsTimeseriesMeasurementsPlotting', cwmsId, currentDateRange[0]],
queryFn: () => {
const { cwms_timeseries_id, cwms_office_id, cwms_extent_earliest_time } = midasCwmsTimeseries.find(el => el.cwms_timeseries_id === ts);
const { cwms_timeseries_id, cwms_office_id, cwms_extent_earliest_time } = midasCwmsTimeseries.find(el => el.cwms_timeseries_id === cwmsId);
const beginDate = Math.max(DateTime.fromJSDate(currentDateRange[0]).toMillis(), DateTime.fromISO(cwms_extent_earliest_time).toMillis());

const uri = `/timeseries${buildQueryParams({ name: cwms_timeseries_id, office: cwms_office_id, begin: DateTime.fromMillis(beginDate).toUTC().toISO() })}`;

return apiGet(uri, 'CWMS');
},
staleTime: Infinity,
enabled: !!midasCwmsTimeseries.length,
enabled: activeConfig && !!cwmsTimeseriesIds.length,
})),
combine: (ret) => {
return {
data: ret.map((result) => result.data),
}
data: ret.map(result => result.data),
errors: ret.map(result => result.isError),
};
},
});

Expand Down Expand Up @@ -126,6 +127,7 @@ const BatchPlotting = connect(
const cwmsProps = {
hasCwmsData: !!cwmsTimeseries.length,
cwmsData: cwmsTimeseriesMeasurements,
cwmsMeasurementsErrors,
midasCwmsTimeseries,
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import BatchPlotChartSettings from '../components/batch-plot-chart-settings';
import Chart from '../../../../app-components/chart/chart';
import ChartErrors from '../components/batch-plot-errors';
import { determineDateRange, generateNewChartData } from '../helper';
import CwmsErrors from '../components/cwms-errors';

const ScatterLinePlot = connect(
// 'doPrintSetData',
Expand All @@ -28,8 +29,11 @@ const ScatterLinePlot = connect(
hasCwmsData,
cwmsData,
midasCwmsTimeseries,
cwmsMeasurementsErrors,
}) => {
const { auto_range, date_range, display, show_masked, show_comments, show_nonvalidated, plot_type, id } = plotConfig || {};

console.log('test cwmsMeasurementsErrors:', cwmsMeasurementsErrors);

Check warning on line 36 in src/app-pages/project/batch-plotting/chart-content/scatter-line-plot.jsx

View workflow job for this annotation

GitHub Actions / build (16.x)

Unexpected console statement

const plotTimeseriesIds = display?.traces?.map(el => el.timeseries_id) || [];
const plotTimeseries = timeseries.filter(ts => plotTimeseriesIds.includes(ts.id));
Expand Down Expand Up @@ -135,6 +139,12 @@ const ScatterLinePlot = connect(
timeseries={timeseries}
plotConfig={plotConfig}
/>
{hasCwmsData && (
<CwmsErrors
midasCwmsTimeseries={midasCwmsTimeseries}
cwmsMeasurementsErrors={cwmsMeasurementsErrors}
/>
)}
{chartSettings ? (
<>
<hr />
Expand Down
32 changes: 32 additions & 0 deletions src/app-pages/project/batch-plotting/components/cwms-errors.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { Box } from '@mui/material';
import React from 'react';

const CwmsErrors = ({
midasCwmsTimeseries,
cwmsMeasurementsErrors,
}) => {
const errorIdxs = cwmsMeasurementsErrors.map((el, ind) => {
if (el === true) return ind;
else return null;
}).filter(e => e);

const errorTimeseries = (errorIdxs?.length) ? midasCwmsTimeseries.filter((_el, ind) => errorIdxs.includes(ind)) : [];
const errorTimeseriesIds = [...new Set(errorTimeseries.map(el => el.cwms_timeseries_id))];

return (
<Box sx={{ marginTop: '10px' }}>
{!!errorTimeseriesIds?.length && (
<span className='text-danger px-2'>
The following selected CWMS timeseries have not returned data. We recommend using a smaller time range or a less frequent sampling rate:
<ul>
{errorTimeseriesIds.map(el => (
<li key={el}>{el}</li>
))}
</ul>
</span>
)}
</Box>
);
};

export default CwmsErrors;

0 comments on commit 071d793

Please sign in to comment.