diff --git a/assets/src/scripts/monitoring-location/components/hydrograph/selectors/thresholds-data.js b/assets/src/scripts/monitoring-location/components/hydrograph/selectors/thresholds-data.js index 461cb93b7611a0cb8475fbcbab6e7062e1e4dc1a..65c4b0f0942702c6f40e96bb89f3f36a71eaf79f 100644 --- a/assets/src/scripts/monitoring-location/components/hydrograph/selectors/thresholds-data.js +++ b/assets/src/scripts/monitoring-location/components/hydrograph/selectors/thresholds-data.js @@ -12,7 +12,7 @@ export const getThresholdsInRange = createSelector( (selectedParameter, selectedMethodDescription, yScale, thresholds) => { const [yStart, yEnd] = yScale.domain(); let thresholdsInRange = []; - if (thresholds) { + if (thresholds && selectedMethodDescription) { thresholds.operatingLimits.forEach(limitSet => { if ( selectedParameter !== null && diff --git a/assets/src/scripts/monitoring-location/store/hydrograph-data.js b/assets/src/scripts/monitoring-location/store/hydrograph-data.js index 9ecb0343c48a907ba32b920ba12439dca80243f8..37adfd3b3a864f877044c48f903f4763b1e6fbec 100644 --- a/assets/src/scripts/monitoring-location/store/hydrograph-data.js +++ b/assets/src/scripts/monitoring-location/store/hydrograph-data.js @@ -297,17 +297,17 @@ const cleanThresholdData = function(properties) { }; -export const retrieveHydrographThresholds = function(agencySiteNumberCode) { +export const retrieveHydrographThresholds = function(agencySiteNumberCode, parameterCode) { return function(dispatch) { - return fetchDataFromSensorThings(agencySiteNumberCode).then((sensorThingsData) => { + return fetchDataFromSensorThings(agencySiteNumberCode, parameterCode).then((sensorThingsData) => { if (Object.keys(sensorThingsData).length !== 0 ) { - const operatingLimits = JSON.parse(sensorThingsData).value[0].Datastreams.map(observedProperty => { - if (observedProperty.properties && observedProperty.properties.Thresholds) { + const operatingLimits = JSON.parse(sensorThingsData).value.map(sampleingMethod => { + if (sampleingMethod.properties && sampleingMethod.properties.Thresholds) { return { - parameterCode: observedProperty.properties.ParameterCode, - methodDescription: observedProperty.properties.WebDescription ? observedProperty.properties.WebDescription : - observedProperty.properties.SubLocationIdentifier ? observedProperty.properties.SubLocationIdentifier : '', - thresholdDetails: cleanThresholdData(observedProperty.properties) + parameterCode: parameterCode, + methodDescription: sampleingMethod.properties.WebDescription ? sampleingMethod.properties.WebDescription : + sampleingMethod.properties.SubLocationIdentifier ? sampleingMethod.properties.SubLocationIdentifier : '', + thresholdDetails: cleanThresholdData(sampleingMethod.properties) }; } }).filter(thresholdData => { @@ -361,8 +361,7 @@ export const retrieveHydrographData = function(siteno, agencyCode, {parameterCod let fetchPromises = []; if (hasIVData) { - // instead of calling this here, it would be called in index - fetchPromises.push(dispatch(retrieveHydrographThresholds(`${agencyCode}-${siteno}`))); + fetchPromises.push(dispatch(retrieveHydrographThresholds(`${agencyCode}-${siteno}`, parameterCode))); fetchPromises.push(dispatch(retrieveIVData( siteno, 'primary', {parameterCode, period, startTime, endTime}))); } diff --git a/assets/src/scripts/web-services/sensor-things.js b/assets/src/scripts/web-services/sensor-things.js index dd8f3151f33667e06770e49b2236b4aabfdf1a90..4beeb9a983a6a99ac95a023806f01836776254dd 100644 --- a/assets/src/scripts/web-services/sensor-things.js +++ b/assets/src/scripts/web-services/sensor-things.js @@ -4,19 +4,23 @@ import config from 'ui/config'; /** * Formats a URL to connect with the Sensor Things API. * @param {String} agencySiteNumberCode - combines the Agency Code with the Site Number for example USGS-01646500 + * @param {String} parameterCode - five digit code that uniquely identifies the observed property * @return {String} URL for Sensor Things API */ -export const getSensorThingsURL = function(agencySiteNumberCode) { - return `${config.SENSOR_THINGS_ENDPOINT}?$filter=name%20eq%20%27${agencySiteNumberCode}%27&$expand=Datastreams($select=name,description,properties,@iot.id)`; +export const getSensorThingsURL = function(agencySiteNumberCode, parameterCode) { + const queryString = `$filter=properties/ParameterCode eq '${parameterCode}' and substringOf('${agencySiteNumberCode}', description)`; + console.log('url', `${config.SENSOR_THINGS_ENDPOINT}Datastreams?${encodeURIComponent(queryString)} `) + return `${config.SENSOR_THINGS_ENDPOINT}Datastreams?${encodeURIComponent(queryString)} `; }; /** * Does the work of contacting the Sensor Things API and returning data * @param {String} agencySiteNumberCode - combines the Agency Code with the Site Number for example USGS-01646500 + * @param {String} parameterCode - five digit code that uniquely identifies the observed property * @return {Promise} resolves to an empty object or one containing threshold information (and other secondary information) */ -export const fetchDataFromSensorThings = function(agencySiteNumberCode) { - return get(getSensorThingsURL(agencySiteNumberCode)) +export const fetchDataFromSensorThings = function(agencySiteNumberCode, parameterCode) { + return get(getSensorThingsURL(agencySiteNumberCode, parameterCode)) .catch(error => { console.error('Sensor Things did not return expected data. Reason: ', error.message); return {}; diff --git a/assets/src/scripts/web-services/sensor-things.test.js b/assets/src/scripts/web-services/sensor-things.test.js index bd82d7f8f3d21011eb9656ded56b63f5577deb55..b6e58e65d0b0be97222b444dd54296d586a14ba6 100644 --- a/assets/src/scripts/web-services/sensor-things.test.js +++ b/assets/src/scripts/web-services/sensor-things.test.js @@ -1,15 +1,17 @@ import mockConsole from 'jest-mock-console'; import sinon from 'sinon'; +import config from 'ui/config'; import {MOCK_SENSOR_THINGS_DATA} from 'ui/mock-service-data'; - -import {getSensorThingsURL, fetchDataFromSensorThings} from './groundwater-levels'; +import {getSensorThingsURL, fetchDataFromSensorThings} from './sensor-things'; describe('web-services/sensor-things', () => { let fakeServer; let restoreConsole; + config.SENSOR_THINGS_ENDPOINT = 'fake-sensor-things-endpoint'; beforeEach(() => { + fakeServer = sinon.createFakeServer(); restoreConsole = mockConsole(); }); @@ -21,10 +23,9 @@ describe('web-services/sensor-things', () => { describe('getSensorThingsURL', () => { it('Expects url to contain combined agency and site number', () => { - const result = getSensorThingsURL({ - siteno: 'USGS-01646500' - }); - expect(result).toContain('sites=11112222'); + const result = getSensorThingsURL('USGS-01646500', '00065'); + expect(result).toContain("ParameterCode%20eq%20'00065'"); + expect(result).toContain("substringOf('USGS-01646500'%2C%20description)"); }); }); diff --git a/wdfn-server/config.py b/wdfn-server/config.py index bc5838f06be3a3fbbf8976a9628b79ea319e3eae..91f94ab18fe641d0376db94150f841dbab30aadc 100644 --- a/wdfn-server/config.py +++ b/wdfn-server/config.py @@ -25,8 +25,8 @@ HISTORICAL_IV_DATA_ENDPOINT = 'https://nwis.waterservices.usgs.gov/nwis/iv' STATISTICS_ENDPOINT = 'https://waterservices.usgs.gov/nwis/stat' GROUNDWATER_LEVELS_ENDPOINT = 'https://waterservices.usgs.gov/nwis/gwlevels/' MONITORING_LOCATIONS_OBSERVATIONS_ENDPOINT = 'https://labs.waterdata.usgs.gov/api/observations/collections/' -SENSOR_THINGS_ENDPOINT = 'https://labs.waterdata.usgs.gov/sta/v1.1/Things' -# SENSOR_THINGS_ENDPOINT = 'https://iow-frost-read-prod-external.wma.chs.usgs.gov/FROST-Server/v1.1/Things' +SENSOR_THINGS_ENDPOINT = 'https://labs.waterdata.usgs.gov/sta/v1.1/' +# SENSOR_THINGS_ENDPOINT = 'https://iow-frost-read-prod-external.wma.chs.usgs.gov/FROST-Server/v1.1/' NWISWEB_ENDPOINTS = {