Add WeatherProvider ID to returned data

This commit is contained in:
Matthew Oslan
2019-05-21 22:35:53 -04:00
parent 0e23e56817
commit bcd006acf3
3 changed files with 10 additions and 0 deletions

View File

@@ -19,6 +19,7 @@ async function getDarkSkyWateringData( coordinates: GeoCoordinates ): Promise< W
} }
return { return {
weatherProvider: "DarkSky",
// Calculate average temperature for the day using hourly data. // Calculate average temperature for the day using hourly data.
temp : historicData.hourly.data.reduce( ( sum, hourlyData ) => sum + hourlyData.temperature, 0 ) / historicData.hourly.data.length, temp : historicData.hourly.data.reduce( ( sum, hourlyData ) => sum + hourlyData.temperature, 0 ) / historicData.hourly.data.length,
humidity: historicData.daily.data[ 0 ].humidity * 100, humidity: historicData.daily.data[ 0 ].humidity * 100,
@@ -40,6 +41,7 @@ async function getDarkSkyWeatherData( coordinates: GeoCoordinates ): Promise< We
} }
const weather: WeatherData = { const weather: WeatherData = {
weatherProvider: "DarkSky",
temp: Math.floor( forecast.currently.temperature ), temp: Math.floor( forecast.currently.temperature ),
humidity: Math.floor( forecast.currently.humidity * 100 ), humidity: Math.floor( forecast.currently.humidity * 100 ),
wind: Math.floor( forecast.currently.windSpeed ), wind: Math.floor( forecast.currently.windSpeed ),

View File

@@ -31,6 +31,7 @@ async function getOWMWateringData( coordinates: GeoCoordinates ): Promise< Water
} }
return { return {
weatherProvider: "OWM",
temp: totalTemp / periods, temp: totalTemp / periods,
humidity: totalHumidity / periods, humidity: totalHumidity / periods,
precip: totalPrecip / 25.4, precip: totalPrecip / 25.4,
@@ -58,6 +59,7 @@ async function getOWMWeatherData( coordinates: GeoCoordinates ): Promise< Weathe
} }
const weather: WeatherData = { const weather: WeatherData = {
weatherProvider: "OWM",
temp: parseInt( current.main.temp ), temp: parseInt( current.main.temp ),
humidity: parseInt( current.main.humidity ), humidity: parseInt( current.main.humidity ),
wind: parseInt( current.wind.speed ), wind: parseInt( current.wind.speed ),

View File

@@ -13,6 +13,8 @@ export interface TimeData {
} }
export interface WeatherData { export interface WeatherData {
/** The WeatherProvider that generated this data. */
weatherProvider: WeatherProviderId;
/** The current temperature (in Fahrenheit). */ /** The current temperature (in Fahrenheit). */
temp: number; temp: number;
/** The current humidity (as a percentage). */ /** The current humidity (as a percentage). */
@@ -54,6 +56,8 @@ export interface WeatherDataForecast {
* available. * available.
*/ */
export interface WateringData { export interface WateringData {
/** The WeatherProvider that generated this data. */
weatherProvider: WeatherProviderId;
/** The average temperature over the window (in Fahrenheit). */ /** The average temperature over the window (in Fahrenheit). */
temp: number; temp: number;
/** The average humidity over the window (as a percentage). */ /** The average humidity over the window (as a percentage). */
@@ -98,3 +102,5 @@ export interface WeatherProvider {
*/ */
getWeatherData( coordinates : GeoCoordinates ): Promise< WeatherData >; getWeatherData( coordinates : GeoCoordinates ): Promise< WeatherData >;
} }
export type WeatherProviderId = "OWM" | "DarkSky";