Skip to content

Commit c0d16f0

Browse files
committed
Progress bar: show expected finish time (and date)
- Display 'done ~HH:mm' for same-day completion - Display 'done ~DOW MM-dd HH:mm' when finish is on a future day - Increase render interval from 100ms to 1000ms - Also fixes left-over characters at bnthe line end Change-Id: I7d79de3017aa22d5dfb27685d3141e8b1764b194
1 parent cd644e3 commit c0d16f0

1 file changed

Lines changed: 20 additions & 4 deletions

File tree

src/main/java/de/ids_mannheim/korap/index/Indexer.java

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
import java.util.Enumeration;
1010
import java.util.Properties;
1111
import java.util.Locale;
12+
import java.time.LocalDateTime;
13+
import java.time.format.DateTimeFormatter;
1214
import java.util.regex.Matcher;
1315
import java.util.regex.Pattern;
1416
import java.util.zip.ZipEntry;
@@ -746,7 +748,7 @@ public void run () {
746748
while (running && !finished) {
747749
render();
748750
try {
749-
Thread.sleep(100);
751+
Thread.sleep(1000);
750752
}
751753
catch (InterruptedException e) {
752754
// ignore
@@ -774,7 +776,7 @@ else if (slidePos <= 0) {
774776
double elapsedSec = (now - startTimeMs) / 1000.0;
775777
double rateMBs = elapsedSec > 0 ? current / 1_000_000.0 / elapsedSec : 0.0;
776778
String rateStr = rateMBs > 0 ? String.format(Locale.US, "%.2f MB/s", rateMBs) : "NA";
777-
String line = String.format(Locale.US, "\r[%s] %.1f MB processed | %s | ETA calculating...", bar, current / 1_000_000.0, rateStr);
779+
String line = String.format(Locale.US, "\r[%s] %.1f MB processed | %s | ETA calculating...\033[K", bar, current / 1_000_000.0, rateStr);
778780
System.err.print(line);
779781
return;
780782
}
@@ -791,13 +793,27 @@ else if (slidePos <= 0) {
791793
double rateBytesPerSec = elapsedSec > 0 ? current / elapsedSec : 0.0;
792794
long etaSec = (rateBytesPerSec > 0 && total > current) ? (long) Math.ceil((total - current) / rateBytesPerSec) : 0;
793795

794-
String etaStr = (rateBytesPerSec > 0) ? Indexer.formatDuration(etaSec) : "NA";
796+
String etaStr;
797+
String finishAt;
798+
if (rateBytesPerSec > 0) {
799+
etaStr = Indexer.formatDuration(etaSec);
800+
LocalDateTime now2 = LocalDateTime.now();
801+
LocalDateTime finishTime = now2.plusSeconds(etaSec);
802+
if (finishTime.toLocalDate().equals(now2.toLocalDate())) {
803+
finishAt = finishTime.format(DateTimeFormatter.ofPattern("HH:mm"));
804+
} else {
805+
finishAt = finishTime.format(DateTimeFormatter.ofPattern("EEE MM-dd HH:mm", Locale.US));
806+
}
807+
} else {
808+
etaStr = "NA";
809+
finishAt = "?";
810+
}
795811
String pctStr = String.format(Locale.US, "%5.1f%%", percent * 100.0);
796812
String rateStr = String.format(Locale.US, "%.2f MB/s", rateBytesPerSec / 1_000_000.0);
797813
double processedMB = current / 1_000_000.0;
798814
double totalMB = total / 1_000_000.0;
799815

800-
String line = String.format(Locale.US, "\r[%s] %s %.1f/%.1f MB | %s | ETA %s", bar, pctStr, processedMB, totalMB, rateStr, etaStr);
816+
String line = String.format(Locale.US, "\r[%s] %s %.1f/%.1f MB | %s | ETA %s (done ~%s)\033[K", bar, pctStr, processedMB, totalMB, rateStr, etaStr, finishAt);
801817
System.err.print(line);
802818
}
803819
}

0 commit comments

Comments
 (0)