From 4089c30017991a936bb19f1fb8d2b51f9568a8fb Mon Sep 17 00:00:00 2001 From: Tor-Einar Skog <tor-einar.skog@nibio.no> Date: Mon, 4 Jun 2018 12:39:28 +0200 Subject: [PATCH] Generalized the code to work with more than one weather station, added new alternative channel for RH --- .../no/nibio/vips/util/weather/MetosAPIDataParser.java | 10 +++++----- .../vips/util/weather/MetosAPIDataParserTest.java | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main/java/no/nibio/vips/util/weather/MetosAPIDataParser.java b/src/main/java/no/nibio/vips/util/weather/MetosAPIDataParser.java index e42cc656..0a11e35f 100644 --- a/src/main/java/no/nibio/vips/util/weather/MetosAPIDataParser.java +++ b/src/main/java/no/nibio/vips/util/weather/MetosAPIDataParser.java @@ -81,10 +81,10 @@ public class MetosAPIDataParser { new ParamInfo(WeatherElements.LEAF_WETNESS, new Integer[] {4}, "time"), new ParamInfo(WeatherElements.GLOBAL_RADIATION, new Integer[] {600}, "avg"), new ParamInfo(WeatherElements.WIND_SPEED_2M, new Integer[] {5}, "avg"), - new ParamInfo(WeatherElements.TEMPERATURE_MEAN, new Integer[] {16385}, "avg"), + new ParamInfo(WeatherElements.TEMPERATURE_MEAN, new Integer[] {0,16385}, "avg"), new ParamInfo(WeatherElements.TEMPERATURE_MAXIMUM, new Integer[] {16385}, "max"), new ParamInfo(WeatherElements.TEMPERATURE_MINIMUM, new Integer[] {16385}, "min"), - new ParamInfo(WeatherElements.RELATIVE_HUMIDITY_MEAN, new Integer[] {1,21778}, "avg") + new ParamInfo(WeatherElements.RELATIVE_HUMIDITY_MEAN, new Integer[] {1,507,21778}, "avg") }; @@ -245,7 +245,7 @@ public class MetosAPIDataParser { //System.out.println("Linje"); } - return this.getParsedObservations(all, this.getWeatherStationTimeZone(accessToken)); // TODO TimeZone + return this.getParsedObservations(all, this.getWeatherStationTimeZone(stationId, accessToken)); // TODO TimeZone } catch(IOException | ParseException | AuthenticationException ex) { @@ -253,9 +253,9 @@ public class MetosAPIDataParser { } } - private TimeZone getWeatherStationTimeZone(String accessToken) throws IOException + private TimeZone getWeatherStationTimeZone(String stationId,String accessToken) throws IOException { - HttpGet httpget = new HttpGet("https://api.fieldclimate.com/v1/station/000024A0"); + HttpGet httpget = new HttpGet("https://api.fieldclimate.com/v1/station/" + stationId); httpget.addHeader("Accept", "application/json"); httpget.addHeader("Authorization", "Bearer " + accessToken); CloseableHttpClient httpclient = HttpClients.createDefault(); diff --git a/src/test/java/no/nibio/vips/util/weather/MetosAPIDataParserTest.java b/src/test/java/no/nibio/vips/util/weather/MetosAPIDataParserTest.java index 555d9009..afeb9a16 100644 --- a/src/test/java/no/nibio/vips/util/weather/MetosAPIDataParserTest.java +++ b/src/test/java/no/nibio/vips/util/weather/MetosAPIDataParserTest.java @@ -70,7 +70,7 @@ public class MetosAPIDataParserTest { @Test public void testGetWeatherObservations() throws Exception { System.out.println("getWeatherObservations"); - String stationId = "000024A0"; + String stationId = "000012DE"; TimeZone timeZone = TimeZone.getTimeZone("Europe/Vilnius"); Calendar cal = Calendar.getInstance(); cal.setTimeZone(timeZone); -- GitLab