From 6e022eb22673229a8e620f773d2844ce357a463f Mon Sep 17 00:00:00 2001 From: Mary Bucknell <mbucknell@usgs.gov> Date: Thu, 26 Apr 2018 15:02:03 -0500 Subject: [PATCH] Rather than nest memoize use the ability to specify multiple parameters. Also a little renaming 'timeseries' to 'timeSeries'. Not a complete check. --- .../scripts/components/hydrograph/audible.js | 2 +- .../src/scripts/components/hydrograph/axes.js | 4 +-- .../scripts/components/hydrograph/cursor.js | 2 +- .../scripts/components/hydrograph/domain.js | 2 +- .../components/hydrograph/drawingData.js | 34 +++++++++---------- .../components/hydrograph/drawingData.spec.js | 16 ++++----- .../scripts/components/hydrograph/index.js | 10 +++--- .../scripts/components/hydrograph/legend.js | 4 +-- .../components/hydrograph/parameters.js | 4 +-- .../scripts/components/hydrograph/scales.js | 20 +++++------ .../{timeseries.js => timeSeries.js} | 10 +++--- ...{timeseries.spec.js => timeSeries.spec.js} | 14 ++++---- .../scripts/components/hydrograph/tooltip.js | 2 +- ...eriesSelector.js => timeSeriesSelector.js} | 8 ++--- ...tor.spec.js => timeSeriesSelector.spec.js} | 26 +++++++------- assets/src/scripts/store/index.js | 4 +-- 16 files changed, 81 insertions(+), 81 deletions(-) rename assets/src/scripts/components/hydrograph/{timeseries.js => timeSeries.js} (94%) rename assets/src/scripts/components/hydrograph/{timeseries.spec.js => timeSeries.spec.js} (97%) rename assets/src/scripts/selectors/{timeseriesSelector.js => timeSeriesSelector.js} (93%) rename assets/src/scripts/selectors/{timeseriesSelector.spec.js => timeSeriesSelector.spec.js} (87%) diff --git a/assets/src/scripts/components/hydrograph/audible.js b/assets/src/scripts/components/hydrograph/audible.js index b6af9974c..7aed45ee5 100644 --- a/assets/src/scripts/components/hydrograph/audible.js +++ b/assets/src/scripts/components/hydrograph/audible.js @@ -5,7 +5,7 @@ const { createSelector, createStructuredSelector } = require('reselect'); const { tsCursorPointsSelector } = require('./cursor'); const { xScaleSelector, yScaleSelector } = require('./scales'); -const { allTimeSeriesSelector } = require('./timeseries'); +const { allTimeSeriesSelector } = require('./timeSeries'); const { TIMESERIES_AUDIO_ENABLED } = require('../../config'); const { dispatch, link } = require('../../lib/redux'); diff --git a/assets/src/scripts/components/hydrograph/axes.js b/assets/src/scripts/components/hydrograph/axes.js index 0970493f8..6db08929c 100644 --- a/assets/src/scripts/components/hydrograph/axes.js +++ b/assets/src/scripts/components/hydrograph/axes.js @@ -8,9 +8,9 @@ const { wrap } = require('../../utils'); const { getYTickDetails } = require('./domain'); const { layoutSelector } = require('./layout'); const { xScaleSelector, yScaleSelector } = require('./scales'); -const { yLabelSelector } = require('./timeseries'); +const { yLabelSelector } = require('./timeSeries'); -const { getCurrentDateRange, getCurrentParmCd } = require('../../selectors/timeseriesSelector'); +const { getCurrentDateRange, getCurrentParmCd } = require('../../selectors/timeSeriesSelector'); const INTERVAL = { P7D: timeDay, diff --git a/assets/src/scripts/components/hydrograph/cursor.js b/assets/src/scripts/components/hydrograph/cursor.js index 55c1d277e..b5b2c7494 100644 --- a/assets/src/scripts/components/hydrograph/cursor.js +++ b/assets/src/scripts/components/hydrograph/cursor.js @@ -5,7 +5,7 @@ const { createSelector } = require('reselect'); const { currentVariablePointsByTsIdSelector } = require('./drawingData'); const { layoutSelector } = require('./layout'); const { xScaleSelector } = require('./scales'); -const { isVisibleSelector } = require('./timeseries'); +const { isVisibleSelector } = require('./timeSeries'); const { Actions } = require('../../store'); const { dispatch, link } = require('../../lib/redux'); diff --git a/assets/src/scripts/components/hydrograph/domain.js b/assets/src/scripts/components/hydrograph/domain.js index 789b641af..0c851d672 100644 --- a/assets/src/scripts/components/hydrograph/domain.js +++ b/assets/src/scripts/components/hydrograph/domain.js @@ -7,7 +7,7 @@ const config = require('../../config'); const { visiblePointsSelector } = require('./drawingData'); -const { getCurrentParmCd } = require('../../selectors/timeseriesSelector'); +const { getCurrentParmCd } = require('../../selectors/timeSeriesSelector'); diff --git a/assets/src/scripts/components/hydrograph/drawingData.js b/assets/src/scripts/components/hydrograph/drawingData.js index aaac967e1..cbfed8cb7 100644 --- a/assets/src/scripts/components/hydrograph/drawingData.js +++ b/assets/src/scripts/components/hydrograph/drawingData.js @@ -2,9 +2,9 @@ const memoize = require('fast-memoize'); const { createSelector } = require('reselect'); const { format } = require('d3-format'); -const {allTimeSeriesSelector, currentVariableTimeSeriesSelector, timeSeriesSelector } = require('./timeseries'); +const {allTimeSeriesSelector, currentVariableTimeSeriesSelector, timeSeriesSelector } = require('./timeSeries'); -const { getVariables, getCurrentVariableTimeseriesRequestKey } = require('../../selectors/timeseriesSelector'); +const { getVariables, getCurrentVariableTimeSeriesRequestKey } = require('../../selectors/timeSeriesSelector'); export const MASK_DESC = { ice: 'Ice Affected', @@ -84,8 +84,8 @@ export const allPointsSelector = createSelector( * @param {String} tsKey * @return {Object} of keys are tsId, values are Array of point Objects */ -export const pointsByTsKeySelector = memoize(tsKey => memoize(period => createSelector( - getCurrentVariableTimeseriesRequestKey(tsKey)(period), +export const pointsByTsKeySelector = memoize((tsKey, period) => createSelector( + getCurrentVariableTimeSeriesRequestKey(tsKey, period), allPointsSelector, state => state.series.timeSeries, (tsRequestKey, points, timeSeries) => { @@ -96,7 +96,7 @@ export const pointsByTsKeySelector = memoize(tsKey => memoize(period => createSe } }); return result; - }))); + })); /* Returns a select that returns all time series point for the ccurrent variable and in the select series, tsKey * by tsId. @@ -105,7 +105,7 @@ export const pointsByTsKeySelector = memoize(tsKey => memoize(period => createSe * @return Object */ export const currentVariablePointsByTsIdSelector = memoize(tsKey => createSelector( - pointsByTsKeySelector(tsKey)(), + pointsByTsKeySelector(tsKey), currentVariableTimeSeriesSelector(tsKey), (points, timeSeries) => { let result = {}; @@ -125,7 +125,7 @@ export const currentVariablePointsByTsIdSelector = memoize(tsKey => createSelect * @return Array of Array of points */ export const currentVariablePointsSelector = memoize(tsKey => createSelector( - pointsByTsKeySelector(tsKey)(), + pointsByTsKeySelector(tsKey), currentVariableTimeSeriesSelector(tsKey), (points, timeSeries) => { return timeSeries ? Object.keys(timeSeries).map((tsId) => points[tsId]) : []; @@ -141,7 +141,7 @@ export const currentVariablePointsSelector = memoize(tsKey => createSelector( * @return {Array} Array of array of points. */ export const pointsSelector = memoize((tsKey) => createSelector( - pointsByTsKeySelector(tsKey)(), + pointsByTsKeySelector(tsKey), (points) => { return Object.values(points); } @@ -213,7 +213,7 @@ export const visiblePointsSelector = createSelector( * @param {Object} - keys are ts id, values are an array of points where each point is an Array as follows: [value, time, qualifiers]. */ export const pointsTableDataSelector = memoize(tsKey => createSelector( - pointsByTsKeySelector(tsKey)(), + pointsByTsKeySelector(tsKey), (allPoints) => { return Object.keys(allPoints).reduce((databyTsId, tsId) => { databyTsId[tsId] = allPoints[tsId].map((value) => { @@ -252,8 +252,8 @@ const getLineClasses = function(pt) { * @param {String} tsKey Timeseries key * @return {Object} Keys are ts Ids, values are of array of line segments. */ -export const lineSegmentsSelector = memoize(tsKey => memoize(period => createSelector( - pointsByTsKeySelector(tsKey)(period), +export const lineSegmentsSelector = memoize((tsKey, period) => createSelector( + pointsByTsKeySelector(tsKey, period), (tsPoints) => { let seriesLines = {}; Object.keys(tsPoints).forEach((tsId) => { @@ -301,16 +301,16 @@ export const lineSegmentsSelector = memoize(tsKey => memoize(period => createSel }); return seriesLines; } -))); +)); /** * Factory function creates a function that, for a given tsKey: * @return {Object} - Mapping of parameter code Array of line segments. */ -export const lineSegmentsByParmCdSelector = memoize(tsKey => memoize(period => createSelector( - lineSegmentsSelector(tsKey)(period), - timeSeriesSelector(tsKey)(period), +export const lineSegmentsByParmCdSelector = memoize((tsKey, period) => createSelector( + lineSegmentsSelector(tsKey, period), + timeSeriesSelector(tsKey, period), getVariables, (lineSegmentsBySeriesID, timeSeriesMap, variables) => { return Object.keys(lineSegmentsBySeriesID).reduce((byVarID, sID) => { @@ -321,7 +321,7 @@ export const lineSegmentsByParmCdSelector = memoize(tsKey => memoize(period => c return byVarID; }, {}); } -))); +)); /** @@ -331,7 +331,7 @@ export const lineSegmentsByParmCdSelector = memoize(tsKey => memoize(period => c */ export const currentVariableLineSegmentsSelector = memoize(tsKey => createSelector( currentVariableTimeSeriesSelector(tsKey), - lineSegmentsSelector(tsKey)(), + lineSegmentsSelector(tsKey), (seriesMap, linesMap) => { return Object.keys(seriesMap).reduce((visMap, sID) => { visMap[sID] = linesMap[sID]; diff --git a/assets/src/scripts/components/hydrograph/drawingData.spec.js b/assets/src/scripts/components/hydrograph/drawingData.spec.js index 8a5d865c6..017b72fa5 100644 --- a/assets/src/scripts/components/hydrograph/drawingData.spec.js +++ b/assets/src/scripts/components/hydrograph/drawingData.spec.js @@ -183,7 +183,7 @@ describe('drawingData module', () => { describe('pointsByTsKeySelector', () => { it('Return the points array for the ts Key selector', () => { - const result = pointsByTsKeySelector('current')()(TEST_DATA); + const result = pointsByTsKeySelector('current')(TEST_DATA); expect(Object.keys(result).length).toBe(2); expect(result['00060']).toBeDefined(); @@ -191,7 +191,7 @@ describe('drawingData module', () => { }); it('return the empty object if no time series for series', () => { - expect(pointsByTsKeySelector('median')()(TEST_DATA)).toEqual({}); + expect(pointsByTsKeySelector('median')(TEST_DATA)).toEqual({}); }); }); @@ -223,7 +223,7 @@ describe('drawingData module', () => { describe('line segment selector', () => { it('should separate on approved', () => { - expect(lineSegmentsSelector('current')()({ + expect(lineSegmentsSelector('current')({ ...TEST_DATA, series: { ...TEST_DATA.series, @@ -290,7 +290,7 @@ describe('drawingData module', () => { }); it('should separate on estimated', () => { - expect(lineSegmentsSelector('current')()({ + expect(lineSegmentsSelector('current')({ ...TEST_DATA, series: { ...TEST_DATA.series, @@ -361,7 +361,7 @@ describe('drawingData module', () => { }); it('should separate out masked values', () => { - expect(lineSegmentsSelector('current')()({ + expect(lineSegmentsSelector('current')({ ...TEST_DATA, series: { ...TEST_DATA.series, @@ -448,7 +448,7 @@ describe('drawingData module', () => { new Date(3 * MAX_LINE_POINT_GAP + 1), new Date(3 * MAX_LINE_POINT_GAP + 2) ]; - expect(lineSegmentsSelector('current')()({ + expect(lineSegmentsSelector('current')({ ...TEST_DATA, series: { ...TEST_DATA.series, @@ -524,7 +524,7 @@ describe('drawingData module', () => { new Date(3 * MAX_LINE_POINT_GAP + 1), new Date(3 * MAX_LINE_POINT_GAP + 2) ]; - expect(lineSegmentsSelector('current')()({ + expect(lineSegmentsSelector('current')({ ...TEST_DATA, series: { ...TEST_DATA.series, @@ -586,7 +586,7 @@ describe('drawingData module', () => { describe('lineSegmentsByParmCdSelector', () => { it('Should return two mappings for current time series', () => { - const result = lineSegmentsByParmCdSelector('current')()(TEST_DATA); + const result = lineSegmentsByParmCdSelector('current')(TEST_DATA); expect(Object.keys(result).length).toBe(2); expect(result['00060']).toBeDefined(); diff --git a/assets/src/scripts/components/hydrograph/index.js b/assets/src/scripts/components/hydrograph/index.js index 9a09e256a..8628f53c9 100644 --- a/assets/src/scripts/components/hydrograph/index.js +++ b/assets/src/scripts/components/hydrograph/index.js @@ -23,10 +23,10 @@ const { drawSimpleLegend, legendMarkerRowsSelector } = require('./legend'); const { plotSeriesSelectTable, availableTimeseriesSelector } = require('./parameters'); const { xScaleSelector, yScaleSelector, timeSeriesScalesByParmCdSelector } = require('./scales'); const { allTimeSeriesSelector, isVisibleSelector, titleSelector, - descriptionSelector, currentVariableTimeSeriesSelector, timeSeriesSelector } = require('./timeseries'); + descriptionSelector, currentVariableTimeSeriesSelector, timeSeriesSelector } = require('./timeSeries'); const { createTooltipFocus, createTooltipText } = require('./tooltip'); -const { getCurrentVariable } = require('../../selectors/timeseriesSelector'); +const { getCurrentVariable } = require('../../selectors/timeSeriesSelector'); const drawMessage = function (elem, message) { @@ -437,7 +437,7 @@ const attachToNode = function (store, node, {siteno} = {}) { .call(createDaterangeControls, siteno); select(node).select('.graph-container') - .call(link(controlGraphDisplay, timeSeriesSelector('current')())) + .call(link(controlGraphDisplay, timeSeriesSelector('current'))) .call(timeSeriesGraph, siteno) .call(cursorSlider) .append('div') @@ -448,8 +448,8 @@ const attachToNode = function (store, node, {siteno} = {}) { .call(link(plotSeriesSelectTable, createStructuredSelector({ siteno: () => siteno, availableTimeseries: availableTimeseriesSelector, - lineSegmentsByParmCd: lineSegmentsByParmCdSelector('current')('P7D'), - timeSeriesScalesByParmCd: timeSeriesScalesByParmCdSelector('current')('P7D')(SPARK_LINE_DIM), + lineSegmentsByParmCd: lineSegmentsByParmCdSelector('current','P7D'), + timeSeriesScalesByParmCd: timeSeriesScalesByParmCdSelector('current', 'P7D', SPARK_LINE_DIM), layout: layoutSelector }))); select(node).select('.provisional-data-alert') diff --git a/assets/src/scripts/components/hydrograph/legend.js b/assets/src/scripts/components/hydrograph/legend.js index d36d84cae..25b4faf1d 100644 --- a/assets/src/scripts/components/hydrograph/legend.js +++ b/assets/src/scripts/components/hydrograph/legend.js @@ -5,9 +5,9 @@ const { createSelector } = require('reselect'); const { CIRCLE_RADIUS } = require('./layout'); const { defineLineMarker, defineTextOnlyMarker, defineCircleMarker, defineRectangleMarker} = require('./markers'); const { currentVariableLineSegmentsSelector, HASH_ID, MASK_DESC} = require('./drawingData'); -const { currentVariableTimeSeriesSelector } = require('./timeseries'); +const { currentVariableTimeSeriesSelector } = require('./timeSeries'); -const { getMethods } = require('../../selectors/timeseriesSelector'); +const { getMethods } = require('../../selectors/timeSeriesSelector'); const TS_LABEL = { 'current': 'Current: ', diff --git a/assets/src/scripts/components/hydrograph/parameters.js b/assets/src/scripts/components/hydrograph/parameters.js index 5c6e46764..713e45ab7 100644 --- a/assets/src/scripts/components/hydrograph/parameters.js +++ b/assets/src/scripts/components/hydrograph/parameters.js @@ -4,13 +4,13 @@ const { select } = require('d3-selection'); const { MASK_DESC } = require('./drawingData'); const { SPARK_LINE_DIM, CIRCLE_RADIUS_SINGLE_PT } = require('./layout'); -const { allTimeSeriesSelector } = require('./timeseries'); +const { allTimeSeriesSelector } = require('./timeSeries'); const { Actions } = require('../../store'); const { sortedParameters } = require('../../models'); const { dispatch } = require('../../lib/redux'); -const { getVariables, getCurrentVariableID } = require('../../selectors/timeseriesSelector'); +const { getVariables, getCurrentVariableID } = require('../../selectors/timeSeriesSelector'); /** diff --git a/assets/src/scripts/components/hydrograph/scales.js b/assets/src/scripts/components/hydrograph/scales.js index 3dd011b53..f89652a4e 100644 --- a/assets/src/scripts/components/hydrograph/scales.js +++ b/assets/src/scripts/components/hydrograph/scales.js @@ -5,10 +5,10 @@ const { createSelector } = require('reselect'); const { default: scaleSymlog } = require('../../lib/symlog'); const { getYDomain, SYMLOG_PARMS } = require('./domain'); const { layoutSelector } = require('./layout'); -const { timeSeriesSelector, requestTimeRangeSelector } = require('./timeseries'); +const { timeSeriesSelector, requestTimeRangeSelector } = require('./timeSeries'); const { visiblePointsSelector, pointsByTsKeySelector } = require('./drawingData'); -const { getVariables, getCurrentParmCd, getCurrentVariableTimeseriesRequestKey } = require('../../selectors/timeseriesSelector'); +const { getVariables, getCurrentParmCd, getCurrentVariableTimeSeriesRequestKey } = require('../../selectors/timeSeriesSelector'); /** @@ -54,7 +54,7 @@ function createYScale(parmCd, extent, size) { */ const xScaleSelector = memoize(tsKey => createSelector( layoutSelector, - getCurrentVariableTimeseriesRequestKey(tsKey)(null), + getCurrentVariableTimeSeriesRequestKey(tsKey), requestTimeRangeSelector, (layout, tsRequestKey, requestTimeRanges) => { return createXScale(requestTimeRanges[tsRequestKey], layout.width - layout.margin.right); @@ -84,9 +84,9 @@ const yScaleSelector = createSelector( * @param {String} tsKey Time series key * @return {Object} - keys are parmCd and values are array of array of points */ -const parmCdPointsSelector = memoize(tsKey => memoize(period => createSelector( - pointsByTsKeySelector(tsKey)(period), - timeSeriesSelector(tsKey)(period), +const parmCdPointsSelector = memoize((tsKey, period) => createSelector( + pointsByTsKeySelector(tsKey, period), + timeSeriesSelector(tsKey, period), getVariables, (tsPoints, timeSeries, variables) => { return Object.keys(tsPoints).reduce((byParmCd, tsID) => { @@ -97,7 +97,7 @@ const parmCdPointsSelector = memoize(tsKey => memoize(period => createSelector( return byParmCd; }, {}); } -))); +)); /** @@ -105,8 +105,8 @@ const parmCdPointsSelector = memoize(tsKey => memoize(period => createSelector( * Returns x and y scales for all "current" time series. * @type {Object} Mapping of parameter code to time series list. */ -const timeSeriesScalesByParmCdSelector = memoize(tsKey => memoize(period => memoize(dimensions => createSelector( - parmCdPointsSelector(tsKey)(period), +const timeSeriesScalesByParmCdSelector = memoize((tsKey, period, dimensions) => createSelector( + parmCdPointsSelector(tsKey, period), requestTimeRangeSelector, (pointsByParmCd, requestTimeRanges) => { return Object.keys(pointsByParmCd).reduce((tsScales, parmCd) => { @@ -119,7 +119,7 @@ const timeSeriesScalesByParmCdSelector = memoize(tsKey => memoize(period => memo return tsScales; }, {}); } -)))); +)); module.exports = {createXScale, createYScale, xScaleSelector, yScaleSelector, timeSeriesScalesByParmCdSelector}; diff --git a/assets/src/scripts/components/hydrograph/timeseries.js b/assets/src/scripts/components/hydrograph/timeSeries.js similarity index 94% rename from assets/src/scripts/components/hydrograph/timeseries.js rename to assets/src/scripts/components/hydrograph/timeSeries.js index fd4a8ac92..db657b569 100644 --- a/assets/src/scripts/components/hydrograph/timeseries.js +++ b/assets/src/scripts/components/hydrograph/timeSeries.js @@ -2,7 +2,7 @@ const { timeFormat } = require('d3-time-format'); const memoize = require('fast-memoize'); const { createSelector } = require('reselect'); -const { getQueryInfo, getCurrentVariable, getCurrentVariableTimeseriesRequestKey } = require('../../selectors/timeseriesSelector'); +const { getQueryInfo, getCurrentVariable, getCurrentVariableTimeSeriesRequestKey } = require('../../selectors/timeSeriesSelector'); // Create a time formatting function from D3's timeFormat @@ -39,7 +39,7 @@ export const allTimeSeriesSelector = createSelector( * @return {Object} Time-series data */ export const currentVariableTimeSeriesSelector = memoize(tsKey => createSelector( - getCurrentVariableTimeseriesRequestKey(tsKey)(), + getCurrentVariableTimeSeriesRequestKey(tsKey), allTimeSeriesSelector, getCurrentVariable, (tsRequestKey, timeSeries, variable) => { @@ -66,8 +66,8 @@ export const currentVariableTimeSeriesSelector = memoize(tsKey => createSelector * @param {Object} state Redux state * @return {Object} - Keys are tsID, values are time-series data */ -export const timeSeriesSelector = memoize(tsKey => memoize(period => createSelector( - getCurrentVariableTimeseriesRequestKey(tsKey)(period), +export const timeSeriesSelector = memoize((tsKey, period) => createSelector( + getCurrentVariableTimeSeriesRequestKey(tsKey, period), allTimeSeriesSelector, (tsRequestKey, timeSeries) => { let x = {}; @@ -79,7 +79,7 @@ export const timeSeriesSelector = memoize(tsKey => memoize(period => createSelec }); return x; } -))); +)); diff --git a/assets/src/scripts/components/hydrograph/timeseries.spec.js b/assets/src/scripts/components/hydrograph/timeSeries.spec.js similarity index 97% rename from assets/src/scripts/components/hydrograph/timeseries.spec.js rename to assets/src/scripts/components/hydrograph/timeSeries.spec.js index b3a2037d8..a23756a99 100644 --- a/assets/src/scripts/components/hydrograph/timeseries.spec.js +++ b/assets/src/scripts/components/hydrograph/timeSeries.spec.js @@ -1,6 +1,6 @@ const { timeSeriesSelector, isVisibleSelector, yLabelSelector, titleSelector, descriptionSelector, currentVariableTimeSeriesSelector, - allTimeSeriesSelector, requestTimeRangeSelector} = require('./timeseries'); + allTimeSeriesSelector, requestTimeRangeSelector} = require('./timeSeries'); const TEST_DATA = { @@ -121,11 +121,11 @@ const TEST_DATA = { } }; -describe('Timeseries module', () => { +describe('TimeSeries module', () => { describe('allTimesSeriesSelector', () => { - it('should return all timeseries if they have data points', () => { + it('should return all time series if they have data points', () => { expect(allTimeSeriesSelector({ series: { timeSeries: { @@ -147,7 +147,7 @@ describe('Timeseries module', () => { }); }); - it('should exclude timeseries if they do not have data points', () => { + it('should exclude time series if they do not have data points', () => { expect(allTimeSeriesSelector({ series: { timeSeries: { @@ -263,7 +263,7 @@ describe('Timeseries module', () => { describe('timeSeriesSelector', () => { it('should return the selected time series', () => { - expect(timeSeriesSelector('current')()(TEST_DATA)).toEqual({ + expect(timeSeriesSelector('current')(TEST_DATA)).toEqual({ '00060': { tsKey: 'current', startTime: new Date('2018-03-06T15:45:00.000Z'), @@ -287,7 +287,7 @@ describe('Timeseries module', () => { variable: '45807197' } }); - expect(timeSeriesSelector('current')('P30D')(TEST_DATA)).toEqual({ + expect(timeSeriesSelector('current','P30D')(TEST_DATA)).toEqual({ '00060:P30D': { tsKey: 'current:P30D:00060', startTime: new Date('2018-02-06T15:45:00.000Z'), @@ -314,7 +314,7 @@ describe('Timeseries module', () => { }); it('should return null the empty set if no time series for the selected key exist', () => { - expect(timeSeriesSelector('median')()(TEST_DATA)).toEqual({}); + expect(timeSeriesSelector('median')(TEST_DATA)).toEqual({}); }); }); diff --git a/assets/src/scripts/components/hydrograph/tooltip.js b/assets/src/scripts/components/hydrograph/tooltip.js index 153ef6919..5fab5671c 100644 --- a/assets/src/scripts/components/hydrograph/tooltip.js +++ b/assets/src/scripts/components/hydrograph/tooltip.js @@ -13,7 +13,7 @@ const { classesForPoint, MASK_DESC } = require('./drawingData'); const { layoutSelector } = require('./layout'); const { xScaleSelector, yScaleSelector } = require('./scales'); -const { getCurrentVariable } = require('../../selectors/timeseriesSelector'); +const { getCurrentVariable } = require('../../selectors/timeSeriesSelector'); const formatTime = timeFormat('%b %-d, %Y, %-I:%M:%S %p'); diff --git a/assets/src/scripts/selectors/timeseriesSelector.js b/assets/src/scripts/selectors/timeSeriesSelector.js similarity index 93% rename from assets/src/scripts/selectors/timeseriesSelector.js rename to assets/src/scripts/selectors/timeSeriesSelector.js index d2e145f9e..83addc72c 100644 --- a/assets/src/scripts/selectors/timeseriesSelector.js +++ b/assets/src/scripts/selectors/timeSeriesSelector.js @@ -49,11 +49,11 @@ const tsRequestKey = function(tsKey, period, parmCd) { * @return {Boolean} - True if the time series with key, period, and parmCd has already been requested * */ -export const hasTimeseries = memoize(tsKey => memoize(period => memoize(parmCd => { +export const hasTimeSeries = memoize((tsKey, period, parmCd) => { const periodToUse = period ? period : 'P7D'; const requestKey = tsRequestKey(tsKey, periodToUse, parmCd); return state => state.series && state.series.requests && state.series.requests[requestKey] ? true : false; -}))); +}); /* * @param {String} tsKey - current, compare, or median @@ -61,7 +61,7 @@ export const hasTimeseries = memoize(tsKey => memoize(period => memoize(parmCd = * @return {String} or null - Return the the request key for the request object for the tsKey and period and currently * selected variable. */ -export const getCurrentVariableTimeseriesRequestKey = memoize(tsKey => memoize(period => createSelector( +export const getCurrentVariableTimeSeriesRequestKey = memoize((tsKey, period )=> createSelector( getCurrentParmCd, getCurrentDateRange, (parmCd, currentPeriod) => { @@ -72,4 +72,4 @@ export const getCurrentVariableTimeseriesRequestKey = memoize(tsKey => memoize(p return null; } }) -)); +); diff --git a/assets/src/scripts/selectors/timeseriesSelector.spec.js b/assets/src/scripts/selectors/timeSeriesSelector.spec.js similarity index 87% rename from assets/src/scripts/selectors/timeseriesSelector.spec.js rename to assets/src/scripts/selectors/timeSeriesSelector.spec.js index 2fe924efd..dff4e644d 100644 --- a/assets/src/scripts/selectors/timeseriesSelector.spec.js +++ b/assets/src/scripts/selectors/timeSeriesSelector.spec.js @@ -1,7 +1,7 @@ const { getVariables, getCurrentVariableID, getCurrentDateRange, getCurrentVariable, getQueryInfo, getCurrentParmCd, - hasTimeseries, getCurrentVariableTimeseriesRequestKey } = require('./timeseriesSelector'); + hasTimeSeries, getCurrentVariableTimeSeriesRequestKey } = require('./timeSeriesSelector'); -describe('timeseriesSelector', () => { +describe('timeSeriesSelector', () => { const TEST_VARS = { '45807042': { variableCode: { @@ -149,7 +149,7 @@ describe('timeseriesSelector', () => { }); }); - describe('hasTimeseries', () => { + describe('hasTimeSeries', () => { const TEST_STATE = { series: { requests : { @@ -161,20 +161,20 @@ describe('timeseriesSelector', () => { }; it('Return false if no requests in series', () => { - expect(hasTimeseries('current')('P7D')('00060')({ + expect(hasTimeSeries('current', 'P7D', '00060')({ series: {} })).toBe(false); }); it('Return false if request is not in state', () => { - expect(hasTimeseries('compare')()()(TEST_STATE)).toBe(false); - expect(hasTimeseries('current')('P1Y')('00060')(TEST_STATE)).toBe(false); - expect(hasTimeseries('current')('P30D')('00010')(TEST_STATE)).toBe(false); + expect(hasTimeSeries('compare')(TEST_STATE)).toBe(false); + expect(hasTimeSeries('current', 'P1Y', '00060')(TEST_STATE)).toBe(false); + expect(hasTimeSeries('current', 'P30D', '00010')(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); + expect(hasTimeSeries('current')(TEST_STATE)).toBe(true); + expect(hasTimeSeries('current', 'P30D', '00060')(TEST_STATE)).toBe(true); }); }); @@ -195,7 +195,7 @@ describe('timeseriesSelector', () => { }; it('Return null if currentVariableID', () => { - expect(getCurrentVariableTimeseriesRequestKey('current')('P30D')({ + expect(getCurrentVariableTimeSeriesRequestKey('current', 'P30D')({ ...TEST_STATE, timeseriesState: { ...TEST_STATE.timeseriesState, @@ -204,7 +204,7 @@ describe('timeseriesSelector', () => { })).toBeNull(); }); it('Return null if period is not specified and current date range is not set', () => { - expect(getCurrentVariableTimeseriesRequestKey('current')()({ + expect(getCurrentVariableTimeSeriesRequestKey('current')({ ...TEST_STATE, timeseriesState: { ...TEST_STATE.timeseriesState, @@ -214,8 +214,8 @@ describe('timeseriesSelector', () => { }); it('Return the ts request key to use for the currently selected variable and date range', () => { - expect(getCurrentVariableTimeseriesRequestKey('current')()(TEST_STATE)).toEqual('current'); - expect(getCurrentVariableTimeseriesRequestKey('current')()({ + expect(getCurrentVariableTimeSeriesRequestKey('current')(TEST_STATE)).toEqual('current'); + expect(getCurrentVariableTimeSeriesRequestKey('current')({ ...TEST_STATE, timeseriesState: { ...TEST_STATE.timeseriesState, diff --git a/assets/src/scripts/store/index.js b/assets/src/scripts/store/index.js index c27d5042a..2d46e905f 100644 --- a/assets/src/scripts/store/index.js +++ b/assets/src/scripts/store/index.js @@ -8,7 +8,7 @@ const { getMedianStatistics, getPreviousYearTimeseries, getTimeseries, parseMedianData, sortedParameters } = require('../models'); const { normalize } = require('../schema'); const { fetchFloodFeatures, fetchFloodExtent } = require('../floodData'); -const { getCurrentParmCd, getCurrentDateRange, hasTimeseries } = require('../selectors/timeseriesSelector'); +const { getCurrentParmCd, getCurrentDateRange, hasTimeSeries } = require('../selectors/timeSeriesSelector'); const { floodDataReducer: floodData } = require('./floodDataReducer'); const { floodStateReducer: floodState } = require('./floodStateReducer'); @@ -111,7 +111,7 @@ export const Actions = { const parmCd = getCurrentParmCd(state); const tsKey = period === 'P7D' ? 'current' : `current:${period}:${parmCd}`; dispatch(Actions.setCurrentDateRange(period)); - if (!hasTimeseries(tsKey)()()(state)) { + if (!hasTimeSeries(tsKey)(state)) { const endTime = new Date(); //TODO get this from the current data let startTime = new Date(endTime); -- GitLab