diff --git a/src/main/java/eu/m724/wtapi/object/Coordinates.java b/src/main/java/eu/m724/wtapi/object/Coordinates.java index 005fedb..8cd69cc 100644 --- a/src/main/java/eu/m724/wtapi/object/Coordinates.java +++ b/src/main/java/eu/m724/wtapi/object/Coordinates.java @@ -8,7 +8,7 @@ public class Coordinates { public double latitude, longitude; public Coordinates(double latitude, double longitude) { - this.latitude = latitude; - this.longitude = longitude; + this.latitude = (((latitude + 90) % 180) + 180) % 180 - 90; + this.longitude = (((longitude + 180) % 360) + 360) % 360 - 180; } } diff --git a/src/main/java/eu/m724/wtapi/object/Weather.java b/src/main/java/eu/m724/wtapi/object/Weather.java index d0ec63e..2853f28 100644 --- a/src/main/java/eu/m724/wtapi/object/Weather.java +++ b/src/main/java/eu/m724/wtapi/object/Weather.java @@ -4,11 +4,52 @@ package eu.m724.wtapi.object; * contains weather conditions */ public class Weather { - public WeatherState weatherState; - public float level = 1; - - public Weather(WeatherState weatherState, float level) { - this.weatherState = weatherState; - this.level = level; + public Coordinates coordinates; + + public Severity rainSeverity, thunderstormSeverity, snowSeverity; + + // secondary conditions + public Severity sleetSeverity, drizzleSeverity; + + public boolean shower; + + /** + * in kelvin + */ + public float temperature, temperatureApparent; + + /** + * in meters per second + */ + public float windSpeed, windGust; + + /** + * 0.0 - 1.0 + */ + public float humidity, cloudiness; + + /** + * as unix timestamp + */ + public long sunrise, sunset; + + public String city; + + /** + * short name of weather + */ + public String description; + + + public boolean isRaining() { + return rainSeverity != null; + } + + public boolean isThundering() { + return thunderstormSeverity != null; + } + + public boolean isSnowing() { + return snowSeverity != null; } } diff --git a/src/main/java/eu/m724/wtapi/provider/WeatherProvider.java b/src/main/java/eu/m724/wtapi/provider/WeatherProvider.java index ceda810..c837843 100644 --- a/src/main/java/eu/m724/wtapi/provider/WeatherProvider.java +++ b/src/main/java/eu/m724/wtapi/provider/WeatherProvider.java @@ -1,6 +1,5 @@ package eu.m724.wtapi.provider; -import java.time.Duration; import java.util.concurrent.CompletableFuture; import eu.m724.wtapi.object.Coordinates; @@ -39,10 +38,11 @@ public abstract class WeatherProvider { public abstract int getQuotaHourly(); /** - * how many requests actually took place last time you called a method - * @return amount of requests, 0 if no calls happened + * how many coordinates in one bulk request + * this is because some apis don't support bulk or limit it + * @return amount of coordinates per bulk request */ - public abstract int getLastRequestQuota(); + public abstract int getBulkLimit(); /** * estimates minimum delay between calls given last request diff --git a/src/main/java/eu/m724/wtapi/provider/exception/ProviderException.java b/src/main/java/eu/m724/wtapi/provider/exception/ProviderException.java index 0802ec0..ee5e7f7 100644 --- a/src/main/java/eu/m724/wtapi/provider/exception/ProviderException.java +++ b/src/main/java/eu/m724/wtapi/provider/exception/ProviderException.java @@ -1,8 +1,8 @@ package eu.m724.wtapi.provider.exception; -import java.util.concurrent.ExecutionException; +import java.util.concurrent.CompletionException; -public class ProviderException extends ExecutionException { +public class ProviderException extends CompletionException { private static final long serialVersionUID = -841882181122537157L; diff --git a/src/test/java/eu/m724/wtapi/ProviderTest.java b/src/test/java/eu/m724/wtapi/ProviderTest.java index 301b52b..bfe5cdb 100644 --- a/src/test/java/eu/m724/wtapi/ProviderTest.java +++ b/src/test/java/eu/m724/wtapi/ProviderTest.java @@ -22,8 +22,9 @@ public class ProviderTest { public void testProvider() throws InterruptedException, ExecutionException { WeatherProvider provider = new MockWeatherProvider(false); provider.init(); + assert provider.getQuotaHourly() == 5; - assert provider.getLastRequestQuota() == 0; + assert provider.getBulkLimit() == 1; CompletableFuture weatherFuture = provider.getWeather(new Coordinates(0, 0)); @@ -31,9 +32,6 @@ public class ProviderTest { Weather weather = weatherFuture.get(); assertNotNull(weather); - assert provider.getLastRequestQuota() == 1; - - CompletableFuture weathersFuture = provider.getWeatherBulk(new Coordinates[] { new Coordinates(0, 0), @@ -45,14 +43,11 @@ public class ProviderTest { assert weathers.length == 2; assertNotNull(weathers[0]); assertNotNull(weathers[1]); - - assert provider.getLastRequestQuota() == 2; } @Test public void testFaultyProvider() throws InterruptedException { WeatherProvider provider = new MockWeatherProvider(true); - assert provider.getLastRequestQuota() == 0; CompletableFuture weatherFuture = provider.getWeather(new Coordinates(0, 0)); @@ -68,9 +63,6 @@ public class ProviderTest { assertNull(weather); - assert provider.getLastRequestQuota() == 1; - - Weather[] weathers = null; CompletableFuture weathersFuture = @@ -87,7 +79,6 @@ public class ProviderTest { assert qee.getRetryIn() == 60; } - assert provider.getLastRequestQuota() == 2; assertNull(weathers); } diff --git a/src/test/java/eu/m724/wtapi/impl/MockWeatherProvider.java b/src/test/java/eu/m724/wtapi/impl/MockWeatherProvider.java index 97a7872..d554ce1 100644 --- a/src/test/java/eu/m724/wtapi/impl/MockWeatherProvider.java +++ b/src/test/java/eu/m724/wtapi/impl/MockWeatherProvider.java @@ -1,20 +1,14 @@ package eu.m724.wtapi.impl; -import java.time.Duration; -import java.time.temporal.TemporalUnit; import java.util.concurrent.CompletableFuture; -import java.util.function.Supplier; - import eu.m724.wtapi.object.Coordinates; import eu.m724.wtapi.object.Weather; -import eu.m724.wtapi.object.WeatherState; import eu.m724.wtapi.provider.WeatherProvider; import eu.m724.wtapi.provider.exception.ProviderException; import eu.m724.wtapi.provider.exception.QuotaExceededException; import eu.m724.wtapi.provider.exception.ServerProviderException; public class MockWeatherProvider extends WeatherProvider { - private int req; // THIS IS NOT HOW IT SHOULD BE DONE private boolean faulty; public MockWeatherProvider(boolean faulty) { @@ -28,8 +22,6 @@ public class MockWeatherProvider extends WeatherProvider { @Override public CompletableFuture getWeather(Coordinates coordinates) { - req++; - if (coordinates == null) throw new NullPointerException("no coordinates passed"); @@ -42,7 +34,7 @@ public class MockWeatherProvider extends WeatherProvider { if (faulty) completableFuture.completeExceptionally(new ServerProviderException("server is on vacation rn")); else - completableFuture.complete(new Weather(WeatherState.CLEAR, 0)); + completableFuture.complete(new Weather()); return completableFuture; } @@ -50,7 +42,6 @@ public class MockWeatherProvider extends WeatherProvider { @Override public CompletableFuture getWeatherBulk(Coordinates[] coordinateses) { int len = coordinateses.length; - req++; if (len == 0) throw new IllegalArgumentException("no coordinates passed"); @@ -67,7 +58,7 @@ public class MockWeatherProvider extends WeatherProvider { if (coordinateses[i] == null) throw new IllegalArgumentException("a coordinate is null"); - weathers[i] = new Weather(WeatherState.CLEAR, 1); + weathers[i] = new Weather(); } if (faulty) @@ -84,8 +75,8 @@ public class MockWeatherProvider extends WeatherProvider { } @Override - public int getLastRequestQuota() { - return this.req; // ONCE AGAIN TJHIS IS NOT HOW IT SHOULD BE DONE + public int getBulkLimit() { + return 1; } }