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

Commit 7bf0716

Browse files
authored
Merge pull request #204 from xspanger3770/develop
some final bug fixes
2 parents 7780b7a + d30c190 commit 7bf0716

File tree

3 files changed

+39
-37
lines changed

3 files changed

+39
-37
lines changed

GlobalQuakeClient/src/main/java/globalquake/ui/globalquake/GlobalQuakePanel.java

+35-33
Original file line numberDiff line numberDiff line change
@@ -318,34 +318,49 @@ private double feltStrongMultiplier(double pga){
318318

319319
private void drawAlertsBox(Graphics2D g) {
320320
Earthquake quake = null;
321-
double maxPGA = 0;
322-
double quakeDist = 1000;
321+
double maxPGA = 0.0;
322+
double distGC = 0;
323+
324+
int secondsP = 0;
325+
int secondsS = 0;
326+
327+
// Select quake to be displayed
323328

324329
for(Earthquake earthquake : GlobalQuake.instance.getEarthquakeAnalysis().getEarthquakes()){
325-
double dist = GeoUtils.geologicalDistance(earthquake.getLat(), earthquake.getLon(), -earthquake.getDepth(), Settings.homeLat, Settings.homeLon, 0);
326-
double pga = GeoUtils.pgaFunction(earthquake.getMag(), dist, earthquake.getDepth());
330+
double _dist = GeoUtils.geologicalDistance(earthquake.getLat(), earthquake.getLon(), -earthquake.getDepth(), Settings.homeLat, Settings.homeLon, 0);
331+
double pga = GeoUtils.pgaFunction(earthquake.getMag(), _dist, earthquake.getDepth());
327332
if(pga > maxPGA){
328333
maxPGA = pga;
329334

330-
double distGC = GeoUtils.greatCircleDistance(earthquake.getLat(), earthquake.getLon(), Settings.homeLat, Settings.homeLon);
335+
double _distGC = GeoUtils.greatCircleDistance(earthquake.getLat(), earthquake.getLon(), Settings.homeLat, Settings.homeLon);
336+
double age = (System.currentTimeMillis() - earthquake.getOrigin()) / 1000.0;
337+
338+
double pTravel = (long) (TauPTravelTimeCalculator.getPWaveTravelTime(earthquake.getDepth(),
339+
TauPTravelTimeCalculator.toAngle(_distGC)));
340+
double sTravel = (long) (TauPTravelTimeCalculator.getSWaveTravelTime(earthquake.getDepth(),
341+
TauPTravelTimeCalculator.toAngle(_distGC)));
342+
343+
int _secondsP = (int) Math.ceil(pTravel - age);
344+
int _secondsS = (int) Math.ceil(sTravel - age);
345+
346+
if(_secondsS < - 60 * 5) {
347+
continue; // S wave already passed
348+
}
331349

332350
if(pga > IntensityScales.INTENSITY_SCALES[Settings.shakingLevelScale].getLevels().get(Settings.shakingLevelIndex).getPga()
333-
|| AlertManager.meetsConditions(earthquake, true)) {
351+
|| AlertManager.meetsConditions(earthquake, false)) {
334352
quake = earthquake;
335-
quakeDist = dist;
353+
distGC = _distGC;
354+
secondsS = Math.max(0, _secondsS);
355+
secondsP = Math.max(0, _secondsP);
336356
}
337357
}
338358
}
339359

340-
if (DEBUG) {
341-
quake = createDebugQuake();
342-
343-
double dist = GeoUtils.geologicalDistance(quake.getLat(), quake.getLon(), -quake.getDepth(), Settings.homeLat, Settings.homeLon, 0);
344-
maxPGA = GeoUtils.pgaFunction(quake.getMag(), dist, quake.getDepth());
345-
quakeDist = dist;
360+
if(quake == null){
361+
return;
346362
}
347363

348-
349364
int width = 240;
350365
int x = getWidth() / 2 - width / 2;
351366
int height = 22;
@@ -356,13 +371,11 @@ private void drawAlertsBox(Graphics2D g) {
356371

357372
g.setFont(new Font("Calibri", Font.BOLD, 16));
358373

359-
if(quake != null) {
360-
height = 136;
361-
color = new Color(0, 90, 192);
362-
g.setFont(new Font("Calibri", Font.BOLD, 22));
363-
str = quakeDist <= 200 ? "Earthquake detected nearby!" : "Earthquake detected!";
364-
width = 400;
365-
}
374+
height = 136;
375+
color = new Color(0, 90, 192);
376+
g.setFont(new Font("Calibri", Font.BOLD, 22));
377+
str = distGC <= 200 ? "Earthquake detected nearby!" : "Earthquake detected!";
378+
width = 400;
366379

367380
if(maxPGA >= IntensityScales.INTENSITY_SCALES[Settings.shakingLevelScale].getLevels().get(Settings.shakingLevelIndex).getPga()){
368381
color = new Color(255,200,0);
@@ -391,7 +404,6 @@ private void drawAlertsBox(Graphics2D g) {
391404
return;
392405
}
393406

394-
double distGC = GeoUtils.greatCircleDistance(quake.getLat(), quake.getLon(), Settings.homeLat, Settings.homeLon);
395407
Level level = IntensityScales.getIntensityScale().getLevel(maxPGA);
396408

397409
drawIntensityBox(g, level, x + 4,y + 30,height - 34);
@@ -409,16 +421,6 @@ private void drawAlertsBox(Graphics2D g) {
409421
str = "Depth: %s".formatted(Settings.getSelectedDistanceUnit().format(quake.getDepth(), 1));
410422
g.drawString(str, _x, y + 72);
411423

412-
double age = (System.currentTimeMillis() - quake.getOrigin()) / 1000.0;
413-
414-
double pTravel = (long) (TauPTravelTimeCalculator.getPWaveTravelTime(quake.getDepth(),
415-
TauPTravelTimeCalculator.toAngle(distGC)));
416-
double sTravel = (long) (TauPTravelTimeCalculator.getSWaveTravelTime(quake.getDepth(),
417-
TauPTravelTimeCalculator.toAngle(distGC)));
418-
419-
int secondsP = (int) Math.max(0, Math.ceil(pTravel - age));
420-
int secondsS = (int) Math.max(0, Math.ceil(sTravel - age));
421-
422424
drawAccuracyBox(g, false, "P Wave arrival: ",x + intW + 15,y + 96, "%ds".formatted(secondsP), secondsP == 0 ? Color.gray : new Color(0,100,220));
423425
drawAccuracyBox(g, false, "S Wave arrival: ",x + intW + 15,y + 122, "%ds".formatted(secondsS), secondsS == 0 ? Color.gray : new Color(255,50,0));
424426

@@ -774,7 +776,7 @@ private void drawLocationAcc(Graphics2D g, Earthquake quake, int y, int x, int w
774776
drawAccuracyBox(g, true, "Err. Origin ", (int) (x + width * 0.55), y + 80,
775777
"%.1fs".formatted(quality.getQualityOrigin().getValue()), quality.getQualityOrigin().getQualityClass().getColor());
776778
drawAccuracyBox(g, true, "No. Stations ", (int) (x + width * 0.55), y + 104,
777-
"%d".formatted((int) quality.getQualityStations().getValue()), quality.getQualityStations().getQualityClass().getColor());
779+
"%.0f".formatted(quality.getQualityStations().getValue()), quality.getQualityStations().getQualityClass().getColor());
778780
drawAccuracyBox(g, true, "Err. N-S ", x + width, y + 56,
779781
units.format(quality.getQualityNS().getValue(), 1), quality.getQualityNS().getQualityClass().getColor());
780782
drawAccuracyBox(g, true, "Err. E-W ", x + width, y + 80,

GlobalQuakeCore/src/main/java/globalquake/core/database/Channel.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,11 @@ public int hashCode() {
8585
@Override
8686
public String toString() {
8787
if (seedlinkNetworks.isEmpty()) {
88-
return "%s %s %dsps (unavailable)".formatted(getCode(), getLocationCode(), (int) getSampleRate());
88+
return "%s %s %.1fsps (unavailable)".formatted(getCode(), getLocationCode(), getSampleRate());
8989
} else if (seedlinkNetworks.size() == 1) {
90-
return "%s %s %dsps (%d seedlink)".formatted(getCode(), getLocationCode(), (int) getSampleRate(), seedlinkNetworks.size());
90+
return "%s %s %.1fsps (%d seedlink)".formatted(getCode(), getLocationCode(), getSampleRate(), seedlinkNetworks.size());
9191
} else {
92-
return "%s %s %dsps (%d seedlinks)".formatted(getCode(), getLocationCode(), (int) getSampleRate(), seedlinkNetworks.size());
92+
return "%s %s %.1fsps (%d seedlinks)".formatted(getCode(), getLocationCode(), getSampleRate(), seedlinkNetworks.size());
9393
}
9494
}
9595

GlobalQuakeCore/src/main/java/globalquake/core/geo/DistanceUnit.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public String toString() {
3535
public String format(double distance, int i) {
3636
double result = distance * getKmRatio();
3737
if(i == 0){
38-
return "%d%s".formatted((int) result, getShortName());
38+
return "%.0f%s".formatted(result, getShortName());
3939
}
4040
return ("%%.%df%%s".formatted(i)).formatted(result, getShortName());
4141
}

0 commit comments

Comments
 (0)