Skip to content

Commit

Permalink
bugfixes/batch-plot-instruments (#200)
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinJJackson authored Jan 30, 2024
1 parent bbdcd59 commit 97c25f2
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 52 deletions.
2 changes: 1 addition & 1 deletion src/app-bundles/batch-plot-configurations-bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export default createRestBundle({
selectInstrumentsByBatchPlotConfigurationsGeoJSON: createSelector(
'selectInstrumentsItems',
'selectBatchPlotConfigurationsItems',
'selectInstrumentTimeseriesItemsByRoute',
'selectInstrumentTimeseriesItems',
'selectBatchPlotConfigurationsActiveId',
(instruments, batchPlotConfigurations, timeseries, activeId) => {
const instrumentMap = {};
Expand Down
24 changes: 1 addition & 23 deletions src/app-bundles/time-series-bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,28 +122,13 @@ export default createRestBundle({
return clone;
}
),
selectInstrumentTimeseriesByProjectId: createSelector(
'selectInstrumentTimeseriesItems',
(timeseries) => {
if (!timeseries || !timeseries.length) return {};
const out = {};
timeseries.forEach((ts) => {
if (!Object.prototype.hasOwnProperty.call(out, ts.project_id)) out[ts.project_id] = [];
out[ts.project_id].push(ts);
});
return out;
}
),

selectInstrumentTimeseriesItemsByRoute: createSelector(
'selectInstrumentsByRoute',
'selectProjectsByRoute',
'selectInstrumentTimeseriesByInstrumentId',
'selectInstrumentTimeseriesByProjectId',
(
instrument,
project,
timeseriesByInstrumentId,
timeseriesByProjectId
) => {
// If on an instrument-specific page
if (
Expand All @@ -152,13 +137,6 @@ export default createRestBundle({
Object.prototype.hasOwnProperty.call(timeseriesByInstrumentId, instrument.id)
) {
return timeseriesByInstrumentId[instrument.id];
} // If on a project page
else if (
project &&
project.id &&
Object.prototype.hasOwnProperty.call(timeseriesByProjectId, project.id)
) {
return timeseriesByProjectId[project.id];
} else {
return [];
}
Expand Down
4 changes: 2 additions & 2 deletions src/app-pages/project/batch-plotting/batch-plotting.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const BatchPlotting = connect(
'selectHashQuery',
'selectBatchPlotConfigurationsActiveId',
'selectBatchPlotConfigurationsItemsObject',
'selectInstrumentTimeseriesItemsByRoute',
'selectInstrumentTimeseriesItems',
'selectInstrumentsItems',
'selectDomainsItemsByGroup',
({
Expand All @@ -54,7 +54,7 @@ const BatchPlotting = connect(
hashQuery,
batchPlotConfigurationsActiveId: batchPlotId,
batchPlotConfigurationsItemsObject: batchPlotItems,
instrumentTimeseriesItemsByRoute: timeseries,
instrumentTimeseriesItems: timeseries,
instrumentsItems: instruments,
domainsItemsByGroup: domains,
}) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,14 @@ const BatchPlotErrors = ({
plotConfig?.timeseries_id?.forEach(el => {
const found = chartData.find(data => data.timeseriesId === el);

if (found?.x?.length) return;
if (!found || found?.x?.length) return;

const ts = timeseries.find(data => data.id === el);
const {instrument, name, unit } = ts;

emptyDataSets.push(`${instrument} - ${name} (${unit})`);
});


return (
emptyDataSets.length ? (
<span className='text-danger px-2'>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ const ConfigurationPanel = connect(
'doBatchPlotConfigurationsSave',
'selectBatchPlotConfigurationsItemsObject',
'selectBatchPlotConfigurationsActiveId',
'selectInstrumentTimeseriesItemsByRoute',
'selectInstrumentTimeseriesItems',
'selectProjectsIdByRoute',
({
doBatchPlotConfigurationsSave,
batchPlotConfigurationsItemsObject,
batchPlotConfigurationsActiveId,
instrumentTimeseriesItemsByRoute: instrumentTimeseries,
instrumentTimeseriesItems: instrumentTimeseries,
projectsIdByRoute: project,
isOpen,
isEditMode,
Expand Down
2 changes: 2 additions & 0 deletions src/app-pages/project/batch-plotting/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ const getStyle = (_index) => ({
export const generateNewChartData = (measurements, timeseries, chartSettings) => {
const { show_comments, show_masked, show_nonvalidated } = chartSettings || {};

console.log('test measurements, ts', measurements, timeseries)

Check warning on line 15 in src/app-pages/project/batch-plotting/helper.js

View workflow job for this annotation

GitHub Actions / build (16.x)

Unexpected console statement

if (measurements.length && timeseries.length) {
const data = measurements.map((elem, index) => {
if (elem && timeseries.length) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const BatchPlotChart = connect(
'selectBatchPlotConfigurationsActiveId',
'selectBatchPlotConfigurationsItemsObject',
'selectTimeseriesMeasurementsItems',
'selectInstrumentTimeseriesItemsByRoute',
'selectInstrumentTimeseriesItems',
({
doPrintSetData,
doInstrumentTimeseriesSetActiveId,
Expand All @@ -24,7 +24,7 @@ const BatchPlotChart = connect(
batchPlotConfigurationsActiveId,
batchPlotConfigurationsItemsObject,
timeseriesMeasurementsItems,
instrumentTimeseriesItemsByRoute,
instrumentTimeseriesItems,
}) => {
const [timeseriesIds, setTimeseriesId] = useState([]);
const [measurements, setMeasurements] = useState([]);
Expand Down Expand Up @@ -95,10 +95,10 @@ const BatchPlotChart = connect(

/** When we get new measurements, update chart data */
useEffect(() => {
const newData = generateNewChartData(measurements, instrumentTimeseriesItemsByRoute, chartSettings);
const newData = generateNewChartData(measurements, instrumentTimeseriesItems, chartSettings);

setChartData(newData);
}, [measurements, instrumentTimeseriesItemsByRoute, withPrecipitation, chartSettings]);
}, [measurements, instrumentTimeseriesItems, withPrecipitation, chartSettings]);

/** When chart data changes, see if there is precip data to adjust plot */
useEffect(() => {
Expand Down Expand Up @@ -128,21 +128,21 @@ const BatchPlotChart = connect(
/>
<ChartErrors
chartData={chartData}
timeseries={instrumentTimeseriesItemsByRoute}
timeseries={instrumentTimeseriesItems}
plotConfig={batchPlotConfigurationsItemsObject[batchPlotConfigurationsActiveId]}
/>
{chartSettings ? (
<>
<hr />
<ChartSettings
chartData={chartData}
threshold={threshold}
setThreshold={setThreshold}
dateRange={dateRange}
setDateRange={setDateRange}
chartSettings={chartSettings}
setChartSettings={setChartSettings}
savePlotSettings={savePlotSettings}
chartData={chartData}
/>
</>
) : null}
Expand Down
28 changes: 12 additions & 16 deletions src/common/forms/instrument-form.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -117,22 +117,13 @@ export default connect(
projOptions[projDisplayProjection]
);

// There's some nasty '', null, and NaN checking going on here for
// number types, not sure if there's a better way to do this,
// this is because '' and null both evaluate to 0 in Number()... so that's fun
// It works for now, it's fast and works.
// console.log(
// `${station}, ${Number(station)}, ${station === null}, ${
// station === null || station === ""
// }`
// );

doInstrumentsSave(
Object.assign({}, item, {
const instrumentObject = {
...item,
...{
name,
project_id,
type_id,
status_id,
type_id: type_id ?? item.type_id,
status_id: status_id ?? item.status_id,
status_time,
opts,
station:
Expand All @@ -151,7 +142,11 @@ export default connect(
type: 'Point',
coordinates: [lonLat[0], lonLat[1]],
},
}),
}
};

doInstrumentsSave(
isEdit ? instrumentObject : [instrumentObject],
doModalClose,
true
);
Expand Down Expand Up @@ -298,7 +293,8 @@ export default connect(

<div className='form-group'>
<label>Offset Descriptor</label>
<DomainSelect defaultValue={item?.status_id} onChange={(val) => setStatusId(val?.id)} domain='offset_descriptor' />
{/* TODO integrate with new domain */}
<DomainSelect defaultValue={''} onChange={(_val) => {}} domain='offset_descriptor' />
</div>

<div className='form-group'>
Expand Down

0 comments on commit 97c25f2

Please sign in to comment.