totalngrams: improve progressbar looks
diff --git a/src/main/java/org/ids_mannheim/Progressbar.java b/src/main/java/org/ids_mannheim/Progressbar.java
index 8b57cb9..c036d99 100644
--- a/src/main/java/org/ids_mannheim/Progressbar.java
+++ b/src/main/java/org/ids_mannheim/Progressbar.java
@@ -4,20 +4,22 @@
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
+import java.time.temporal.ChronoUnit;
+import java.util.Date;
public class Progressbar {
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 static final DateTimeFormatter longFormatter = DateTimeFormatter.ofPattern("ccc dd. LLL HH:mm");
+ private static final DateTimeFormatter shortFormatter = DateTimeFormatter.ofPattern("HH:mm:ss");
private final long max;
private final long start;
private long current;
private long lastUpdate;
- public Progressbar(long max, String name) {
+ public Progressbar(long max) {
this.start = System.currentTimeMillis();
this.max = max;
- System.err.println(name + ":");
this.printBar(false);
}
@@ -34,12 +36,30 @@
this.printBar(true);
}
+ private static boolean isSameDay(LocalDateTime date1, Date date2) {
+ Instant instant1 = date1.toInstant(ZoneId.systemDefault().getRules().getOffset(date1))
+ .truncatedTo(ChronoUnit.DAYS);
+ Instant instant2 = date2.toInstant()
+ .truncatedTo(ChronoUnit.DAYS);
+ return instant1.equals(instant2);
+ }
+
+ public static boolean isToday(LocalDateTime date) {
+ return isSameDay(date, new Date());
+ }
+
public String shortDateTimeFromMillis(long millis) {
+ if(millis < 0) {
+ return "";
+ }
LocalDateTime date = LocalDateTime.ofInstant(Instant.ofEpochMilli(millis), ZoneId.systemDefault());
- return date.format(formatter);
+ return date.format(isToday(date)? shortFormatter: longFormatter);
}
public String hmsFromMillis(long millis) {
+ if(millis < 0) {
+ return "--:--:--";
+ }
int seconds = (int) (millis / 1000) % 60;
int minutes = (int) (millis / 1000) % 3600 / 60;
int hours = (int) (millis / 1000) / 3600;
@@ -72,7 +92,7 @@
hmsFromMillis(elapsed),
hmsFromMillis(ttg),
shortDateTimeFromMillis(start + elapsed + ttg)
- ));
+ ));
if (finished) {
System.err.print("\n");
}
diff --git a/src/main/java/org/ids_mannheim/TotalNGram.java b/src/main/java/org/ids_mannheim/TotalNGram.java
index 47c4ec1..44bd6e1 100644
--- a/src/main/java/org/ids_mannheim/TotalNGram.java
+++ b/src/main/java/org/ids_mannheim/TotalNGram.java
@@ -110,7 +110,7 @@
FoldedEntry.setFolds(FOLDS);
ConcurrentHashMap<String, FoldedEntry> map = new ConcurrentHashMap<>();
long totalFilesSizes = inputFiles.parallelStream().mapToLong(fname -> new File(fname).length()).sum();
- etaPrinter = new Progressbar(totalFilesSizes, "MB");
+ etaPrinter = new Progressbar(totalFilesSizes);
BlockingQueue<Integer> queue = new LinkedBlockingQueue<>(inputFiles.size());
ExecutorService es = Executors.newCachedThreadPool();
WorkerNodePool workerNodePool = new WorkerNodePool(worker_pool_specification);