current conditions LDL

This commit is contained in:
Matt Walsh 2020-09-25 09:55:29 -05:00
parent 0a6a31217b
commit 4826801491
14 changed files with 80 additions and 346 deletions

2
dist/index.html vendored

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -24,7 +24,8 @@ class Almanac extends WeatherDisplay {
}
async getData(weatherParameters) {
super.getData();
super.getData(weatherParameters);
if (!weatherParameters) weatherParameters = this.weatherParameters;
// get images for outlook
const imagePromises = [

View file

@ -10,7 +10,9 @@ class CurrentWeather extends WeatherDisplay {
}
async getData(weatherParameters) {
super.getData();
super.getData(weatherParameters);
if (!weatherParameters) weatherParameters = this.weatherParameters;
// Load the observations
let observations, station;
try {
@ -58,6 +60,7 @@ class CurrentWeather extends WeatherDisplay {
// values from api are provided in metric
data.observations = observations;
data.Temperature = Math.round(observations.temperature.value);
data.TemperatureUnit = 'C';
data.DewPoint = Math.round(observations.dewpoint.value);
data.Ceiling = Math.round(observations.cloudLayers[0].base.value);
data.CeilingUnit = 'm.';
@ -69,6 +72,7 @@ class CurrentWeather extends WeatherDisplay {
data.HeatIndex = Math.round(observations.heatIndex.value);
data.WindChill = Math.round(observations.windChill.value);
data.WindGust = Math.round(observations.windGust.value);
data.WindUnit = 'KPH';
data.Humidity = Math.round(observations.relativeHumidity.value);
data.Icon = icons.getWeatherIconFromIconLink(observations.icon);
data.PressureDirection = '';
@ -81,12 +85,14 @@ class CurrentWeather extends WeatherDisplay {
if (navigation.units() === UNITS.english) {
data.Temperature = utils.units.celsiusToFahrenheit(data.Temperature);
data.TemperatureUnit = 'F';
data.DewPoint = utils.units.celsiusToFahrenheit(data.DewPoint);
data.Ceiling = Math.round(utils.units.metersToFeet(data.Ceiling)/100)*100;
data.CeilingUnit = 'ft.';
data.Visibility = utils.units.kilometersToMiles(observations.visibility.value/1000);
data.VisibilityUnit = ' mi.';
data.WindSpeed = utils.units.kphToMph(data.WindSpeed);
data.WindUnit = 'MPH';
data.Pressure = utils.units.pascalToInHg(data.Pressure);
data.HeatIndex = utils.units.celsiusToFahrenheit(data.HeatIndex);
data.WindChill = utils.units.celsiusToFahrenheit(data.WindChill);

View file

@ -4,6 +4,9 @@
// eslint-disable-next-line no-unused-vars
const currentWeatherScroll = (() => {
// constants
const degree = String.fromCharCode(176);
// local variables
let context; // currently active context
let blankDrawArea; // original state of context
@ -28,7 +31,7 @@ const currentWeatherScroll = (() => {
// set up the interval if needed
if (!interval) {
interval = setInterval(incrementInterval, 700);
interval = setInterval(incrementInterval, 4000);
}
// draw the data
@ -50,7 +53,7 @@ const currentWeatherScroll = (() => {
// increment interval, roll over
const incrementInterval = () => {
screenIndex = (screenIndex+1)%2;
screenIndex = (screenIndex+1)%(screens.length);
// draw new text
drawScreen();
};
@ -66,17 +69,49 @@ const currentWeatherScroll = (() => {
// clean up any old text
context.putImageData(blankDrawArea, 0, 405);
switch (screenIndex) {
case 0:
default:
drawCondition(`Conditions at ${station.name.substr(0,20)}`);
break;
case 1:
drawCondition(`Page 2`);
break;
}
drawCondition(screens[screenIndex](data));
};
// the "screens" are stored in an array for easy addition and removal
const screens = [
// station name
() => `Conditions at ${station.name.substr(0,20)}`,
// temperature
(data) => {
let text = `Temp: ${data.Temperature}${degree} ${data.TemperatureUnit}`;
if (data.HeatIndex !== data.Temperature) {
text += ` Heat Index: ${data.HeatIndex}${degree} ${data.TemperatureUnit}`;
} else if (data.WindChill !== '' && data.WindChill < data.Temperature) {
text += ` Wind Chill: ${data.WindChill}${degree} ${data.TemperatureUnit}`;
}
return text;
},
// humidity
(data) => `Humidity: ${data.Humidity}${degree} ${data.TemperatureUnit} Dewpoint: ${data.DewPoint}${degree} ${data.TemperatureUnit}`,
// barometric pressure
(data) => `Barometric Pressure: ${data.Pressure} ${data.PressureDirection}`,
// wind
(data) => {
let text = '';
if (data.WindSpeed > 0) {
text = `Wind: ${data.WindDirection} ${data.WindSpeed} ${data.WindUnit}`;
} else {
text = 'Wind: Calm';
}
if (data.WindGust > 0) {
text += ` Gusts to ${data.WindGust}`;
}
return text;
},
// visibility
(data) => `Visib: ${data.Visibility} ${data.VisibilityUnit} Ceiling: ${data.Ceiling===0?'Unlimited':`${data.Ceiling} ${data.CeilingUnit}`}`,
];
// internal draw function with preset parameters
const drawCondition = (text) => {
draw.text(context, 'Star4000', '24pt', '#ffffff', 70, 430, text, 2);

View file

@ -16,7 +16,9 @@ class ExtendedForecast extends WeatherDisplay {
}
async getData(weatherParameters) {
super.getData();
super.getData(weatherParameters);
if (!weatherParameters) weatherParameters = this.weatherParameters;
// request us or si units
let units = 'us';

View file

@ -13,7 +13,9 @@ class LatestObservations extends WeatherDisplay {
}
async getData(weatherParameters) {
super.getData();
super.getData(weatherParameters);
if (!weatherParameters) weatherParameters = this.weatherParameters;
// calculate distance to each station
const stationsByDistance = Object.keys(_StationInfo).map(key => {
const station = _StationInfo[key];

View file

@ -15,7 +15,9 @@ class LocalForecast extends WeatherDisplay {
}
async getData(weatherParameters) {
super.getData();
super.getData(weatherParameters);
if (!weatherParameters) weatherParameters = this.weatherParameters;
// get raw data
const rawData = await this.getRawData(weatherParameters);

View file

@ -37,7 +37,8 @@ class Radar extends WeatherDisplay {
}
async getData(weatherParameters) {
super.getData();
super.getData(weatherParameters);
if (!weatherParameters) weatherParameters = this.weatherParameters;
// ALASKA ISN'T SUPPORTED!
if (weatherParameters.state === 'AK') {

View file

@ -16,7 +16,9 @@ class RegionalForecast extends WeatherDisplay {
}
async getData(weatherParameters) {
super.getData();
super.getData(weatherParameters);
if (!weatherParameters) weatherParameters = this.weatherParameters;
// pre-load the base map (returns promise)
let src = 'images/Basemap2.png';
if (weatherParameters.State === 'HI') {

View file

@ -24,7 +24,7 @@ class WeatherDisplay {
// default navigation timing
this.timing = {
totalScreens: 1,
baseDelay: 5000, // 5 seconds
baseDelay: 9000, // 5 seconds
delay: 1, // 1*1second = 1 second total display time
};
this.navBaseCount = 0;
@ -106,11 +106,14 @@ class WeatherDisplay {
}
// get necessary data for this display
getData() {
getData(weatherParameters) {
// clear current data
this.data = undefined;
// set status
// store weatherParameters locally in case we need them later
if (weatherParameters) this.weatherParameters = weatherParameters;
// set status
if (this.enabled) {
this.setStatus(STATUS.loading);
} else {

View file

@ -1,85 +1,3 @@
/* globals luxon, _TravelCities */
var canvasRegionalObservations;
var canvasRegionalForecast1;
var canvasRegionalForecast2;
var canvasLocalRadar;
var canvasCurrentWeather;
var canvasExtendedForecast1;
var canvasExtendedForecast2;
var canvasLocalForecast;
var divHazards;
var divHazardsScroll;
var canvasHazards;
var canvasAlmanac;
var canvasAlmanacTides;
var canvasOutlook;
var canvasMarineForecast;
var canvasAirQuality;
var canvasTravelForecast;
var divOutlookTemp;
var divOutlookPrcp;
var canvasLatestObservations;
var _WeatherParameters = null;
var _UpdateWeatherUpdateMs = 50;
var canvasBackGroundDateTime = null;
var canvasBackGroundCurrentConditions = null;
var _UpdateWeatherCurrentConditionType = CurrentConditionTypes.Title;
var _UpdateWeatherCurrentConditionCounterMs = 0;
var _UpdateCustomScrollTextMs = 0;
var _UpdateHazardsY = 0;
const GetMonthPrecipitation = async (WeatherParameters) => {
const DateTime = luxon.DateTime;
const today = DateTime.local().startOf('day').toISO().replace('.000','');
try {
const cliProducts = await $.ajaxCORS({
type: 'GET',
url: 'https://api.weather.gov/products',
data: {
location: WeatherParameters.WeatherOffice,
type: 'CLI',
start: today,
},
dataType: 'json',
crossDomain: true,
});
// get the first url from the list
const cli = await $.ajaxCORS({
type: 'GET',
url: cliProducts['@graph'][0]['@id'],
dataType: 'json',
crossDomain: true,
});
WeatherParameters.WeatherMonthlyTotals = WeatherMonthlyTotalsParser(cli.productText);
console.log(WeatherParameters.WeatherMonthlyTotals);
} catch (e) {
console.error('GetMonthPrecipitation failed');
console.error(e.status, e.responseJSON);
return false;
}
};
var GetWeatherHazards3 = function (WeatherParameters) {
var ZoneId = WeatherParameters.ZoneId;
var HazardUrls = [];
@ -166,87 +84,6 @@ var GetWeatherHazards3 = function (WeatherParameters) {
});
};
$(() => {
canvasBackGroundDateTime = $('#canvasBackGroundDateTime');
canvasBackGroundCurrentConditions = $('#canvasBackGroundCurrentConditions');
canvasProgress = $('#canvasProgress');
divProgress = $('#divProgress');
canvasLocalRadar = $('#canvasLocalRadar');
canvasRegionalForecast1 = $('#canvasRegionalForecast1');
canvasRegionalForecast2 = $('#canvasRegionalForecast2');
canvasRegionalObservations = $('#canvasRegionalObservations');
canvasCurrentWeather = $('#canvasCurrentWeather');
canvasExtendedForecast1 = $('#canvasExtendedForecast1');
canvasExtendedForecast2 = $('#canvasExtendedForecast2');
canvasLocalForecast = $('#canvasLocalForecast');
divHazards = $('#divHazards');
divHazardsScroll = $('#divHazardsScroll');
canvasHazards = $('#canvasHazards');
canvasAlmanac = $('#canvasAlmanac');
canvasAlmanacTides = $('#canvasAlmanacTides');
canvasOutlook = $('#canvasOutlook');
canvasMarineForecast = $('#canvasMarineForecast');
canvasAirQuality = $('#canvasAirQuality');
divOutlookTemp = $('#divOutlookTemp');
divOutlookPrcp = $('#divOutlookPrcp');
canvasTravelForecast = $('#canvasTravelForecast');
canvasLatestObservations = $('#canvasLatestObservations');
canvasProgress.mousemove(canvasProgress_mousemove);
canvasProgress.click(canvasProgress_click);
_WeatherParameters = {};
_WeatherParameters.WeatherHazardConditions = {};
const WeatherCanvases = [];
WeatherCanvases.push(canvasProgress);
WeatherCanvases.push(canvasCurrentWeather);
WeatherCanvases.push(canvasLatestObservations);
WeatherCanvases.push(canvasTravelForecast);
WeatherCanvases.push(canvasRegionalForecast1);
WeatherCanvases.push(canvasRegionalForecast2);
WeatherCanvases.push(canvasRegionalObservations);
WeatherCanvases.push(canvasAlmanac);
WeatherCanvases.push(canvasAlmanacTides);
WeatherCanvases.push(canvasOutlook);
WeatherCanvases.push(canvasMarineForecast);
WeatherCanvases.push(canvasAirQuality);
WeatherCanvases.push(canvasLocalForecast);
WeatherCanvases.push(canvasExtendedForecast1);
WeatherCanvases.push(canvasExtendedForecast2);
WeatherCanvases.push(canvasHazards);
WeatherCanvases.push(canvasLocalRadar);
_WeatherParameters.WeatherCanvases = WeatherCanvases;
$(WeatherCanvases).each(function () {
var WeatherCanvas = $(this);
WeatherCanvas.css('position', 'absolute');
WeatherCanvas.css('top', '0px');
WeatherCanvas.css('left', '0px');
WeatherCanvas.hide();
});
canvasProgress.show();
_WeatherParameters.TravelCities = _TravelCities;
_WeatherParameters.Progress = new Progress({
WeatherParameters: _WeatherParameters,
});
});
var canvasProgress_mousemove = function (e) {
canvasProgress.css('cursor', '');
@ -449,161 +286,3 @@ var UpdateHazards = function (Offset) {
};
const WeatherMonthlyTotalsParser = (text) => {
return +text.match(/MONTH TO DATE\s*(\d{1,2}\.\d\d)/)[1];
};
const DrawCustomScrollText = (WeatherParameters, context) => {
const font = 'Star4000';
const size = '24pt';
const color = '#ffffff';
const shadow = 2;
let x = 640;
const y = 430;
if (WeatherParameters.Progress.GetTotalPercentage() !== 100) {
return;
}
// Clear the date and time area.
context.drawImage(canvasBackGroundCurrentConditions[0], 0, 0, 640, 75, 0, 405, 640, 75);
const text = _ScrollText;
x = 640 - ((_UpdateCustomScrollTextMs / _UpdateWeatherUpdateMs) * 5);
// Wait an extra 5 characters.
if (x < ((text.length + 10) * 15 * -1)) {
_UpdateCustomScrollTextMs = 0;
x = 640;
}
// Draw the current condition.
DrawText(context, font, size, color, x, y, text, shadow);
};
const AssignScrollText = (e) => {
_ScrollText = e.ScrollText;
_UpdateCustomScrollTextMs = 0;
_UpdateWeatherCurrentConditionType = CurrentConditionTypes.Title;
_UpdateWeatherCurrentConditionCounterMs = 0;
};
var DrawCurrentConditions = function (WeatherParameters, context) {
var Humidity;
var DewPoint;
var Temperature;
var TemperatureUnit;
var HeatIndex;
var WindChill;
var Pressure;
var PressureDirection;
var WindSpeed;
var WindDirection;
var WindGust;
var WindUnit;
var Visibility;
var VisibilityUnit;
var Ceiling;
var CeilingUnit;
var PrecipitationTotal;
var PrecipitationTotalUnit;
var text;
if (WeatherParameters.Progress.GetTotalPercentage() != 100) {
return;
}
// Clear the date and time area.
context.drawImage(canvasBackGroundCurrentConditions[0], 0, 0, 640, 75, 0, 405, 640, 75);
var WeatherCurrentConditions = WeatherParameters.WeatherCurrentConditions;
var WeatherMonthlyTotals = WeatherParameters.WeatherMonthlyTotals;
if (_UpdateWeatherCurrentConditionCounterMs >= 4000) {
_UpdateWeatherCurrentConditionCounterMs = 0;
_UpdateWeatherCurrentConditionType++;
if (_UpdateWeatherCurrentConditionType > CurrentConditionTypes.MonthPrecipitation) {
_UpdateWeatherCurrentConditionType = CurrentConditionTypes.Title;
}
}
switch(_UpdateWeatherCurrentConditionType) {
case CurrentConditionTypes.Title:
// mjb 06/01/19 text = "Conditions at " + WeatherCurrentConditions.StationName;
text = 'Conditions at ' + WeatherCurrentConditions.StationName.substr(0, 20); // mjb 06/01/19
break;
case CurrentConditionTypes.Conditions:
text = WeatherCurrentConditions.Conditions;
break;
case CurrentConditionTypes.Temperature:
text = 'Temp: ' + Temperature + String.fromCharCode(176) + TemperatureUnit;
if (HeatIndex != Temperature) {
text += ' ';
text += 'Heat Index: ' + HeatIndex + String.fromCharCode(176) + TemperatureUnit;
} else if (WindChill != '' && WindChill < Temperature) {
text += ' ';
text += 'Wind Chill: ' + WindChill + String.fromCharCode(176) + TemperatureUnit;
}
break;
case CurrentConditionTypes.HumidityDewpoint:
text = 'Humidity: ' + Humidity + '%';
text += ' ';
text += 'Dewpoint: ' + DewPoint + String.fromCharCode(176) + TemperatureUnit;
break;
case CurrentConditionTypes.BarometricPressure:
text = 'Barometric Pressure: ' + Pressure + ' ' + PressureDirection;
break;
case CurrentConditionTypes.Wind:
if (WindSpeed > 0) {
text = 'Wind: ' + WindDirection + ' ' + WindSpeed + WindUnit;
} else if (WindSpeed == 'NA') {
text = 'Wind: NA';
} else {
text = 'Wind: Calm';
}
if (WindGust != '') {
text += ' ';
text += 'Gusts to ' + WindGust;
}
break;
case CurrentConditionTypes.VisibilityCeiling:
text = 'Visib: ' + parseInt(Visibility).toString() + VisibilityUnit;
text += ' ';
text += 'Ceiling: ' + (Ceiling == '' ? 'Unlimited' : Ceiling + CeilingUnit);
break;
case CurrentConditionTypes.MonthPrecipitation:
if (PrecipitationTotal.toString() == '') {
_UpdateWeatherCurrentConditionCounterMs += 4000;
DrawCurrentConditions(WeatherParameters, context);
return;
}
// mjb 10/02/19 Begin
//text = WeatherMonthlyTotals.MonthName + " Precipitation: " + PrecipitationTotal.toString() + PrecipitationTotalUnit;
if (PrecipitationTotal.toString() == 'T') {
text = WeatherMonthlyTotals.MonthName + ' Precipitation: Trace';
} else {
text = WeatherMonthlyTotals.MonthName + ' Precipitation: ' + PrecipitationTotal.toString() + PrecipitationTotalUnit;
}
// mjb 10/02/19 End
break;
default:
}
// Draw the current condition.
DrawText(context, font, size, color, x, y, text, shadow);
//_UpdateWeatherCurrentConditionCounterMs += _UpdateWeatherUpdateMs;
//console.log(_UpdateWeatherUpdateMs);
};

View file

@ -1 +1 @@
module.exports = '3.3.0';
module.exports = '3.4.0';

View file

@ -20,6 +20,7 @@
"Noaa",
"T",
"T'storm",
"Visib",
"arcgis",
"devbridge",
"nosleep"