From d1bcd8059b522a6e5ca65a75a8d26cf66a1e3334 Mon Sep 17 00:00:00 2001 From: Darius Williams <dswilliams@contractor.usgs.gov> Date: Fri, 3 Jun 2022 15:47:33 -0500 Subject: [PATCH] Actually using the redux store --- .../hydrograph/download-data.test.js | 4 +- .../components/hydrograph/graph-controls.js | 4 +- .../hydrograph/graph-controls.test.js | 8 +- .../components/hydrograph/index.js | 8 +- .../components/hydrograph/index.test.js | 28 +++---- .../hydrograph/mock-hydrograph-state.js | 41 +++++++++-- .../components/hydrograph/parameters.test.js | 3 +- .../hydrograph/select-actions.test.js | 4 +- .../hydrograph/selectors/domain.test.js | 4 +- .../hydrograph/selectors/time-series-data.js | 4 +- .../selectors/time-series-data.test.js | 12 +-- .../components/hydrograph/statistics.js | 48 ++++-------- .../components/hydrograph/statistics.test.js | 73 +++++++++---------- .../hydrograph/time-series-graph.test.js | 4 +- .../hydrograph/time-span-controls.test.js | 9 +-- .../hydrograph/time-span-shortcuts.test.js | 3 +- .../selectors/hydrograph-data-selector.js | 21 +++++- .../hydrograph-data-selector.test.js | 42 ++++++++--- .../selectors/hydrograph-state-selector.js | 5 +- .../hydrograph-state-selector.test.js | 12 +-- .../store/hydrograph-data.js | 27 +++---- .../store/hydrograph-data.test.js | 59 ++++++--------- .../templates/macros/components.html | 2 +- 23 files changed, 223 insertions(+), 202 deletions(-) diff --git a/assets/src/scripts/monitoring-location/components/hydrograph/download-data.test.js b/assets/src/scripts/monitoring-location/components/hydrograph/download-data.test.js index fe02b2f26..d67a0eb6f 100644 --- a/assets/src/scripts/monitoring-location/components/hydrograph/download-data.test.js +++ b/assets/src/scripts/monitoring-location/components/hydrograph/download-data.test.js @@ -6,7 +6,7 @@ import {configureStore} from 'ml/store'; import {setCompareDataVisibility, setMedianDataVisibility} from 'ml/store/hydrograph-state'; import {drawDownloadForm} from './download-data'; -import {TEST_CURRENT_TIME_RANGE, TEST_PRIMARY_IV_DATA, TEST_MEDIAN_DATA, TEST_GW_LEVELS} from './mock-hydrograph-state'; +import {TEST_CURRENT_TIME_RANGE, TEST_PRIMARY_IV_DATA, TEST_STATS_DATA, TEST_GW_LEVELS} from './mock-hydrograph-state'; describe('monitoring-location/components/hydrograph/download-data', () => { @@ -23,7 +23,7 @@ describe('monitoring-location/components/hydrograph/download-data', () => { prioryearTimeRange: TEST_CURRENT_TIME_RANGE, primaryIVData: TEST_PRIMARY_IV_DATA, compareIVData: TEST_PRIMARY_IV_DATA, - medianStatisticsData: TEST_MEDIAN_DATA + statisticsData: TEST_STATS_DATA }, groundwaterLevelData: { all: [TEST_GW_LEVELS] diff --git a/assets/src/scripts/monitoring-location/components/hydrograph/graph-controls.js b/assets/src/scripts/monitoring-location/components/hydrograph/graph-controls.js index 546ce7d8b..451fb9038 100644 --- a/assets/src/scripts/monitoring-location/components/hydrograph/graph-controls.js +++ b/assets/src/scripts/monitoring-location/components/hydrograph/graph-controls.js @@ -6,7 +6,7 @@ import {link} from 'ui/lib/d3-redux'; import {getSelectedParameterCode, getSelectedTimeSpan} from 'ml/selectors/hydrograph-state-selector'; import {getTimeRange} from 'ml/selectors/hydrograph-data-selector'; -import {retrieveMedianStatistics, retrievePriorYearIVData} from 'ml/store/hydrograph-data'; +import {retrieveStatistics, retrievePriorYearIVData} from 'ml/store/hydrograph-data'; import {setCompareDataVisibility, setMedianDataVisibility} from 'ml/store/hydrograph-state'; import {isVisible} from './selectors/time-series-data'; @@ -91,7 +91,7 @@ export const drawGraphControls = function(elem, store, siteno) { store.dispatch(setMedianDataVisibility(this.checked)); if (this.checked) { showDataIndicators(true, store); - store.dispatch(retrieveMedianStatistics(siteno, getSelectedParameterCode(store.getState()))) + store.dispatch(retrieveStatistics(siteno, getSelectedParameterCode(store.getState()))) .then(() => { showDataIndicators(false, store); }); diff --git a/assets/src/scripts/monitoring-location/components/hydrograph/graph-controls.test.js b/assets/src/scripts/monitoring-location/components/hydrograph/graph-controls.test.js index 0676fc1a0..658491f00 100644 --- a/assets/src/scripts/monitoring-location/components/hydrograph/graph-controls.test.js +++ b/assets/src/scripts/monitoring-location/components/hydrograph/graph-controls.test.js @@ -35,7 +35,7 @@ describe('monitoring-location/components/hydrograph/graph-controls', () => { let div; let store; - let retrievePriorYearSpy, retrieveMedianStatisticsSpy; + let retrievePriorYearSpy, retrieveStatisticsSpy; let showDataIndicatorSpy; beforeEach(() => { @@ -52,7 +52,7 @@ describe('monitoring-location/components/hydrograph/graph-controls', () => { } }); retrievePriorYearSpy = jest.spyOn(hydrographData, 'retrievePriorYearIVData'); - retrieveMedianStatisticsSpy = jest.spyOn(hydrographData, 'retrieveMedianStatistics'); + retrieveStatisticsSpy = jest.spyOn(hydrographData, 'retrieveStatistics'); showDataIndicatorSpy = jest.spyOn(dataIndicator, 'showDataIndicators'); drawGraphControls(div, store, '11112222'); @@ -140,7 +140,7 @@ describe('monitoring-location/components/hydrograph/graph-controls', () => { expect(store.getState().hydrographState.showMedianData).toBe(true); expect(showDataIndicatorSpy.mock.calls).toHaveLength(1); expect(showDataIndicatorSpy.mock.calls[0][0]).toBe(true); - expect(retrieveMedianStatisticsSpy).toHaveBeenCalledWith('11112222', '72019'); + expect(retrieveStatisticsSpy).toHaveBeenCalledWith('11112222', '72019'); }); it('Changing the median visibility back to false should set isLoading to false to check for no data availability', () => { @@ -153,7 +153,7 @@ describe('monitoring-location/components/hydrograph/graph-controls', () => { expect(store.getState().hydrographState.showMedianData).toBe(false); expect(showDataIndicatorSpy.mock.calls).toHaveLength(2); expect(showDataIndicatorSpy.mock.calls[1][0]).toBe(false); - expect(retrieveMedianStatisticsSpy.mock.calls).toHaveLength(1); + expect(retrieveStatisticsSpy.mock.calls).toHaveLength(1); }); }); }); diff --git a/assets/src/scripts/monitoring-location/components/hydrograph/index.js b/assets/src/scripts/monitoring-location/components/hydrograph/index.js index 941e134b6..b5d052d8f 100644 --- a/assets/src/scripts/monitoring-location/components/hydrograph/index.js +++ b/assets/src/scripts/monitoring-location/components/hydrograph/index.js @@ -24,7 +24,8 @@ import {setSelectedParameterCode, setCompareDataVisibility, setSelectedTimeSpan, import {Actions as floodDataActions} from 'ml/store/flood-data'; -import {getPreferredIVMethodID} from './selectors/time-series-data'; +import {getPreferredIVMethodID, getTitle} from './selectors/time-series-data'; +import {getStatisticsData, getLatestPrimaryValue} from 'ml/selectors/hydrograph-data-selector'; import {showDataIndicators} from './data-indicator'; import {drawDataTables} from './data-table'; @@ -158,8 +159,9 @@ export const attachToNode = function(store, renderTimeSeriesUrlParams(store); nodeElem.select('#stats-container') .call(link(store, drawStatsTable, createStructuredSelector({ - primaryIVData: (state) => state.hydrographData.primaryIVData, - siteno: () => siteno + stats: getStatisticsData, + latestValue: getLatestPrimaryValue, + parameterName: getTitle }))); } }) 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 97abc9d76..5693c5881 100644 --- a/assets/src/scripts/monitoring-location/components/hydrograph/index.test.js +++ b/assets/src/scripts/monitoring-location/components/hydrograph/index.test.js @@ -17,7 +17,7 @@ import {attachToNode} from './index'; import { TEST_CURRENT_TIME_RANGE, TEST_GW_LEVELS, - TEST_HYDROGRAPH_PARAMETERS, TEST_MEDIAN_DATA, + TEST_HYDROGRAPH_PARAMETERS, TEST_STATS_DATA, TEST_PRIMARY_IV_DATA } from './mock-hydrograph-state'; @@ -144,8 +144,7 @@ describe('monitoring-location/components/hydrograph module', () => { period: 'P7D', startTime: null, endTime: null, - loadCompare: false, - loadMedian: false + loadCompare: false }); expect(store.getState().hydrographState).toEqual({ selectedParameterCode: '72019', @@ -165,8 +164,7 @@ describe('monitoring-location/components/hydrograph module', () => { period: 'P45D', startTime: null, endTime: null, - loadCompare: false, - loadMedian: false + loadCompare: false }); expect(store.getState().hydrographState).toEqual({ selectedParameterCode: '72019', @@ -187,8 +185,7 @@ describe('monitoring-location/components/hydrograph module', () => { period: null, startTime: '2020-02-01T00:00:00.000-06:00', endTime: '2020-02-15T23:59:59.999-06:00', - loadCompare: false, - loadMedian: false + loadCompare: false }); expect(store.getState().hydrographState).toEqual({ selectedParameterCode: '72019', @@ -211,8 +208,7 @@ describe('monitoring-location/components/hydrograph module', () => { period: 'P7D', startTime: null, endTime: null, - loadCompare: true, - loadMedian: false + loadCompare: true }); expect(store.getState().hydrographState).toEqual({ selectedParameterCode: '72019', @@ -244,8 +240,7 @@ describe('monitoring-location/components/hydrograph module', () => { period: 'P7D', startTime: null, endTime: null, - loadCompare: false, - loadMedian: false + loadCompare: false }); expect(store.getState().hydrographState).toEqual({ selectedParameterCode: '72019', @@ -264,7 +259,7 @@ describe('monitoring-location/components/hydrograph module', () => { hydrographData: { primaryIVData: TEST_PRIMARY_IV_DATA, currentTimeRange: TEST_CURRENT_TIME_RANGE, - medianStatisticsData: TEST_MEDIAN_DATA + statisticsData: TEST_STATS_DATA }, groundwaterLevelData: { all: [TEST_GW_LEVELS] @@ -279,6 +274,7 @@ describe('monitoring-location/components/hydrograph module', () => { ui: { width: 1000 } + }); hydrographData.retrieveHydrographData = jest.fn(() => { @@ -296,6 +292,12 @@ describe('monitoring-location/components/hydrograph module', () => { ...INITIAL_PARAMETERS, showOnlyGraph: false }); + jest.useFakeTimers('modern'); + jest.setSystemTime(new Date(2020, 0, 1)); + }); + + afterEach(() => { + jest.useRealTimers(); }); it('loading indicator should be hidden', () => { @@ -376,7 +378,7 @@ describe('monitoring-location/components/hydrograph module', () => { hydrographData: { primaryIVData: TEST_PRIMARY_IV_DATA, currentTimeRange: TEST_CURRENT_TIME_RANGE, - medianStatisticsData: TEST_MEDIAN_DATA + statisticsData: TEST_STATS_DATA }, groundwaterLevelData: { all: [TEST_GW_LEVELS] diff --git a/assets/src/scripts/monitoring-location/components/hydrograph/mock-hydrograph-state.js b/assets/src/scripts/monitoring-location/components/hydrograph/mock-hydrograph-state.js index 7e5934441..e8654173b 100644 --- a/assets/src/scripts/monitoring-location/components/hydrograph/mock-hydrograph-state.js +++ b/assets/src/scripts/monitoring-location/components/hydrograph/mock-hydrograph-state.js @@ -37,14 +37,41 @@ export const TEST_PRIMARY_IV_DATA = { } }; -export const TEST_MEDIAN_DATA = { +export const TEST_STATS_DATA = { '153885': [ - {month_nu: 2, day_nu: 24, p50_va: 16, ts_id: '153885', loc_web_ds: 'Method1', begin_yr: '2011', end_yr: '2020'}, - {month_nu: 2, day_nu: 25, p50_va: 16.2, ts_id: '153885', loc_web_ds: 'Method1', begin_yr: '2011', end_yr: '2020'}, - {month_nu: 2, day_nu: 26, p50_va: 15.9, ts_id: '153885', loc_web_ds: 'Method1', begin_yr: '2011', end_yr: '2020'}, - {month_nu: 2, day_nu: 27, p50_va: 16.3, ts_id: '153885', loc_web_ds: 'Method1', begin_yr: '2011', end_yr: '2020'}, - {month_nu: 2, day_nu: 28, p50_va: 16.4, ts_id: '153885', loc_web_ds: 'Method1', begin_yr: '2011', end_yr: '2020'} - ] + {month_nu: 2, day_nu: 24, p50_va: 16, ts_id: '153885', loc_web_ds: 'Method1', begin_yr: '2011', end_yr: '2020', max_va_yr: '2020', + max_va: '273', min_va_yr: '2006', min_va: '55.5', mean_va: '153', p05_va: '', p10_va: '61', p20_va: '88', p25_va: '100', + p75_va: '224', p80_va: '264', p90_va: '271', p95_va: ''}, + {month_nu: 2, day_nu: 25, p50_va: 16.2, ts_id: '153885', loc_web_ds: 'Method1', begin_yr: '2011', end_yr: '2020', max_va_yr: '2020', + max_va: '273', min_va_yr: '2006', min_va: '55.5', mean_va: '153', p05_va: '', p10_va: '61', p20_va: '88', p25_va: '100', + p75_va: '224', p80_va: '264', p90_va: '271', p95_va: ''}, + {month_nu: 2, day_nu: 26, p50_va: 15.9, ts_id: '153885', loc_web_ds: 'Method1', begin_yr: '2011', end_yr: '2020', max_va_yr: '2020', + max_va: '273', min_va_yr: '2006', min_va: '55.5', mean_va: '153', p05_va: '', p10_va: '61', p20_va: '88', p25_va: '100', + p75_va: '224', p80_va: '264', p90_va: '271', p95_va: ''}, + {month_nu: 2, day_nu: 27, p50_va: 16.3, ts_id: '153885', loc_web_ds: 'Method1', begin_yr: '2011', end_yr: '2020', max_va_yr: '2020', + max_va: '273', min_va_yr: '2006', min_va: '55.5', mean_va: '153', p05_va: '', p10_va: '61', p20_va: '88', p25_va: '100', + p75_va: '224', p80_va: '264', p90_va: '271', p95_va: ''}, + {month_nu: 2, day_nu: 28, p50_va: 16.4, ts_id: '153885', loc_web_ds: 'Method1', begin_yr: '2011', end_yr: '2020', max_va_yr: '2020', + max_va: '273', min_va_yr: '2006', min_va: '55.5', mean_va: '153', p05_va: '', p10_va: '61', p20_va: '88', p25_va: '100', + p75_va: '224', p80_va: '264', p90_va: '271', p95_va: ''} + ], + '90649': [ + {month_nu: 2, day_nu: 24, p50_va: 16, ts_id: '153885', loc_web_ds: 'Method1', begin_yr: '2011', end_yr: '2020', max_va_yr: '2020', + max_va: '273', min_va_yr: '2006', min_va: '55.5', mean_va: '153', p05_va: '', p10_va: '61', p20_va: '88', p25_va: '100', + p75_va: '224', p80_va: '264', p90_va: '271', p95_va: ''}, + {month_nu: 2, day_nu: 25, p50_va: 16.2, ts_id: '153885', loc_web_ds: 'Method1', begin_yr: '2011', end_yr: '2020', max_va_yr: '2020', + max_va: '273', min_va_yr: '2006', min_va: '55.5', mean_va: '153', p05_va: '', p10_va: '61', p20_va: '88', p25_va: '100', + p75_va: '224', p80_va: '264', p90_va: '271', p95_va: ''}, + {month_nu: 2, day_nu: 26, p50_va: 15.9, ts_id: '153885', loc_web_ds: 'Method1', begin_yr: '2011', end_yr: '2020', max_va_yr: '2020', + max_va: '273', min_va_yr: '2006', min_va: '55.5', mean_va: '153', p05_va: '', p10_va: '61', p20_va: '88', p25_va: '100', + p75_va: '224', p80_va: '264', p90_va: '271', p95_va: ''}, + {month_nu: 2, day_nu: 27, p50_va: 16.3, ts_id: '153885', loc_web_ds: 'Method1', begin_yr: '2011', end_yr: '2020', max_va_yr: '2020', + max_va: '273', min_va_yr: '2006', min_va: '55.5', mean_va: '153', p05_va: '', p10_va: '61', p20_va: '88', p25_va: '100', + p75_va: '224', p80_va: '264', p90_va: '271', p95_va: ''}, + {month_nu: 2, day_nu: 28, p50_va: 16.4, ts_id: '153885', loc_web_ds: 'Method1', begin_yr: '2011', end_yr: '2020', max_va_yr: '2020', + max_va: '273', min_va_yr: '2006', min_va: '55.5', mean_va: '153', p05_va: '', p10_va: '61', p20_va: '88', p25_va: '100', + p75_va: '224', p80_va: '264', p90_va: '271', p95_va: ''} + ] }; export const TEST_GW_LEVELS = { diff --git a/assets/src/scripts/monitoring-location/components/hydrograph/parameters.test.js b/assets/src/scripts/monitoring-location/components/hydrograph/parameters.test.js index 944d46564..84f270415 100644 --- a/assets/src/scripts/monitoring-location/components/hydrograph/parameters.test.js +++ b/assets/src/scripts/monitoring-location/components/hydrograph/parameters.test.js @@ -109,8 +109,7 @@ describe('monitoring-location/components/hydrograph/parameters module', () => { period: 'P7D', startTime: null, endTime: null, - loadCompare: false, - loadMedian: false + loadCompare: false }); }); diff --git a/assets/src/scripts/monitoring-location/components/hydrograph/select-actions.test.js b/assets/src/scripts/monitoring-location/components/hydrograph/select-actions.test.js index 32c90a4d3..b5640ce3b 100644 --- a/assets/src/scripts/monitoring-location/components/hydrograph/select-actions.test.js +++ b/assets/src/scripts/monitoring-location/components/hydrograph/select-actions.test.js @@ -4,7 +4,7 @@ import config from 'ui/config.js'; import {configureStore} from 'ml/store'; -import {TEST_PRIMARY_IV_DATA, TEST_MEDIAN_DATA, TEST_GW_LEVELS, TEST_CURRENT_TIME_RANGE} from './mock-hydrograph-state'; +import {TEST_PRIMARY_IV_DATA, TEST_STATS_DATA, TEST_GW_LEVELS, TEST_CURRENT_TIME_RANGE} from './mock-hydrograph-state'; import {drawSelectActions} from './select-actions'; describe('monitoring-location/components/hydrograph/select-actions', () => { @@ -18,7 +18,7 @@ describe('monitoring-location/components/hydrograph/select-actions', () => { hydrographData: { currentTimeRange: TEST_CURRENT_TIME_RANGE, primaryIVData: TEST_PRIMARY_IV_DATA, - medianStatistics: TEST_MEDIAN_DATA + medianStatistics: TEST_STATS_DATA }, groundwaterLevelData: { all: [TEST_GW_LEVELS] diff --git a/assets/src/scripts/monitoring-location/components/hydrograph/selectors/domain.test.js b/assets/src/scripts/monitoring-location/components/hydrograph/selectors/domain.test.js index b0a5179c9..fbd2030b4 100644 --- a/assets/src/scripts/monitoring-location/components/hydrograph/selectors/domain.test.js +++ b/assets/src/scripts/monitoring-location/components/hydrograph/selectors/domain.test.js @@ -1,7 +1,7 @@ import { TEST_PRIMARY_IV_DATA, TEST_GW_LEVELS, - TEST_MEDIAN_DATA, + TEST_STATS_DATA, TEST_CURRENT_TIME_RANGE } from '../mock-hydrograph-state'; import { @@ -154,7 +154,7 @@ describe('monitoring-location/components/hydrograph/selectors/domain module', () hydrographData: { currentTimeRange: TEST_CURRENT_TIME_RANGE, primaryIVData: TEST_PRIMARY_IV_DATA, - medianStatisticsData: TEST_MEDIAN_DATA + statisticsData: TEST_STATS_DATA }, groundwaterLevelData: { all: [TEST_GW_LEVELS] 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 32f314b1c..b28857c30 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 {getSelectedGroundwaterLevels} from 'ml/selectors/groundwater-level-field-visits-selector'; -import {getIVData, getMedianStatisticsData, getPrimaryMethods, getIVPrimaryParameter, +import {getIVData, getStatisticsData, getPrimaryMethods, getIVPrimaryParameter, getTimeRange } from 'ml/selectors/hydrograph-data-selector'; import {getSelectedIVMethodID, isCompareIVDataVisible, isMedianDataVisible} from 'ml/selectors/hydrograph-state-selector'; @@ -66,7 +66,7 @@ export const hasVisibleIVData = memoize(dataKind => createSelector( export const hasVisibleMedianStatisticsData = createSelector( isVisible('median'), - getMedianStatisticsData, + getStatisticsData, (isVisible, medianStats) => isVisible && medianStats ? Object.keys(medianStats).length > 0 : false ); diff --git a/assets/src/scripts/monitoring-location/components/hydrograph/selectors/time-series-data.test.js b/assets/src/scripts/monitoring-location/components/hydrograph/selectors/time-series-data.test.js index 96d2fb1fd..29bf49635 100644 --- a/assets/src/scripts/monitoring-location/components/hydrograph/selectors/time-series-data.test.js +++ b/assets/src/scripts/monitoring-location/components/hydrograph/selectors/time-series-data.test.js @@ -1,6 +1,6 @@ import config from 'ui/config'; -import {TEST_PRIMARY_IV_DATA, TEST_MEDIAN_DATA, TEST_GW_LEVELS} from '../mock-hydrograph-state'; +import {TEST_PRIMARY_IV_DATA, TEST_STATS_DATA, TEST_GW_LEVELS} from '../mock-hydrograph-state'; import { isVisible, hasVisibleIVData, hasVisibleGroundwaterLevels, hasVisibleMedianStatisticsData, hasAnyVisibleData, getTitle, getDescription, getPrimaryParameterUnitCode, getPreferredIVMethodID, getSortedIVMethods, @@ -131,7 +131,7 @@ describe('monitoring-location/components/hydrograph/selectors/time-series-data m it('Return false if median data is available for not selected for display', () => { expect(hasVisibleMedianStatisticsData({ hydrographData: { - medianStatisticsData: TEST_MEDIAN_DATA + statisticsData: TEST_STATS_DATA }, hydrographState: { showMedianData: false @@ -142,7 +142,7 @@ describe('monitoring-location/components/hydrograph/selectors/time-series-data m it('Return false if no median data is available and but is selected for display', () => { expect(hasVisibleMedianStatisticsData({ hydrographData: { - medianStatisticsData: {} + statisticsData: {} }, hydrographState: { showMedianData: true @@ -153,7 +153,7 @@ describe('monitoring-location/components/hydrograph/selectors/time-series-data m it('return true if median data is available and it is selected for display', () => { expect(hasVisibleMedianStatisticsData({ hydrographData: { - medianStatisticsData: TEST_MEDIAN_DATA + statisticsData: TEST_STATS_DATA }, hydrographState: { showMedianData: true @@ -235,7 +235,7 @@ describe('monitoring-location/components/hydrograph/selectors/time-series-data m })).toBe(true); expect(hasAnyVisibleData({ hydrographData: { - medianStatisticsData: TEST_MEDIAN_DATA + statisticsData: TEST_STATS_DATA }, groundwaterLevelData: { all: [] @@ -319,7 +319,7 @@ describe('monitoring-location/components/hydrograph/selectors/time-series-data m })).toBe(false); expect(hasAnyVisibleData({ hydrographData: { - medianStatisticsData: TEST_MEDIAN_DATA + statisticsData: TEST_STATS_DATA }, groundwaterLevelData: { all: [] diff --git a/assets/src/scripts/monitoring-location/components/hydrograph/statistics.js b/assets/src/scripts/monitoring-location/components/hydrograph/statistics.js index 48dd23060..15334474b 100644 --- a/assets/src/scripts/monitoring-location/components/hydrograph/statistics.js +++ b/assets/src/scripts/monitoring-location/components/hydrograph/statistics.js @@ -1,9 +1,5 @@ import {select} from 'd3-selection'; -import {fetchSitesStatisticsRDB} from 'ui/web-services/statistics-data'; -import {parseRDB} from 'ui/utils'; - - const COLUMN_HEADINGS = ['Latest Value', 'Lowest Value', '25th Percentile', 'Median', '75th Percentile', 'Mean', 'Highest Value']; const DATA_HEADINGS = ['min_va', 'p25_va', 'p50_va', 'p75_va', 'mean_va', 'max_va']; @@ -70,38 +66,24 @@ const drawStats = function(elem, currentData, name) { /* * Create the hydrograph data daily statistics section * @param {D3 selection} elem - * @param {Redux store subset} primaryIVData object from the Redux store - * @param {String} siteno + * @param {Redux store subset} statisticsData object from the Redux store + * @param {String} latest reported value of the parameter + * @param {String} name of the parameter */ -export const drawStatsTable = async function(elem, {primaryIVData, siteno}) { - if (!Object.keys(primaryIVData).length) { +export const drawStatsTable = async function(elem, {stats, latestValue, parameterName}) { + if (!latestValue || !stats || !Object.keys(stats).length) { select('#stats-accordion') .attr('hidden', ''); return; } - var currentParameterCode = primaryIVData.parameter.parameterCode; - fetchSitesStatisticsRDB({siteno, 'statType':'ALL', - 'parameterCode': currentParameterCode}).then((result) => { - var statsData = parseRDB(result); - if (!Object.keys(statsData).length) { - select('#stats-accordion') - .attr('hidden', ''); - return; - } - - select('#stats-accordion') - .attr('hidden', null); - let currentIVDataValues = primaryIVData.values; - let currentIVDataArray = currentIVDataValues[Object.keys(currentIVDataValues)[0]].points; - let latestValue = currentIVDataArray[currentIVDataArray.length - 1].value; - let parameterName = primaryIVData.parameter.name; - elem.select('#daily-stats-container').remove(); - elem.append('div') - .attr('id', 'daily-stats-container') - .call(drawStats, [latestValue, statsData[dayIndex(new Date)]], parameterName); - }).catch(() => { - select('#stats-accordion') - .attr('hidden', ''); - return; - }); + + var statsData = stats[Object.keys(stats)[0]]; + + select('#stats-accordion') + .attr('hidden', null); + elem.select('#daily-stats-container').remove(); + elem.append('div') + .attr('id', 'daily-stats-container') + .call(drawStats, [latestValue, statsData[dayIndex(new Date)]], parameterName); + }; \ No newline at end of file diff --git a/assets/src/scripts/monitoring-location/components/hydrograph/statistics.test.js b/assets/src/scripts/monitoring-location/components/hydrograph/statistics.test.js index 776302d2f..405195688 100644 --- a/assets/src/scripts/monitoring-location/components/hydrograph/statistics.test.js +++ b/assets/src/scripts/monitoring-location/components/hydrograph/statistics.test.js @@ -3,9 +3,7 @@ import {select} from 'd3-selection'; import {configureStore} from 'ml/store'; import * as stats from './statistics'; -import {TEST_PRIMARY_IV_DATA} from './mock-hydrograph-state'; -import {MOCK_STATISTICS_RDB_ALT} from 'ui/mock-service-data'; -import * as statisticsDataService from 'ui/web-services/statistics-data'; +import {TEST_STATS_DATA} from './mock-hydrograph-state'; describe('monitoring-location/components/hydrograph/statistics', () => { let testDiv; @@ -14,8 +12,6 @@ describe('monitoring-location/components/hydrograph/statistics', () => { beforeEach(() => { testDiv = select('body').append('div').attr('id', 'stats-accordion'); - statisticsDataService.fetchSitesStatisticsRDB = - jest.fn().mockResolvedValue(MOCK_STATISTICS_RDB_ALT); jest.useFakeTimers('modern'); jest.setSystemTime(new Date(2020, 0, 1)); }); @@ -28,62 +24,63 @@ describe('monitoring-location/components/hydrograph/statistics', () => { it('Creates the stats table elements', async() => { store = configureStore({ hydrographData: { - primaryIVData: TEST_PRIMARY_IV_DATA + statisticsData: TEST_STATS_DATA } }); - await testDiv.call(stats.drawStatsTable, {primaryIVData: store.getState().hydrographData.primaryIVData, siteno: '05428500'}); + await testDiv.call(stats.drawStatsTable, + {stats: store.getState().hydrographData.statisticsData, latestValue: '11', parameterName: 'Test Name'}); - expect(testDiv.select('caption').text()).toContain('Daily Depth to water level for Wed Jan 01 2020 based on 19'); + expect(testDiv.select('caption').text()).toContain('Test Name'); expect(testDiv.select('#daily-stats-container').size()).toBe(1); expect(testDiv.select('#stats-table').size()).toBe(1); }); - it('Does not create the table if there is no primaryIVData', async() => { + it('Does not create the table if there is no stats data', async() => { store = configureStore({ hydrographData: { - primaryIVData: {} + statisticsData: TEST_STATS_DATA } }); - await testDiv.call(stats.drawStatsTable, {primaryIVData: store.getState().hydrographData.primaryIVData, siteno: '05428500'}); + await testDiv.call(stats.drawStatsTable, + {stats: {}, latestValue: '11', parameterName: 'Test Name'}); expect(testDiv.select('#daily-stats-container').size()).toBe(0); expect(testDiv.select('#stats-table').size()).toBe(0); }); - it('Does not create the table if there is no statsData available', async() => { + it('Does not create the table if there is no latestValue available', async() => { store = configureStore({ hydrographData: { - primaryIVData: TEST_PRIMARY_IV_DATA + statisticsData: TEST_STATS_DATA } }); - statisticsDataService.fetchSitesStatisticsRDB = - jest.fn().mockResolvedValue(''); - await testDiv.call(stats.drawStatsTable, {primaryIVData: store.getState().hydrographData.primaryIVData, siteno: '05428500'}); + await testDiv.call(stats.drawStatsTable, + {stats: store.getState().hydrographData.statisticsData, latestValue: '', parameterName: 'Test Name'}); expect(testDiv.select('#daily-stats-container').size()).toBe(0); expect(testDiv.select('#stats-table').size()).toBe(0); }); - it('Hides the accordion if there is no primaryIVData', async() => { + it('Hides the accordion if there is no stats data', async() => { store = configureStore({ hydrographData: { - primaryIVData: {} + statisticsData: TEST_STATS_DATA } }); - await testDiv.call(stats.drawStatsTable, {primaryIVData: store.getState().hydrographData.primaryIVData, siteno: '05428500'}); + await testDiv.call(stats.drawStatsTable, + {stats: {}, latestValue: '11', parameterName: 'Test Name'}); expect(testDiv.attr('hidden')).toBe(''); }); - it('Hides the accordion if there is no statsData', async() => { + it('Hides the accordion if there is no latestValue', async() => { store = configureStore({ hydrographData: { - primaryIVData: TEST_PRIMARY_IV_DATA + statisticsData: TEST_STATS_DATA } }); - statisticsDataService.fetchSitesStatisticsRDB = - jest.fn().mockResolvedValue(''); - await testDiv.call(stats.drawStatsTable, {primaryIVData: store.getState().hydrographData.primaryIVData, siteno: '05428500'}); + await testDiv.call(stats.drawStatsTable, + {stats: store.getState().hydrographData.statisticsData, latestValue: '', parameterName: 'Test Name'}); expect(testDiv.attr('hidden')).toBe(''); }); @@ -91,38 +88,38 @@ describe('monitoring-location/components/hydrograph/statistics', () => { it('Expects the table to have headers', async() => { store = configureStore({ hydrographData: { - primaryIVData: TEST_PRIMARY_IV_DATA + statisticsData: TEST_STATS_DATA } }); - - await testDiv.call(stats.drawStatsTable, {primaryIVData: store.getState().hydrographData.primaryIVData, siteno: '05428500'}); + await testDiv.call(stats.drawStatsTable, + {stats: store.getState().hydrographData.statisticsData, latestValue: '11', parameterName: 'Test Name'}); let tableHeaders = testDiv.select('thead').select('tr').selectAll('tr > th'); expect(tableHeaders.size()).toBe(7); expect(tableHeaders.nodes()[0].textContent).toBe('Latest Value'); - expect(tableHeaders.nodes()[1].textContent).toBe('Lowest Value (2018)'); + expect(tableHeaders.nodes()[1].textContent).toBe('Lowest Value (2006)'); expect(tableHeaders.nodes()[2].textContent).toBe('25th Percentile'); expect(tableHeaders.nodes()[3].textContent).toBe('Median'); expect(tableHeaders.nodes()[4].textContent).toBe('75th Percentile'); expect(tableHeaders.nodes()[5].textContent).toBe('Mean'); - expect(tableHeaders.nodes()[6].textContent).toBe('Highest Value (1980)'); + expect(tableHeaders.nodes()[6].textContent).toBe('Highest Value (2020)'); }); it('Expects the table to have data in it', async() => { store = configureStore({ hydrographData: { - primaryIVData: TEST_PRIMARY_IV_DATA + statisticsData: TEST_STATS_DATA } }); - - await testDiv.call(stats.drawStatsTable, {primaryIVData: store.getState().hydrographData.primaryIVData, siteno: '05428500'}); + await testDiv.call(stats.drawStatsTable, + {stats: store.getState().hydrographData.statisticsData, latestValue: '25.9', parameterName: 'Test Name'}); let tableHeaders = testDiv.select('tbody').select('tr').selectAll('tr > th'); expect(tableHeaders.size()).toBe(7); expect(tableHeaders.nodes()[0].textContent).toBe('25.9'); - expect(tableHeaders.nodes()[1].textContent).toBe('1.2'); - expect(tableHeaders.nodes()[2].textContent).toBe('1.7'); - expect(tableHeaders.nodes()[3].textContent).toBe('2.1'); - expect(tableHeaders.nodes()[4].textContent).toBe('3'); - expect(tableHeaders.nodes()[5].textContent).toBe('2.2'); - expect(tableHeaders.nodes()[6].textContent).toBe('3.9'); + expect(tableHeaders.nodes()[1].textContent).toBe('55.5'); + expect(tableHeaders.nodes()[2].textContent).toBe('100'); + expect(tableHeaders.nodes()[3].textContent).toBe('16'); + expect(tableHeaders.nodes()[4].textContent).toBe('224'); + expect(tableHeaders.nodes()[5].textContent).toBe('153'); + expect(tableHeaders.nodes()[6].textContent).toBe('273'); }); }); diff --git a/assets/src/scripts/monitoring-location/components/hydrograph/time-series-graph.test.js b/assets/src/scripts/monitoring-location/components/hydrograph/time-series-graph.test.js index 44a349f64..6242c6177 100644 --- a/assets/src/scripts/monitoring-location/components/hydrograph/time-series-graph.test.js +++ b/assets/src/scripts/monitoring-location/components/hydrograph/time-series-graph.test.js @@ -5,7 +5,7 @@ import * as utils from 'ui/utils'; import {configureStore} from 'ml/store'; import {setMedianDataVisibility} from 'ml/store/hydrograph-state'; -import {TEST_PRIMARY_IV_DATA, TEST_GW_LEVELS, TEST_MEDIAN_DATA, +import {TEST_PRIMARY_IV_DATA, TEST_GW_LEVELS, TEST_STATS_DATA, TEST_CURRENT_TIME_RANGE } from './mock-hydrograph-state'; import {drawTimeSeriesGraphData, initializeTimeSeriesGraph} from './time-series-graph'; @@ -14,7 +14,7 @@ import {drawTimeSeriesGraphData, initializeTimeSeriesGraph} from './time-series- const TEST_STATE = { hydrographData: { primaryIVData: TEST_PRIMARY_IV_DATA, - medianStatisticsData: TEST_MEDIAN_DATA, + statisticsData: TEST_STATS_DATA, currentTimeRange: TEST_CURRENT_TIME_RANGE }, groundwaterLevelData: { diff --git a/assets/src/scripts/monitoring-location/components/hydrograph/time-span-controls.test.js b/assets/src/scripts/monitoring-location/components/hydrograph/time-span-controls.test.js index ab7225e47..767933727 100644 --- a/assets/src/scripts/monitoring-location/components/hydrograph/time-span-controls.test.js +++ b/assets/src/scripts/monitoring-location/components/hydrograph/time-span-controls.test.js @@ -161,8 +161,7 @@ describe('monitoring-location/components/hydrograph/time-span-controls', () => { period: null, startTime: '2020-02-05T00:00:00.000-06:00', endTime: '2020-02-28T23:59:59.999-06:00', - loadCompare: false, - loadMedian: false + loadCompare: false }); expect(showDataIndicatorSpy).toHaveBeenCalled(); expect(getSelectedTimeSpan(state)).toEqual({ @@ -250,8 +249,7 @@ describe('monitoring-location/components/hydrograph/time-span-controls', () => { period: null, startTime: '2020-01-01T00:00:00.000-06:00', endTime: '2020-01-05T23:59:59.999-06:00', - loadCompare: false, - loadMedian: false + loadCompare: false }); expect(showDataIndicatorSpy).toHaveBeenCalled(); expect(getSelectedTimeSpan(state)).toEqual({ @@ -306,8 +304,7 @@ describe('monitoring-location/components/hydrograph/time-span-controls', () => { period: 'P45D', startTime: null, endTime: null, - loadCompare: false, - loadMedian: false + loadCompare: false }); expect(showDataIndicatorSpy).toHaveBeenCalled(); expect(getSelectedTimeSpan(state)).toEqual('P45D'); diff --git a/assets/src/scripts/monitoring-location/components/hydrograph/time-span-shortcuts.test.js b/assets/src/scripts/monitoring-location/components/hydrograph/time-span-shortcuts.test.js index adfd62328..06552c89a 100644 --- a/assets/src/scripts/monitoring-location/components/hydrograph/time-span-shortcuts.test.js +++ b/assets/src/scripts/monitoring-location/components/hydrograph/time-span-shortcuts.test.js @@ -148,8 +148,7 @@ describe('monitoring-location/components/hydrograph/time-span-shortcuts', () => period: 'P30D', startTime: null, endTime: null, - loadCompare: false, - loadMedian: false + loadCompare: false }); expect(showDataIndicatorSpy).toHaveBeenCalled(); expect(getSelectedTimeSpan(state)).toEqual('P30D'); 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 4ded7fc1a..44b913ef2 100644 --- a/assets/src/scripts/monitoring-location/selectors/hydrograph-data-selector.js +++ b/assets/src/scripts/monitoring-location/selectors/hydrograph-data-selector.js @@ -12,7 +12,6 @@ import config from 'ui/config'; */ export const getThresholds = state => state.hydrographData.thresholds || null; - /* * Returns a selector function which returns the time range for the timeRangeKind. * @param {String} timeRangeKind - 'current' or 'prioryear' @@ -28,11 +27,25 @@ export const getTimeRange = memoize((timeRangeKind) => state => state.hydrograph export const getIVData = memoize((dataKind) => state => state.hydrographData[`${dataKind}IVData`] || null); /* - * Returns a selector function which returns the median statistics data + * Returns a selector function which returns the daily statistics data * @return {Function} */ -export const getMedianStatisticsData = state => state.hydrographData.medianStatisticsData || null; +export const getStatisticsData = state => state.hydrographData.statisticsData || null; +/* + * Returns a selector function which returns the most recently reported value for the primary parameter + * @return {function} + */ +export const getLatestPrimaryValue = createSelector( + getIVData('primary'), + (data) => { + if (!data || !Object.keys(data).length || !Object.keys(data.values).length) { + return null; + } + let currentIVDataValues = data.values || {}; + let currentIVDataArray = currentIVDataValues[Object.keys(currentIVDataValues)[0]].points || []; + return currentIVDataArray[currentIVDataArray.length - 1].value || null; + }); /* * Returns a selector function which returns the parameter that the hydrographData is representing @@ -75,7 +88,7 @@ export const getPrimaryMethods = createSelector( */ export const getPrimaryMedianStatisticsData = createSelector( getTimeRange('current'), - getMedianStatisticsData, + getStatisticsData, (timeRange, stats) => { if (!stats || !timeRange) { return null; diff --git a/assets/src/scripts/monitoring-location/selectors/hydrograph-data-selector.test.js b/assets/src/scripts/monitoring-location/selectors/hydrograph-data-selector.test.js index 41622c5a0..6f2bd6ceb 100644 --- a/assets/src/scripts/monitoring-location/selectors/hydrograph-data-selector.test.js +++ b/assets/src/scripts/monitoring-location/selectors/hydrograph-data-selector.test.js @@ -1,8 +1,8 @@ import config from 'ui/config'; -import {getThresholds, getTimeRange, getIVData, getMedianStatisticsData, getIVPrimaryParameter, +import {getThresholds, getTimeRange, getIVData, getStatisticsData, getIVPrimaryParameter, getPrimaryMethods, getPrimaryMedianStatisticsData, - getPrimaryMedianStatisticsValueRange + getPrimaryMedianStatisticsValueRange, getLatestPrimaryValue } from './hydrograph-data-selector'; describe('monitoring-location/selectors/hydrograph-data-selectors', () => { @@ -44,7 +44,7 @@ describe('monitoring-location/selectors/hydrograph-data-selectors', () => { } }; - const TEST_MEDIAN_DATA = { + const TEST_STATS_DATA = { '153885': [ {month_nu: 2, day_nu: 1, p50_va: 16, ts_id: '153885', loc_web_ds: 'Method1', begin_yr: '2011', end_yr: '2020'}, {month_nu: 2, day_nu: 2, p50_va: 16.2, ts_id: '153885', loc_web_ds: 'Method1', begin_yr: '2011', end_yr: '2020'}, @@ -138,17 +138,17 @@ describe('monitoring-location/selectors/hydrograph-data-selectors', () => { describe('getMedianStatistics', () => { it('Returns null if no median data', () => { - expect(getMedianStatisticsData({ + expect(getStatisticsData({ hydrographData: {} })).toBeNull(); }); it('Returns the median data', () => { - expect(getMedianStatisticsData({ + expect(getStatisticsData({ hydrographData: { - medianStatisticsData: TEST_MEDIAN_DATA + statisticsData: TEST_STATS_DATA } - })).toEqual(TEST_MEDIAN_DATA); + })).toEqual(TEST_STATS_DATA); }); }); @@ -198,7 +198,7 @@ describe('monitoring-location/selectors/hydrograph-data-selectors', () => { start: 1612280374000, end: 1612539574000 }, - medianStatisticsData: TEST_MEDIAN_DATA + statisticsData: TEST_STATS_DATA } })).toEqual({ '153885': { @@ -230,9 +230,33 @@ describe('monitoring-location/selectors/hydrograph-data-selectors', () => { start: 1612280374000, end: 1612539574000 }, - medianStatisticsData: TEST_MEDIAN_DATA + statisticsData: TEST_STATS_DATA } })).toEqual([15.9, 16.3]); }); }); + + describe('getLatestPrimaryValue', () => { + it('Return null if no iv data', () => { + expect(getLatestPrimaryValue({ + hydrographData: { + primaryIVData: {} + }, + hydrographState: { + selectedIVMethodID: '15776' + } + })).toBeNull(); + }); + + it('Returns latest primary parameter value', () => { + expect(getLatestPrimaryValue({ + hydrographData: { + primaryIVData: TEST_PRIMARY_IV_DATA + }, + hydrographState: { + selectedIVMethodID: '15776' + } + })).toEqual('19.9'); + }); + }); }); \ No newline at end of file diff --git a/assets/src/scripts/monitoring-location/selectors/hydrograph-state-selector.js b/assets/src/scripts/monitoring-location/selectors/hydrograph-state-selector.js index 0db27ca56..53b21c49b 100644 --- a/assets/src/scripts/monitoring-location/selectors/hydrograph-state-selector.js +++ b/assets/src/scripts/monitoring-location/selectors/hydrograph-state-selector.js @@ -29,7 +29,7 @@ export const getInputsForRetrieval = createSelector( getSelectedTimeSpan, isCompareIVDataVisible, isMedianDataVisible, - (parameterCode, selectedTimeSpan, loadCompare, loadMedian) => { + (parameterCode, selectedTimeSpan, loadCompare) => { const timeSpanIsDuration = typeof selectedTimeSpan === 'string'; const period = timeSpanIsDuration && selectedTimeSpan.endsWith('D') ? selectedTimeSpan : null; let startTime = null; @@ -60,8 +60,7 @@ export const getInputsForRetrieval = createSelector( period, startTime, endTime, - loadCompare, - loadMedian + loadCompare }; } ); diff --git a/assets/src/scripts/monitoring-location/selectors/hydrograph-state-selector.test.js b/assets/src/scripts/monitoring-location/selectors/hydrograph-state-selector.test.js index 544833a48..65b09b31e 100644 --- a/assets/src/scripts/monitoring-location/selectors/hydrograph-state-selector.test.js +++ b/assets/src/scripts/monitoring-location/selectors/hydrograph-state-selector.test.js @@ -176,8 +176,7 @@ describe('monitoring-location/selectors/hydrograph-state-selector', () => { period: 'P30D', startTime: null, endTime: null, - loadCompare: false, - loadMedian: true + loadCompare: false }); }); it('Return expects inputs when selectedTimeSpan is a date range', () => { @@ -196,8 +195,7 @@ describe('monitoring-location/selectors/hydrograph-state-selector', () => { period: null, startTime: '2021-02-01T00:00:00.000-06:00', endTime: '2021-02-06T23:59:59.999-06:00', - loadCompare: true, - loadMedian: false + loadCompare: true }); }); @@ -214,8 +212,7 @@ describe('monitoring-location/selectors/hydrograph-state-selector', () => { period: null, startTime: '2011-10-01T00:00:00.000-05:00', endTime: '2021-10-01T05:00:00.000-05:00', - loadCompare: true, - loadMedian: false + loadCompare: true }); }); @@ -232,8 +229,7 @@ describe('monitoring-location/selectors/hydrograph-state-selector', () => { period: null, startTime: '2019-01-01T00:00:00.000-06:00', endTime: '2021-10-01T05:00:00.000-05:00', - loadCompare: true, - loadMedian: false + loadCompare: true }); }); }); diff --git a/assets/src/scripts/monitoring-location/store/hydrograph-data.js b/assets/src/scripts/monitoring-location/store/hydrograph-data.js index f3b595166..b7992e0c0 100644 --- a/assets/src/scripts/monitoring-location/store/hydrograph-data.js +++ b/assets/src/scripts/monitoring-location/store/hydrograph-data.js @@ -58,13 +58,13 @@ const addIVHydrographData = function(dataKind, ivData) { }; /* - * Synchronous Redux action which sets the median data + * Synchronous Redux action which sets the statistics data * @param {Object} statsData * @return {Object} Redux action */ -const addMedianStatisticsData = function(statsData) { +const addStatisticsData = function(statsData) { return { - type: 'ADD_MEDIAN_STATISTICS_DATA', + type: 'ADD_STATISTICS_DATA', statsData }; }; @@ -202,14 +202,14 @@ export const retrievePriorYearIVData = function(siteno, {parameterCode, startTim * @param {String} parameterCode * @return {Function} that returns a Promise */ -export const retrieveMedianStatistics = function(siteno, parameterCode) { +export const retrieveStatistics = function(siteno, parameterCode) { return function(dispatch, getState) { - if ('medianStatisticsData' in getState().hydrographData) { + if ('statisticsData' in getState().hydrographData) { return Promise.resolve(); } else { const isCalculatedParameterCode = isCalculatedTemperature(parameterCode); const parameterToFetch = getParameterToFetch(parameterCode); - return fetchSiteStatistics({siteno: siteno, statType: 'median', parameterCode: parameterToFetch}) + return fetchSiteStatistics({siteno: siteno, statType: 'All', parameterCode: parameterToFetch}) .then(stats => { let resultStats = {}; if (parameterToFetch in stats) { @@ -225,7 +225,7 @@ export const retrieveMedianStatistics = function(siteno, parameterCode) { }); }); } - dispatch(addMedianStatisticsData(resultStats)); + dispatch(addStatisticsData(resultStats)); }); } }; @@ -302,10 +302,9 @@ export const retrieveHydrographThresholds = function(agencySiteNumberCode, param * @param {String} startTime - ISO 8601 time string * @param {String} endTime - ISO 8601 time string * @param {Boolean} loadCompare - * @param {Boolean} loadMedian * @return {Function} that returns a promise */ -export const retrieveHydrographData = function(siteno, agencyCode, {parameterCode, period, startTime, endTime, loadCompare, loadMedian}) { +export const retrieveHydrographData = function(siteno, agencyCode, {parameterCode, period, startTime, endTime, loadCompare}) { return function(dispatch) { const parameterToFetch = getParameterToFetch(parameterCode); const hasIVData = config.ivPeriodOfRecord && parameterToFetch in config.ivPeriodOfRecord; @@ -331,6 +330,8 @@ export const retrieveHydrographData = function(siteno, agencyCode, {parameterCod fetchPromises.push(dispatch(retrieveHydrographThresholds(`${agencyCode}-${siteno}`, parameterCode))); fetchPromises.push(dispatch(retrieveIVData( siteno, 'primary', {parameterCode, period, startTime, endTime}))); + fetchPromises.push(dispatch( + retrieveStatistics(siteno, parameterCode))); } if (hasIVData && loadCompare && ALLOW_COMPARE_FOR_DURATIONS.includes(period)) { @@ -341,10 +342,6 @@ export const retrieveHydrographData = function(siteno, agencyCode, {parameterCod endTime: timeRange.end }))); } - if (hasIVData && loadMedian) { - fetchPromises.push(dispatch( - retrieveMedianStatistics(siteno, parameterCode))); - } return Promise.all(fetchPromises); }; @@ -365,10 +362,10 @@ export const hydrographDataReducer = function(hydrographData = {}, action) { newData[`${action.dataKind}IVData`] = action.ivData; return Object.assign({}, hydrographData, newData); } - case 'ADD_MEDIAN_STATISTICS_DATA': { + case 'ADD_STATISTICS_DATA': { return { ...hydrographData, - medianStatisticsData: action.statsData + statisticsData: action.statsData }; } case 'ADD_THRESHOLDS': { 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 34cb28294..8c86c23a1 100644 --- a/assets/src/scripts/monitoring-location/store/hydrograph-data.test.js +++ b/assets/src/scripts/monitoring-location/store/hydrograph-data.test.js @@ -19,7 +19,7 @@ import config from 'ui/config'; import { hydrographDataReducer, retrieveHydrographData, - retrieveMedianStatistics, + retrieveStatistics, retrievePriorYearIVData } from './hydrograph-data'; @@ -69,8 +69,7 @@ describe('monitoring-location/store/hydrograph-data', () => { period: 'P7D', startTime: null, endTime: null, - loadCompare: false, - loadMedian: false + loadCompare: false })); const mockIVCalls = ivDataService.fetchTimeSeries.mock.calls; @@ -83,7 +82,7 @@ describe('monitoring-location/store/hydrograph-data', () => { startTime: null, endTime: null }]); - expect(mockStatsCalls).toHaveLength(0); + expect(mockStatsCalls).toHaveLength(1); }); it('Expects to retrieve all data when all are available or requested', () => { @@ -96,8 +95,7 @@ describe('monitoring-location/store/hydrograph-data', () => { period: 'P7D', startTime: null, endTime: null, - loadCompare: true, - loadMedian: true + loadCompare: true })); const mockIVCalls = ivDataService.fetchTimeSeries.mock.calls; @@ -120,7 +118,7 @@ describe('monitoring-location/store/hydrograph-data', () => { expect(mockStatsCalls).toHaveLength(1); expect(mockStatsCalls[0][0]).toEqual({ siteno: '11112222', - statType: 'median', + statType: 'All', parameterCode: '00060' }); }); @@ -135,8 +133,7 @@ describe('monitoring-location/store/hydrograph-data', () => { period: 'P7D', startTime: null, endTime: null, - loadCompare: false, - loadMedian: true + loadCompare: false })); const mockIVCalls = ivDataService.fetchTimeSeries.mock.calls; @@ -152,7 +149,7 @@ describe('monitoring-location/store/hydrograph-data', () => { expect(mockStatsCalls).toHaveLength(1); expect(mockStatsCalls[0][0]).toEqual({ siteno: '11112222', - statType: 'median', + statType: 'All', parameterCode: '00060' }); }); @@ -166,8 +163,7 @@ describe('monitoring-location/store/hydrograph-data', () => { period: 'P7D', startTime: null, endTime: null, - loadCompare: true, - loadMedian: true + loadCompare: true })); expect(ivDataService.fetchTimeSeries.mock.calls).toHaveLength(2); @@ -182,8 +178,7 @@ describe('monitoring-location/store/hydrograph-data', () => { period: 'P10D', startTime: null, endTime: null, - loadCompare: true, - loadMedian: true + loadCompare: true })); expect(ivDataService.fetchTimeSeries.mock.calls).toHaveLength(1); @@ -198,8 +193,7 @@ describe('monitoring-location/store/hydrograph-data', () => { period: null, startTime: '2020-01-01', endTime: '2020-01-31', - loadCompare: true, - loadMedian: true + loadCompare: true })); expect(ivDataService.fetchTimeSeries.mock.calls).toHaveLength(1); @@ -226,8 +220,7 @@ describe('monitoring-location/store/hydrograph-data', () => { period: 'P7D', startTime: null, endTime: null, - loadCompare: false, - loadMedian: true + loadCompare: false })).then(() => { const hydrographData = store.getState().hydrographData; @@ -260,8 +253,7 @@ describe('monitoring-location/store/hydrograph-data', () => { period: 'P7D', startTime: null, endTime: null, - loadCompare: false, - loadMedian: true + loadCompare: false })).then(() => { const hydrographData = store.getState().hydrographData; @@ -289,8 +281,7 @@ describe('monitoring-location/store/hydrograph-data', () => { period: 'P7D', startTime: null, endTime: null, - loadCompare: false, - loadMedian: true + loadCompare: false })).then(() => { const hydrographData = store.getState().hydrographData; @@ -320,8 +311,7 @@ describe('monitoring-location/store/hydrograph-data', () => { period: 'P7D', startTime: null, endTime: null, - loadCompare: false, - loadMedian: true + loadCompare: false })); const mockIVCalls = ivDataService.fetchTimeSeries.mock.calls; @@ -341,8 +331,7 @@ describe('monitoring-location/store/hydrograph-data', () => { period: 'P7D', startTime: null, endTime: null, - loadCompare: false, - loadMedian: true + loadCompare: false })).then(() => { const hydrographData = store.getState().hydrographData; @@ -375,8 +364,7 @@ describe('monitoring-location/store/hydrograph-data', () => { period: 'P7D', startTime: null, endTime: null, - loadCompare: false, - loadMedian: false + loadCompare: false })); }); @@ -426,7 +414,7 @@ describe('monitoring-location/store/hydrograph-data', () => { }); }); - describe('retrieveMedianStatistics', () => { + describe('retrieveStatistics', () => { beforeEach(() => { ivDataService.fetchTimeSeries = jest.fn().mockReturnValue(Promise.resolve(JSON.parse(MOCK_IV_DATA))); @@ -443,28 +431,27 @@ describe('monitoring-location/store/hydrograph-data', () => { period: 'P7D', startTime: null, endTime: null, - loadCompare: false, - loadMedian: false + loadCompare: false })); }); it('Expects median data to fetched and stored', () => { - return store.dispatch(retrieveMedianStatistics('11112222', '00060')).then(() => { + return store.dispatch(retrieveStatistics('11112222', '00060')).then(() => { const mockStatsCalls = statisticsDataService.fetchSiteStatistics.mock.calls; expect(mockStatsCalls).toHaveLength(1); expect(mockStatsCalls[0][0]).toEqual({ siteno: '11112222', - statType: 'median', + statType: 'All', parameterCode: '00060' }); - expect(store.getState().hydrographData.medianStatisticsData).toBeDefined(); + expect(store.getState().hydrographData.statisticsData).toBeDefined(); }); }); it('Expects a second call to median data does not fetch the data again', () => { - const firstRetrieve = store.dispatch(retrieveMedianStatistics('11112222', '00060')); + const firstRetrieve = store.dispatch(retrieveStatistics('11112222', '00060')); return firstRetrieve.then(() => { - store.dispatch(retrieveMedianStatistics('11112222', '00060')) + store.dispatch(retrieveStatistics('11112222', '00060')) .then(() => { const mockStatsCalls = statisticsDataService.fetchSiteStatistics.mock.calls; expect(mockStatsCalls).toHaveLength(1); diff --git a/wdfn-server/waterdata/templates/macros/components.html b/wdfn-server/waterdata/templates/macros/components.html index 60ef603c4..cbddae09a 100644 --- a/wdfn-server/waterdata/templates/macros/components.html +++ b/wdfn-server/waterdata/templates/macros/components.html @@ -27,7 +27,7 @@ </div> {% endif %} <div class="select-time-series-container"></div> - <div id="stats-accordion" class="wdfn-accordion usa-accordion"> + <div id="stats-accordion" class="wdfn-accordion usa-accordion" hidden=""> <h2 class="usa-accordion__heading"> <button class="usa-accordion__button" aria-expanded="false" aria-controls="stats-container" -- GitLab