From bcd006acf361bee13f24296a01e521c8bd9e8cd6 Mon Sep 17 00:00:00 2001 From: Matthew Oslan Date: Tue, 21 May 2019 22:35:53 -0400 Subject: [PATCH] Add WeatherProvider ID to returned data --- routes/weatherProviders/DarkSky.ts | 2 ++ routes/weatherProviders/OWM.ts | 2 ++ types.ts | 6 ++++++ 3 files changed, 10 insertions(+) diff --git a/routes/weatherProviders/DarkSky.ts b/routes/weatherProviders/DarkSky.ts index c934d94..b5acddd 100644 --- a/routes/weatherProviders/DarkSky.ts +++ b/routes/weatherProviders/DarkSky.ts @@ -19,6 +19,7 @@ async function getDarkSkyWateringData( coordinates: GeoCoordinates ): Promise< W } return { + weatherProvider: "DarkSky", // Calculate average temperature for the day using hourly data. temp : historicData.hourly.data.reduce( ( sum, hourlyData ) => sum + hourlyData.temperature, 0 ) / historicData.hourly.data.length, humidity: historicData.daily.data[ 0 ].humidity * 100, @@ -40,6 +41,7 @@ async function getDarkSkyWeatherData( coordinates: GeoCoordinates ): Promise< We } const weather: WeatherData = { + weatherProvider: "DarkSky", temp: Math.floor( forecast.currently.temperature ), humidity: Math.floor( forecast.currently.humidity * 100 ), wind: Math.floor( forecast.currently.windSpeed ), diff --git a/routes/weatherProviders/OWM.ts b/routes/weatherProviders/OWM.ts index d225d1e..096fae2 100644 --- a/routes/weatherProviders/OWM.ts +++ b/routes/weatherProviders/OWM.ts @@ -31,6 +31,7 @@ async function getOWMWateringData( coordinates: GeoCoordinates ): Promise< Water } return { + weatherProvider: "OWM", temp: totalTemp / periods, humidity: totalHumidity / periods, precip: totalPrecip / 25.4, @@ -58,6 +59,7 @@ async function getOWMWeatherData( coordinates: GeoCoordinates ): Promise< Weathe } const weather: WeatherData = { + weatherProvider: "OWM", temp: parseInt( current.main.temp ), humidity: parseInt( current.main.humidity ), wind: parseInt( current.wind.speed ), diff --git a/types.ts b/types.ts index 5f94ab5..ada033a 100644 --- a/types.ts +++ b/types.ts @@ -13,6 +13,8 @@ export interface TimeData { } export interface WeatherData { + /** The WeatherProvider that generated this data. */ + weatherProvider: WeatherProviderId; /** The current temperature (in Fahrenheit). */ temp: number; /** The current humidity (as a percentage). */ @@ -54,6 +56,8 @@ export interface WeatherDataForecast { * available. */ export interface WateringData { + /** The WeatherProvider that generated this data. */ + weatherProvider: WeatherProviderId; /** The average temperature over the window (in Fahrenheit). */ temp: number; /** The average humidity over the window (as a percentage). */ @@ -98,3 +102,5 @@ export interface WeatherProvider { */ getWeatherData( coordinates : GeoCoordinates ): Promise< WeatherData >; } + +export type WeatherProviderId = "OWM" | "DarkSky";