mirror of
https://github.com/netbymatt/ws4kp.git
synced 2026-04-14 07:39:29 -07:00
filter station list upon receipt
This commit is contained in:
@@ -8,13 +8,11 @@ import states from './stations-states.mjs';
|
|||||||
import chunk from './chunk.mjs';
|
import chunk from './chunk.mjs';
|
||||||
import overrides from './stations-overrides.mjs';
|
import overrides from './stations-overrides.mjs';
|
||||||
import postProcessor from './stations-postprocessor.mjs';
|
import postProcessor from './stations-postprocessor.mjs';
|
||||||
|
import { stationFilter } from '../server/scripts/modules/utils/string.mjs';
|
||||||
|
|
||||||
// check for cached flag
|
// check for cached flag
|
||||||
const USE_CACHE = process.argv.includes('--use-cache');
|
const USE_CACHE = process.argv.includes('--use-cache');
|
||||||
|
|
||||||
// skip stations starting with these letters
|
|
||||||
const skipStations = ['U', 'C', 'H', 'W', 'Y', 'T', 'S', 'M', 'O', 'L', 'A', 'F', 'B', 'N', 'V', 'R', 'D', 'E', 'I', 'G', 'J'];
|
|
||||||
|
|
||||||
// chunk the list of states
|
// chunk the list of states
|
||||||
const chunkStates = chunk(states, 3);
|
const chunkStates = chunk(states, 3);
|
||||||
|
|
||||||
@@ -41,10 +39,8 @@ if (!USE_CACHE) {
|
|||||||
// eslint-disable-next-line no-await-in-loop
|
// eslint-disable-next-line no-await-in-loop
|
||||||
const stationsRaw = await https(next);
|
const stationsRaw = await https(next);
|
||||||
stations = JSON.parse(stationsRaw);
|
stations = JSON.parse(stationsRaw);
|
||||||
// filter stations for 4 letter identifiers
|
|
||||||
const stationsFiltered4 = stations.features.filter((station) => station.properties.stationIdentifier.match(/^[A-Z]{4}$/));
|
|
||||||
// filter against starting letter
|
// filter against starting letter
|
||||||
const stationsFiltered = stationsFiltered4.filter((station) => !skipStations.includes(station.properties.stationIdentifier.slice(0, 1)));
|
const stationsFiltered = stations.filter(stationFilter);
|
||||||
// add each resulting station to the output
|
// add each resulting station to the output
|
||||||
stationsFiltered.forEach((station) => {
|
stationsFiltered.forEach((station) => {
|
||||||
const id = station.properties.stationIdentifier;
|
const id = station.properties.stationIdentifier;
|
||||||
|
|||||||
@@ -15,9 +15,6 @@ import { debugFlag } from './utils/debug.mjs';
|
|||||||
import { isDataStale, enhanceObservationWithMapClick } from './utils/mapclick.mjs';
|
import { isDataStale, enhanceObservationWithMapClick } from './utils/mapclick.mjs';
|
||||||
import { DateTime } from '../vendor/auto/luxon.mjs';
|
import { DateTime } from '../vendor/auto/luxon.mjs';
|
||||||
|
|
||||||
// some stations prefixed do not provide all the necessary data
|
|
||||||
const skipStations = ['U', 'C', 'H', 'W', 'Y', 'T', 'S', 'M', 'O', 'L', 'A', 'F', 'B', 'N', 'V', 'R', 'D', 'E', 'I', 'G', 'J'];
|
|
||||||
|
|
||||||
class CurrentWeather extends WeatherDisplay {
|
class CurrentWeather extends WeatherDisplay {
|
||||||
constructor(navId, elemId) {
|
constructor(navId, elemId) {
|
||||||
super(navId, elemId, 'Current Conditions', true);
|
super(navId, elemId, 'Current Conditions', true);
|
||||||
@@ -29,8 +26,8 @@ class CurrentWeather extends WeatherDisplay {
|
|||||||
// note: current weather does not use old data on a silent refresh
|
// note: current weather does not use old data on a silent refresh
|
||||||
// this is deliberate because it can pull data from more than one station in sequence
|
// this is deliberate because it can pull data from more than one station in sequence
|
||||||
|
|
||||||
// filter for 4-letter observation stations, only those contain sky conditions and thus an icon
|
// get the available stations
|
||||||
const filteredStations = this.weatherParameters.stations.filter((station) => station?.properties?.stationIdentifier?.length === 4 && !skipStations.includes(station.properties.stationIdentifier.slice(0, 1)));
|
const { stations } = this.weatherParameters;
|
||||||
|
|
||||||
// Load the observations
|
// Load the observations
|
||||||
let observations;
|
let observations;
|
||||||
@@ -38,9 +35,9 @@ class CurrentWeather extends WeatherDisplay {
|
|||||||
|
|
||||||
// station number counter
|
// station number counter
|
||||||
let stationNum = 0;
|
let stationNum = 0;
|
||||||
while (!observations && stationNum < filteredStations.length) {
|
while (!observations && stationNum < stations.length) {
|
||||||
// get the station
|
// get the station
|
||||||
station = filteredStations[stationNum];
|
station = stations[stationNum];
|
||||||
const stationId = station.properties.stationIdentifier;
|
const stationId = station.properties.stationIdentifier;
|
||||||
|
|
||||||
stationNum += 1;
|
stationNum += 1;
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import { safeJson } from './utils/fetch.mjs';
|
|||||||
import { getPoint } from './utils/weather.mjs';
|
import { getPoint } from './utils/weather.mjs';
|
||||||
import { debugFlag } from './utils/debug.mjs';
|
import { debugFlag } from './utils/debug.mjs';
|
||||||
import settings from './settings.mjs';
|
import settings from './settings.mjs';
|
||||||
|
import { stationFilter } from './utils/string.mjs';
|
||||||
|
|
||||||
document.addEventListener('DOMContentLoaded', () => {
|
document.addEventListener('DOMContentLoaded', () => {
|
||||||
init();
|
init();
|
||||||
@@ -85,7 +86,15 @@ const getWeather = async (latLon, haveDataCallback) => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const StationId = stations.features[0].properties.stationIdentifier;
|
// filter stations for proper format
|
||||||
|
const stationsFiltered = stations.features.filter(stationFilter);
|
||||||
|
// check for stations available after filtering
|
||||||
|
if (stationsFiltered.length === 0) {
|
||||||
|
console.warn('No observation stations left for location after filtering');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const StationId = stationsFiltered[0].properties.stationIdentifier;
|
||||||
|
|
||||||
let { city } = point.properties.relativeLocation.properties;
|
let { city } = point.properties.relativeLocation.properties;
|
||||||
const { state } = point.properties.relativeLocation.properties;
|
const { state } = point.properties.relativeLocation.properties;
|
||||||
@@ -108,7 +117,7 @@ const getWeather = async (latLon, haveDataCallback) => {
|
|||||||
weatherParameters.timeZone = point.properties.timeZone;
|
weatherParameters.timeZone = point.properties.timeZone;
|
||||||
weatherParameters.forecast = point.properties.forecast;
|
weatherParameters.forecast = point.properties.forecast;
|
||||||
weatherParameters.forecastGridData = point.properties.forecastGridData;
|
weatherParameters.forecastGridData = point.properties.forecastGridData;
|
||||||
weatherParameters.stations = stations.features;
|
weatherParameters.stations = stationsFiltered;
|
||||||
weatherParameters.relativeLocation = point.properties.relativeLocation.properties;
|
weatherParameters.relativeLocation = point.properties.relativeLocation.properties;
|
||||||
|
|
||||||
// update the main process for display purposes
|
// update the main process for display purposes
|
||||||
|
|||||||
@@ -13,7 +13,12 @@ const locationCleanup = (input) => {
|
|||||||
return regexes.reduce((value, regex) => value.replace(regex, ''), input);
|
return regexes.reduce((value, regex) => value.replace(regex, ''), input);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// stations must be 4 alpha characters and not start with the provided list
|
||||||
|
const skipStations = ['U', 'C', 'H', 'W', 'Y', 'T', 'S', 'M', 'O', 'L', 'A', 'F', 'B', 'N', 'V', 'R', 'D', 'E', 'I', 'G', 'J'];
|
||||||
|
const stationFilter = (station) => station.properties.stationIdentifier.match(/^[A-Z]{4}$/) && !skipStations.includes(station.properties.stationIdentifier.slice(0, 1));
|
||||||
|
|
||||||
export {
|
export {
|
||||||
// eslint-disable-next-line import/prefer-default-export
|
|
||||||
locationCleanup,
|
locationCleanup,
|
||||||
|
stationFilter,
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user