Skip to content
This repository has been archived by the owner on Jan 15, 2025. It is now read-only.

Commit

Permalink
sending of advanced hypocenter data
Browse files Browse the repository at this point in the history
  • Loading branch information
xspanger3770 committed Oct 24, 2023
1 parent 005b21b commit ecbb698
Show file tree
Hide file tree
Showing 23 changed files with 119 additions and 59 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package gqserver.core.earthquake.quality;
package globalquake.earthquake.quality;

public class Quality {
private static final double[] THRESHOLDS_ORIGIN = {1.0, 2.5, 10.0, 30.0};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package gqserver.core.earthquake.quality;
package globalquake.earthquake.quality;

import java.awt.*;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package gqserver.core.earthquake.quality;
package globalquake.earthquake.quality;

public final class QualityCriteria {

Expand Down
4 changes: 2 additions & 2 deletions GlobalQuakeAPI/src/main/java/gqserver/api/Packet.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import java.io.IOException;
import java.io.Serializable;

public abstract class Packet implements Serializable {
public interface Packet extends Serializable {

public void onServerReceive(ServerClient serverClient) throws IOException {}
default void onServerReceive(ServerClient serverClient) throws IOException {};

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package gqserver.api;

import gqserver.api.data.ServerClientConfig;
import gqserver.api.data.system.ServerClientConfig;
import gqserver.api.exception.UnknownPacketException;

import java.io.IOException;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package gqserver.api.data;
package gqserver.api.data.earthquake;

import java.io.Serializable;
import java.util.UUID;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package gqserver.api.data.earthquake;

import java.io.Serializable;
import java.util.UUID;

public record HypocenterData(UUID uuid, int revisionID, float lat, float lon, float depth, long origin, float magnitude) implements Serializable {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package gqserver.api.data.earthquake.advanced;

import java.io.Serializable;

public record AdvancedHypocenterData(HypocenterQualityData qualityData,
DepthConfidenceIntervalData depthIntervalData,
LocationConfidenceIntervalData locationConfidenceIntervalData) implements Serializable {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package gqserver.api.data.earthquake.advanced;

import java.io.Serializable;

public record DepthConfidenceIntervalData(float minDepth, float maxDepth) implements Serializable {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package gqserver.api.data.earthquake.advanced;

import java.io.Serializable;

public record HypocenterQualityData(float errOrigin, float errDepth, float errNS, float errEW, int stations, float pct) implements Serializable {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package gqserver.api.data.earthquake.advanced;

import java.io.Serializable;
import java.util.List;

public record LocationConfidenceIntervalData(List<PolygonConfidenceIntervalData> polygonConfidenceIntervalDataList) implements Serializable {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package gqserver.api.data.earthquake.advanced;

import java.io.Serializable;
import java.util.List;

public record PolygonConfidenceIntervalData(int n, float offset, List<Float> lengths) implements Serializable {
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package gqserver.api.data;
package gqserver.api.data.system;

import java.io.Serializable;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,8 @@
package gqserver.api.packets.earthquake;

import gqserver.api.Packet;
import gqserver.api.data.EarthquakeInfo;
import gqserver.api.data.earthquake.EarthquakeInfo;

public class EarthquakeCheckPacket extends Packet {
public record EarthquakeCheckPacket(EarthquakeInfo info) implements Packet {

private final EarthquakeInfo info;

public EarthquakeCheckPacket(EarthquakeInfo info){
this.info = info;
}

public EarthquakeInfo getInfo() {
return info;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,6 @@

import java.util.UUID;

public class EarthquakeRequestPacket extends Packet {
public record EarthquakeRequestPacket(UUID uuid) implements Packet {

private final UUID uuid;

public EarthquakeRequestPacket(UUID uuid){
this.uuid = uuid;
}

public UUID getUuid() {
return uuid;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

import gqserver.api.Packet;

public class EarthquakesRequestPacket extends Packet {
public record EarthquakesRequestPacket() implements Packet {

}
Original file line number Diff line number Diff line change
@@ -1,17 +1,9 @@
package gqserver.api.packets.earthquake;

import gqserver.api.Packet;
import gqserver.api.data.HypocenterData;
import gqserver.api.data.earthquake.HypocenterData;
import gqserver.api.data.earthquake.advanced.AdvancedHypocenterData;

public class HypocenterDataPacket extends Packet {
public record HypocenterDataPacket(HypocenterData data, AdvancedHypocenterData advancedHypocenterData) implements Packet {

private final HypocenterData data;

public HypocenterDataPacket(HypocenterData data){
this.data = data;
}

public HypocenterData getData() {
return data;
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package gqserver.api.packets.system;

import gqserver.api.Packet;
import gqserver.api.data.ServerClientConfig;
import gqserver.api.data.system.ServerClientConfig;

public class HandshakePacket extends Packet {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package gqserver.core.earthquake.data;

import globalquake.earthquake.quality.Quality;
import gqserver.core.earthquake.interval.DepthConfidenceInterval;
import gqserver.core.earthquake.interval.PolygonConfidenceInterval;
import gqserver.core.earthquake.quality.*;

import java.util.List;

Expand Down
64 changes: 57 additions & 7 deletions GlobalQuakeServerUI/src/main/java/gqserver/server/DataService.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
package gqserver.server;

import globalquake.earthquake.quality.Quality;
import gqserver.api.Packet;
import gqserver.api.ServerClient;
import gqserver.api.data.EarthquakeInfo;
import gqserver.api.data.HypocenterData;
import gqserver.api.data.earthquake.EarthquakeInfo;
import gqserver.api.data.earthquake.HypocenterData;
import gqserver.api.data.earthquake.advanced.*;
import gqserver.api.packets.earthquake.EarthquakeCheckPacket;
import gqserver.api.packets.earthquake.EarthquakeRequestPacket;
import gqserver.api.packets.earthquake.EarthquakesRequestPacket;
import gqserver.api.packets.earthquake.HypocenterDataPacket;
import gqserver.core.GlobalQuakeServer;
import gqserver.core.earthquake.data.Earthquake;
import gqserver.core.earthquake.data.Hypocenter;
import gqserver.core.earthquake.interval.DepthConfidenceInterval;
import gqserver.core.earthquake.interval.PolygonConfidenceInterval;
import gqserver.events.GlobalQuakeEventAdapter;
import gqserver.events.specific.QuakeCreateEvent;
import gqserver.events.specific.QuakeRemoveEvent;
Expand All @@ -26,6 +31,7 @@
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;
import java.util.stream.Collectors;

public class DataService {

Expand Down Expand Up @@ -114,10 +120,54 @@ private boolean existsQuake(UUID uuid) {
}

private Packet createQuakePacket(Earthquake earthquake) {
return new HypocenterDataPacket(new HypocenterData(
earthquake.getUuid(),earthquake.getRevisionID(), earthquake.getLat(), earthquake.getLon(),
earthquake.getDepth(),earthquake.getOrigin(), earthquake.getMag())
);
return new HypocenterDataPacket(createHypocenterData(earthquake), createAdvancedHypocenterData(earthquake));
}

private AdvancedHypocenterData createAdvancedHypocenterData(Earthquake earthquake) {
Hypocenter hypocenter = earthquake.getHypocenter();
if(hypocenter == null || hypocenter.quality == null ||
hypocenter.polygonConfidenceIntervals == null || hypocenter.depthConfidenceInterval == null){
return null;
}

return new AdvancedHypocenterData(
createQualityData(hypocenter.quality),
createDepthConfidenceData(hypocenter.depthConfidenceInterval),
createLocationConfidenceData(hypocenter.polygonConfidenceIntervals));
}

private LocationConfidenceIntervalData createLocationConfidenceData(List<PolygonConfidenceInterval> intervals) {
List<PolygonConfidenceIntervalData> list = new ArrayList<>();
for(PolygonConfidenceInterval interval : intervals){
list.add(new PolygonConfidenceIntervalData(
interval.n(),
(float) interval.offset(),
interval.lengths().stream().map(Double::floatValue).collect(Collectors.toList())));
}

return new LocationConfidenceIntervalData(list);
}

private DepthConfidenceIntervalData createDepthConfidenceData(DepthConfidenceInterval interval) {
return new DepthConfidenceIntervalData(
(float) interval.minDepth(),
(float) interval.maxDepth());
}

private HypocenterQualityData createQualityData(Quality quality) {
return new HypocenterQualityData(
(float) quality.getQualityOrigin().getValue(),
(float) quality.getQualityDepth().getValue(),
(float) quality.getQualityNS().getValue(),
(float) quality.getQualityEW().getValue(),
(int) quality.getQualityStations().getValue(),
(float) quality.getQualityPercentage().getValue());
}

private static HypocenterData createHypocenterData(Earthquake earthquake) {
return new HypocenterData(
earthquake.getUuid(), earthquake.getRevisionID(), (float) earthquake.getLat(), (float) earthquake.getLon(),
(float) earthquake.getDepth(), earthquake.getOrigin(), (float) earthquake.getMag());
}

private void broadcast(List<ServerClient> clients, Packet packet) {
Expand Down Expand Up @@ -152,7 +202,7 @@ public void processPacket(ServerClient client, Packet packet) {

private void processEarthquakeRequest(ServerClient client, EarthquakeRequestPacket earthquakeRequestPacket) throws IOException {
for(Earthquake earthquake : GlobalQuakeServer.instance.getEarthquakeAnalysis().getEarthquakes()){
if(earthquake.getUuid().equals(earthquakeRequestPacket.getUuid())){
if(earthquake.getUuid().equals(earthquakeRequestPacket.uuid())){
client.sendPacket(createQuakePacket(earthquake));
return;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package gqserver.ui.server.table.model;

import gqserver.core.earthquake.data.Earthquake;
import gqserver.core.earthquake.quality.QualityClass;
import globalquake.earthquake.quality.QualityClass;
import gqserver.ui.server.table.Column;
import gqserver.ui.server.table.LastUpdateRenderer;
import gqserver.ui.server.table.TableCellRendererAdapter;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package gqserver.server;

import gqserver.api.data.ServerClientConfig;
import gqserver.api.data.system.ServerClientConfig;
import gqserver.api.packets.system.HandshakePacket;
import gqserver.api.packets.system.HeartbeatPacket;

Expand Down

0 comments on commit ecbb698

Please sign in to comment.