Skip to content

Commit

Permalink
allow unknown delay
Browse files Browse the repository at this point in the history
  • Loading branch information
xspanger3770 committed Aug 22, 2023
1 parent 3e836ce commit 5d0bfa8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
20 changes: 15 additions & 5 deletions src/main/java/globalquake/database/SeedlinkCommunicator.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package globalquake.database;

import edu.sc.seis.seisFile.seedlink.SeedlinkReader;
import org.tinylog.Logger;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
Expand All @@ -16,6 +17,7 @@

public class SeedlinkCommunicator {

public static final long UNKNOWN_DELAY = Long.MIN_VALUE;
private static final SimpleDateFormat FORMAT_UTC_SHORT = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
private static final SimpleDateFormat FORMAT_UTC_LONG = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss.SSSS");
private static final long MAX_DELAY_MS = 1000 * 60 * 60 * 24L;
Expand Down Expand Up @@ -62,13 +64,21 @@ private static void parseAvailability(String infoString, StationDatabase station
String locationCode = channel.getAttributes().getNamedItem("location").getTextContent();
String channelName = channel.getAttributes().getNamedItem("seedname").getTextContent();
String endDate = channel.getAttributes().getNamedItem("end_time").getTextContent();
Calendar end = Calendar.getInstance();
end.setTime(endDate.contains("-") ? FORMAT_UTC_SHORT.parse(endDate) : FORMAT_UTC_LONG.parse(endDate));

long delay = System.currentTimeMillis() - end.getTimeInMillis();
long delay = UNKNOWN_DELAY;

if(delay > MAX_DELAY_MS){
continue;
try {
Calendar end = Calendar.getInstance();
end.setTime(endDate.contains("-") ? FORMAT_UTC_SHORT.parse(endDate) : FORMAT_UTC_LONG.parse(endDate));

delay = System.currentTimeMillis() - end.getTimeInMillis();

if (delay > MAX_DELAY_MS) {
continue;
}

} catch(NumberFormatException e){
Logger.warn(new RuntimeException("Failed to get delay from %s, %s: %s".formatted(stationCode, seedlinkNetwork.getHost(), e.getMessage())));
}

addAvailableChannel(networkCode, stationCode, channelName, locationCode, delay, seedlinkNetwork, stationDatabase);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package globalquake.ui.stationselect;

import globalquake.database.Channel;
import globalquake.database.SeedlinkCommunicator;
import globalquake.database.Station;
import globalquake.ui.globe.GlobeRenderer;
import globalquake.ui.globe.Point2D;
Expand Down Expand Up @@ -117,7 +118,9 @@ private void drawInfo(Graphics2D g, int x, int y, Station original) {
}

private static String getDelayString(long delay){
if(delay <= 60 * 1000L){
if(delay == SeedlinkCommunicator.UNKNOWN_DELAY){
return "???";
} else if(delay <= 60 * 1000L){
return "%.1fs".formatted(delay / 1000.0);
} else if (delay < 60 * 60 * 1000L) {
return "%d:%02d".formatted(delay / (1000 * 60), (delay / 1000) % 60);
Expand Down

0 comments on commit 5d0bfa8

Please sign in to comment.