Skip to content
Snippets Groups Projects
Commit efb2ae6b authored by Briggs, Aaron Shane's avatar Briggs, Aaron Shane
Browse files

started test for sensor things

parent 12d427cb
No related branches found
No related tags found
1 merge request!33WDFN 580 present operational limits
......@@ -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 &&
......
......@@ -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})));
}
......
......@@ -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 {};
......
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)");
});
});
......
......@@ -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 = {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment