Skip to content
Snippets Groups Projects
Commit 027ddec9 authored by Jan Kožusznik's avatar Jan Kožusznik
Browse files

feat: format remaining time

parent 264699eb
No related branches found
No related tags found
No related merge requests found
...@@ -25,7 +25,7 @@ public class UpdatableBenchmarkJob extends UpdatableObservableValue<BenchmarkJob ...@@ -25,7 +25,7 @@ public class UpdatableBenchmarkJob extends UpdatableObservableValue<BenchmarkJob
public interface TransferProgress { public interface TransferProgress {
public Long getRemainingSeconds(); public Long getRemainingMiliseconds();
public boolean isDone(); public boolean isDone();
...@@ -66,7 +66,7 @@ public class UpdatableBenchmarkJob extends UpdatableObservableValue<BenchmarkJob ...@@ -66,7 +66,7 @@ public class UpdatableBenchmarkJob extends UpdatableObservableValue<BenchmarkJob
private boolean working; private boolean working;
// private boolean done; // private boolean done;
private long start; private long start;
private Long remainingSeconds; private Long remainingMiliseconds;
private Float remainingPercents; private Float remainingPercents;
private Supplier<Boolean> doneStatusSupplier; private Supplier<Boolean> doneStatusSupplier;
private Consumer<Boolean> doneStatusConsumer; private Consumer<Boolean> doneStatusConsumer;
...@@ -80,11 +80,11 @@ public class UpdatableBenchmarkJob extends UpdatableObservableValue<BenchmarkJob ...@@ -80,11 +80,11 @@ public class UpdatableBenchmarkJob extends UpdatableObservableValue<BenchmarkJob
public synchronized void setCount(int count, int total) { public synchronized void setCount(int count, int total) {
if (total < -1) { if (total < -1) {
working = false; working = false;
remainingSeconds = null; remainingMiliseconds = null;
remainingPercents = null; remainingPercents = null;
} else { } else {
long delta = System.currentTimeMillis() - start; long delta = System.currentTimeMillis() - start;
remainingSeconds = (long) ((double) delta / count * (total - count)) / 1000; remainingMiliseconds = (long) ((double) delta / count * (total - count));
remainingPercents = (((float) total - count) / total * 100); remainingPercents = (((float) total - count) / total * 100);
} }
fireValueChangedEvent(); fireValueChangedEvent();
...@@ -106,7 +106,7 @@ public class UpdatableBenchmarkJob extends UpdatableObservableValue<BenchmarkJob ...@@ -106,7 +106,7 @@ public class UpdatableBenchmarkJob extends UpdatableObservableValue<BenchmarkJob
setDone(true); setDone(true);
} }
working = false; working = false;
remainingSeconds = 0l; remainingMiliseconds = 0l;
remainingPercents = 0.f; remainingPercents = 0.f;
fireValueChangedEvent(); fireValueChangedEvent();
} }
...@@ -117,8 +117,8 @@ public class UpdatableBenchmarkJob extends UpdatableObservableValue<BenchmarkJob ...@@ -117,8 +117,8 @@ public class UpdatableBenchmarkJob extends UpdatableObservableValue<BenchmarkJob
} }
@Override @Override
public synchronized Long getRemainingSeconds() { public synchronized Long getRemainingMiliseconds() {
return remainingSeconds; return remainingMiliseconds;
} }
@Override @Override
......
...@@ -210,8 +210,8 @@ public class BenchmarkSPIMController extends BorderPane implements CloseableCont ...@@ -210,8 +210,8 @@ public class BenchmarkSPIMController extends BorderPane implements CloseableCont
if (!progress.isWorking() && !progress.isDone()) { if (!progress.isWorking() && !progress.isDone()) {
return ""; return "";
} else if (progress.isWorking()) { } else if (progress.isWorking()) {
Long secs = progress.getRemainingSeconds(); Long msecs = progress.getRemainingMiliseconds();
return string + "ing - time remains " + (secs != null ? secs : "N/A"); return string + "ing - time remains " + (msecs != null ? RemainingTimeFormater.format(msecs) : "N/A");
} else if (progress.isDone()) { } else if (progress.isDone()) {
return string + "ed"; return string + "ed";
} }
......
package cz.it4i.fiji.haas_spim_benchmark.ui;
public class RemainingTimeFormater {
public static String format(long duration) {
long s = duration / 1000;
return String.format("%d:%02d:%02d", s / 3600, (s % 3600) / 60, (s % 60));
}
}
package cz.it4i.fiji.haas;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import cz.it4i.fiji.haas_spim_benchmark.ui.RemainingTimeFormater;
public class TestTimeFormater {
public static final Logger log = LoggerFactory.getLogger(cz.it4i.fiji.haas.TestTimeFormater.class);
public static void main(String[] args) {
log.info( RemainingTimeFormater.format((25*3600 + 5*60 + 6) * 1000 + 200));
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment