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

some final bug fixes #204

Merged
merged 5 commits into from
Jan 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -318,34 +318,49 @@ private double feltStrongMultiplier(double pga){

private void drawAlertsBox(Graphics2D g) {
Earthquake quake = null;
double maxPGA = 0;
double quakeDist = 1000;
double maxPGA = 0.0;
double distGC = 0;

int secondsP = 0;
int secondsS = 0;

// Select quake to be displayed

for(Earthquake earthquake : GlobalQuake.instance.getEarthquakeAnalysis().getEarthquakes()){
double dist = GeoUtils.geologicalDistance(earthquake.getLat(), earthquake.getLon(), -earthquake.getDepth(), Settings.homeLat, Settings.homeLon, 0);
double pga = GeoUtils.pgaFunction(earthquake.getMag(), dist, earthquake.getDepth());
double _dist = GeoUtils.geologicalDistance(earthquake.getLat(), earthquake.getLon(), -earthquake.getDepth(), Settings.homeLat, Settings.homeLon, 0);
double pga = GeoUtils.pgaFunction(earthquake.getMag(), _dist, earthquake.getDepth());
if(pga > maxPGA){
maxPGA = pga;

double distGC = GeoUtils.greatCircleDistance(earthquake.getLat(), earthquake.getLon(), Settings.homeLat, Settings.homeLon);
double _distGC = GeoUtils.greatCircleDistance(earthquake.getLat(), earthquake.getLon(), Settings.homeLat, Settings.homeLon);
double age = (System.currentTimeMillis() - earthquake.getOrigin()) / 1000.0;

double pTravel = (long) (TauPTravelTimeCalculator.getPWaveTravelTime(earthquake.getDepth(),
TauPTravelTimeCalculator.toAngle(_distGC)));
double sTravel = (long) (TauPTravelTimeCalculator.getSWaveTravelTime(earthquake.getDepth(),
TauPTravelTimeCalculator.toAngle(_distGC)));

int _secondsP = (int) Math.ceil(pTravel - age);
int _secondsS = (int) Math.ceil(sTravel - age);

if(_secondsS < - 60 * 5) {
continue; // S wave already passed
}

if(pga > IntensityScales.INTENSITY_SCALES[Settings.shakingLevelScale].getLevels().get(Settings.shakingLevelIndex).getPga()
|| AlertManager.meetsConditions(earthquake, true)) {
|| AlertManager.meetsConditions(earthquake, false)) {
quake = earthquake;
quakeDist = dist;
distGC = _distGC;
secondsS = Math.max(0, _secondsS);
secondsP = Math.max(0, _secondsP);
}
}
}

if (DEBUG) {
quake = createDebugQuake();

double dist = GeoUtils.geologicalDistance(quake.getLat(), quake.getLon(), -quake.getDepth(), Settings.homeLat, Settings.homeLon, 0);
maxPGA = GeoUtils.pgaFunction(quake.getMag(), dist, quake.getDepth());
quakeDist = dist;
if(quake == null){
return;
}


int width = 240;
int x = getWidth() / 2 - width / 2;
int height = 22;
Expand All @@ -356,13 +371,11 @@ private void drawAlertsBox(Graphics2D g) {

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

if(quake != null) {
height = 136;
color = new Color(0, 90, 192);
g.setFont(new Font("Calibri", Font.BOLD, 22));
str = quakeDist <= 200 ? "Earthquake detected nearby!" : "Earthquake detected!";
width = 400;
}
height = 136;
color = new Color(0, 90, 192);
g.setFont(new Font("Calibri", Font.BOLD, 22));
str = distGC <= 200 ? "Earthquake detected nearby!" : "Earthquake detected!";
width = 400;

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

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

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

double age = (System.currentTimeMillis() - quake.getOrigin()) / 1000.0;

double pTravel = (long) (TauPTravelTimeCalculator.getPWaveTravelTime(quake.getDepth(),
TauPTravelTimeCalculator.toAngle(distGC)));
double sTravel = (long) (TauPTravelTimeCalculator.getSWaveTravelTime(quake.getDepth(),
TauPTravelTimeCalculator.toAngle(distGC)));

int secondsP = (int) Math.max(0, Math.ceil(pTravel - age));
int secondsS = (int) Math.max(0, Math.ceil(sTravel - age));

drawAccuracyBox(g, false, "P Wave arrival: ",x + intW + 15,y + 96, "%ds".formatted(secondsP), secondsP == 0 ? Color.gray : new Color(0,100,220));
drawAccuracyBox(g, false, "S Wave arrival: ",x + intW + 15,y + 122, "%ds".formatted(secondsS), secondsS == 0 ? Color.gray : new Color(255,50,0));

Expand Down Expand Up @@ -774,7 +776,7 @@ private void drawLocationAcc(Graphics2D g, Earthquake quake, int y, int x, int w
drawAccuracyBox(g, true, "Err. Origin ", (int) (x + width * 0.55), y + 80,
"%.1fs".formatted(quality.getQualityOrigin().getValue()), quality.getQualityOrigin().getQualityClass().getColor());
drawAccuracyBox(g, true, "No. Stations ", (int) (x + width * 0.55), y + 104,
"%d".formatted((int) quality.getQualityStations().getValue()), quality.getQualityStations().getQualityClass().getColor());
"%.0f".formatted(quality.getQualityStations().getValue()), quality.getQualityStations().getQualityClass().getColor());
drawAccuracyBox(g, true, "Err. N-S ", x + width, y + 56,
units.format(quality.getQualityNS().getValue(), 1), quality.getQualityNS().getQualityClass().getColor());
drawAccuracyBox(g, true, "Err. E-W ", x + width, y + 80,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,11 @@ public int hashCode() {
@Override
public String toString() {
if (seedlinkNetworks.isEmpty()) {
return "%s %s %dsps (unavailable)".formatted(getCode(), getLocationCode(), (int) getSampleRate());
return "%s %s %.1fsps (unavailable)".formatted(getCode(), getLocationCode(), getSampleRate());
} else if (seedlinkNetworks.size() == 1) {
return "%s %s %dsps (%d seedlink)".formatted(getCode(), getLocationCode(), (int) getSampleRate(), seedlinkNetworks.size());
return "%s %s %.1fsps (%d seedlink)".formatted(getCode(), getLocationCode(), getSampleRate(), seedlinkNetworks.size());
} else {
return "%s %s %dsps (%d seedlinks)".formatted(getCode(), getLocationCode(), (int) getSampleRate(), seedlinkNetworks.size());
return "%s %s %.1fsps (%d seedlinks)".formatted(getCode(), getLocationCode(), getSampleRate(), seedlinkNetworks.size());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public String toString() {
public String format(double distance, int i) {
double result = distance * getKmRatio();
if(i == 0){
return "%d%s".formatted((int) result, getShortName());
return "%.0f%s".formatted(result, getShortName());
}
return ("%%.%df%%s".formatted(i)).formatted(result, getShortName());
}
Expand Down