mirror of
https://github.com/netbymatt/temperature-express.git
synced 2026-11-28 18:38:04 -08:00
Add get of normal temperatures
This commit is contained in:
1 parent
5143b83535
commit
d44f40acaf
6 files changed
+124
-76
No files matched your search
+1
-1
@@ -15,7 +15,7 @@ module.exports = {
|
||||
SharedArrayBuffer: 'readonly',
|
||||
},
|
||||
parserOptions: {
|
||||
ecmaVersion: 2021,
|
||||
ecmaVersion: 2024,
|
||||
},
|
||||
plugins: [
|
||||
],
|
||||
|
||||
@@ -11,7 +11,7 @@ const trendConfig = (displayName, scale, units, yAxis, lineType, valueFunction)
|
||||
lineType, // 0=no fill, 1=fill to zero, 2=points only
|
||||
valueFunction,
|
||||
};
|
||||
// set default display units
|
||||
// set default display units
|
||||
obj.scale.setUnit(units);
|
||||
return obj;
|
||||
};
|
||||
@@ -23,25 +23,25 @@ const getLineType = (lineType, name, forceState = false) => {
|
||||
const opt = (visible === undefined) ? true : visible ?? forceState;
|
||||
|
||||
switch (lineType) {
|
||||
case 2:
|
||||
// points only
|
||||
return {
|
||||
show: false,
|
||||
};
|
||||
case 1:
|
||||
// filled under line to zero
|
||||
return {
|
||||
fill: opt,
|
||||
lineWidth: 0,
|
||||
show: opt,
|
||||
};
|
||||
case 0:
|
||||
default:
|
||||
// line only, no fill
|
||||
return {
|
||||
show: opt,
|
||||
lineWidth: 2,
|
||||
};
|
||||
case 2:
|
||||
// points only
|
||||
return {
|
||||
show: false,
|
||||
};
|
||||
case 1:
|
||||
// filled under line to zero
|
||||
return {
|
||||
fill: opt,
|
||||
lineWidth: 0,
|
||||
show: opt,
|
||||
};
|
||||
case 0:
|
||||
default:
|
||||
// line only, no fill
|
||||
return {
|
||||
show: opt,
|
||||
lineWidth: 2,
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -183,35 +183,35 @@ const getInfo = (type) => {
|
||||
// can't get anything if the plot isn't drawn
|
||||
if (plot === null) return null;
|
||||
switch (type) {
|
||||
// all available data
|
||||
case 'xMin':
|
||||
return plot.getAxes().xaxis.datamin;
|
||||
case 'xMax':
|
||||
return plot.getAxes().xaxis.datamax;
|
||||
// all available data
|
||||
case 'xMin':
|
||||
return plot.getAxes().xaxis.datamin;
|
||||
case 'xMax':
|
||||
return plot.getAxes().xaxis.datamax;
|
||||
|
||||
// visible data
|
||||
case 'xMinVisible':
|
||||
return plot.getAxes().xaxis.min;
|
||||
case 'xMaxVisible':
|
||||
return plot.getAxes().xaxis.max;
|
||||
case 'xMinVisible':
|
||||
return plot.getAxes().xaxis.min;
|
||||
case 'xMaxVisible':
|
||||
return plot.getAxes().xaxis.max;
|
||||
|
||||
// oldest data
|
||||
case 'oldestData':
|
||||
return metaData.oldestData;
|
||||
case 'forecastTimestamp':
|
||||
return metaData.forecastTimestamp;
|
||||
case 'lastUpdate':
|
||||
return metaData.lastUpdate;
|
||||
case 'oldestData':
|
||||
return metaData.oldestData;
|
||||
case 'forecastTimestamp':
|
||||
return metaData.forecastTimestamp;
|
||||
case 'lastUpdate':
|
||||
return metaData.lastUpdate;
|
||||
|
||||
// x axis limits
|
||||
case 'xLimits':
|
||||
return {
|
||||
min: plot.getAxes().xaxis.min,
|
||||
max: plot.getAxes().xaxis.max,
|
||||
};
|
||||
case 'xLimits':
|
||||
return {
|
||||
min: plot.getAxes().xaxis.min,
|
||||
max: plot.getAxes().xaxis.max,
|
||||
};
|
||||
|
||||
default:
|
||||
return plot[type];
|
||||
default:
|
||||
return plot[type];
|
||||
}
|
||||
};
|
||||
|
||||
@@ -346,11 +346,22 @@ const updateCurrentTemperature = (dataset) => {
|
||||
}
|
||||
};
|
||||
|
||||
// store and format the normal temperatures received
|
||||
const formatNormalTemperatures = (data) => {
|
||||
const { timeZone } = getSavedLocation();
|
||||
if (timeZone) {
|
||||
const placeTime = (DateTime.now().setZone(timeZone).startOf('day'));
|
||||
const userTime = (DateTime.now().startOf('day'));
|
||||
convertTimestamp.timeZoneOffset = (new Date()).getTimezoneOffset() * 60_000 - (userTime - placeTime); // time zone offset in milliseconds
|
||||
}
|
||||
};
|
||||
|
||||
export {
|
||||
getInfo,
|
||||
formatData,
|
||||
chartVisibility,
|
||||
setUnits,
|
||||
readVisibility,
|
||||
formatNormalTemperatures,
|
||||
OLD_FORECAST_LIMIT,
|
||||
};
|
||||
@@ -67,24 +67,24 @@ const getPlaceFailed = (e, isRetry) => {
|
||||
ProgressBar.message('Geolocation lookup failed', true);
|
||||
ProgressBar.message(e, true);
|
||||
switch (e.code ?? 0) {
|
||||
case 1:
|
||||
// user denied
|
||||
// turn off gps option on location screen and force a user input
|
||||
Dialog.mustEnterPlaceName();
|
||||
break;
|
||||
case 1:
|
||||
// user denied
|
||||
// turn off gps option on location screen and force a user input
|
||||
Dialog.mustEnterPlaceName();
|
||||
break;
|
||||
// position unavailable (internal position source failed)
|
||||
// intentional fall-through to "force user input" below
|
||||
case 2:
|
||||
case 3:
|
||||
// timeout expired
|
||||
// retry once then force user to enter a location
|
||||
if (isRetry) {
|
||||
Dialog.mustEnterPlaceName();
|
||||
} else {
|
||||
getPlace(true);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
case 2:
|
||||
case 3:
|
||||
// timeout expired
|
||||
// retry once then force user to enter a location
|
||||
if (isRetry) {
|
||||
Dialog.mustEnterPlaceName();
|
||||
} else {
|
||||
getPlace(true);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
}
|
||||
};
|
||||
|
||||
@@ -144,7 +144,7 @@ const latLonReceived = (places, _place) => {
|
||||
const newLon = parseFloat(places[0].lon);
|
||||
// if less than 0.01 from previous location forgo location lookup and use cached point
|
||||
if (Math.abs(newLat - place.lat) <= 0.01 && Math.abs(newLon - place.lon) <= 0.01
|
||||
&& place.pointX !== null && pointReceived.placeY !== null) {
|
||||
&& place.pointX !== null && pointReceived.placeY !== null) {
|
||||
Outlook.show([place.lon, place.lat]);
|
||||
// jump to point received
|
||||
pointReceived(false, place);
|
||||
@@ -243,6 +243,7 @@ const pointReceived = (point, _place) => {
|
||||
|
||||
// pass point data to hourly forecast api
|
||||
getHourlyForecast(baseUrl);
|
||||
getNormalTemperatures(place.office);
|
||||
// get text forecast
|
||||
Menu.getTextForecast(baseUrl);
|
||||
|
||||
@@ -401,9 +402,45 @@ const visibilityChange = () => {
|
||||
const lastUpdate = Forecast.getInfo('lastUpdate');
|
||||
const forecastTimestamp = Date.parse(Forecast.getInfo('forecastTimestamp'));
|
||||
if (now > lastUpdate + 15 * 60_000
|
||||
|| now > forecastTimestamp + 60 * 60_000) {
|
||||
|| now > forecastTimestamp + 60 * 60_000) {
|
||||
// trigger an update
|
||||
getPlace();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// normal high/low temperatures for the WFO
|
||||
const getNormalTemperatures = async (wfo) => {
|
||||
// cancel previous request if present
|
||||
getNormalTemperatures?.cancel?.();
|
||||
|
||||
// prepare the body of the request
|
||||
const requestParams = {
|
||||
elems: [{
|
||||
name: 'maxt', interval: 'dly', duration: 'dly', normal: '91', prec: 0,
|
||||
}, {
|
||||
name: 'mint', interval: 'dly', duration: 'dly', normal: '91', prec: 0,
|
||||
}],
|
||||
sid: wfo,
|
||||
sDate: DateTime.now().minus({ days: 10 }).toISODate(),
|
||||
eDate: DateTime.now().plus({ days: 10 }).toISODate(),
|
||||
};
|
||||
const requestBody = new URLSearchParams();
|
||||
requestBody.append('output', 'json');
|
||||
requestBody.append('params', JSON.stringify(requestParams));
|
||||
|
||||
try {
|
||||
const response = await fetch('https://data.rcc-acis.org/StnData', {
|
||||
headers: {
|
||||
accept: 'application/json',
|
||||
},
|
||||
body: requestBody,
|
||||
method: 'POST',
|
||||
});
|
||||
const data = await response.json();
|
||||
ProgressBar.set('Normal temperatures received');
|
||||
Forecast.formatNormalTemperatures(data);
|
||||
} catch (e) {
|
||||
ProgressBar.message('Get normal temperatures failed', true);
|
||||
}
|
||||
};
|
||||
@@ -1,4 +1,4 @@
|
||||
const max = 7;
|
||||
const max = 8;
|
||||
let messageContainer;
|
||||
let dialog;
|
||||
let element;
|
||||
|
||||
+14
-14
@@ -34,14 +34,14 @@ const dark = () => isDark;
|
||||
|
||||
const backoff = (iteration) => {
|
||||
switch (iteration) {
|
||||
case 0: return 2;
|
||||
case 1: return 2;
|
||||
case 2: return 4;
|
||||
case 3: return 8;
|
||||
case 4: return 16;
|
||||
case 5:
|
||||
default:
|
||||
return 32;
|
||||
case 0: return 2;
|
||||
case 1: return 2;
|
||||
case 2: return 4;
|
||||
case 3: return 8;
|
||||
case 4: return 16;
|
||||
case 5:
|
||||
default:
|
||||
return 32;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -97,7 +97,7 @@ const getFile = async (url, name) => {
|
||||
if (response.status !== 200) throw new Error(`Status code ${response.status}`);
|
||||
const fileData = await response.json();
|
||||
return fileData.features;
|
||||
} catch (error) {
|
||||
} catch (error) {
|
||||
ProgressBar.message(`Error getting ${name ?? ''} spc outlook: ${url}`, true);
|
||||
ProgressBar.message(error, true);
|
||||
return null;
|
||||
@@ -106,11 +106,11 @@ const getFile = async (url, name) => {
|
||||
|
||||
const formatDay = (index) => {
|
||||
switch (index) {
|
||||
case 0:
|
||||
return 'Today';
|
||||
case 1:
|
||||
return 'Tomorrow';
|
||||
default:
|
||||
case 0:
|
||||
return 'Today';
|
||||
case 1:
|
||||
return 'Tomorrow';
|
||||
default:
|
||||
}
|
||||
|
||||
// calculate date
|
||||
|
||||
Reference in new issue
Block a user