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
public interface TransferProgress {
public Long getRemainingSeconds();
public Long getRemainingMiliseconds();
public boolean isDone();
......@@ -66,7 +66,7 @@ public class UpdatableBenchmarkJob extends UpdatableObservableValue<BenchmarkJob
private boolean working;
// private boolean done;
private long start;
private Long remainingSeconds;
private Long remainingMiliseconds;
private Float remainingPercents;
private Supplier<Boolean> doneStatusSupplier;
private Consumer<Boolean> doneStatusConsumer;
......@@ -80,11 +80,11 @@ public class UpdatableBenchmarkJob extends UpdatableObservableValue<BenchmarkJob
public synchronized void setCount(int count, int total) {
if (total < -1) {
working = false;
remainingSeconds = null;
remainingMiliseconds = null;
remainingPercents = null;
} else {
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);
}
fireValueChangedEvent();
......@@ -106,7 +106,7 @@ public class UpdatableBenchmarkJob extends UpdatableObservableValue<BenchmarkJob
setDone(true);
}
working = false;
remainingSeconds = 0l;
remainingMiliseconds = 0l;
remainingPercents = 0.f;
fireValueChangedEvent();
}
......@@ -117,8 +117,8 @@ public class UpdatableBenchmarkJob extends UpdatableObservableValue<BenchmarkJob
}
@Override
public synchronized Long getRemainingSeconds() {
return remainingSeconds;
public synchronized Long getRemainingMiliseconds() {
return remainingMiliseconds;
}
@Override
......
......@@ -210,8 +210,8 @@ public class BenchmarkSPIMController extends BorderPane implements CloseableCont
if (!progress.isWorking() && !progress.isDone()) {
return "";
} else if (progress.isWorking()) {
Long secs = progress.getRemainingSeconds();
return string + "ing - time remains " + (secs != null ? secs : "N/A");
Long msecs = progress.getRemainingMiliseconds();
return string + "ing - time remains " + (msecs != null ? RemainingTimeFormater.format(msecs) : "N/A");
} else if (progress.isDone()) {
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