From acdeb7d04268fedffd81cbe228ba05fa6c66c618 Mon Sep 17 00:00:00 2001 From: mbucknell <mbucknell@usgs.gov> Date: Thu, 11 Feb 2021 10:04:04 -0600 Subject: [PATCH] Removed no longer needed code and updated the store and selectors for the new hydrographData and hydrographState properties --- .../components/hydrograph/audible.js | 137 -- .../components/hydrograph/download-links.js | 2 +- .../hydrograph/download-links.test.js | 2 +- .../components/hydrograph/graph-brush.js | 10 +- .../components/hydrograph/index.js | 8 +- .../components/hydrograph/index.test.js | 2 +- .../hydrograph/selectors/audible-data.js | 59 - .../components/hydrograph/selectors/cursor.js | 6 +- .../hydrograph/selectors/legend-data.js | 13 +- .../hydrograph/selectors/parameter-data.js | 20 +- .../selectors/parameter-data.test.js | 2 +- .../components/hydrograph/selectors/scales.js | 4 +- .../hydrograph/selectors/time-series-data.js | 23 +- .../hydrograph/time-series-graph.js | 6 +- .../components/hydrograph/tooltip.js | 9 +- .../selectors/flood-data-selector.js | 6 +- .../selectors/hydrograph-data-selector.js | 26 +- .../selectors/hydrograph-state-selector.js | 12 + .../selectors/time-series-selector.js | 31 - .../selectors/time-series-selector.test.js | 1201 ----------------- .../selectors/time-zone-selector.js | 3 - .../selectors/time-zone-selector.test.js | 17 - .../store/hydrograph-data.js | 2 +- .../store/hydrograph-data.test.js | 6 +- .../scripts/monitoring-location/url-params.js | 27 +- wdfn-server/waterdata/location_utils.py | 20 + .../templates/macros/components.html | 7 +- .../templates/monitoring_location.html | 8 +- wdfn-server/waterdata/views.py | 11 +- 29 files changed, 140 insertions(+), 1540 deletions(-) delete mode 100644 assets/src/scripts/monitoring-location/components/hydrograph/audible.js delete mode 100644 assets/src/scripts/monitoring-location/components/hydrograph/selectors/audible-data.js create mode 100644 assets/src/scripts/monitoring-location/selectors/hydrograph-state-selector.js delete mode 100644 assets/src/scripts/monitoring-location/selectors/time-series-selector.js delete mode 100644 assets/src/scripts/monitoring-location/selectors/time-series-selector.test.js delete mode 100644 assets/src/scripts/monitoring-location/selectors/time-zone-selector.js delete mode 100644 assets/src/scripts/monitoring-location/selectors/time-zone-selector.test.js diff --git a/assets/src/scripts/monitoring-location/components/hydrograph/audible.js b/assets/src/scripts/monitoring-location/components/hydrograph/audible.js deleted file mode 100644 index 93845856e..000000000 --- a/assets/src/scripts/monitoring-location/components/hydrograph/audible.js +++ /dev/null @@ -1,137 +0,0 @@ -/* - * Note the audible interface is not currently enabled and will likely need a major implementation - * The current patterns of putting the selectors in a separate module from rendering code and - * updating the selectors to use is* or get* pattern. - */ -import {scaleLinear} from 'd3-scale'; -import memoize from 'fast-memoize'; -import {createStructuredSelector} from 'reselect'; - -import config from 'ui/config'; -import {link} from 'ui/lib/d3-redux'; - -import {Actions} from 'ml/store/instantaneous-value-time-series-state'; - -import {isAudiblePlaying, getAudiblePoints} from './selectors/audible-data'; -import {getMainXScale} from './selectors/scales'; - - -// Higher tones get lower volume -const volumeScale = scaleLinear().range([2, .3]); - -const AudioContext = config.TIMESERIES_AUDIO_ENABLED ? window.AudioContext || window.webkitAudioContext : null; -const getAudioContext = memoize(function() { - return new AudioContext(); -}); - -export const createSound = memoize(/* eslint no-unused-vars: off */ tsKey => { - const audioCtx = getAudioContext(); - const oscillator = audioCtx.createOscillator(); - const gainNode = audioCtx.createGain(); - const compressor = audioCtx.createDynamicsCompressor(); - - // Connect the oscillator to the gainNode to modulate volume - oscillator.type = 'sine'; - oscillator.connect(gainNode); - - // Connect the gainNode to the compressor to address clipping - gainNode.connect(compressor); - - // Connect the compressor to the output context - compressor.connect(audioCtx.destination); - - // Start the oscillator - oscillator.start(); - - // Initialize with null values so the first pass of updateSound doesn't - // create a transition. - oscillator.frequency.setTargetAtTime(null, audioCtx.currentTime, 0); - gainNode.gain.setTargetAtTime(null, audioCtx.currentTime, 0); - - return {oscillator, gainNode, compressor}; -}); - -export const updateSound = function({enabled, points}) { - const audioCtx = getAudioContext(); - for (const tsKey of Object.keys(points)) { - const point = points[tsKey]; - const {compressor, oscillator, gainNode} = createSound(tsKey); - - compressor.threshold.setValueAtTime(-50, audioCtx.currentTime); - compressor.knee.setValueAtTime(40, audioCtx.currentTime); - compressor.ratio.setValueAtTime(12, audioCtx.currentTime); - compressor.attack.setValueAtTime(0, audioCtx.currentTime); - compressor.release.setValueAtTime(0.25, audioCtx.currentTime); - - oscillator.frequency.setTargetAtTime( - enabled && point ? point : null, - audioCtx.currentTime, - .2 - ); - - gainNode.gain.setTargetAtTime( - enabled && point ? volumeScale(point) : null, - audioCtx.currentTime, - .2 - ); - } -}; - -/* - * Renders the audible control if enabled. - */ -export const audibleUI = function(elem, store) { - if (!config.TIMESERIES_AUDIO_ENABLED) { - return; - } - - if (!AudioContext) { - console.warn('AudioContext not available'); - return; - } - - const button = elem.append('button') - .classed('usa-button', true) - .classed('usa-button--outline', true) - .attr('ga-on', 'click') - .attr('ga-event-category', 'TimeSeriesGraph') - .html('Audible '); - button.append('i') - .classed('fas', true); - button.call(link(store, function(elem, audibleOn) { - if (audibleOn) { - elem.attr('title', 'Stop') - .attr('ga-event-action', 'stopAudible'); - } else { - elem.attr('title', 'Play') - .attr('ga-event-action', 'playAudible'); - } - elem.select('i') - .classed('fa-play', !audibleOn) - .classed('fa-stop', audibleOn); - }, isAudiblePlaying)) - .call(link(store, function(elem, xScale) { - const domain = xScale.domain(); - elem.attr('data-max-offset', domain[1] - domain[0]); - }, getMainXScale('current'))) - .on('click', () => { - if (button.attr('title') === 'Play') { - store.dispatch(Actions.startTimeSeriesPlay(button.attr('data-max-offset'))); - } else { - store.dispatch(Actions.stopTimeSeriesPlay()); - } - }); - - // Listen for focus changes, and play back the audio representation of - // the selected points. - // TODO: This does not correctly handle parameter codes with multiple time series. - elem.call(link(store,function(elem, {enabled, points}) { - updateSound({ - points, - enabled - }); - }, createStructuredSelector({ - enabled: isAudiblePlaying, - points: getAudiblePoints - }))); -}; diff --git a/assets/src/scripts/monitoring-location/components/hydrograph/download-links.js b/assets/src/scripts/monitoring-location/components/hydrograph/download-links.js index c75d4290f..98b23fb91 100644 --- a/assets/src/scripts/monitoring-location/components/hydrograph/download-links.js +++ b/assets/src/scripts/monitoring-location/components/hydrograph/download-links.js @@ -62,7 +62,7 @@ export const renderDownloadLinks = function(elem, store, siteno) { anyVisibleGroundwaterLevels, requestTimeRange }) => { - const hasIVData = config.uvPeriodOfRecord && parameterCode in config.uvPeriodOfRecord; + const hasIVData = config.ivPeriodOfRecord && parameterCode in config.ivPeriodOfRecord; const hasGWData = config.gwPeriodOfRecord && parameterCode in config.gwPeriodOfRecord; elem.select('#iv-data-download-list').remove(); diff --git a/assets/src/scripts/monitoring-location/components/hydrograph/download-links.test.js b/assets/src/scripts/monitoring-location/components/hydrograph/download-links.test.js index dff4a61ae..0405bef1b 100644 --- a/assets/src/scripts/monitoring-location/components/hydrograph/download-links.test.js +++ b/assets/src/scripts/monitoring-location/components/hydrograph/download-links.test.js @@ -10,7 +10,7 @@ describe('monitoring-location/components/hydrograph/download-links', () => { config.SERVICE_ROOT = 'https://fakeserviceroot.com'; config.GROUNDWATER_LEVELS_ENDPOINT = 'https://fakegroundwater.org/gw/'; - config.uvPeriodOfRecord = { + config.ivPeriodOfRecord = { '00060': { begin_date: '2000-01-01', end_date: '2020-01-01' diff --git a/assets/src/scripts/monitoring-location/components/hydrograph/graph-brush.js b/assets/src/scripts/monitoring-location/components/hydrograph/graph-brush.js index fc26c6945..22e8761c3 100644 --- a/assets/src/scripts/monitoring-location/components/hydrograph/graph-brush.js +++ b/assets/src/scripts/monitoring-location/components/hydrograph/graph-brush.js @@ -7,9 +7,9 @@ import {mediaQuery} from 'ui/utils'; import {appendXAxis} from 'd3render/axes'; -import {getCurrentMethodID} from 'ml/selectors/time-series-selector'; +import {getSelectedIVMethodID, getGraphBrushOffset} from 'ml/selectors/hydrograph-state-selector'; -import {Actions} from 'ml/store/instantaneous-value-time-series-state'; +import {setGraphBrushOffset} from 'ml/store/hydrograph-state'; import {getBrushXAxis} from './selectors/axes'; import {getGroundwaterLevelPoints} from './selectors/discrete-data'; @@ -53,7 +53,7 @@ export const drawGraphBrush = function(container, store) { if (event.sourceEvent.type === 'mouseup' || event.sourceEvent.type === 'touchend') { const adjustedBrush = brushRange.map(xScale.invert, xScale); - store.dispatch(Actions.setIVGraphBrushOffset( + store.dispatch(setGraphBrushOffset( adjustedBrush[0]- xScale.domain()[0], xScale.domain()[1] - adjustedBrush[1])); } @@ -90,7 +90,7 @@ export const drawGraphBrush = function(container, store) { }))) .call(link(store, drawDataSegments, createStructuredSelector({ visible: () => true, - currentMethodID: getCurrentMethodID, + currentMethodID: getSelectedIVMethodID, tsSegmentsMap: getIVDataSegments('primary'), dataKind: () => 'primary', xScale: getBrushXScale, @@ -166,7 +166,7 @@ export const drawGraphBrush = function(container, store) { }, createStructuredSelector({ layout: getBrushLayout, - hydrographBrushOffset: (state) => state.ivTimeSeriesState.ivGraphBrushOffset, + hydrographBrushOffset: getGraphBrushOffset, xScale: getBrushXScale }))); }; diff --git a/assets/src/scripts/monitoring-location/components/hydrograph/index.js b/assets/src/scripts/monitoring-location/components/hydrograph/index.js index 509fa5cac..5315d48f1 100644 --- a/assets/src/scripts/monitoring-location/components/hydrograph/index.js +++ b/assets/src/scripts/monitoring-location/components/hydrograph/index.js @@ -54,8 +54,8 @@ export const attachToNode = function(store, node, { siteno, - agencyCode='',//TODO - set these in markup - sitename='',//TODO - set these in markup + agencyCode, + sitename, latitude, longitude, parameterCode, @@ -68,7 +68,7 @@ export const attachToNode = function(store, showMLName = false } = {}) { const nodeElem = select(node); - if (!siteno && !config.uvPeriodOfRecord && !config.gwPeriodOfRecord) { + if (!siteno && !config.ivPeriodOfRecord && !config.gwPeriodOfRecord) { select(node).call(drawWarningAlert, {title: 'Hydrograph Alert', body: 'No IV or field visit data is available.'}); return; } @@ -82,7 +82,7 @@ export const attachToNode = function(store, //store.dispatch(floodDataActions.retrieveWaterwatchData(siteno)); // Need to set default parameter code in server and insert in markup */ const fetchDataPromise = store.dispatch(retrieveHydrographData(siteno, { - parameterCode: parameterCode || '00060', + parameterCode: parameterCode, period: startDT && endDT ? null : period || 'P7D', startTime: DateTime.fromISO(startDT, {zone: config.locationTimeZone}), endTime: DateTime.fromISO(endDT, {zone: config.locationTimeZone}), diff --git a/assets/src/scripts/monitoring-location/components/hydrograph/index.test.js b/assets/src/scripts/monitoring-location/components/hydrograph/index.test.js index 58c02f3bf..9423a4af8 100644 --- a/assets/src/scripts/monitoring-location/components/hydrograph/index.test.js +++ b/assets/src/scripts/monitoring-location/components/hydrograph/index.test.js @@ -171,7 +171,7 @@ const TEST_STATE = { describe('monitoring-location/components/hydrograph module', () => { utils.mediaQuery = jest.fn().mockReturnValue(true); utils.wrap = jest.fn(); - config.uvPeriodOfRecord = { + config.ivPeriodOfRecord = { '00010': { begin_date: '01-02-2001', end_date: '10-15-2015' diff --git a/assets/src/scripts/monitoring-location/components/hydrograph/selectors/audible-data.js b/assets/src/scripts/monitoring-location/components/hydrograph/selectors/audible-data.js deleted file mode 100644 index 952cc36d1..000000000 --- a/assets/src/scripts/monitoring-location/components/hydrograph/selectors/audible-data.js +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Note the audible interface is not currently enabled and will likely need a major implementation - * The current patterns of putting the selectors in a separate module from rendering code and - * updating the selectors to use is* or get* pattern. - */ -import {scaleLinear} from 'd3-scale'; -import {createSelector} from 'reselect'; - -import {getTimeSeries} from 'ml/selectors/time-series-selector'; - -import {getTsCursorPoints} from './cursor'; -import {getMainYScale} from './scales'; - -/* - * Returns a Redux selector function that returns true if the audible interface is playing. - */ -export const isAudiblePlaying = state => state.ivTimeSeriesState.audiblePlayId !== null; - -const getAudibleYScale = createSelector( - getMainYScale, - (yScale) => { - return scaleLinear() - .domain(yScale.domain()) - .range([80, 1500]); - } -); - -/* - * Returns a Redux selector function which retrieves an array of time series points where the - * value can be used for pitches. - */ -export const getAudiblePoints = createSelector( - getTimeSeries, - getTsCursorPoints('current'), - getTsCursorPoints('compare'), - getAudibleYScale, - (allTimeSeries, currentPoints, comparePoints, yScale) => { - // Set null points for all time series, so we can turn audio for those - // points off when toggling to other time series. - let points = Object.keys(allTimeSeries).reduce((points, tsID) => { - points[tsID] = null; - return points; - }, {}); - - // Get the pitches for the current-year points - points = Object.keys(currentPoints).reduce((points, tsID) => { - const pt = currentPoints[tsID]; - points[tsID] = yScale(pt.value); - return points; - }, points); - - // Get the pitches for the compare-year points - return Object.keys(comparePoints).reduce((points, tsID) => { - const pt = comparePoints[tsID]; - points[tsID] = yScale(pt.value); - return points; - }, points); - } -); \ No newline at end of file diff --git a/assets/src/scripts/monitoring-location/components/hydrograph/selectors/cursor.js b/assets/src/scripts/monitoring-location/components/hydrograph/selectors/cursor.js index fdd5be772..a2876ddfa 100644 --- a/assets/src/scripts/monitoring-location/components/hydrograph/selectors/cursor.js +++ b/assets/src/scripts/monitoring-location/components/hydrograph/selectors/cursor.js @@ -3,7 +3,7 @@ import {createSelector} from 'reselect'; import {getNearestTime} from 'ui/utils'; -import {getCurrentMethodID} from 'ml/selectors/time-series-selector'; +import {getSelectedIVMethodID, getGraphCursorOffset} from 'ml/selectors/hydrograph-state-selector'; import {getGroundwaterLevelPoints} from './discrete-data'; import {getIVDataPoints} from './iv-data'; @@ -16,7 +16,7 @@ const isInTimeRange = function(dateTime, timeRange) { export const getCursorOffset = createSelector( getMainXScale('current'), - state => state.ivTimeSeriesState.ivGraphCursorOffset, + getGraphCursorOffset, (xScale, cursorOffset) => { // If cursorOffset is false, don't show it if (cursorOffset === false) { @@ -54,7 +54,7 @@ export const getCursorTime = memoize(timeRangeKind => createSelector( */ export const getIVDataCursorPoints = memoize((dataRange, timeRangeKind) => createSelector( getIVDataPoints(dataRange), - getCurrentMethodID, + getSelectedIVMethodID, getCursorTime(timeRangeKind), isVisible(dataRange), getGraphTimeRange('MAIN', timeRangeKind), diff --git a/assets/src/scripts/monitoring-location/components/hydrograph/selectors/legend-data.js b/assets/src/scripts/monitoring-location/components/hydrograph/selectors/legend-data.js index 1b6da2f69..688eea041 100644 --- a/assets/src/scripts/monitoring-location/components/hydrograph/selectors/legend-data.js +++ b/assets/src/scripts/monitoring-location/components/hydrograph/selectors/legend-data.js @@ -3,6 +3,8 @@ import {createSelector} from 'reselect'; import {defineLineMarker, defineRectangleMarker, defineTextOnlyMarker} from 'd3render/markers'; import {getWaterwatchFloodLevels, isWaterwatchVisible} from 'ml/selectors/flood-data-selector'; +import {isCompareIVDataVisible, isMedianDataVisible} from 'ml/selectors/hydrograph-state-selector'; + //import {getCurrentVariableMedianMetadata} from 'ml/selectors/median-statistics-selector'; import {getGroundwaterLevelsMarker} from '../discrete-data'; @@ -26,18 +28,19 @@ const TS_LABEL = { * @prop floodLevels {Object} - */ const getLegendDisplay = createSelector( - (state) => state.ivTimeSeriesState.showIVTimeSeries, + isCompareIVDataVisible, + isMedianDataVisible, () => null, //getCurrentVariableMedianMetadata, getIVUniqueDataKinds('primary'), getIVUniqueDataKinds('compare'), isWaterwatchVisible, getWaterwatchFloodLevels, anyVisibleGroundwaterLevels, - (showSeries, medianSeries, currentClasses, compareClasses, showWaterWatch, floodLevels, showGroundWaterLevels) => { + (showCompare, showMedian, medianSeries, currentClasses, compareClasses, showWaterWatch, floodLevels, showGroundWaterLevels) => { return { - primaryIV: showSeries.current ? currentClasses : undefined, - compareIV: showSeries.compare ? compareClasses : undefined, - median: showSeries.median ? medianSeries : undefined, + primaryIV: currentClasses, + compareIV: showCompare ? compareClasses : undefined, + median: showMedian ? medianSeries : undefined, floodLevels: showWaterWatch ? floodLevels : undefined, groundwaterLevels: showGroundWaterLevels }; diff --git a/assets/src/scripts/monitoring-location/components/hydrograph/selectors/parameter-data.js b/assets/src/scripts/monitoring-location/components/hydrograph/selectors/parameter-data.js index f13b0b566..201e03d5b 100644 --- a/assets/src/scripts/monitoring-location/components/hydrograph/selectors/parameter-data.js +++ b/assets/src/scripts/monitoring-location/components/hydrograph/selectors/parameter-data.js @@ -29,25 +29,25 @@ export const getAvailableParameterCodes = createSelector( .map((variable) => { const parameterCode = variable.variableCode.value; const measuredParameterCode = parameterCode.replace(config.CALCULATED_TEMPERATURE_VARIABLE_CODE, ''); - const isUVParameterCode = config.uvPeriodOfRecord && measuredParameterCode in config.uvPeriodOfRecord; + const isIVParameterCode = config.ivPeriodOfRecord && measuredParameterCode in config.ivPeriodOfRecord; const isGWParameterCode = config.gwPeriodOfRecord && measuredParameterCode in config.gwPeriodOfRecord; - const uvPeriodOfRecord = isUVParameterCode ? config.uvPeriodOfRecord[measuredParameterCode] : null; + const ivPeriodOfRecord = isIVParameterCode ? config.ivPeriodOfRecord[measuredParameterCode] : null; const gwPeriodOfRecord = isGWParameterCode ? config.gwPeriodOfRecord[measuredParameterCode] : null; let periodOfRecord; - if (!uvPeriodOfRecord) { + if (!ivPeriodOfRecord) { periodOfRecord = gwPeriodOfRecord; } else if (!gwPeriodOfRecord) { - periodOfRecord = uvPeriodOfRecord; + periodOfRecord = ivPeriodOfRecord; } else { periodOfRecord = { - begin_date: DateTime.fromISO(uvPeriodOfRecord.begin_date) < DateTime.fromISO(gwPeriodOfRecord.begin_date) ? - uvPeriodOfRecord.begin_date : gwPeriodOfRecord.begin_date, - end_date: DateTime.fromISO(uvPeriodOfRecord.end_date) > DateTime.fromISO(gwPeriodOfRecord.end_date) ? - uvPeriodOfRecord.end_date : gwPeriodOfRecord.end_date + begin_date: DateTime.fromISO(ivPeriodOfRecord.begin_date) < DateTime.fromISO(gwPeriodOfRecord.begin_date) ? + ivPeriodOfRecord.begin_date : gwPeriodOfRecord.begin_date, + end_date: DateTime.fromISO(ivPeriodOfRecord.end_date) > DateTime.fromISO(gwPeriodOfRecord.end_date) ? + ivPeriodOfRecord.end_date : gwPeriodOfRecord.end_date }; } - const hasWaterAlert = !!(isUVParameterCode && config.WATER_ALERT_PARAMETER_CODES.includes(measuredParameterCode)); + const hasWaterAlert = !!(isIVParameterCode && config.WATER_ALERT_PARAMETER_CODES.includes(measuredParameterCode)); let waterAlertDisplayText; let waterAlertTooltipText; if (hasWaterAlert) { @@ -59,7 +59,7 @@ export const getAvailableParameterCodes = createSelector( } } else { waterAlertDisplayText = 'N/A'; - if (isUVParameterCode) { + if (isIVParameterCode) { waterAlertTooltipText = `Sorry, there are no WaterAlerts for this parameter (${parameterCode})`; } else { waterAlertTooltipText = 'Sorry, WaterAlert is only available for parameters that have IV data'; diff --git a/assets/src/scripts/monitoring-location/components/hydrograph/selectors/parameter-data.test.js b/assets/src/scripts/monitoring-location/components/hydrograph/selectors/parameter-data.test.js index ee3669c65..7ba478a08 100644 --- a/assets/src/scripts/monitoring-location/components/hydrograph/selectors/parameter-data.test.js +++ b/assets/src/scripts/monitoring-location/components/hydrograph/selectors/parameter-data.test.js @@ -3,7 +3,7 @@ import config from 'ui/config'; import {getAvailableParameterCodes} from './parameter-data'; describe('monitoring-location/components/hydrograph/selectors/parameter-data', () => { - config.uvPeriodOfRecord = { + config.ivPeriodOfRecord = { '00060': { begin_date: '1980-01-01', end_date: '2020-01-01' diff --git a/assets/src/scripts/monitoring-location/components/hydrograph/selectors/scales.js b/assets/src/scripts/monitoring-location/components/hydrograph/selectors/scales.js index ded88aa6f..0a481480a 100644 --- a/assets/src/scripts/monitoring-location/components/hydrograph/selectors/scales.js +++ b/assets/src/scripts/monitoring-location/components/hydrograph/selectors/scales.js @@ -6,7 +6,7 @@ import { getPrimaryParameter, getTimeRange } from 'ml/selectors/hydrograph-data-selector'; -import {getIVGraphBrushOffset} from 'ml/selectors/time-series-selector'; +import {getGraphBrushOffset} from 'ml/selectors/hydrograph-state-selector'; import {SYMLOG_PARMS, getPrimaryValueRange} from './domain'; import {getLayout} from './layout'; @@ -73,7 +73,7 @@ export const createYScale = function(parameterCode, extent, size) { */ export const getGraphTimeRange = memoize((graphKind, timeRangeKind) => createSelector( getTimeRange(timeRangeKind), - getIVGraphBrushOffset, + getGraphBrushOffset, (timeRange, brushOffset) => { let result; diff --git a/assets/src/scripts/monitoring-location/components/hydrograph/selectors/time-series-data.js b/assets/src/scripts/monitoring-location/components/hydrograph/selectors/time-series-data.js index 669e11a70..69fc295cd 100644 --- a/assets/src/scripts/monitoring-location/components/hydrograph/selectors/time-series-data.js +++ b/assets/src/scripts/monitoring-location/components/hydrograph/selectors/time-series-data.js @@ -5,7 +5,7 @@ import {createSelector} from 'reselect'; import config from 'ui/config'; import {getPrimaryMethods, getPrimaryParameter, getTimeRange} from 'ml/selectors/hydrograph-data-selector'; -import {getCurrentMethodID} from 'ml/selectors/time-series-selector'; +import {getSelectedIVMethodID, isCompareIVDataVisible, isMedianDataVisible} from 'ml/selectors/hydrograph-state-selector'; const formatTime = function(timeInMillis) { return DateTime.fromMillis(timeInMillis, {zone: config.locationTimeZone}).toFormat('L/d/yyyy tt ZZZ'); @@ -17,9 +17,22 @@ const formatTime = function(timeInMillis) { * @param {String} tsKey Time series key * @return {Boolean} Show state of the time series */ -export const isVisible = memoize(dataKind => (state) => { - return dataKind === 'primary' ? true : state.ivTimeSeriesState.showIVTimeSeries[dataKind]; -}); +export const isVisible = memoize(dataKind => createSelector( + isCompareIVDataVisible, + isMedianDataVisible, + (compareVisible, medianVisible) => { + switch (dataKind) { + case 'primary': + return true; + case 'compare': + return compareVisible; + case 'median': + return medianVisible; + default: + return false; + } + }) +); /** * Returns a Redux selector function which returns the label to be used for the Y axis @@ -42,7 +55,7 @@ export const getSecondaryYLabel= function() { */ export const getTitle = createSelector( getPrimaryParameter, - getCurrentMethodID, + getSelectedIVMethodID, getPrimaryMethods, (parameter, methodID, methods) => { let title = parameter ? parameter.name : ''; diff --git a/assets/src/scripts/monitoring-location/components/hydrograph/time-series-graph.js b/assets/src/scripts/monitoring-location/components/hydrograph/time-series-graph.js index d78e1bab7..4b3fd4177 100644 --- a/assets/src/scripts/monitoring-location/components/hydrograph/time-series-graph.js +++ b/assets/src/scripts/monitoring-location/components/hydrograph/time-series-graph.js @@ -16,7 +16,7 @@ import {isWaterwatchVisible, getWaterwatchFloodLevels} from 'ml/selectors/flood- import {getAxes} from './selectors/axes'; import {getGroundwaterLevelPoints} from './selectors/discrete-data'; import {getIVDataSegments, HASH_ID} from './selectors/iv-data'; -import {getCurrentMethodID} from 'ml/selectors/time-series-selector'; +import {getSelectedIVMethodID} from 'ml/selectors/hydrograph-state-selector'; import {getTitle, getDescription, isVisible} from './selectors/time-series-data'; import {getMainLayout} from './selectors/layout'; @@ -248,7 +248,7 @@ export const drawTimeSeriesGraph = function(elem, store, siteNo, agencyCode, sit .call(link(store, appendAxes, getAxes('MAIN'))) .call(link(store, drawDataSegments, createStructuredSelector({ visible: () => true, - currentMethodID: getCurrentMethodID, + currentMethodID: getSelectedIVMethodID, tsSegmentsMap: getIVDataSegments('primary'), dataKind: () => 'primary', xScale: getMainXScale('current'), @@ -257,7 +257,7 @@ export const drawTimeSeriesGraph = function(elem, store, siteNo, agencyCode, sit }))) .call(link(store, drawDataSegments, createStructuredSelector({ visible: isVisible('compare'), - currentMethodID: getCurrentMethodID, + currentMethodID: getSelectedIVMethodID, tsSegmentsMap: getIVDataSegments('compare'), dataKind: () => 'compare', xScale: getMainXScale('prioryear'), diff --git a/assets/src/scripts/monitoring-location/components/hydrograph/tooltip.js b/assets/src/scripts/monitoring-location/components/hydrograph/tooltip.js index 015844905..11f52e9eb 100644 --- a/assets/src/scripts/monitoring-location/components/hydrograph/tooltip.js +++ b/assets/src/scripts/monitoring-location/components/hydrograph/tooltip.js @@ -8,7 +8,8 @@ import {drawCursorSlider} from 'd3render/cursor-slider'; import {drawFocusOverlay, drawFocusCircles, drawFocusLine} from 'd3render/graph-tooltip'; import {getPrimaryParameter} from 'ml/selectors/hydrograph-data-selector'; -import {Actions} from 'ml/store/instantaneous-value-time-series-state'; +import {getGraphCursorOffset} from 'ml/selectors/hydrograph-state-selector'; +import {setGraphCursorOffset} from 'ml/store/hydrograph-state'; import {getCursorTime, getIVDataCursorPoints, getIVDataTooltipPoints, getGroundwaterLevelCursorPoint, getGroundwaterLevelTooltipPoint @@ -140,7 +141,7 @@ export const drawTooltipFocus = function(elem, store) { layout: getMainLayout }), store, - Actions.setIVGraphCursorOffset) + setGraphCursorOffset) ); }; @@ -157,8 +158,8 @@ export const drawTooltipCursorSlider = function(elem, store) { elem.attr('viewBox', `0 0 ${layout.width + layout.margin.left + layout.margin.right} 25`); }, getMainLayout)) .call(link(store, drawCursorSlider, createStructuredSelector({ - cursorOffset: (state) => state.ivTimeSeriesState.ivGraphCursorOffset, + cursorOffset: getGraphCursorOffset, xScale: getMainXScale('current'), layout: getMainLayout - }), store, Actions.setIVGraphCursorOffset)); + }), store, setGraphCursorOffset)); }; diff --git a/assets/src/scripts/monitoring-location/selectors/flood-data-selector.js b/assets/src/scripts/monitoring-location/selectors/flood-data-selector.js index 475f4336b..b8c623944 100644 --- a/assets/src/scripts/monitoring-location/selectors/flood-data-selector.js +++ b/assets/src/scripts/monitoring-location/selectors/flood-data-selector.js @@ -1,5 +1,5 @@ import {createSelector} from 'reselect'; -import {getCurrentParameterCode} from './time-series-selector'; +import {getSelectedParameterCode} from './hydrograph-state-selector'; export const getFloodStages = state => state.floodData.stages || []; @@ -31,9 +31,9 @@ export const hasWaterwatchData = createSelector( */ export const isWaterwatchVisible = createSelector( hasWaterwatchData, - getCurrentParameterCode, + getSelectedParameterCode, (hasFloodLevels, paramCd) => - hasFloodLevels && paramCd == '00065' + hasFloodLevels && paramCd === '00065' ); /* diff --git a/assets/src/scripts/monitoring-location/selectors/hydrograph-data-selector.js b/assets/src/scripts/monitoring-location/selectors/hydrograph-data-selector.js index 989cc733f..8fbccf8b3 100644 --- a/assets/src/scripts/monitoring-location/selectors/hydrograph-data-selector.js +++ b/assets/src/scripts/monitoring-location/selectors/hydrograph-data-selector.js @@ -61,6 +61,16 @@ export const getPrimaryParameter = createSelector( } ); +export const getPrimaryMethods = createSelector( + getIVData('primary'), + ivData => { + if (!ivData) { + return null; + } + return Object.values(ivData.values).map(value => value.method); + } +); + /* * @return {Function} which returns an Object with keys by tsId. Each property * is an {Object} as follows: @@ -121,19 +131,3 @@ export const getPrimaryMedianStatisticsValueRange = createSelector( } } ); - -/* - * @returns {Function} which returns {Object} with method ID keys and method details. - */ -export const getPrimaryMethods = createSelector( - getIVData('current'), - (ivData) => { - if (!ivData) { - return null; - } - return Object.keys(ivData.values).reduce((byMethodId, methodID) => { - byMethodId[methodID] = ivData.values[methodID].method; - return byMethodId; - }, {}); - } -); diff --git a/assets/src/scripts/monitoring-location/selectors/hydrograph-state-selector.js b/assets/src/scripts/monitoring-location/selectors/hydrograph-state-selector.js new file mode 100644 index 000000000..a671b5dbf --- /dev/null +++ b/assets/src/scripts/monitoring-location/selectors/hydrograph-state-selector.js @@ -0,0 +1,12 @@ + +export const isCompareIVDataVisible = state => state.hydrographState.showCompareIVData || false; +export const isMedianDataVisible = state => state.hydrographState.showMedianData || false; + +export const getSelectedDateRange = state => state.hydrographState.selectedDateRange || null; +export const getSelectedCustomTimeRange = state => state.hydrographState.selectedCustomTimeRange || null; +export const getSelectedParameterCode = state => state.hydrographState.selectedParameterCOde || null; +export const getSelectedIVMethodID = state => state.hydrographState.selectedIVMethodID || null; +export const getGraphCursorOffset = state => state.hydrographState.graphCursorOffset || null; +export const getGraphBrushOffset = state => state.hydrographState.graphBrushOffset || null; +export const getUserInputsForTimeRange = state => state.hydrographState.userInputsForTimeRange || null; + diff --git a/assets/src/scripts/monitoring-location/selectors/time-series-selector.js b/assets/src/scripts/monitoring-location/selectors/time-series-selector.js deleted file mode 100644 index 8095c91fa..000000000 --- a/assets/src/scripts/monitoring-location/selectors/time-series-selector.js +++ /dev/null @@ -1,31 +0,0 @@ -import memoize from 'fast-memoize'; -import uniq from 'lodash/uniq'; -import _includes from 'lodash/includes'; -import {DateTime} from 'luxon'; -import {createSelector} from 'reselect'; - -import {getIanaTimeZone} from './time-zone-selector'; - -/* - * Selectors that return properties from the state - */ - -export const getShowIVTimeSeries = state => state.ivTimeSeriesState.showIVTimeSeries || {}; - -export const getUserInputsForSelectingTimespan = state => state.ivTimeSeriesState.userInputsForTimeRange; - -export const getCurrentVariableID = state => state.ivTimeSeriesState.currentIVVariableID; - -export const getCurrentMethodID = state => state.ivTimeSeriesState.currentIVMethodID; - -export const getCurrentParameterCode = state => state.ivTimeSeriesState.currentParameterCode; - -export const getCurrentDateRange = (state) => { - return state.ivTimeSeriesState.currentIVDateRange || null; -}; - -export const getIVGraphBrushOffset = state => state.ivTimeSeriesState.ivGraphBrushOffset || null; - -export const getLoadingTsKeys = state => state.ivTimeSeriesState.loadingIVTSKeys || []; - -export const getCustomTimeRange = state => state.ivTimeSeriesState.customIVTimeRange; diff --git a/assets/src/scripts/monitoring-location/selectors/time-series-selector.test.js b/assets/src/scripts/monitoring-location/selectors/time-series-selector.test.js deleted file mode 100644 index 48fff375a..000000000 --- a/assets/src/scripts/monitoring-location/selectors/time-series-selector.test.js +++ /dev/null @@ -1,1201 +0,0 @@ -import { - getVariables, - getShowIVTimeSeries, - getSourceInfo, - getSiteCodes, - getCurrentVariableID, - getCurrentDateRange, - getIVGraphBrushOffset, - getTimeSeries, - hasAnyTimeSeries, - hasAnyVariables, - getMonitoringLocationName, - getAgencyCode, - getUserInputsForSelectingTimespan, - getCurrentVariable, - getQueryInfo, - getRequests, - getCurrentParmCd, - hasTimeSeries, - getTsRequestKey, - getTsQueryInfo, - getRequestTimeRange, - isLoadingTS, - getTSRequest, - getTimeSeriesCollectionIds, - getNwisTimeZone, - getAllMethodsForCurrentVariable, - getCurrentVariableTimeSeries, - getTimeSeriesForTsKey -} from './time-series-selector'; - -const TEST_DATA = { - ivTimeSeriesData: { - timeSeries: { - '00060': { - tsKey: 'current:P7D', - startTime: 1520351100000, - endTime: 1520948700000, - variable: '45807197', - method: 69929, - points: [{ - value: 10, - qualifiers: ['P'], - approved: false, - estimated: false - }, { - value: null, - qualifiers: ['P', 'ICE'], - approved: false, - estimated: false - }, { - value: null, - qualifiers: ['P', 'FLD'], - approved: false, - estimated: false - }] - }, - '00010': { - tsKey: 'compare:P7D', - startTime: 1520351100000, - endTime: 1520948700000, - variable: '45807196', - method: 69931, - points: [{ - value: 1, - qualifiers: ['P'], - approved: false, - estimated: false - }, { - value: 2, - qualifiers: ['P'], - approved: false, - estimated: false - }, { - value: 3, - qualifiers: ['P'], - approved: false, - estimated: false - }] - }, - '00010:2': { - tsKey: 'current:P7D', - startTime: 1520351100000, - endTime: 1520948700000, - variable: '45807196', - method: 69930, - points: [{ - value: 1, - qualifiers: ['P'], - approved: false, - estimated: false - }, { - value: 2, - qualifiers: ['P'], - approved: false, - estimated: false - }, { - value: 3, - qualifiers: ['P'], - approved: false, - estimated: false - }] - }, - '00011': { - tsKey: 'compare:P7D', - startTime: 1520351100000, - endTime: 1520948700000, - variable: '45807195', - method: 69929, - points: [{ - value: 68, - qualifiers: ['P'], - approved: false, - estimated: false - }, { - value: 70, - qualifiers: ['P'], - approved: false, - estimated: false - }, { - value: 77, - qualifiers: ['P'], - approved: false, - estimated: false - }] - }, - '00060:P30D': { - tsKey: 'current:P30D:00060', - startTime: 1520351100000, - endTime: 1520948700000, - variable: '45807197', - method: 69929, - points: [{ - value: 10, - qualifiers: ['P'], - approved: false, - estimated: false - }, { - value: null, - qualifiers: ['P', 'ICE'], - approved: false, - estimated: false - }, { - value: null, - qualifiers: ['P', 'FLD'], - approved: false, - estimated: false - }] - } - }, - timeSeriesCollections: { - 'coll1': { - variable: 45807197, - timeSeries: ['00060'] - } - }, - requests: { - 'current:P7D': { - timeSeriesCollections: ['coll1'] - }, - 'current:P30D:00060': {} - }, - variables: { - '45807197': { - variableCode: { - value: '00060' - }, - variableName: 'Streamflow', - variableDescription: 'Discharge, cubic feet per second', - oid: '45807197' - }, - '45807196': { - variableCode: { - value: '00010' - }, - variableName: 'Temperature, water, degrees Celsius', - variableDescription: 'Water Temperature in Celsius', - oid: '45807196' - }, - '45807195': { - variableCode: { - value: '00011' - }, - variableName: 'Temperature, water, degrees Fahrenheit', - variableDescription: 'Water Temperature in Fahrenheit', - oid: '45807195' - }, - '55807196' : { - variableCode: { - value: '11111' - }, - variableName: 'My variable', - variableDescription: 'My awesome variable', - oid: '55807196' - } - }, - methods: { - 69329: { - methodDescription: '', - methodID: 69928 - }, - 69330: { - methodDescription: '4.1 ft from riverbed (middle)', - methodID: 69930 - }, - 69331: { - methodDescription: '1.0 ft from riverbed (bottom)', - methodID: 69931 - } - }, - queryInfo: { - 'current:P7D': { - notes: { - requestDT: 1483994767572, - 'filter:timeRange': { - mode: 'PERIOD', - periodDays: 7, - modifiedSince: null - } - } - }, - 'current:P30D:00060': { - notes: { - requestDT: 1483994767572, - 'filter:timeRange': { - mode: 'RANGE', - interval: { - start: 1483941600000, - end: 1486533600000 - }, - modifiedSince: null - } - } - } - } - }, - ivTimeSeriesState: { - showIVTimeSeries: { - current: true, - compare: true, - median: false - }, - currentIVVariableID: '45807197', - currentIVDateRange: 'P7D' - } -}; - -describe('monitoring-location/selectors/time-series-selector', () => { - const TEST_VARS = { - '45807042': { - variableCode: { - 'value': '00060' - } - }, - '450807142': { - variableCode: { - 'value': '00010' - } - } - }; - - describe('getVariables', () => { - it('Return null if series is empty', () => { - expect(getVariables({ - ivTimeSeriesData: {} - })).toBeNull(); - }); - - it('Return the variables if in series', () => { - expect(getVariables({ - ivTimeSeriesData: { - variables: TEST_VARS - } - })).toEqual(TEST_VARS); - }); - }); - - describe('getTimeSeries', () => { - it('Return empty object if series is empty', () => { - expect(getTimeSeries({ - ivTimeSeriesData: {} - })).toEqual({}); - }); - - it('Return the timeSeries if in series', () => { - expect(getTimeSeries({ - ivTimeSeriesData: { - timeSeries: { - '00010': { - prop1: 'value1' - } - } - } - })).toEqual({ - '00010': { - prop1: 'value1' - } - }); - }); - }); - - describe('hasAnyTimeSeries', () => { - it('Return false if series is empty', () => { - expect(hasAnyTimeSeries({ - ivTimeSeriesData: {} - })).toBe(false); - }); - - it('Return true if series is not empty', () => { - expect(hasAnyTimeSeries({ - ivTimeSeriesData: { - timeSeries: { - '00010': { - prop1: 'value1' - } - } - } - })).toBe(true); - }); - }); - - describe('hasAnyVariables', () => { - it('Return false if state contains no variables', () => { - expect(hasAnyVariables({ - ivTimeSeriesData: {} - })).toBe(false); - }); - - it('Return true if state contains variables', () => { - expect(hasAnyVariables(TEST_DATA)).toBe(true); - }); - }); - - describe('getSourceInfo', () => { - it('Return an empty object if series is empty', () => { - expect(getSourceInfo({ - ivTimeSeriesData: {} - })).toEqual({}); - }); - - it('Return the sourceInfo if in series', () => { - expect(getSourceInfo({ - ivTimeSeriesData: { - sourceInfo: { - '0537000': { - siteName: 'Site Name' - } - } - } - })).toEqual({ - '0537000': { - siteName: 'Site Name' - } - }); - }); - }); - - describe('getSiteCodes', () => { - it('Return an empty object if series is empty', () => { - expect(getSiteCodes({ - ivTimeSeriesData: {} - })).toEqual({}); - }); - - it('Return the siteCodes if in series', () => { - expect(getSiteCodes({ - ivTimeSeriesData: { - siteCodes: { - '0537000': { - agencyCode: 'USGS' - } - } - } - })).toEqual({ - '0537000': { - agencyCode: 'USGS' - } - }); - }); - }); - - describe('getQueryInfo', () => { - it('Return empty object if series is empty', () => { - expect(getQueryInfo({ - ivTimeSeriesData: {} - })).toEqual({}); - }); - - it('Return queryinfo is state', () => { - expect(getQueryInfo({ - ivTimeSeriesData: { - queryInfo: { - 'current:P7D': { - queryURL: 'http://waterservices.usgs.gov/nwis/iv/sites=05370000&period=P7D' - } - } - } - })).toEqual({ - 'current:P7D': { - queryURL: 'http://waterservices.usgs.gov/nwis/iv/sites=05370000&period=P7D' - } - }); - }); - }); - - describe('getRequests', () => { - it('Empty object if series is empty', () => { - expect(getRequests({ - ivTimeSeriesData: {} - })).toEqual({}); - }); - - it('Requests object if in state', () => { - expect(getRequests({ - ivTimeSeriesData: { - requests : { - 'current:P7D': { - timeSeriesCollections: ['1', '2'] - }, - 'compare:P30D:00010': { - timeSeriesCollections: ['3'] - }, - 'current:P30D:00060': { - timeSeriesCollections: ['4'] - } - } - } - })).toEqual({ - 'current:P7D': { - timeSeriesCollections: ['1', '2'] - }, - 'compare:P30D:00010': { - timeSeriesCollections: ['3'] - }, - 'current:P30D:00060': { - timeSeriesCollections: ['4'] - } - }); - }); - }); - - describe('getMonitoringLocationName', () => { - const TEST_INFO = { - ivTimeSeriesData: { - sourceInfo: { - '01010101': { - 'siteName': 'My Site Name' - } - } - } - }; - it('Returns empty string if state has no sourceInfo', () => { - expect(getMonitoringLocationName('12345678')({ - ivTimeSeriesData: {} - })).toBe(''); - }); - - it('Returns empty string if siteNo is not in sourceInfo', () => { - expect(getMonitoringLocationName('12345678')(TEST_INFO)).toBe(''); - }); - - it('Returns the monitoring location name for the site', () => { - expect(getMonitoringLocationName('01010101')(TEST_INFO)).toBe('My Site Name'); - }); - }); - - describe('getAgencyCode', () => { - const TEST_SITE_CODES = { - ivTimeSeriesData: { - siteCodes: { - '01010101': { - 'agencyCode': 'USGS' - } - } - } - }; - it('Returns empty string if state has no siteCodes', () => { - expect(getAgencyCode('12345678')({ - ivTimeSeriesData: {} - })).toBe(''); - }); - - it('Returns empty string if siteNo is not in siteCodes', () => { - expect(getAgencyCode('12345678')(TEST_SITE_CODES)).toBe(''); - }); - - it('Returns the agency code for the site', () => { - expect(getAgencyCode('01010101')(TEST_SITE_CODES)).toBe('USGS'); - }); - }); - - describe('getTimespanUserInputs', () => { - it('Returns the an object with user input selections for time ranges', () => { - expect(getUserInputsForSelectingTimespan({ - ivTimeSeriesState: { - userInputsForTimeRange: { - mainTimeRangeSelectionButton: 'custom', - customTimeRangeSelectionButton: 'days-input', - numberOfDaysFieldValue: '3' - } - } - })).toEqual({ - mainTimeRangeSelectionButton: 'custom', - customTimeRangeSelectionButton: 'days-input', - numberOfDaysFieldValue: '3' - }); - }); - }); - - - describe('getCurrentVariableID', () => { - it('Return the current variable ID', () => { - expect(getCurrentVariableID({ - ivTimeSeriesState: { - currentIVVariableID: '00060' - } - })).toEqual('00060'); - }); - }); - - describe('getCurrentDateRange', () => { - it('Return the current date range', () => { - expect(getCurrentDateRange({ - ivTimeSeriesState: { - currentIVDateRange: 'P30D' - } - })).toEqual('P30D'); - }); - }); - - describe('getIVGraphBrushOffset', () => { - it('Return null if no ivGraphBrushOffset defined', () => { - expect(getIVGraphBrushOffset({ - ivTimeSeriesState: {} - })).toBeNull(); - }); - - it('Return the current date range', () => { - expect(getIVGraphBrushOffset({ - ivTimeSeriesState: { - ivGraphBrushOffset: { - start: 1580318458000, - end: 1611940858000 - } - } - })).toEqual({ - start: 1580318458000, - end: 1611940858000 - }); - }); - }); - - describe('getCurrentVariable', () => { - const TEST_STATE = { - ivTimeSeriesData: { - variables: TEST_VARS - }, - ivTimeSeriesState: { - currentIVVariableID: '45807042' - } - }; - - it('Return null if no variable is selected', () => { - expect(getCurrentVariable({ - ...TEST_STATE, - ivTimeSeriesState: { - currentIVVariableID: null - } - })).toBeNull(); - }); - - it('Return null if no variables are in series', () => { - expect(getCurrentVariable({ - ...TEST_STATE, - ivTimeSeriesData: { - variables: {} - } - })).toBeNull(); - expect(getCurrentVariable({ - ...TEST_STATE, - ivTimeSeriesData: {} - })).toBeNull(); - }); - - it('Return selected variable', () => { - expect(getCurrentVariable(TEST_STATE)).toEqual(TEST_VARS['45807042']); - }); - }); - - describe('getCurrentParmCd', () => { - const TEST_STATE = { - ivTimeSeriesData: { - variables: TEST_VARS - }, - ivTimeSeriesState: { - currentIVVariableID: '45807042' - } - }; - - it('Return null if no variable is selected', () => { - expect(getCurrentParmCd({ - ...TEST_STATE, - ivTimeSeriesState: { - currentIVVariableID: null - } - })).toBeNull(); - }); - - it('Return null if no variables are in series', () => { - expect(getCurrentParmCd({ - ...TEST_STATE, - ivTimeSeriesData: { - variables: {} - } - })).toBeNull(); - expect(getCurrentParmCd({ - ...TEST_STATE, - ivTimeSeriesData: {} - })).toBeNull(); - }); - - it('Return selected parm code', () => { - expect(getCurrentParmCd(TEST_STATE)).toEqual('00060'); - }); - }); - - describe('hasTimeSeries', () => { - const TEST_STATE = { - ivTimeSeriesData: { - variables: TEST_VARS, - requests : { - 'current:P7D': {}, - 'current:P30D:00060': {} - } - }, - ivTimeSeriesState: { - currentIVDateRange: 'P7D', - currentIVVariableID: '45807042' - } - }; - - it('Return false if no requests in series', () => { - expect(hasTimeSeries('current', 'P7D', '00060')({ - ivTimeSeriesData: {}, - ivTimeSeriesState: { - currentIVDateRange: 'P7D', - currentIVVariableID: '45807042' - } - })).toBe(false); - }); - - it('Return false if request is not in state', () => { - expect(hasTimeSeries('current', 'P30D', '00010')(TEST_STATE)).toBe(false); - expect(hasTimeSeries('current', 'P1Y')(TEST_STATE)).toBe(false); - }); - - it('Return true if request is in state', () => { - expect(hasTimeSeries('current')(TEST_STATE)).toBe(true); - expect(hasTimeSeries('current', 'P30D', '00060')(TEST_STATE)).toBe(true); - }); - }); - - describe('getTsRequestKey', () => { - const TEST_STATE = { - ivTimeSeriesData: { - variables: TEST_VARS - }, - ivTimeSeriesState: { - currentIVDateRange: 'P7D', - currentIVVariableID: '45807042' - } - }; - it('Return the expected request key if period and parmCd are not specified', () => { - expect(getTsRequestKey('current')(TEST_STATE)).toBe('current:P7D'); - expect(getTsRequestKey('compare')(TEST_STATE)).toBe('compare:P7D'); - }); - - it('Return the expected request key if parmCd is not specified', () => { - expect(getTsRequestKey('current', 'P30D')(TEST_STATE)).toBe('current:P30D:00060'); - expect(getTsRequestKey('compare', 'P30D')(TEST_STATE)).toBe('compare:P30D:00060'); - }); - - it('Return the expected request key if all parameters are specified', () => { - expect(getTsRequestKey('current', 'P30D', '00010')(TEST_STATE)).toBe('current:P30D:00010'); - expect(getTsRequestKey('compare', 'P30D', '00010')(TEST_STATE)).toBe('compare:P30D:00010'); - }); - }); - - describe('getTsQueryInfo', () => { - const TEST_DATA = { - ivTimeSeriesData: { - queryInfo: { - 'current:P7D': { - notes: { - requestDT: 1490936400000, - 'filter:timeRange': { - mode: 'PERIOD', - periodDays: 7, - modifiedSince: null - } - } - }, - 'current:P30D:00060': { - notes: { - requestDT: 1490936400000, - 'filter:timeRange': { - mode: 'RANGE', - interval: { - start: 1488348000000, - end: 1490763600000 - } - } - } - } - }, - variables: TEST_VARS - }, - ivTimeSeriesState: { - currentIVDateRange: 'P7D', - currentIVVariableID: '45807042' - } - }; - - it('Return the query info requested by tsKey using current date range', () => { - expect(getTsQueryInfo('current')(TEST_DATA)).toEqual(TEST_DATA.ivTimeSeriesData.queryInfo['current:P7D']); - expect(getTsQueryInfo('compare')(TEST_DATA)).toEqual({}); - }); - - it('Return the query info request by tsKey and period and parmCd', () => { - expect(getTsQueryInfo('current', 'P1Y')(TEST_DATA)).toEqual({}); - expect(getTsQueryInfo('current', 'P30D')(TEST_DATA)).toEqual(TEST_DATA.ivTimeSeriesData.queryInfo['current:P30D:00060']); - expect(getTsQueryInfo('current', 'P30D', '00010')(TEST_DATA)).toEqual({}); - }); - }); - - - describe('getRequestTimeRange', () => { - const TEST_DATA = { - ianaTimeZone: 'America/Chicago', - ivTimeSeriesData: { - queryInfo: { - 'current:P7D': { - notes: { - requestDT: 1490936400000, - 'filter:timeRange': { - mode: 'PERIOD', - periodDays: 7, - modifiedSince: null - } - } - }, - 'current:P30D:00060': { - notes: { - requestDT: 1490936400000, - 'filter:timeRange': { - mode: 'RANGE', - interval: { - start: 1488348000000, - end: 1490763600000 - } - } - } - }, - 'current:custom:00095': { - notes: { - requestDT: 1568729153803, - 'filter:timeRange': { - mode: 'RANGE', - interval: { - start: 1454738400000, - end: 1557896400000 - } - } - } - } - }, - variables: TEST_VARS - }, - ivTimeSeriesState: { - currentIVDateRange: 'P7D', - currentIVVariableID: '45807042' - } - }; - - it('should return null if there is no series data', () => { - const newTestData = { - ...TEST_DATA, - ivTimeSeriesData: {} - }; - expect(getRequestTimeRange('current')(newTestData)).toBeNull(); - }); - - it('should return null if the data has not been requests', () => { - expect(getRequestTimeRange('compare')(TEST_DATA)).toBeNull(); - expect(getRequestTimeRange('current', 'P30D', '00010')(TEST_DATA)).toBeNull(); - }); - - it('should use the requestDT for requests with mode PERIOD', () => { - expect(getRequestTimeRange('current')(TEST_DATA)).toEqual({ - start: 1490331600000, - end: 1490936400000 - }); - }); - - it('should use the interval for request with mode RANGE', () => { - expect(getRequestTimeRange('current', 'P30D', '00060')(TEST_DATA)).toEqual({ - start: 1488348000000, - end: 1490763600000 - }); - }); - - it('should use the interval for a request with a custom RANGE', () => { - expect(getRequestTimeRange('current', 'custom', '00095')(TEST_DATA)).toEqual({ - start: 1454738400000, - end: 1557896400000 - }); - }); - }); - - describe('getNwisTimeZone', () => { - - it('returns an empty object if series is empty', () => { - expect(getNwisTimeZone({ - ivTimeSeriesData: {} - })).toEqual({}); - }); - - it('returns the NWIS provide timezones when present', () => { - expect(getNwisTimeZone({ - ivTimeSeriesData: { - timeZones: { - CDT: { - content: 'x' - }, - CST: { - content: 'y' - } - } - } - })).toEqual({ - CDT: { - content: 'x' - }, - CST: { - content: 'y' - } - }); - }); - }); - - describe('isLoadingTS', () => { - const TEST_DATA = { - ivTimeSeriesData: { - variables: TEST_VARS - }, - ivTimeSeriesState: { - currentIVDateRange: 'P30D', - currentIVVariableID: '45807042', - loadingIVTSKeys: ['compare:P7D', 'current:P30D:00060'] - } - }; - - it('true for ts requests that are loading', () => { - expect(isLoadingTS('current')(TEST_DATA)).toBe(true); - expect(isLoadingTS('compare', 'P7D')(TEST_DATA)).toBe(true); - }); - - it('false for ts requests that are not loading', () => { - expect(isLoadingTS('compare')(TEST_DATA)).toBe(false); - expect(isLoadingTS('current', 'P30D', '00010')(TEST_DATA)).toBe(false); - expect(isLoadingTS('current', 'P7D')(TEST_DATA)).toBe(false); - }); - }); - - describe('getShowIVTimeSeries', () => { - const expectedObject = { - current: true, - compare: true, - median: false - }; - it('Expects to return the selections for which time series are active', () => { - expect(getShowIVTimeSeries(TEST_DATA)).toEqual(expectedObject); - }); - }); - - - describe('getTSRequest', () => { - const TEST_DATA = { - ivTimeSeriesData: { - requests: { - 'current:P7D': { - timeSeriesCollections: ['1', '2'] - }, - 'compare:P30D:00010': { - timeSeriesCollections: [] - }, - 'current:P30D:00060': { - timeSeriesCollections: ['4'] - } - }, - variables: TEST_VARS - }, - ivTimeSeriesState: { - currentIVDateRange: 'P30D', - currentIVVariableID: '45807042' - } - }; - - it('Expects to retrieve requested requests', () => { - expect(getTSRequest('current', 'P7D')(TEST_DATA)).toEqual({ - timeSeriesCollections: ['1', '2'] - }); - expect(getTSRequest('current')(TEST_DATA)).toEqual({ - timeSeriesCollections: ['4'] - }); - expect(getTSRequest('compare', 'P30D', '00010')(TEST_DATA)).toEqual({ - timeSeriesCollections: [] - }); - }); - - it('Return the empty object if the request does not contain the request key', () => { - expect(getTSRequest('compare')(TEST_DATA)).toEqual({}); - expect(getTSRequest('compare', 'P7D')(TEST_DATA)).toEqual({}); - expect(getTSRequest('current', 'P1Y', '00010')(TEST_DATA)).toEqual({}); - }); - }); - - describe('getTimeSeriesCollectionIds', () => { - const TEST_DATA = { - ivTimeSeriesData: { - requests: { - 'current:P7D': { - timeSeriesCollections: ['1', '2'] - }, - 'compare:P30D:00010': { - timeSeriesCollections: [] - }, - 'current:P30D:00060': { - timeSeriesCollections: ['4'] - } - }, - variables: TEST_VARS - }, - ivTimeSeriesState: { - currentIVDateRange: 'P30D', - currentIVVariableID: '45807042' - } - }; - - it('Expects to retrieve requested timeSeriesCollections', () => { - expect(getTimeSeriesCollectionIds('current', 'P7D')(TEST_DATA)).toEqual(['1', '2']); - expect(getTimeSeriesCollectionIds('current')(TEST_DATA)).toEqual(['4']); - expect(getTimeSeriesCollectionIds('compare', 'P30D', '00010')(TEST_DATA)).toEqual([]); - }); - - it('Return null if the request does not contain the request key', () => { - expect(getTimeSeriesCollectionIds('compare')(TEST_DATA)).toBeNull(); - expect(getTimeSeriesCollectionIds('compare', 'P7D')(TEST_DATA)).toBeNull(); - expect(getTimeSeriesCollectionIds('current', 'P1Y', '00010')(TEST_DATA)).toBeNull(); - }); - }); - - describe('getCurrentVariableTimeSeries', () => { - it('works', () => { - expect(getCurrentVariableTimeSeries('current', 'P7D')({ - ivTimeSeriesData: { - requests: { - 'current:P7D': { - timeSeriesCollections: ['coll1', 'coll2'] - } - }, - timeSeriesCollections: { - 'coll1': { - timeSeries: ['one', 'two'], - variable: 45807197 - }, - 'coll2': { - timeSeries: ['three', 'four'], - variable: 45807197 - }, - 'coll3': { - timeSeries: ['five', 'six'], - variable: 'do not match' - } - }, - timeSeries: { - one: { - item: 'one', - points: [1, 2], - tsKey: 'current:P7D', - variable: 45807197 - }, - two: { - item: 'two', - points: [], - tsKey: 'current:P7D', - variable: 45807197 - }, - three: { - item: 'three', - points: [3, 4], - tsKey: 'current:P7D', - variable: 45807197 - }, - four: { - item: 'four', - points: [4, 5], - tsKey: 'current:P7D', - variable: 45807197 - }, - five: { - item: 'five', - points: [5, 6], - tsKey: 'compare:P7D', - variable: 45807190 - }, - six: { - item: 'six', - points: [6, 7], - tsKey: 'compare:P7D', - variable: 45807190 - } - }, - variables: { - '45807197': { - oid: 45807197, - variableCode: { - value: '00060', - variableID: 45807197 - } - } - } - }, - ivTimeSeriesState: { - currentIVVariableID: '45807197', - currentIVDateRange: 'P7D' - } - })).toEqual({ - one: {item: 'one', points: [1, 2], tsKey: 'current:P7D', variable: 45807197}, - two: {item: 'two', points: [], tsKey: 'current:P7D', variable: 45807197}, - three: {item: 'three', points: [3, 4], tsKey: 'current:P7D', variable: 45807197}, - four: {item: 'four', points: [4, 5], tsKey: 'current:P7D', variable: 45807197} - }); - }); - - it('returns {} if there is no currentVariableId', () => { - expect(getCurrentVariableTimeSeries('current', 'P7D')({ - ivTimeSeriesData: {}, - ivTimeSeriesState: { - currentIVVariableID: null, - currentIVDateRange: 'P7D' - } - })).toEqual({}); - }); - }); - - describe('getAllMethodsForCurrentVariable', () => { - it('Expect empty array if current variable has no time series', () => { - const newTestData = { - ...TEST_DATA, - ivTimeSeriesState: { - ...TEST_DATA.ivTimeSeriesState, - currentIVVariableID: '55807196' - } - }; - expect(getAllMethodsForCurrentVariable(newTestData)).toEqual([]); - }); - - it('Expect method ids for current variable', () => { - const newTestData = { - ...TEST_DATA, - ivTimeSeriesData: { - ...TEST_DATA.ivTimeSeriesData, - timeSeries: { - ...TEST_DATA.ivTimeSeriesData.timeSeries, - '00010:current:P7D': { - tsKey: 'current:P7D', - startTime: 1520351100000, - endTime: 1520948700000, - variable: '45807196', - method: 69931, - points: [{ - value: 1, - qualifiers: ['P'], - approved: false, - estimated: false - }, { - value: 2, - qualifiers: ['P'], - approved: false, - estimated: false - }, { - value: 3, - qualifiers: ['P'], - approved: false, - estimated: false - }] - } - } - }, - ivTimeSeriesState: { - ...TEST_DATA.ivTimeSeriesState, - currentIVVariableID: '45807196' - } - }; - const result = getAllMethodsForCurrentVariable(newTestData); - expect(result).toHaveLength(2); - expect(result).toContainEqual({ - methodDescription: '4.1 ft from riverbed (middle)', - methodID: 69930 - }); - expect(result).toContainEqual({ - methodDescription: '1.0 ft from riverbed (bottom)', - methodID: 69931 - }); - }); - }); - - describe('getTimeSeriesForTsKey', () => { - - it('should return the selected time series', () => { - expect(getTimeSeriesForTsKey('current')(TEST_DATA)).toEqual({ - '00060': { - tsKey: 'current:P7D', - startTime: 1520351100000, - endTime: 1520948700000, - points: [{ - value: 10, - qualifiers: ['P'], - approved: false, - estimated: false - }, { - value: null, - qualifiers: ['P', 'ICE'], - approved: false, - estimated: false - }, { - value: null, - qualifiers: ['P', 'FLD'], - approved: false, - estimated: false - }], - variable: '45807197', - method: 69929 - }, - '00010:2': { - tsKey: 'current:P7D', - startTime: 1520351100000, - endTime: 1520948700000, - variable: '45807196', - method: 69930, - points: [{ - value: 1, - qualifiers: ['P'], - approved: false, - estimated: false - }, { - value: 2, - qualifiers: ['P'], - approved: false, - estimated: false - }, { - value: 3, - qualifiers: ['P'], - approved: false, - estimated: false - }] - } - }); - expect(getTimeSeriesForTsKey('current','P30D')(TEST_DATA)).toEqual({ - '00060:P30D': { - tsKey: 'current:P30D:00060', - startTime: 1520351100000, - endTime: 1520948700000, - variable: '45807197', - method: 69929, - points: [{ - value: 10, - qualifiers: ['P'], - approved: false, - estimated: false - }, { - value: null, - qualifiers: ['P', 'ICE'], - approved: false, - estimated: false - }, { - value: null, - qualifiers: ['P', 'FLD'], - approved: false, - estimated: false - }] - } - }); - }); - - it('should return null the empty set if no time series for the selected key exist', () => { - expect(getTimeSeriesForTsKey('compare:P7D')(TEST_DATA)).toEqual({}); - }); - }); -}); diff --git a/assets/src/scripts/monitoring-location/selectors/time-zone-selector.js b/assets/src/scripts/monitoring-location/selectors/time-zone-selector.js deleted file mode 100644 index d3f3cff16..000000000 --- a/assets/src/scripts/monitoring-location/selectors/time-zone-selector.js +++ /dev/null @@ -1,3 +0,0 @@ -export const getIanaTimeZone = state => state.ianaTimeZone ? state.ianaTimeZone : null; - - diff --git a/assets/src/scripts/monitoring-location/selectors/time-zone-selector.test.js b/assets/src/scripts/monitoring-location/selectors/time-zone-selector.test.js deleted file mode 100644 index eda6895b9..000000000 --- a/assets/src/scripts/monitoring-location/selectors/time-zone-selector.test.js +++ /dev/null @@ -1,17 +0,0 @@ -import {getIanaTimeZone} from './time-zone-selector'; - -describe('monitoring-location/selectors/time-zone-selector', () => { - describe('getIanaTimeZone', () => { - it('returns null if saved time zone is null', () => { - expect(getIanaTimeZone({ - ianaTimeZone: null - })).toBeNull(); - }); - - it('returns the time zone when present', () => { - expect(getIanaTimeZone({ - ianaTimeZone: 'America/Los_Angeles' - })).toEqual('America/Los_Angeles'); - }); - }); -}); \ No newline at end of file diff --git a/assets/src/scripts/monitoring-location/store/hydrograph-data.js b/assets/src/scripts/monitoring-location/store/hydrograph-data.js index 35903686c..1c73e0c21 100644 --- a/assets/src/scripts/monitoring-location/store/hydrograph-data.js +++ b/assets/src/scripts/monitoring-location/store/hydrograph-data.js @@ -268,7 +268,7 @@ const retrieveGroundwaterLevels = function(site, {parameterCode, period, startTi export const retrieveHydrographData = function(siteno, {parameterCode, period, startTime, endTime, loadCompare, loadMedian}) { return function(dispatch) { const parameterToFetch = getParameterToFetch(parameterCode); - const hasIVData = config.uvPeriodOfRecord && parameterToFetch in config.uvPeriodOfRecord; + const hasIVData = config.ivPeriodOfRecord && parameterToFetch in config.ivPeriodOfRecord; const hasGWData = config.gwPeriodOfRecord && parameterToFetch in config.gwPeriodOfRecord; dispatch(clearHydrographData()); diff --git a/assets/src/scripts/monitoring-location/store/hydrograph-data.test.js b/assets/src/scripts/monitoring-location/store/hydrograph-data.test.js index 8e961b9e0..ff94ed917 100644 --- a/assets/src/scripts/monitoring-location/store/hydrograph-data.test.js +++ b/assets/src/scripts/monitoring-location/store/hydrograph-data.test.js @@ -51,7 +51,7 @@ describe('monitoring-location/store/hydrograph-data', () => { describe('retrieveHydrographData', () => { describe('The correct web services are called', () => { it('Expects to retrieve groundwater and IV data if both are in the period of record', () => { - config.uvPeriodOfRecord = { + config.ivPeriodOfRecord = { '00060': {begin_date: '2010-01-01', end_date: '2020-01-01'} }; config.gwPeriodOfRecord = { @@ -90,7 +90,7 @@ describe('monitoring-location/store/hydrograph-data', () => { }); it('Expects to retrieve all data when all are available or requested', () => { - config.uvPeriodOfRecord = { + config.ivPeriodOfRecord = { '00060': {begin_date: '2010-01-01', end_date: '2020-01-01'} }; config.gwPeriodOfRecord = { @@ -176,7 +176,7 @@ describe('monitoring-location/store/hydrograph-data', () => { }); it('Only gw if no parameter iv in the period of record', () => { - config.uvPeriodOfRecord = {}; + config.ivPeriodOfRecord = {}; config.gwPeriodOfRecord = { '00060': {begin_date: '2010-01-01', end_date: '2020-01-01'} }; diff --git a/assets/src/scripts/monitoring-location/url-params.js b/assets/src/scripts/monitoring-location/url-params.js index 714f069ed..31013f1d9 100644 --- a/assets/src/scripts/monitoring-location/url-params.js +++ b/assets/src/scripts/monitoring-location/url-params.js @@ -1,10 +1,12 @@ import {DateTime} from 'luxon'; import {createStructuredSelector} from 'reselect'; +import config from 'ui/config'; import {listen} from 'ui/lib/d3-redux'; -import {getCurrentMethodID, getCurrentDateRange, getCustomTimeRange, getCurrentParameterCode} - from 'ml/selectors/time-series-selector'; -import {getIanaTimeZone} from 'ml/selectors/time-zone-selector'; +import {getPrimaryMethods} from 'ml/selectors/hydrograph-data-selector'; +import {isCompareIVDataVisible, getSelectedIVMethodID, getSelectedDateRange, getSelectedCustomTimeRange, + getSelectedParameterCode +} from 'ml/selectors/hydrograph-state-selector'; /* * Return {String} hash part of url minus the leading '#'. @@ -17,14 +19,13 @@ export const getParamString = function() { export const renderTimeSeriesUrlParams = function(store) { // subscribe to selectors for setting url parameter state listen(store, createStructuredSelector({ - parameterCode: getCurrentParameterCode, - methodId: getCurrentMethodID, - methods: [], //getAllMethodsForCurrentVariable, - compare: (state) => state.ivTimeSeriesState.showIVTimeSeries.compare, - currentDateRange: getCurrentDateRange, - customTimeRange: getCustomTimeRange, - timeZone: getIanaTimeZone - }), ({parameterCode, methodId, methods, compare, currentDateRange, customTimeRange, timeZone}) => { + parameterCode: getSelectedParameterCode, + methodId: getSelectedIVMethodID, + methods: getPrimaryMethods, + compare: isCompareIVDataVisible, + currentDateRange: getSelectedDateRange, + customTimeRange: getSelectedCustomTimeRange + }), ({parameterCode, methodId, methods, compare, currentDateRange, customTimeRange}) => { let params = new window.URLSearchParams(); /* filter the 'currentDateRange', which comes in one of two forms @@ -56,10 +57,10 @@ export const renderTimeSeriesUrlParams = function(store) { case 'custom': params.set( 'startDT', - DateTime.fromMillis(customTimeRange.start, {zone: timeZone}).toFormat('yyyy-LL-dd')); + DateTime.fromMillis(customTimeRange.start, {zone: config.locationTimeZone}).toFormat('yyyy-LL-dd')); params.set( 'endDT', - DateTime.fromMillis(customTimeRange.end, {zone: timeZone}).toFormat('yyyy-LL-dd')); + DateTime.fromMillis(customTimeRange.end, {zone: config.locationTimeZone}).toFormat('yyyy-LL-dd')); } if (compare) { params.set('compare', true); diff --git a/wdfn-server/waterdata/location_utils.py b/wdfn-server/waterdata/location_utils.py index e74d6a740..4582c42a4 100644 --- a/wdfn-server/waterdata/location_utils.py +++ b/wdfn-server/waterdata/location_utils.py @@ -341,3 +341,23 @@ def get_period_of_record_by_parm_cd(site_records, data_type_cd='uv'): } return records_by_parm_cd + + +def get_default_parameter_code(iv_parameters, gw_parameters): + """ + Return the default parameter code to use to retrieve data if no other parameter code is specified + :param iv_parameters: dict - where parameter codes are the keys + :param gw_parameters :dict - wher parameter codes are the keys + :return str + """ + preference = ['00065', '00060', '72019'] + for parameter_code in preference: + if parameter_code in iv_parameters or parameter_code in gw_parameters: + return parameter_code + + if iv_parameters: + return list(iv_parameters)[0] + elif gw_parameters: + return list(gw_parameters)[0] + else: + return '' diff --git a/wdfn-server/waterdata/templates/macros/components.html b/wdfn-server/waterdata/templates/macros/components.html index bb31a1c83..19de1f983 100644 --- a/wdfn-server/waterdata/templates/macros/components.html +++ b/wdfn-server/waterdata/templates/macros/components.html @@ -1,5 +1,8 @@ -{% macro TimeSeriesComponent(site_no, latitude, longitude) -%} - <div class="wdfn-component" data-component="hydrograph" data-siteno="{{ site_no }}", data-latitude="{{ latitude }}" data-longitude="{{ longitude }}"> +{% macro TimeSeriesComponent(site_data, default_parameter_code) -%} + <div class="wdfn-component" data-component="hydrograph" data-siteno="{{ site_data.site_no }}" + data-latitude="{{ site_data.dec_lat_va }}" data-longitude="{{ site_data.dec_long_va }}" + data-agency-cd="{{ site_data.agency_cd }}" data-sitename="{{ site_data.station_nm }}" + data-parameter-code="{{ default_parameter_code }}"> <div class="loading-indicator-container"></div> <div class="graph-container"></div> <div class="provisional-data-statement"> diff --git a/wdfn-server/waterdata/templates/monitoring_location.html b/wdfn-server/waterdata/templates/monitoring_location.html index 71d25904d..899714dc7 100644 --- a/wdfn-server/waterdata/templates/monitoring_location.html +++ b/wdfn-server/waterdata/templates/monitoring_location.html @@ -32,13 +32,11 @@ {% block page_script %} <script type="application/javascript"> CONFIG.locationTimeZone = "{{ time_zone }}" - {% if uv_period_of_record %} - CONFIG.uvPeriodOfRecord = {{ uv_period_of_record | tojson }}; + {% if iv_period_of_record %} + CONFIG.ivPeriodOfRecord = {{ iv_period_of_record | tojson }}; {% endif %} {% if gw_period_of_record %} CONFIG.gwPeriodOfRecord = {{ gw_period_of_record | tojson }}; - {% else %} - CONFIG.gwPeriodOfRecord = null; {% endif %} </script> <script src="{{ 'bundle.js' | asset_url }}"></script> @@ -163,7 +161,7 @@ </div> {% endif %} {% if request.user_agent.browser != 'msie' %} - {{ components.TimeSeriesComponent(stations[0].site_no, stations[0].dec_lat_va, stations[0].dec_long_va) }} + {{ components.TimeSeriesComponent(stations[0], default_parameter_code) }} {% if cameras %} {{ components.CameraComponent(cameras) }} {% endif %} diff --git a/wdfn-server/waterdata/views.py b/wdfn-server/waterdata/views.py index 4c0c850e9..df43d3433 100644 --- a/wdfn-server/waterdata/views.py +++ b/wdfn-server/waterdata/views.py @@ -11,7 +11,7 @@ from markdown import markdown from . import app, __version__ from .location_utils import build_linked_data, get_disambiguated_values, rollup_dataseries, \ - get_period_of_record_by_parm_cd + get_period_of_record_by_parm_cd, get_default_parameter_code from .utils import defined_when, parse_rdb, set_cookie_for_banner_message, create_message from .services import sifta, ogc from .services.camera import get_monitoring_location_camera_details @@ -110,6 +110,9 @@ def monitoring_location(site_no): if len(site_data_list) == 1: parameter_data = NWIS.get_site_parameters(site_no, agency_cd) + iv_period_of_record = get_period_of_record_by_parm_cd(parameter_data) + gw_period_of_record = get_period_of_record_by_parm_cd(parameter_data, 'gw') if app.config[ + 'GROUNDWATER_LEVELS_ENABLED'] else {} if parameter_data: site_dataseries = [ get_disambiguated_values( @@ -171,9 +174,9 @@ def monitoring_location(site_no): 'json_ld': Markup(json.dumps(json_ld, indent=4)), 'available_data_types': available_data_types, 'time_zone': time_zone if time_zone else 'local', - 'uv_period_of_record': get_period_of_record_by_parm_cd(parameter_data), - 'gw_period_of_record': get_period_of_record_by_parm_cd(parameter_data, 'gw') if app.config[ - 'GROUNDWATER_LEVELS_ENABLED'] else None, + 'iv_period_of_record': iv_period_of_record, + 'gw_period_of_record': gw_period_of_record, + 'default_parameter_code': get_default_parameter_code(iv_period_of_record, gw_period_of_record), 'parm_grp_summary': grouped_dataseries, 'cooperators': cooperators, 'email_for_data_questions': email_for_data_questions, -- GitLab