Compare commits

...

6 Commits

Author SHA1 Message Date
Matt Walsh
8a25881d5b 5.9.6 2023-01-05 14:19:43 -06:00
Matt Walsh
0743b9e2bb filter current conditions for missing icon or current conditions 2023-01-05 14:19:33 -06:00
Matt Walsh
784c074e32 capture dist 2022-12-22 14:48:05 -06:00
Matt Walsh
4840909098 5.9.5 2022-12-22 14:47:08 -06:00
Matt Walsh
03dfbc462b better latest observation get data routine 2022-12-22 14:46:58 -06:00
Matt Walsh
25291efff5 capture dist 2022-12-21 16:20:54 -06:00
10 changed files with 53 additions and 28 deletions

2
dist/index.html vendored

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

4
package-lock.json generated
View File

@@ -1,12 +1,12 @@
{ {
"name": "ws4kp", "name": "ws4kp",
"version": "5.9.4", "version": "5.9.6",
"lockfileVersion": 2, "lockfileVersion": 2,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "ws4kp", "name": "ws4kp",
"version": "5.9.4", "version": "5.9.6",
"license": "MIT", "license": "MIT",
"devDependencies": { "devDependencies": {
"del": "^6.0.0", "del": "^6.0.0",

View File

@@ -1,6 +1,6 @@
{ {
"name": "ws4kp", "name": "ws4kp",
"version": "5.9.4", "version": "5.9.6",
"description": "Welcome to the WeatherStar 4000+ project page!", "description": "Welcome to the WeatherStar 4000+ project page!",
"main": "index.js", "main": "index.js",
"scripts": { "scripts": {

View File

@@ -53,7 +53,9 @@ class CurrentWeather extends WeatherDisplay {
// test data quality // test data quality
if (observations.features[0].properties.temperature.value === null if (observations.features[0].properties.temperature.value === null
|| observations.features[0].properties.windSpeed.value === null || observations.features[0].properties.windSpeed.value === null
|| observations.features[0].properties.textDescription === null) { || observations.features[0].properties.textDescription === null
|| observations.features[0].properties.textDescription === ''
|| observations.features[0].properties.icon === null) {
observations = undefined; observations = undefined;
throw new Error(`Unable to get observations: ${station.properties.stationIdentifier}, trying next station`); throw new Error(`Unable to get observations: ${station.properties.stationIdentifier}, trying next station`);
} }

View File

@@ -87,6 +87,7 @@ const getWeatherRegionalIconFromIconLink = (link, _isNightTime) => {
return addPath('Light-Snow.gif'); return addPath('Light-Snow.gif');
case 'rain_snow': case 'rain_snow':
case 'rain_snow-n':
return addPath('Rain-Snow-1992.gif'); return addPath('Rain-Snow-1992.gif');
case 'snow_fzra': case 'snow_fzra':

View File

@@ -32,26 +32,20 @@ class LatestObservations extends WeatherDisplay {
const regionalStations = sortedStations.slice(0, 30); const regionalStations = sortedStations.slice(0, 30);
// get data for regional stations // get data for regional stations
const allConditions = await Promise.all(regionalStations.map(async (station) => { // get first 7 stations
try { const actualConditions = [];
const data = await json(`https://api.weather.gov/stations/${station.id}/observations/latest`, { retryCount: 3, stillWaiting: () => this.stillWaiting() }); let lastStation = Math.min(regionalStations.length, 7);
// test for temperature, weather and wind values present let firstStation = 0;
if (data.properties.temperature.value === null while (actualConditions.length < 7 && (lastStation) <= regionalStations.length) {
|| data.properties.textDescription === '' // eslint-disable-next-line no-await-in-loop
|| data.properties.windSpeed.value === null) return false; const someStations = await getStations(regionalStations.slice(firstStation, lastStation));
// format the return values
return { actualConditions.push(...someStations);
...data.properties, // update counters
StationId: station.id, firstStation += lastStation;
city: station.city, lastStation = Math.min(regionalStations.length + 1, firstStation + 7 - actualConditions.length);
}; }
} catch (e) {
console.log(`Unable to get latest observations for ${station.id}`);
return false;
}
}));
// remove and stations that did not return data
const actualConditions = allConditions.filter((condition) => condition);
// cut down to the maximum of 7 // cut down to the maximum of 7
this.data = actualConditions.slice(0, this.MaximumRegionalStations); this.data = actualConditions.slice(0, this.MaximumRegionalStations);
@@ -119,5 +113,28 @@ const shortenCurrentConditions = (_condition) => {
condition = condition.replace(/ with /, '/'); condition = condition.replace(/ with /, '/');
return condition; return condition;
}; };
const getStations = async (stations) => {
const stationData = await Promise.all(stations.map(async (station) => {
try {
const data = await json(`https://api.weather.gov/stations/${station.id}/observations/latest`, { retryCount: 1, stillWaiting: () => this.stillWaiting() });
// test for temperature, weather and wind values present
if (data.properties.temperature.value === null
|| data.properties.textDescription === ''
|| data.properties.windSpeed.value === null) return false;
// format the return values
return {
...data.properties,
StationId: station.id,
city: station.city,
};
} catch (e) {
console.log(`Unable to get latest observations for ${station.id}`);
return false;
}
}));
// filter false (no data or other error)
return stationData.filter((d) => d);
};
// register display // register display
registerDisplay(new LatestObservations(2, 'latest-observations')); registerDisplay(new LatestObservations(2, 'latest-observations'));

View File

@@ -23,7 +23,9 @@ const getRegionalObservation = async (point, city) => {
const observation = await json(`${station}/observations/latest`); const observation = await json(`${station}/observations/latest`);
// preload the image // preload the image
if (!observation.properties.icon) return false; if (!observation.properties.icon) return false;
preloadImg(getWeatherRegionalIconFromIconLink(observation.properties.icon, !observation.properties.daytime)); const icon = getWeatherRegionalIconFromIconLink(observation.properties.icon, !observation.properties.daytime);
if (!icon) return false;
preloadImg(icon);
// return the observation // return the observation
return observation.properties; return observation.properties;
} catch (e) { } catch (e) {

View File

@@ -87,6 +87,9 @@ class RegionalForecast extends WeatherDisplay {
// wait for the regional observation if it's not done yet // wait for the regional observation if it's not done yet
const observation = await observationPromise; const observation = await observationPromise;
if (!observation) return false;
// format the observation the same as the forecast // format the observation the same as the forecast
const regionalObservation = { const regionalObservation = {
daytime: !!observation.icon.match(/\/day\//), daytime: !!observation.icon.match(/\/day\//),