From dcda0b841a21e59abc6630ecdf357c5d4dbe91e8 Mon Sep 17 00:00:00 2001 From: Minecon724 Date: Sun, 2 Jun 2024 17:52:59 +0200 Subject: [PATCH] new thunder provider old one is spotty --- release.properties | 21 +++++ .../m724/wtapi/thunder/ThunderProvider.java | 1 - .../BlitzortungProvider.java} | 10 +- .../BlitzortungWebsocketClient.java | 91 +++++++++++++++++++ .../TimedStrike.java | 9 +- .../impl/lightningmaps/LMWebsocketClient.java | 71 --------------- .../eu/m724/wtapi/object/CoordinateTest.java | 2 - ...ningMapsTest.java => BlitzortungTest.java} | 13 +-- .../wtapi/thunder/MockThunderProvider.java | 3 +- .../wtapi/thunder/ThunderProviderTest.java | 1 - 10 files changed, 131 insertions(+), 91 deletions(-) create mode 100644 release.properties rename src/main/java/eu/m724/wtapi/thunder/impl/{lightningmaps/LightningMapsProvider.java => blitzortung/BlitzortungProvider.java} (85%) create mode 100644 src/main/java/eu/m724/wtapi/thunder/impl/blitzortung/BlitzortungWebsocketClient.java rename src/main/java/eu/m724/wtapi/thunder/impl/{lightningmaps => blitzortung}/TimedStrike.java (69%) delete mode 100644 src/main/java/eu/m724/wtapi/thunder/impl/lightningmaps/LMWebsocketClient.java rename src/test/java/eu/m724/wtapi/thunder/{LightningMapsTest.java => BlitzortungTest.java} (66%) diff --git a/release.properties b/release.properties new file mode 100644 index 0000000..b2dad3c --- /dev/null +++ b/release.properties @@ -0,0 +1,21 @@ +#release configuration +#Sun Jun 02 17:52:56 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=HEAD +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/thunder/ThunderProvider.java b/src/main/java/eu/m724/wtapi/thunder/ThunderProvider.java index cdf50be..598adb0 100644 --- a/src/main/java/eu/m724/wtapi/thunder/ThunderProvider.java +++ b/src/main/java/eu/m724/wtapi/thunder/ThunderProvider.java @@ -1,6 +1,5 @@ package eu.m724.wtapi.thunder; -import java.util.concurrent.Callable; import java.util.function.Consumer; import eu.m724.wtapi.object.Coordinates; diff --git a/src/main/java/eu/m724/wtapi/thunder/impl/lightningmaps/LightningMapsProvider.java b/src/main/java/eu/m724/wtapi/thunder/impl/blitzortung/BlitzortungProvider.java similarity index 85% rename from src/main/java/eu/m724/wtapi/thunder/impl/lightningmaps/LightningMapsProvider.java rename to src/main/java/eu/m724/wtapi/thunder/impl/blitzortung/BlitzortungProvider.java index d4d57fc..f06d77d 100644 --- a/src/main/java/eu/m724/wtapi/thunder/impl/lightningmaps/LightningMapsProvider.java +++ b/src/main/java/eu/m724/wtapi/thunder/impl/blitzortung/BlitzortungProvider.java @@ -1,19 +1,15 @@ -package eu.m724.wtapi.thunder.impl.lightningmaps; +package eu.m724.wtapi.thunder.impl.blitzortung; import java.util.ArrayList; -import java.util.HashMap; -import java.util.Queue; import java.util.concurrent.CopyOnWriteArrayList; -import java.util.concurrent.DelayQueue; import java.util.function.Consumer; import eu.m724.wtapi.object.Coordinates; -import eu.m724.wtapi.object.Weather; import eu.m724.wtapi.provider.exception.ProviderException; import eu.m724.wtapi.thunder.ThunderProvider; -public class LightningMapsProvider extends ThunderProvider { - LMWebsocketClient websocketClient = new LMWebsocketClient(this); +public class BlitzortungProvider extends ThunderProvider { + BlitzortungWebsocketClient websocketClient = new BlitzortungWebsocketClient(this); ArrayList> strikeHandlers = new ArrayList<>(); CopyOnWriteArrayList strikes = new CopyOnWriteArrayList<>(); // TODO optimize? diff --git a/src/main/java/eu/m724/wtapi/thunder/impl/blitzortung/BlitzortungWebsocketClient.java b/src/main/java/eu/m724/wtapi/thunder/impl/blitzortung/BlitzortungWebsocketClient.java new file mode 100644 index 0000000..9b39322 --- /dev/null +++ b/src/main/java/eu/m724/wtapi/thunder/impl/blitzortung/BlitzortungWebsocketClient.java @@ -0,0 +1,91 @@ +package eu.m724.wtapi.thunder.impl.blitzortung; + +import java.net.URI; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.java_websocket.client.WebSocketClient; +import org.java_websocket.handshake.ServerHandshake; + +import com.google.gson.JsonObject; +import com.google.gson.JsonParser; +import com.google.gson.JsonSyntaxException; + +import eu.m724.wtapi.object.Coordinates; + +class BlitzortungWebsocketClient extends WebSocketClient { + BlitzortungProvider lightningMapsProvider; + + private static URI[] uris = new URI[] { + URI.create("wss://ws1.blitzortung.org/"), + URI.create("wss://ws7.blitzortung.org/"), + URI.create("wss://ws8.blitzortung.org/") + }; + private int currentUri = 0; + + public BlitzortungWebsocketClient(BlitzortungProvider lightningMapsProvider) { + super(uris[0]); + this.lightningMapsProvider = lightningMapsProvider; + } + + @Override + public void onOpen(ServerHandshake handshakedata) { + this.send("{\"a\":111}"); + } + + public static String decode(String b) { // lzw + Map e = new HashMap<>(); + char[] d = b.toCharArray(); + String c = String.valueOf(d[0]), f = c; + List g = new ArrayList<>(); + g.add(c); + int h = 256, o = h; + + for (int i = 1; i < d.length; i++) { + int a = d[i]; + String aStr = (h > a) ? String.valueOf(d[i]) : e.getOrDefault(a, f + c); + g.add(aStr); + c = String.valueOf(aStr.charAt(0)); + e.put(o++, f + c); + f = aStr; + } + + return String.join("", g); + } + + @Override + public void onMessage(String message) { + try { + JsonObject json = + JsonParser.parseString(decode(message)) + .getAsJsonObject(); + + long time = json.getAsJsonPrimitive("time").getAsLong() / 1000000; + double lat = json.getAsJsonPrimitive("lat").getAsDouble(); + double lon = json.getAsJsonPrimitive("lon").getAsDouble(); + + Coordinates coordinates = new Coordinates(lat, lon); + lightningMapsProvider.submitStrike(coordinates, time); + } catch (JsonSyntaxException e) { + // ignore invalid json + } + + } + + @Override + public void onClose(int code, String reason, boolean remote) { + System.out.printf("%s Closed: %d %s\n", this.uri, code, reason); + this.uri = uris[++currentUri % uris.length]; + lightningMapsProvider.reconnect(); + + } + + @Override + public void onError(Exception ex) { + this.uri = uris[++currentUri % uris.length]; + lightningMapsProvider.reconnect(); + } + +} diff --git a/src/main/java/eu/m724/wtapi/thunder/impl/lightningmaps/TimedStrike.java b/src/main/java/eu/m724/wtapi/thunder/impl/blitzortung/TimedStrike.java similarity index 69% rename from src/main/java/eu/m724/wtapi/thunder/impl/lightningmaps/TimedStrike.java rename to src/main/java/eu/m724/wtapi/thunder/impl/blitzortung/TimedStrike.java index 240d092..faa245f 100644 --- a/src/main/java/eu/m724/wtapi/thunder/impl/lightningmaps/TimedStrike.java +++ b/src/main/java/eu/m724/wtapi/thunder/impl/blitzortung/TimedStrike.java @@ -1,9 +1,16 @@ -package eu.m724.wtapi.thunder.impl.lightningmaps; +package eu.m724.wtapi.thunder.impl.blitzortung; import eu.m724.wtapi.object.Coordinates; public class TimedStrike { + /** + * unix millis + */ public long timestamp; + + /** + * coordinates of strike + */ public Coordinates coordinates; public TimedStrike(long timestamp, Coordinates coordinates) { diff --git a/src/main/java/eu/m724/wtapi/thunder/impl/lightningmaps/LMWebsocketClient.java b/src/main/java/eu/m724/wtapi/thunder/impl/lightningmaps/LMWebsocketClient.java deleted file mode 100644 index 702afd9..0000000 --- a/src/main/java/eu/m724/wtapi/thunder/impl/lightningmaps/LMWebsocketClient.java +++ /dev/null @@ -1,71 +0,0 @@ -package eu.m724.wtapi.thunder.impl.lightningmaps; - -import java.net.URI; - -import org.java_websocket.client.WebSocketClient; -import org.java_websocket.handshake.ServerHandshake; - -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import com.google.gson.JsonParser; -import com.google.gson.JsonSyntaxException; - -import eu.m724.wtapi.object.Coordinates; - -class LMWebsocketClient extends WebSocketClient { - LightningMapsProvider lightningMapsProvider; - - private static URI[] uris = new URI[] { - URI.create("wss://live.lightningmaps.org/"), - URI.create("wss://live2.lightningmaps.org/") - }; - private int currentUri = 0; - - public LMWebsocketClient(LightningMapsProvider lightningMapsProvider) { - super(uris[0]); - this.lightningMapsProvider = lightningMapsProvider; - } - - @Override - public void onOpen(ServerHandshake handshakedata) { - this.send("{\"v\":24,\"i\":{},\"s\":false,\"x\":0,\"w\":4,\"tx\":0,\"tw\":3,\"a\":4,\"z\":2,\"b\":true,\"h\":\"#m=oss;t=3;s=0;o=0;b=;ts=0;z=2;y=45.4601;x=17.5814;d=2;dl=2;dc=0;\",\"l\":5,\"t\":5,\"from_lightningmaps_org\":true,\"p\":[87,309,-72.5,-273.9],\"r\":\"re\"}"); - } - - @Override - public void onMessage(String message) { - try { - JsonObject json = - JsonParser.parseString(message) - .getAsJsonObject(); - - if (!json.has("strokes")) return; - - json.getAsJsonArray("strokes").forEach(ele -> { - long time = ele.getAsJsonObject().getAsJsonPrimitive("time").getAsLong(); - double lat = ele.getAsJsonObject().getAsJsonPrimitive("lat").getAsDouble(); - double lon = ele.getAsJsonObject().getAsJsonPrimitive("lon").getAsDouble(); - - Coordinates coordinates = new Coordinates(lat, lon); - lightningMapsProvider.submitStrike(coordinates, time); - }); - } catch (JsonSyntaxException e) { - // ignore invalid json - } - - } - - @Override - public void onClose(int code, String reason, boolean remote) { - System.out.printf("%s Closed: %d %s\n", this.uri, code, reason); - this.uri = uris[++currentUri % 2]; - lightningMapsProvider.reconnect(); - - } - - @Override - public void onError(Exception ex) { - this.uri = uris[++currentUri % 2]; - lightningMapsProvider.reconnect(); - } - -} diff --git a/src/test/java/eu/m724/wtapi/object/CoordinateTest.java b/src/test/java/eu/m724/wtapi/object/CoordinateTest.java index 748c34d..ca2dfa1 100644 --- a/src/test/java/eu/m724/wtapi/object/CoordinateTest.java +++ b/src/test/java/eu/m724/wtapi/object/CoordinateTest.java @@ -2,8 +2,6 @@ package eu.m724.wtapi.object; import org.junit.Test; -import eu.m724.wtapi.object.Coordinates; - public class CoordinateTest { @Test public void testCoordinates() { diff --git a/src/test/java/eu/m724/wtapi/thunder/LightningMapsTest.java b/src/test/java/eu/m724/wtapi/thunder/BlitzortungTest.java similarity index 66% rename from src/test/java/eu/m724/wtapi/thunder/LightningMapsTest.java rename to src/test/java/eu/m724/wtapi/thunder/BlitzortungTest.java index ba02ae9..65f56e1 100644 --- a/src/test/java/eu/m724/wtapi/thunder/LightningMapsTest.java +++ b/src/test/java/eu/m724/wtapi/thunder/BlitzortungTest.java @@ -5,18 +5,19 @@ import java.util.ArrayList; import org.junit.Test; import eu.m724.wtapi.object.Coordinates; -import eu.m724.wtapi.thunder.ThunderProvider; -import eu.m724.wtapi.thunder.impl.lightningmaps.LightningMapsProvider; +import eu.m724.wtapi.thunder.impl.blitzortung.BlitzortungProvider; -public class LightningMapsTest { +public class BlitzortungTest { @Test public void lightningMapsTest() throws InterruptedException { ArrayList coordinatesList = new ArrayList<>(); - ThunderProvider provider = new LightningMapsProvider(); + ThunderProvider provider = new BlitzortungProvider(); - provider.registerStrikeHandler(coordinates -> - coordinatesList.add(coordinates)); + provider.registerStrikeHandler(coordinates -> { + coordinatesList.add(coordinates); + System.out.printf("%f %f\n", coordinates.latitude, coordinates.longitude); + }); provider.init(); diff --git a/src/test/java/eu/m724/wtapi/thunder/MockThunderProvider.java b/src/test/java/eu/m724/wtapi/thunder/MockThunderProvider.java index e661c70..4976d5b 100644 --- a/src/test/java/eu/m724/wtapi/thunder/MockThunderProvider.java +++ b/src/test/java/eu/m724/wtapi/thunder/MockThunderProvider.java @@ -6,8 +6,7 @@ import java.util.function.Consumer; import eu.m724.wtapi.object.Coordinates; import eu.m724.wtapi.provider.exception.ProviderException; -import eu.m724.wtapi.thunder.ThunderProvider; -import eu.m724.wtapi.thunder.impl.lightningmaps.TimedStrike; +import eu.m724.wtapi.thunder.impl.blitzortung.TimedStrike; public class MockThunderProvider extends ThunderProvider { ArrayList> strikeHandlers = new ArrayList<>(); diff --git a/src/test/java/eu/m724/wtapi/thunder/ThunderProviderTest.java b/src/test/java/eu/m724/wtapi/thunder/ThunderProviderTest.java index a02a45a..dce3efa 100644 --- a/src/test/java/eu/m724/wtapi/thunder/ThunderProviderTest.java +++ b/src/test/java/eu/m724/wtapi/thunder/ThunderProviderTest.java @@ -5,7 +5,6 @@ import java.util.ArrayList; import org.junit.Test; import eu.m724.wtapi.object.Coordinates; -import eu.m724.wtapi.thunder.ThunderProvider; public class ThunderProviderTest { @Test