new thunder provider

old one is spotty
This commit is contained in:
Minecon724 2024-06-02 17:52:59 +02:00
parent fc467c9b94
commit dcda0b841a
Signed by: Minecon724
GPG key ID: 3CCC4D267742C8E8
10 changed files with 131 additions and 91 deletions

21
release.properties Normal file
View file

@ -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>${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

View file

@ -1,6 +1,5 @@
package eu.m724.wtapi.thunder; package eu.m724.wtapi.thunder;
import java.util.concurrent.Callable;
import java.util.function.Consumer; import java.util.function.Consumer;
import eu.m724.wtapi.object.Coordinates; import eu.m724.wtapi.object.Coordinates;

View file

@ -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.ArrayList;
import java.util.HashMap;
import java.util.Queue;
import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.DelayQueue;
import java.util.function.Consumer; import java.util.function.Consumer;
import eu.m724.wtapi.object.Coordinates; import eu.m724.wtapi.object.Coordinates;
import eu.m724.wtapi.object.Weather;
import eu.m724.wtapi.provider.exception.ProviderException; import eu.m724.wtapi.provider.exception.ProviderException;
import eu.m724.wtapi.thunder.ThunderProvider; import eu.m724.wtapi.thunder.ThunderProvider;
public class LightningMapsProvider extends ThunderProvider { public class BlitzortungProvider extends ThunderProvider {
LMWebsocketClient websocketClient = new LMWebsocketClient(this); BlitzortungWebsocketClient websocketClient = new BlitzortungWebsocketClient(this);
ArrayList<Consumer<Coordinates>> strikeHandlers = new ArrayList<>(); ArrayList<Consumer<Coordinates>> strikeHandlers = new ArrayList<>();
CopyOnWriteArrayList<TimedStrike> strikes = new CopyOnWriteArrayList<>(); // TODO optimize? CopyOnWriteArrayList<TimedStrike> strikes = new CopyOnWriteArrayList<>(); // TODO optimize?

View file

@ -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<Integer, String> e = new HashMap<>();
char[] d = b.toCharArray();
String c = String.valueOf(d[0]), f = c;
List<String> 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();
}
}

View file

@ -1,9 +1,16 @@
package eu.m724.wtapi.thunder.impl.lightningmaps; package eu.m724.wtapi.thunder.impl.blitzortung;
import eu.m724.wtapi.object.Coordinates; import eu.m724.wtapi.object.Coordinates;
public class TimedStrike { public class TimedStrike {
/**
* unix millis
*/
public long timestamp; public long timestamp;
/**
* coordinates of strike
*/
public Coordinates coordinates; public Coordinates coordinates;
public TimedStrike(long timestamp, Coordinates coordinates) { public TimedStrike(long timestamp, Coordinates coordinates) {

View file

@ -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();
}
}

View file

@ -2,8 +2,6 @@ package eu.m724.wtapi.object;
import org.junit.Test; import org.junit.Test;
import eu.m724.wtapi.object.Coordinates;
public class CoordinateTest { public class CoordinateTest {
@Test @Test
public void testCoordinates() { public void testCoordinates() {

View file

@ -5,18 +5,19 @@ import java.util.ArrayList;
import org.junit.Test; import org.junit.Test;
import eu.m724.wtapi.object.Coordinates; import eu.m724.wtapi.object.Coordinates;
import eu.m724.wtapi.thunder.ThunderProvider; import eu.m724.wtapi.thunder.impl.blitzortung.BlitzortungProvider;
import eu.m724.wtapi.thunder.impl.lightningmaps.LightningMapsProvider;
public class LightningMapsTest { public class BlitzortungTest {
@Test @Test
public void lightningMapsTest() throws InterruptedException { public void lightningMapsTest() throws InterruptedException {
ArrayList<Coordinates> coordinatesList = new ArrayList<>(); ArrayList<Coordinates> coordinatesList = new ArrayList<>();
ThunderProvider provider = new LightningMapsProvider(); ThunderProvider provider = new BlitzortungProvider();
provider.registerStrikeHandler(coordinates -> provider.registerStrikeHandler(coordinates -> {
coordinatesList.add(coordinates)); coordinatesList.add(coordinates);
System.out.printf("%f %f\n", coordinates.latitude, coordinates.longitude);
});
provider.init(); provider.init();

View file

@ -6,8 +6,7 @@ import java.util.function.Consumer;
import eu.m724.wtapi.object.Coordinates; import eu.m724.wtapi.object.Coordinates;
import eu.m724.wtapi.provider.exception.ProviderException; import eu.m724.wtapi.provider.exception.ProviderException;
import eu.m724.wtapi.thunder.ThunderProvider; import eu.m724.wtapi.thunder.impl.blitzortung.TimedStrike;
import eu.m724.wtapi.thunder.impl.lightningmaps.TimedStrike;
public class MockThunderProvider extends ThunderProvider { public class MockThunderProvider extends ThunderProvider {
ArrayList<Consumer<Coordinates>> strikeHandlers = new ArrayList<>(); ArrayList<Consumer<Coordinates>> strikeHandlers = new ArrayList<>();

View file

@ -5,7 +5,6 @@ import java.util.ArrayList;
import org.junit.Test; import org.junit.Test;
import eu.m724.wtapi.object.Coordinates; import eu.m724.wtapi.object.Coordinates;
import eu.m724.wtapi.thunder.ThunderProvider;
public class ThunderProviderTest { public class ThunderProviderTest {
@Test @Test