Skip to content

Commit

Permalink
Merge branch 'release/1.1.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
caseycesari committed Jan 23, 2020
2 parents f1651a2 + a564051 commit 9ed202b
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 37 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
1.1.0

- Use special endpoint for waterservices data > 120 days
- Update dates of last data update
- Adjust "fair" rating for turbidity
- Update variable descriptions with client-provided copy

1.0.0

- Initial production release
2 changes: 1 addition & 1 deletion src/app/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ism-watershed-wellness-snapshot",
"version": "1.0.0",
"version": "1.1.0",
"private": true,
"dependencies": {
"axios": "0.18.1",
Expand Down
26 changes: 15 additions & 11 deletions src/app/src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,25 @@ export const VARIABLE_DETAILS = {
[TEMPERATURE]: {
name: 'Water Temperature',
description:
'Water temperature affects the growth and reproduction of living organisms as well as water density.',
'Water temperature affects the growth and reproduction of plants and animals in the water.',
unit: '°F',
},
[OXYGEN]: {
name: 'Dissolved Oxygen',
description:
'A measure of the concentration of oxygen dissolved in a body of water, relative to the maximum concentration.',
'Dissolved oxygen is a measure of the concentration of oxygen in a body of water. Plants and animals need oxygen to breath underwater.',
unit: 'mg/L',
},
[PH]: {
name: 'pH',
description:
'pH is a quantitative measure of the acidity (below 7.0pH) or basicity (above 7.0pH) in a body of water.',
'pH tells us how acidic (below 7.0pH) or basic (above 7.0pH) the water is. This determines if the water is healthy enough to support plants and animals.',
unit: 'pH',
},
[TURBIDITY]: {
name: 'Turbidity',
description:
'Turbidity is a measurement of the cloudiness in a body of water. This cloudiness is caused by the presense of particles that can be invisible to the human eye.',
'Turbidity is a measure of the cloudiness of the water. Particles, sediment and pollution may raise turbidity levels.',
unit: 'NTU',
},
};
Expand All @@ -53,16 +53,20 @@ export const RATING_FAIR = 'FAIR';
export const RATING_POOR = 'POOR';
export const OVERALL_RATING = 'OVERALL_RATING';
export const RATING_DESCRIPTIONS = Object.freeze({
[RATING_GOOD]: 'This means that conditions are ideal for wildlife to thrive. These areas should be protected to preserve this condition.',
[RATING_FAIR]: 'This means that conditions are declining. Conditions indicate that wildlife could be becoming stressed. These areas could be restored to GOOD status.',
[RATING_POOR]: 'This means that conditions might be harmful to wildlife. The conditions are not normal compared to other surrounding areas. Conditions could be improved through restoration and protection.'
[RATING_GOOD]:
'This means that conditions are ideal for wildlife to thrive. These areas should be protected to preserve this condition.',
[RATING_FAIR]:
'This means that conditions are declining. Conditions indicate that wildlife could be becoming stressed. These areas could be restored to GOOD status.',
[RATING_POOR]:
'This means that conditions might be harmful to wildlife. The conditions are not normal compared to other surrounding areas. Conditions could be improved through restoration and protection.',
});

// The selected live sensors last worked on 08/01/2019
export const LAST_LIVE_SENSOR_DATE = '2019-08-01';
// The nwis.waterservices endpoint was intended for historic data (> 120 days ago)
// If updating, only use a date > 120 days from the time of writing
export const LAST_LIVE_SENSOR_DATE = '2019-09-22';

// Quarterly data was taken for all surveys on or after 5/28/2019
export const LAST_QUARTERLY_SURVEY_DATE = '2019-05-28';
// Quarterly data was taken for all surveys on or after 08/20/2019
export const LAST_QUARTERLY_SURVEY_DATE = '2019-08-20';

export const DEFAULT_SENSOR_DATA = SENSORS.features.reduce(
(acc, sensor) =>
Expand Down
44 changes: 30 additions & 14 deletions src/app/src/sensorUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
LAST_LIVE_SENSOR_DATE,
LAST_QUARTERLY_SURVEY_DATE,
TEMPERATURE,
TURBIDITY,
msPerHour,
msPerMonth,
msPerWeek,
Expand All @@ -39,7 +40,7 @@ export function makeRiverGaugeRequest(id, isApiRequest) {
const cleanedCodes = commaSeparatedCodes.slice(0, -1);

const url = isApiRequest
? `https://waterservices.usgs.gov/nwis/iv/?format=json&sites=${id}&param=${cleanedCodes}&startDT=${LAST_LIVE_SENSOR_DATE}`
? `https://nwis.waterservices.usgs.gov/nwis/iv/?format=json&sites=${id}&param=${cleanedCodes}&startDT=${LAST_LIVE_SENSOR_DATE}`
: `https://nwis.waterdata.usgs.gov/nwis/qwdata/?site_no=${id}&agency_cd=USGS&inventory_output=retrieval&rdb_inventory_output=value&begin_date=${LAST_QUARTERLY_SURVEY_DATE}&TZoutput=0&pm_cd_compare=Greater%20than&radio_parm_cds=all_parm_cds&qw_attributes=0&format=rdb&qw_sample_wide=wide&rdb_qw_attributes=0&date_format=YYYY-MM-DD&rdb_compression=value&submitted_form=brief_list`;
return axios.get(url);
}
Expand Down Expand Up @@ -148,24 +149,39 @@ function inRangeInclusive(x, lowerLimit, upperLimit) {
return lowerLimit <= x && x <= upperLimit;
}

function checkIfVariableNearEdgeOfHealthyRange(
variableValue,
lower,
upper,
variable
) {
// A variable is in fair condition if it is within 10%
// of the upper or lower end of the healthy range,
// except for turbidity, which is only considered fair
// if it is within 10% of the upper end.
const isInUpperTenth = v =>
inRangeInclusive(v, upper - (upper - lower) / 10, upper);
const isInLowerTenth = v =>
inRangeInclusive(v, lower, (upper - lower) / 10 + lower);
const isVariableNearEdgeOfHealthyRange =
variable === TURBIDITY
? isInUpperTenth(variableValue)
: isInUpperTenth(variableValue) || isInLowerTenth(variableValue);

return isVariableNearEdgeOfHealthyRange;
}

export function transformSensorDataToRatings(sensorData) {
const sensor = getSensorByProp('Id', sensorData.id).properties;
const sensorRatings = VARIABLES.reduce((acc, variable) => {
const { lower, upper } = sensor.HealthyRanges[variable];
const variableValue = sensorData[variable];
// A variable is in fair condition if it is within 10%
// of the upper or lower end of the healthy range.
const isVariableNearEdgeOfHealthyRange =
inRangeInclusive(
variableValue,
lower,
(upper - lower) / 10 + lower
) ||
inRangeInclusive(
variableValue,
upper - (upper - lower) / 10,
upper
);
const isVariableNearEdgeOfHealthyRange = checkIfVariableNearEdgeOfHealthyRange(
variableValue,
lower,
upper,
variable
);
const isVariableWithinHealthyRange =
lower <= variableValue && variableValue <= upper;
const variableRating = isVariableNearEdgeOfHealthyRange
Expand Down
22 changes: 11 additions & 11 deletions src/app/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2411,10 +2411,10 @@ commander@~2.13.0:
resolved "https://registry.yarnpkg.com/commander/-/commander-2.13.0.tgz#6964bca67685df7c1f1430c584f07d7597885b9c"
integrity sha512-MVuS359B+YzaWqjCL/c+22gfryv+mCBPHAv3zyVI2GN8EY6IRP8VwtasXn8jyyhvvq84R4ImN1OKRtcbIasjYA==

commander@~2.20.0:
version "2.20.0"
resolved "https://registry.yarnpkg.com/commander/-/commander-2.20.0.tgz#d58bb2b5c1ee8f87b0d340027e9e94e222c5a422"
integrity sha512-7j2y+40w61zy6YC2iRNpUe/NwhNyoXrYpHMrSunaMG64nRnaf96zO/KMQR4OyN/UnE5KLyEBnKHd4aG3rskjpQ==
commander@~2.20.3:
version "2.20.3"
resolved "https://registry.yarnpkg.com/commander/-/commander-2.20.3.tgz#fd485e84c03eb4881c20722ba48035e8531aeb33"
integrity sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ==

common-tags@^1.4.0:
version "1.8.0"
Expand Down Expand Up @@ -4495,9 +4495,9 @@ handle-thing@^1.2.5:
integrity sha1-/Xqtcmvxpf0W38KbL3pmAdJxOcQ=

handlebars@^4.0.3:
version "4.1.2"
resolved "https://registry.yarnpkg.com/handlebars/-/handlebars-4.1.2.tgz#b6b37c1ced0306b221e094fc7aca3ec23b131b67"
integrity sha512-nvfrjqvt9xQ8Z/w0ijewdD/vvWDTOweBUm96NTr66Wfvo1mJenBLwcYmPs3TIBP5ruzYGD7Hx/DaM9RmhroGPw==
version "4.5.3"
resolved "https://registry.yarnpkg.com/handlebars/-/handlebars-4.5.3.tgz#5cf75bd8714f7605713511a56be7c349becb0482"
integrity sha512-3yPecJoJHK/4c6aZhSvxOyG4vJKDshV36VHp0iVCDVh7o9w2vwi3NSnL2MMPj3YdduqaBcu7cGbggJQM0br9xA==
dependencies:
neo-async "^2.6.0"
optimist "^0.6.1"
Expand Down Expand Up @@ -10218,11 +10218,11 @@ [email protected]:
source-map "~0.6.1"

uglify-js@^3.1.4:
version "3.6.0"
resolved "https://registry.yarnpkg.com/uglify-js/-/uglify-js-3.6.0.tgz#704681345c53a8b2079fb6cec294b05ead242ff5"
integrity sha512-W+jrUHJr3DXKhrsS7NUVxn3zqMOFn0hL/Ei6v0anCIMoKC93TjcflTagwIHLW7SfMFfiQuktQyFVCFHGUE0+yg==
version "3.7.3"
resolved "https://registry.yarnpkg.com/uglify-js/-/uglify-js-3.7.3.tgz#f918fce9182f466d5140f24bb0ff35c2d32dcc6a"
integrity sha512-7tINm46/3puUA4hCkKYo4Xdts+JDaVC9ZPRcG8Xw9R4nhO/gZgUM3TENq8IF4Vatk8qCig4MzP/c8G4u2BkVQg==
dependencies:
commander "~2.20.0"
commander "~2.20.3"
source-map "~0.6.1"

uglifyjs-webpack-plugin@^1.2.4:
Expand Down

0 comments on commit 9ed202b

Please sign in to comment.