totalngrams: sanitize progressbar
diff --git a/src/main/java/org/ids_mannheim/Progressbar.java b/src/main/java/org/ids_mannheim/Progressbar.java
index 9bddc6a..8b57cb9 100644
--- a/src/main/java/org/ids_mannheim/Progressbar.java
+++ b/src/main/java/org/ids_mannheim/Progressbar.java
@@ -6,30 +6,22 @@
import java.time.format.DateTimeFormatter;
public class Progressbar {
- private final long max;
- private long current;
- private final long start;
- private long lastUpdate;
- private static final int width=40;
-// private static final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
+ private static final int width = 40;
+ // private static final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
private static final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("ccc dd. LLL HH:mm:ss");
+ private final long max;
+ private final long start;
+ private long current;
+ private long lastUpdate;
public Progressbar(long max, String name) {
this.start = System.currentTimeMillis();
- this.max = max;
+ this.max = max;
System.err.println(name + ":");
this.printBar(false);
}
- public void setVal(long i) {
- this.current = i;
- if ((System.currentTimeMillis() - this.lastUpdate) > 100) {
- this.lastUpdate = System.currentTimeMillis();
- this.printBar(false);
- }
- }
-
- public void update(long i) {
+ public synchronized void update(long i) {
this.current += i;
if ((System.currentTimeMillis() - this.lastUpdate) > 100) {
this.lastUpdate = System.currentTimeMillis();
@@ -57,40 +49,30 @@
private void printBar(boolean finished) {
double numbar = Math.floor(width * (double) current / (double) max);
StringBuilder strbar = new StringBuilder();
- String percent = String.format("%3d%%", (int)(100 * (double) current / (double) max));
int i;
- for (i = 0; i < numbar-1; i++) {
+ for (i = 0; i < numbar - 1; i++) {
strbar.append("=");
}
- for (i = (int) numbar-1; i < numbar; i++) {
- if (i < width-1) {
- strbar.append(">");
- } else {
- strbar.append("=");
- }
+ for (i = (int) numbar - 1; i < numbar; i++) {
+ if (i < width - 1) {
+ strbar.append(">");
+ } else {
+ strbar.append("=");
+ }
}
for (i = (int) numbar; i < width; i++) {
strbar.append(" ");
}
long elapsed = (System.currentTimeMillis() - this.start);
- String strend = hmsFromMillis(elapsed);
-
- String strETA;
- if (elapsed < 2000) {
- strETA = "--:--:--";
- } else {
- long timeETA = elapsed * (long) ((double) max / (double) current);
- strETA = hmsFromMillis(timeETA) + " -> " + shortDateTimeFromMillis(start + elapsed + timeETA);
- }
-
- String speed = String.format("@%.1fMB/s", 1000.0 * current / (1024*1024) / elapsed);
- if (finished) {
- strend = "Finished: " + speed + " " + strend + " = " + shortDateTimeFromMillis(System.currentTimeMillis());
- } else {
-// strend = "Elapsed: " + strend + " ETA: " + strETA + "\u001B[0K";
- strend = speed + " ETA: " + strETA + "\u001B[0K";
- }
- System.err.print("\r" + percent+ " [" + strbar + "] " + strend + "\u001B[0K");
+ long ttg = (long) (((double) elapsed / (double) current) * (max - current));
+ System.err.print(String.format("\r%3d%% [%s] %.1fMB/s ELA: %s TTG: %s ETA: %s\u001B[0K",
+ (int) (100 * (double) current / (double) max),
+ strbar,
+ 1000.0 * current / (1024 * 1024) / elapsed,
+ hmsFromMillis(elapsed),
+ hmsFromMillis(ttg),
+ shortDateTimeFromMillis(start + elapsed + ttg)
+ ));
if (finished) {
System.err.print("\n");
}