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

Commit

Permalink
Merge branch 'develop' into 0.10.1-real-one
Browse files Browse the repository at this point in the history
  • Loading branch information
xspanger3770 authored Jan 28, 2024
2 parents 43cecd4 + 1bca4cb commit 4b22c1f
Show file tree
Hide file tree
Showing 15 changed files with 1,017 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
import java.io.Serializable;
import java.util.UUID;

public record ArchivedQuakeData(UUID uuid, float lat, float lon, float depth, float magnitude, long origin, byte qualityID) implements Serializable {
public record ArchivedQuakeData(UUID uuid, float lat, float lon, float depth, float magnitude, long origin, byte qualityID, long finalUpdateMillis) implements Serializable {
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public void archiveQuake(ArchivedQuakePacket quakePacket, Earthquake earthquake)
private ArchivedQuake createArchivedQuake(ArchivedQuakePacket quakePacket) {
ArchivedQuakeData data = quakePacket.archivedQuakeData();
ArchivedQuake archivedQuake = new ArchivedQuake(
data.uuid(), data.lat(), data.lon(), data.depth(), data.magnitude(), data.origin(), QualityClass.values()[data.qualityID()]
data.uuid(), data.lat(), data.lon(), data.depth(), data.magnitude(), data.origin(), QualityClass.values()[data.qualityID()], data.finalUpdateMillis()
);

quakePacket.archivedEventDataList().forEach(archivedEventData -> archivedQuake.getArchivedEvents().add(new ArchivedEvent(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ private void createArchived() {
Settings.oldEventsTimeFilterEnabled = false;
Settings.oldEventsMagnitudeFilterEnabled = false;
for(double mag = 0.5; mag <= 11; mag += 0.2) {
archivedQuakes.add(new ArchivedQuake(null, 0, 0, 0, mag, r.nextLong() % System.currentTimeMillis(), QualityClass.S));
archivedQuakes.add(new ArchivedQuake(null, 0, 0, 0, mag, r.nextLong() % System.currentTimeMillis(), QualityClass.S, System.currentTimeMillis()+100)); //100ms added to make finalUpdateMillis > origin
}
//archivedQuakes.sort(Comparator.comparing(ArchivedQuake::getOrigin));
}
Expand Down
16 changes: 14 additions & 2 deletions GlobalQuakeCore/src/main/java/globalquake/core/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,10 @@ public final class Settings {
public static Boolean displayAlertBox;
public static Boolean displayTime;

public static Integer globalVolume;

public static String timezoneStr;

public static String lastServerIP;

public static Integer lastServerPORT;
Expand All @@ -139,10 +143,11 @@ public final class Settings {
public static Boolean displayCityIntensities;
public static Boolean displayCapitalCities;


public static Integer globalVolume;

public static String timezoneStr;
public static Boolean alertPossibleShaking;
public static Boolean alertPossibleShaking;
public static Double alertPossibleShakingDistance;
public static Boolean enableEarthquakeSounds;
public static Double earthquakeSoundsMinMagnitude;
Expand All @@ -151,8 +156,11 @@ public final class Settings {
public static Integer eewLevelIndex;
public static Integer qualityFilter;
public static Integer eewClusterLevel;
public static String FDSNWSEventIP;
public static Integer FDSNWSEventPort;
public static Boolean autoStartFDSNWSEventServer;

static {
static {
load();
save();
try {
Expand Down Expand Up @@ -200,6 +208,10 @@ private static void load() {
loadProperty("lastServerIP", "0.0.0.0");
loadProperty("lastServerPORT", "38000");

loadProperty("FDSNWSEventIP", "localhost"); //As a default, localhost is used for security.
loadProperty("FDSNWSEventPort", "8080");
loadProperty("autoStartFDSNWSEventServer", "false");

loadProperty("shakingLevelScale", "0",
o -> validateInt(0, IntensityScales.INTENSITY_SCALES.length - 1, (Integer) o));
loadProperty("shakingLevelIndex", "0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,19 @@
import java.io.Serial;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.TimeZone;
import java.util.UUID;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import java.text.SimpleDateFormat;
import java.util.Date;

import org.json.JSONArray;
import org.json.JSONObject;


public class ArchivedQuake implements Serializable, Comparable<ArchivedQuake>, Regional {

@Serial
Expand All @@ -34,6 +43,7 @@ public class ArchivedQuake implements Serializable, Comparable<ArchivedQuake>, R
private double maxRatio;
private double maxPGA;
private String region;
private long finalUpdateMillis;

private final ArrayList<ArchivedEvent> archivedEvents;

Expand All @@ -53,7 +63,7 @@ public ArchivedQuake(Earthquake earthquake) {
this(earthquake.getUuid(), earthquake.getLat(), earthquake.getLon(), earthquake.getDepth(), earthquake.getMag(),
earthquake.getOrigin(),
earthquake.getHypocenter() == null || earthquake.getHypocenter().quality == null ? null :
earthquake.getHypocenter().quality.getSummary());
earthquake.getHypocenter().quality.getSummary(), earthquake.getLastUpdate());
copyEvents(earthquake);
}

Expand Down Expand Up @@ -82,7 +92,7 @@ private void copyEvents(Earthquake earthquake) {
}
}

public ArchivedQuake(UUID uuid, double lat, double lon, double depth, double mag, long origin, QualityClass qualityClass) {
public ArchivedQuake(UUID uuid, double lat, double lon, double depth, double mag, long origin, QualityClass qualityClass, long finalUpdateMillis) {
this.uuid = uuid;
this.lat = lat;
this.lon = lon;
Expand All @@ -95,13 +105,16 @@ public ArchivedQuake(UUID uuid, double lat, double lon, double depth, double mag
this.maxPGA = 0.0;

pgaService.submit(this::calculatePGA);
this.finalUpdateMillis = finalUpdateMillis;


}

private void calculatePGA() {
double distGEO = globalquake.core.regions.Regions.getOceanDistance(lat, lon, false, depth);
this.maxPGA = GeoUtils.pgaFunction(mag, distGEO, depth);


}

public double getDepth() {
Expand Down Expand Up @@ -170,6 +183,7 @@ public int compareTo(ArchivedQuake archivedQuake) {
return Long.compare(archivedQuake.getOrigin(), this.getOrigin());
}


public double getMaxPGA() {
return maxPGA;
}
Expand All @@ -185,6 +199,17 @@ public boolean shouldBeDisplayed() {

return !Settings.oldEventsTimeFilterEnabled || !((GlobalQuake.instance.currentTimeMillis() - getOrigin()) > 1000 * 60 * 60L * Settings.oldEventsTimeFilter);
}

public long getFinalUpdateMillis() {
return finalUpdateMillis;
}

public String formattedUtcOrigin() {
SimpleDateFormat utcFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
utcFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
return utcFormat.format(new Date(getOrigin()));
}


@Override
public String toString() {
Expand All @@ -201,4 +226,92 @@ public String toString() {
", wrong=" + wrong +
'}';
}

public JSONObject getGeoJSON() {
JSONObject earthquakeJSON = new JSONObject();

earthquakeJSON.put("type", "Feature");
earthquakeJSON.put("id", getUuid());

JSONObject properties = new JSONObject();
properties.put("lastupdate", finalUpdateMillis);
properties.put("magtype", "gqm");
properties.put("evtype", "earthquake"); // TODO: this will need to be changed when there are other event types.
properties.put("lon", getLon());
properties.put("auth", "GlobalQuake"); // TODO: allow user to set this
properties.put("lat", getLat());
properties.put("depth", Math.round(getDepth() * 1000.0) / 1000.0); //round to 3 decimal places
properties.put("unid", getUuid());

properties.put("mag", Math.round(getMag() * 10.0) / 10.0); //round to 1 decimal place

properties.put("time", formattedUtcOrigin());

properties.put("source_id", "GlobalQuake_"+getUuid().toString()); // TODO: allow user to set this
properties.put("source_catalog", "GlobalQuake"); // TODO: allow user to set this
properties.put("flynn_region", getRegion());

earthquakeJSON.put("properties", properties);

JSONObject geometry = new JSONObject();
geometry.put("type", "Point");

JSONArray coordinates = new JSONArray();
coordinates.put(getLon());
coordinates.put(getLat());


//Depth is rounded to 3 decimal places and flipped to create altitude
coordinates.put(Math.round(getDepth() * 1000.0) / 1000.0 * -1);

geometry.put("coordinates", coordinates);

earthquakeJSON.put("geometry", geometry);

return earthquakeJSON;
}

public String getQuakeML() {
String quakeml = "<event publicID=\"quakeml:GlobalQuake:"+getUuid().toString()+"\">";
quakeml += "<description>";
quakeml += "<type>Flinn-Engdahl region</type>";
quakeml += "<text>"+getRegion()+"</text>";
quakeml += "</description>";
quakeml += "<origin>";
quakeml += "<time>";
quakeml += "<value>"+formattedUtcOrigin()+"</value>";
quakeml += "</time>";
quakeml += "<latitude>";
quakeml += "<value>"+getLat()+"</value>";
quakeml += "</latitude>";
quakeml += "<longitude>";
quakeml += "<value>"+getLon()+"</value>";
quakeml += "</longitude>";
quakeml += "<depth>";
quakeml += "<value>"+getDepth()+"</value>";
quakeml += "</depth>";
quakeml += "</origin>";
quakeml += "<magnitude>";
quakeml += "<mag>";
quakeml += "<value>"+getMag()+"</value>";
quakeml += "</mag>";
quakeml += "</magnitude>";
quakeml += "</event>\n";
return quakeml;
}

public String getFdsnText() {
//EventID|Time|Latitude|Longitude|Depth/km|Author|Catalog|Contributor|ContributorID|MagType|Magnitude|MagAuthor|EventLocationName
String fdsnText = "GlobalQuake_"+getUuid().toString()+"|";
fdsnText += formattedUtcOrigin()+"|";
fdsnText += getLat()+"|";
fdsnText += getLon()+"|";
fdsnText += getDepth()+"|";
fdsnText += "GlobalQuake|GlobalQuake|GlobalQuake|GlobalQuake_"+getUuid().toString()+"|";
fdsnText += "gqm|";
fdsnText += getMag()+"|";
fdsnText += "GlobalQuake|";
fdsnText += getRegion();
return fdsnText;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package globalquake.core.earthquake;

import java.util.List;
import java.util.stream.Collectors;

import globalquake.core.GlobalQuake;
import globalquake.core.archive.ArchivedQuake;
import globalquake.core.earthquake.data.Earthquake;

import java.util.UUID;
import org.json.JSONArray;
import org.json.JSONObject;

public class EarthquakeDataExport {

public static List<ArchivedQuake> getArchivedAndLiveEvents(){
//make a copy of the earthquakes, both archived and current.
List<ArchivedQuake> archivedQuakes = GlobalQuake.instance.getArchive().getArchivedQuakes().stream().collect(Collectors.toList());
List<Earthquake> currentEarthquakes = GlobalQuake.instance.getEarthquakeAnalysis().getEarthquakes().stream().collect(Collectors.toList());

//Combine the archived and current earthquakes
List<ArchivedQuake> earthquakes = archivedQuakes;
List<UUID> uuids = earthquakes.stream().map(ArchivedQuake::getUuid).collect(Collectors.toList());
for (Earthquake quake : currentEarthquakes) {
if (!uuids.contains(quake.getUuid())) {
ArchivedQuake archivedQuake = new ArchivedQuake(quake);
archivedQuake.setRegion(quake.getRegion());
earthquakes.add(archivedQuake);
}
}

return earthquakes;
}

public static String getQuakeMl(List<ArchivedQuake> earthquakes) {
String quakeml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
"<q:quakeml xmlns=\"http://quakeml.org/xmlns/bed/1.2\" xmlns:q=\"http://quakeml.org/xmlns/quakeml/1.2\">\n" +
"<eventParameters>\n";

for (ArchivedQuake quake : earthquakes) {
quakeml += quake.getQuakeML();
}

quakeml += "</eventParameters>\n" +
"</q:quakeml>";

return quakeml;
}

public static JSONObject getGeoJSON(List<ArchivedQuake> earthquakes) {
JSONArray features = new JSONArray();

for (ArchivedQuake quake : earthquakes) {
features.put(quake.getGeoJSON());
}

JSONObject geoJSON = new JSONObject();
geoJSON.put("type", "FeatureCollection");
geoJSON.put("features", features);

return geoJSON;

}

/*#EventID|Time|Latitude|Longitude|Depth/km|Author|Catalog|Contributor|ContributorID|MagType|Magnitude|MagAuthor|EventLocationName
uw61977871|2023-12-24T15:14:04.220|47.81966666666667|-122.96|52.39|uw|uw|uw|uw61977871|ml|4.04|uw|6 km W of Quilcene, Washington */

public static String getText(List<ArchivedQuake> earthquakes) {
String text = "#EventID|Time|Latitude|Longitude|Depth/km|Author|Catalog|Contributor|ContributorID|MagType|Magnitude|MagAuthor|EventLocationName\n";

for (ArchivedQuake quake : earthquakes) {
text += quake.getFdsnText() + "\n";
}

return text;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@

import globalquake.core.GlobalQuake;
import globalquake.core.alert.Warnable;

import globalquake.core.intensity.CityIntensity;

import globalquake.core.archive.ArchivedQuake;

import globalquake.core.regions.RegionUpdater;
import globalquake.core.regions.Regional;

Expand All @@ -13,6 +17,9 @@
import java.util.List;
import java.util.UUID;

import org.json.JSONArray;
import org.json.JSONObject;

public class Earthquake implements Regional, Warnable {

private final UUID uuid;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public void testEarthquakeRegion(){

@Test
public void testArchivedEarthquakeRegion(){
ArchivedQuake archivedQuake = new ArchivedQuake(null, 50,17,0,0,0, QualityClass.S);
ArchivedQuake archivedQuake = new ArchivedQuake(null, 50,17,0,0,0, QualityClass.S, 100);
assertNotNull(archivedQuake.getRegion());
}

Expand Down
Loading

0 comments on commit 4b22c1f

Please sign in to comment.