mirror of
https://github.com/netbymatt/ws4kp.git
synced 2026-04-17 17:19:30 -07:00
Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8a25881d5b | ||
|
|
0743b9e2bb | ||
|
|
784c074e32 | ||
|
|
4840909098 | ||
|
|
03dfbc462b | ||
|
|
25291efff5 |
2
dist/index.html
vendored
2
dist/index.html
vendored
File diff suppressed because one or more lines are too long
2
dist/resources/ws.min.css
vendored
2
dist/resources/ws.min.css
vendored
File diff suppressed because one or more lines are too long
2
dist/resources/ws.min.js
vendored
2
dist/resources/ws.min.js
vendored
File diff suppressed because one or more lines are too long
4
package-lock.json
generated
4
package-lock.json
generated
@@ -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",
|
||||||
|
|||||||
@@ -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": {
|
||||||
|
|||||||
@@ -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`);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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':
|
||||||
|
|||||||
@@ -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'));
|
||||||
|
|||||||
@@ -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) {
|
||||||
|
|||||||
@@ -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\//),
|
||||||
|
|||||||
Reference in New Issue
Block a user