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(); });
|
||||
|
||||
$('#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,
|
||||
paramName: 'text',
|
||||
params: {
|
||||
|
@ -492,7 +492,7 @@ const index = (() => {
|
|||
|
||||
let data;
|
||||
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: {
|
||||
location: longitude + ',' + latitude,
|
||||
distance: 1000, // Find location up to 1 KM.
|
||||
|
|
|
@ -15,24 +15,37 @@ class CurrentWeather extends WeatherDisplay {
|
|||
|
||||
// Load the observations
|
||||
let observations, station;
|
||||
try {
|
||||
// station observations
|
||||
const observationsPromise = utils.fetch.json(`https://api.weather.gov/stations/${weatherParameters.stationId}/observations`,{
|
||||
cors: true,
|
||||
data: {
|
||||
limit: 2,
|
||||
},
|
||||
});
|
||||
// station info
|
||||
const stationPromise = utils.fetch.json(`https://api.weather.gov/stations/${weatherParameters.stationId}`);
|
||||
// station number counter
|
||||
let stationNum = 0;
|
||||
while (!observations && stationNum < weatherParameters.stations.length) {
|
||||
// get the station
|
||||
station = weatherParameters.stations[stationNum];
|
||||
stationNum++;
|
||||
try {
|
||||
// station observations
|
||||
observations = await utils.fetch.json(`${station.id}/observations`,{
|
||||
cors: true,
|
||||
data: {
|
||||
limit: 2,
|
||||
},
|
||||
});
|
||||
|
||||
// wait for the promises to resolve
|
||||
[observations, station] = await Promise.all([observationsPromise, stationPromise]);
|
||||
// test data quality
|
||||
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
|
||||
} catch (e) {
|
||||
console.error('Unable to get current observations');
|
||||
console.error(e);
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
}
|
||||
}
|
||||
// test for data received
|
||||
if (!observations) {
|
||||
console.error('All current weather stations exhausted');
|
||||
this.setStatus(STATUS.failed);
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -32,6 +32,10 @@ class LatestObservations extends WeatherDisplay {
|
|||
const allConditions = await Promise.all(regionalStations.map(async station => {
|
||||
try {
|
||||
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
|
||||
return Object.assign({}, data.properties, {
|
||||
StationId: station.id,
|
||||
|
|
Loading…
Reference in a new issue