detect stations not reporting critical values close #4
This commit is contained in:
parent
4363f3967f
commit
eeeb7ec3e8
1
server/debug.log
Normal file
1
server/debug.log
Normal file
|
@ -0,0 +1 @@
|
||||||
|
[1016/115344.136:ERROR:directory_reader_win.cc(43)] FindFirstFile: The system cannot find the path specified. (0x3)
|
|
@ -53,7 +53,7 @@ const index = (() => {
|
||||||
document.addEventListener('touchmove', e => { if (_FullScreenOverride) e.preventDefault(); });
|
document.addEventListener('touchmove', e => { if (_FullScreenOverride) e.preventDefault(); });
|
||||||
|
|
||||||
$('#frmGetLatLng #txtAddress').devbridgeAutocomplete({
|
$('#frmGetLatLng #txtAddress').devbridgeAutocomplete({
|
||||||
serviceUrl: location.protocol + '//geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer/suggest',
|
serviceUrl: 'https://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer/suggest',
|
||||||
deferRequestBy: 300,
|
deferRequestBy: 300,
|
||||||
paramName: 'text',
|
paramName: 'text',
|
||||||
params: {
|
params: {
|
||||||
|
@ -492,7 +492,7 @@ const index = (() => {
|
||||||
|
|
||||||
let data;
|
let data;
|
||||||
try {
|
try {
|
||||||
data = await utils.fetch.json(location.protocol + '//geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer/reverseGeocode', {
|
data = await utils.fetch.json('https://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer/reverseGeocode', {
|
||||||
data: {
|
data: {
|
||||||
location: longitude + ',' + latitude,
|
location: longitude + ',' + latitude,
|
||||||
distance: 1000, // Find location up to 1 KM.
|
distance: 1000, // Find location up to 1 KM.
|
||||||
|
|
|
@ -15,24 +15,37 @@ class CurrentWeather extends WeatherDisplay {
|
||||||
|
|
||||||
// Load the observations
|
// Load the observations
|
||||||
let observations, station;
|
let observations, station;
|
||||||
|
// station number counter
|
||||||
|
let stationNum = 0;
|
||||||
|
while (!observations && stationNum < weatherParameters.stations.length) {
|
||||||
|
// get the station
|
||||||
|
station = weatherParameters.stations[stationNum];
|
||||||
|
stationNum++;
|
||||||
try {
|
try {
|
||||||
// station observations
|
// station observations
|
||||||
const observationsPromise = utils.fetch.json(`https://api.weather.gov/stations/${weatherParameters.stationId}/observations`,{
|
observations = await utils.fetch.json(`${station.id}/observations`,{
|
||||||
cors: true,
|
cors: true,
|
||||||
data: {
|
data: {
|
||||||
limit: 2,
|
limit: 2,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
// station info
|
|
||||||
const stationPromise = utils.fetch.json(`https://api.weather.gov/stations/${weatherParameters.stationId}`);
|
|
||||||
|
|
||||||
// wait for the promises to resolve
|
// test data quality
|
||||||
[observations, station] = await Promise.all([observationsPromise, stationPromise]);
|
if (observations.features[0].properties.temperature.value === null ||
|
||||||
|
observations.features[0].properties.windSpeed.value === null ||
|
||||||
|
observations.features[0].properties.textDescription === null) {
|
||||||
|
observations = undefined;
|
||||||
|
throw new Error(`Unable to get observations: ${station.properties.stationIdentifier}, trying next station`);
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: add retry for further stations if observations are unavailable
|
// TODO: add retry for further stations if observations are unavailable
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error('Unable to get current observations');
|
|
||||||
console.error(e);
|
console.error(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// test for data received
|
||||||
|
if (!observations) {
|
||||||
|
console.error('All current weather stations exhausted');
|
||||||
this.setStatus(STATUS.failed);
|
this.setStatus(STATUS.failed);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,6 +32,10 @@ class LatestObservations extends WeatherDisplay {
|
||||||
const allConditions = await Promise.all(regionalStations.map(async station => {
|
const allConditions = await Promise.all(regionalStations.map(async station => {
|
||||||
try {
|
try {
|
||||||
const data = await utils.fetch.json(`https://api.weather.gov/stations/${station.id}/observations/latest`);
|
const data = await utils.fetch.json(`https://api.weather.gov/stations/${station.id}/observations/latest`);
|
||||||
|
// test for temperature, weather and wind values present
|
||||||
|
if (data.properties.temperature.value === null ||
|
||||||
|
data.properties.textDescription === '' ||
|
||||||
|
data.properties.windSpeed.value === null) return;
|
||||||
// format the return values
|
// format the return values
|
||||||
return Object.assign({}, data.properties, {
|
return Object.assign({}, data.properties, {
|
||||||
StationId: station.id,
|
StationId: station.id,
|
||||||
|
|
Loading…
Reference in a new issue