tidy up code for weather

This commit is contained in:
vincep5 2019-02-27 09:09:37 -06:00
parent d8765578c8
commit ebc1e5bf12
2 changed files with 28 additions and 42 deletions

View File

@ -103,13 +103,13 @@ WeatherProvider.register("openweathermap", {
// initial variable declaration // initial variable declaration
const days = []; const days = [];
// variables for temperature range and rain // variables for temperature range and rain
var minTemp = []; let minTemp = [];
var maxTemp = []; let maxTemp = [];
var rain = 0; let rain = 0;
var snow = 0; let snow = 0;
// variable for date // variable for date
let date = ""; let date = "";
var weather = new WeatherObject(this.config.units); let weather = new WeatherObject(this.config.units);
for (const forecast of forecasts) { for (const forecast of forecasts) {

View File

@ -29,8 +29,6 @@ WeatherProvider.register("weathergov", {
return; return;
} }
//this.setFetchedLocation(`${data.name}, ${data.sys.country}`);
const currentWeather = this.generateWeatherObjectFromCurrentWeather(data.properties.periods[0]); const currentWeather = this.generateWeatherObjectFromCurrentWeather(data.properties.periods[0]);
this.setCurrentWeather(currentWeather); this.setCurrentWeather(currentWeather);
}) })
@ -49,8 +47,6 @@ WeatherProvider.register("weathergov", {
return; return;
} }
//this.setFetchedLocation(`${data.city.name}, ${data.city.country}`);
const forecast = this.generateWeatherObjectsFromForecast(data.properties.periods); const forecast = this.generateWeatherObjectsFromForecast(data.properties.periods);
this.setWeatherForecast(forecast); this.setWeatherForecast(forecast);
}) })
@ -73,13 +69,10 @@ WeatherProvider.register("weathergov", {
generateWeatherObjectFromCurrentWeather(currentWeatherData) { generateWeatherObjectFromCurrentWeather(currentWeatherData) {
const currentWeather = new WeatherObject(this.config.units); const currentWeather = new WeatherObject(this.config.units);
//currentWeather.humidity = currentWeatherData.main.humidity;
currentWeather.temperature = currentWeatherData.temperature; currentWeather.temperature = currentWeatherData.temperature;
currentWeather.windSpeed = currentWeatherData.windSpeed.split(" ", 1); currentWeather.windSpeed = currentWeatherData.windSpeed.split(" ", 1);
currentWeather.windDirection = this.convertDirectiontoDegrees(currentWeatherData.windDirection); currentWeather.windDirection = this.convertDirectiontoDegrees(currentWeatherData.windDirection);
currentWeather.weatherType = this.convertWeatherType(currentWeatherData.shortForecast, currentWeatherData.isDaytime); currentWeather.weatherType = this.convertWeatherType(currentWeatherData.shortForecast, currentWeatherData.isDaytime);
//currentWeather.sunrise = moment(currentWeatherData.sys.sunrise, "X");
//currentWeather.sunset = moment(currentWeatherData.sys.sunset, "X");
return currentWeather; return currentWeather;
}, },
@ -98,11 +91,11 @@ WeatherProvider.register("weathergov", {
// initial variable declaration // initial variable declaration
const days = []; const days = [];
// variables for temperature range and rain // variables for temperature range and rain
var minTemp = []; let minTemp = [];
var maxTemp = []; let maxTemp = [];
// variable for date // variable for date
let date = ""; let date = "";
var weather = new WeatherObject(this.config.units); let weather = new WeatherObject(this.config.units);
weather.precipitation = 0; weather.precipitation = 0;
for (const forecast of forecasts) { for (const forecast of forecasts) {
@ -162,53 +155,55 @@ WeatherProvider.register("weathergov", {
if (weatherType.includes("Cloudy") || weatherType.includes("Partly")) { if (weatherType.includes("Cloudy") || weatherType.includes("Partly")) {
if (isDaytime) { if (isDaytime) {
return "day-cloudy"; return "day-cloudy";
} else {
return "night-cloudy";
} }
return "night-cloudy";
} else if (weatherType.includes("Overcast")) { } else if (weatherType.includes("Overcast")) {
if (isDaytime) { if (isDaytime) {
return "cloudy"; return "cloudy";
} else {
return "night-cloudy";
} }
return "night-cloudy";
} else if (weatherType.includes("Freezing") || weatherType.includes("Ice")) { } else if (weatherType.includes("Freezing") || weatherType.includes("Ice")) {
return "rain-mix"; return "rain-mix";
} else if (weatherType.includes("Snow")) { } else if (weatherType.includes("Snow")) {
if (isDaytime) { if (isDaytime) {
return "snow"; return "snow";
} else {
return "night-snow";
} }
return "night-snow";
} else if (weatherType.includes("Thunderstorm")) { } else if (weatherType.includes("Thunderstorm")) {
if (isDaytime) { if (isDaytime) {
return "thunderstorm"; return "thunderstorm";
} else {
return "night-thunderstorm";
} }
return "night-thunderstorm";
} else if (weatherType.includes("Showers")) { } else if (weatherType.includes("Showers")) {
if (isDaytime) { if (isDaytime) {
return "showers"; return "showers";
} else {
return "night-showers";
} }
} else if (weatherType.includes("Rain")) {
return "night-showers";
} else if (weatherType.includes("Rain") || weatherType.includes("Drizzle")) {
if (isDaytime) { if (isDaytime) {
return "rain"; return "rain";
} else {
return "night-rain";
} }
return "night-rain";
} else if (weatherType.includes("Breezy") || weatherType.includes("Windy")) { } else if (weatherType.includes("Breezy") || weatherType.includes("Windy")) {
if (isDaytime) { if (isDaytime) {
return "cloudy-windy"; return "cloudy-windy";
} else {
return "night-alt-cloudy-windy";
} }
} else if (weatherType.includes("Fair") || weatherType.includes("Clear") || weatherType.includes("Few")) {
return "night-alt-cloudy-windy";
} else if (weatherType.includes("Fair") || weatherType.includes("Clear") || weatherType.includes("Few") || weatherType.includes("Sunny")) {
if (isDaytime) { if (isDaytime) {
return "day-sunny"; return "day-sunny";
} else {
return "night-clear";
} }
return "night-clear";
} else if (weatherType.includes("Dust") || weatherType.includes("Sand")) {
return "dust";
} else if (weatherType.includes("Fog")) { } else if (weatherType.includes("Fog")) {
return "fog"; return "fog";
} else if (weatherType.includes("Smoke")) { } else if (weatherType.includes("Smoke")) {
@ -220,15 +215,6 @@ WeatherProvider.register("weathergov", {
return null; return null;
}, },
/* getParams(compliments)
* Generates an url with api parameters based on the config.
*
* return String - URL params.
*/
getParams() {
},
/* /*
Convert the direction into Degrees Convert the direction into Degrees
*/ */