Skip to content
Snippets Groups Projects
Unverified Commit 2fbdd085 authored by Bucknell, Mary S.'s avatar Bucknell, Mary S. Committed by GitHub
Browse files

Merge pull request #813 from mbucknell/fix_long_periods

Fixes to use the correct service url when using the period to retriev…
parents f047cd8e 257bc550
No related branches found
No related tags found
No related merge requests found
......@@ -25,6 +25,15 @@ function tsServiceRoot(date) {
return olderThan120Days(date) ? PAST_SERVICE_ROOT : SERVICE_ROOT;
}
function getNumberOfDays(period) {
const days = period.match(/\d+/);
if (days.length === 1) {
return parseInt(days[0]);
} else {
return null;
}
}
/**
* Get a given time series dataset from Water Services.
* @param {Array} sites Array of site IDs to retrieve.
......@@ -40,8 +49,9 @@ export const getTimeSeries = function ({sites, params=null, startDate=null, endD
if (!startDate && !endDate) {
const timePeriod = period || 'P7D';
const dayCount = getNumberOfDays(timePeriod);
timeParams = `period=${timePeriod}`;
serviceRoot = SERVICE_ROOT;
serviceRoot = dayCount && dayCount < 120 ? SERVICE_ROOT : PAST_SERVICE_ROOT;
} else {
let startString = startDate ? isoFormatTime(startDate) : '';
let endString = endDate ? isoFormatTime(endDate) : '';
......
......@@ -88,6 +88,18 @@ describe('Models module', () => {
let request = jasmine.Ajax.requests.mostRecent();
expect(request.url).toContain('https://nwis.waterservices.usgs.gov/nwis');
});
it('Uses current data service root if period requested is less than P120D', () => {
getTimeSeries({sites: [siteID], params: [paramCode], period: 'P14D'});
let request = jasmine.Ajax.requests.mostRecent();
expect(request.url).toContain('https://waterservices.usgs.gov/nwis');
});
it('Uses past data service root if period requested is greater than P120D', () => {
getTimeSeries({sites: [siteID], params: [paramCode], period: 'P140D'});
let request = jasmine.Ajax.requests.mostRecent();
expect(request.url).toContain('https://nwis.waterservices.usgs.gov/nwis');
});
});
describe('getPreviousYearTimeSeries', () => {
......
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