Skip to content

Commit

Permalink
disable hazards
Browse files Browse the repository at this point in the history
  • Loading branch information
mwood77 committed Feb 22, 2025
1 parent 5d586de commit 41829f9
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 26 deletions.
44 changes: 22 additions & 22 deletions server/scripts/modules/hazards.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -33,28 +33,28 @@ class Hazards extends WeatherDisplay {
const alert = this.checkbox.querySelector('.alert');
alert.classList.remove('show');

try {
// get the forecast
const url = new URL('https://api.weather.gov/alerts/active');
url.searchParams.append('point', `${this.weatherParameters.latitude},${this.weatherParameters.longitude}`);
url.searchParams.append('limit', 5);
const alerts = await json(url, { retryCount: 3, stillWaiting: () => this.stillWaiting() });
const unsortedAlerts = alerts.features ?? [];
const hasImmediate = unsortedAlerts.reduce((acc, hazard) => acc || hazard.properties.urgency === 'Immediate', false);
const sortedAlerts = unsortedAlerts.sort((a, b) => (calcSeverity(b.properties.severity, b.properties.event)) - (calcSeverity(a.properties.severity, a.properties.event)));
const filteredAlerts = sortedAlerts.filter((hazard) => hazard.properties.severity !== 'Unknown' && (!hasImmediate || (hazard.properties.urgency === 'Immediate')));
this.data = filteredAlerts;

// show alert indicator
if (this.data.length > 0) alert.classList.add('show');
} catch (error) {
console.error('Get hourly forecast failed');
console.error(error.status, error.responseJSON);
if (this.isEnabled) this.setStatus(STATUS.failed);
// return undefined to other subscribers
this.getDataCallback(undefined);
return;
}
// try {
// // get the forecast
// const url = new URL('https://api.weather.gov/alerts/active');
// url.searchParams.append('point', `${this.weatherParameters.latitude},${this.weatherParameters.longitude}`);
// url.searchParams.append('limit', 5);
// const alerts = await json(url, { retryCount: 3, stillWaiting: () => this.stillWaiting() });
// const unsortedAlerts = alerts.features ?? [];
// const hasImmediate = unsortedAlerts.reduce((acc, hazard) => acc || hazard.properties.urgency === 'Immediate', false);
// const sortedAlerts = unsortedAlerts.sort((a, b) => (calcSeverity(b.properties.severity, b.properties.event)) - (calcSeverity(a.properties.severity, a.properties.event)));
// const filteredAlerts = sortedAlerts.filter((hazard) => hazard.properties.severity !== 'Unknown' && (!hasImmediate || (hazard.properties.urgency === 'Immediate')));
// this.data = filteredAlerts;

// // show alert indicator
// if (this.data.length > 0) alert.classList.add('show');
// } catch (error) {
// console.error('Get hourly forecast failed');
// console.error(error.status, error.responseJSON);
// if (this.isEnabled) this.setStatus(STATUS.failed);
// // return undefined to other subscribers
// this.getDataCallback(undefined);
// return;
// }

this.getDataCallback();

Expand Down
11 changes: 7 additions & 4 deletions server/scripts/modules/navigation.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import noSleep from './utils/nosleep.mjs';
import STATUS from './status.mjs';
import { wrap } from './utils/calc.mjs';
import { json } from './utils/fetch.mjs';
import { getPoint, getGeocoding, aggregateWeatherForecastData } from './utils/weather.mjs';
import settings from './settings.mjs';

Expand Down Expand Up @@ -59,6 +58,10 @@ const getWeather = async (latLon, haveDataCallback) => {
// therefore we need to split on the "," to get the locality name for open-meteo
const locality = await getGeocoding(localityName.split(',')[0]);

// @todo - this shouldn't be hardcoded
// when a user searches for a location that doesn't have a city
// this will error out.

// set the city and state
let city = locality.results[0].name;
let country = locality.results[0].country;
Expand All @@ -72,13 +75,13 @@ const getWeather = async (latLon, haveDataCallback) => {
weatherParameters.state = state;
weatherParameters.country = country;
weatherParameters.timeZone = timezone;

// WeatherParameters to modify...
weatherParameters.forecast = aggregatedForecastData;
// weatherParameters.forecastGridData = point.properties.forecastGridData;
// weatherParameters.stations = stations.features;
// WeatherParameters that might be optional to modify

// WeatherParameters that might be optional to modify
// or aren't obviously used anywhere for data retrieval...
weatherParameters.stationId = 'stationId-dont-matter-anymore';
weatherParameters.zoneId = 'zoneId-dont-matter';
Expand Down

0 comments on commit 41829f9

Please sign in to comment.