From cbe97329b2191dba9f913dae7e7c8dc04547ec77 Mon Sep 17 00:00:00 2001 From: Minecon724 Date: Sat, 22 Jun 2024 12:52:19 +0200 Subject: [PATCH] city in coordinates --- release.properties | 21 +++++++++++++++++++ .../eu/m724/wtapi/object/Coordinates.java | 11 ++++++++++ .../java/eu/m724/wtapi/object/Weather.java | 2 -- .../openweathermap/OWMResponseConverter.java | 11 +++++----- .../eu/m724/wtapi/object/CoordinateTest.java | 6 +++++- .../wtapi/weather/OpenWeatherMapTest.java | 4 ++-- 6 files changed, 45 insertions(+), 10 deletions(-) create mode 100644 release.properties diff --git a/release.properties b/release.properties new file mode 100644 index 0000000..74922f2 --- /dev/null +++ b/release.properties @@ -0,0 +1,21 @@ +#release configuration +#Sat Jun 22 12:52:10 CEST 2024 +completedPhase=check-poms +exec.pomFileName=pom.xml +exec.snapshotReleasePluginAllowed=false +pinExternals=false +preparationGoals=clean verify +project.scm.eu.m724\:wtapi.developerConnection=scm\:git\:git@git.724.rocks\:Minecon724/wtapi.git +project.scm.eu.m724\:wtapi.tag=wtapi-0.5 +projectVersionPolicyConfig=${projectVersionPolicyConfig}\n +projectVersionPolicyId=default +pushChanges=true +releaseStrategyId=default +remoteTagging=true +scm.branchCommitComment=@{prefix} prepare branch @{releaseLabel} +scm.commentPrefix=[maven-release-plugin] +scm.developmentCommitComment=@{prefix} prepare for next development iteration +scm.releaseCommitComment=@{prefix} prepare release @{releaseLabel} +scm.rollbackCommitComment=@{prefix} rollback the release of @{releaseLabel} +scm.tagNameFormat=@{project.artifactId}-@{project.version} +scm.url=scm\:git\:git@git.724.rocks\:Minecon724/wtapi.git diff --git a/src/main/java/eu/m724/wtapi/object/Coordinates.java b/src/main/java/eu/m724/wtapi/object/Coordinates.java index 8cd69cc..8e8479d 100644 --- a/src/main/java/eu/m724/wtapi/object/Coordinates.java +++ b/src/main/java/eu/m724/wtapi/object/Coordinates.java @@ -6,9 +6,20 @@ package eu.m724.wtapi.object; */ public class Coordinates { public double latitude, longitude; + public String country, city; // TODO should it stay here? public Coordinates(double latitude, double longitude) { this.latitude = (((latitude + 90) % 180) + 180) % 180 - 90; this.longitude = (((longitude + 180) % 360) + 360) % 360 - 180; } + + public Coordinates setAddress(String country, String city) { + this.country = country; + this.city = city; + return this; + } + + public String getAddress() { + return city + ", " + country; + } } diff --git a/src/main/java/eu/m724/wtapi/object/Weather.java b/src/main/java/eu/m724/wtapi/object/Weather.java index 2853f28..76400b9 100644 --- a/src/main/java/eu/m724/wtapi/object/Weather.java +++ b/src/main/java/eu/m724/wtapi/object/Weather.java @@ -33,8 +33,6 @@ public class Weather { */ public long sunrise, sunset; - public String city; - /** * short name of weather */ diff --git a/src/main/java/eu/m724/wtapi/provider/weather/impl/openweathermap/OWMResponseConverter.java b/src/main/java/eu/m724/wtapi/provider/weather/impl/openweathermap/OWMResponseConverter.java index c1e57b9..ea6649c 100644 --- a/src/main/java/eu/m724/wtapi/provider/weather/impl/openweathermap/OWMResponseConverter.java +++ b/src/main/java/eu/m724/wtapi/provider/weather/impl/openweathermap/OWMResponseConverter.java @@ -167,11 +167,16 @@ public class OWMResponseConverter { break; } + String city = json.getAsJsonPrimitive("name").getAsString(); + if (city.equals("Globe") || city.equals("")) city = null; + JsonPrimitive countryJson = json.getAsJsonObject("sys").getAsJsonPrimitive("country"); + String country = countryJson != null ? countryJson.getAsString() : null; + weather.coordinates = new Coordinates( json.getAsJsonObject("coord").getAsJsonPrimitive("lon").getAsDouble(), json.getAsJsonObject("coord").getAsJsonPrimitive("lat").getAsDouble() - ); + ).setAddress(country, city); weather.temperature = json .getAsJsonObject("main") @@ -215,10 +220,6 @@ public class OWMResponseConverter { .getAsJsonPrimitive("sunrise") .getAsLong(); - weather.city = json - .getAsJsonPrimitive("name") - .getAsString(); - weather.description = json .getAsJsonArray("weather") .get(0).getAsJsonObject() diff --git a/src/test/java/eu/m724/wtapi/object/CoordinateTest.java b/src/test/java/eu/m724/wtapi/object/CoordinateTest.java index ca2dfa1..6ed05ae 100644 --- a/src/test/java/eu/m724/wtapi/object/CoordinateTest.java +++ b/src/test/java/eu/m724/wtapi/object/CoordinateTest.java @@ -13,6 +13,10 @@ public class CoordinateTest { assert coordinates.longitude == -179.99; coordinates = new Coordinates(-91.1, 180.1); - assert coordinates.longitude != -179.9; // TODO + System.out.printf("Precision loss expected: %f\n", coordinates.longitude); + assert coordinates.longitude != -179.9; // TODO fix precision loss + + coordinates.setAddress("SQ", "San Escobar"); + assert coordinates.getAddress().equals("San Escobar, SQ"); } } diff --git a/src/test/java/eu/m724/wtapi/weather/OpenWeatherMapTest.java b/src/test/java/eu/m724/wtapi/weather/OpenWeatherMapTest.java index 506a4c2..ceabd06 100644 --- a/src/test/java/eu/m724/wtapi/weather/OpenWeatherMapTest.java +++ b/src/test/java/eu/m724/wtapi/weather/OpenWeatherMapTest.java @@ -27,7 +27,7 @@ public class OpenWeatherMapTest { Weather weather = weatherFuture.get(); assertNotNull(weather); - System.out.printf("current weather in %s: %s\n", weather.city, weather.description); + System.out.printf("current weather in %s, %s: %s\n", weather.coordinates.city, weather.coordinates.country, weather.description); CompletableFuture weatherBulkFuture = provider.getWeatherBulk( @@ -41,7 +41,7 @@ public class OpenWeatherMapTest { assert weathers.length == 3; for (Weather weather1 : weathers) { - System.out.printf("current weather in %s: %s\n", weather1.city, weather1.description); + System.out.printf("current weather in %s, %s: %s\n", weather.coordinates.city, weather.coordinates.country, weather1.description); } } }