mirror of
https://github.com/netbymatt/ws4kp.git
synced 2026-04-17 17:19:30 -07:00
Augment missing weather data from METAR when possible; use centralized error handling
- Add utility function to augment missing weather observation data from METAR - Switch from json() to safeJson() for centralized error handling - Data quality validation and age checks - Add null/undefined value handling for wind direction calculations
This commit is contained in:
@@ -1,5 +1,9 @@
|
||||
// wind direction
|
||||
const directionToNSEW = (Direction) => {
|
||||
// Handle null, undefined, or invalid direction values
|
||||
if (Direction === null || Direction === undefined || typeof Direction !== 'number' || Number.isNaN(Direction)) {
|
||||
return 'VAR'; // Variable (or unknown) direction
|
||||
}
|
||||
const val = Math.floor((Direction / 22.5) + 0.5);
|
||||
const arr = ['N', 'NNE', 'NE', 'ENE', 'E', 'ESE', 'SE', 'SSE', 'S', 'SSW', 'SW', 'WSW', 'W', 'WNW', 'NW', 'NNW'];
|
||||
return arr[(val % 16)];
|
||||
|
||||
Reference in New Issue
Block a user