- also log after a certain amount of time if processing is slow

This commit is contained in:
fabianArbeit 2024-11-06 10:00:35 +01:00
parent 8426fa4a33
commit 4c76542f54

View File

@ -87,15 +87,27 @@ public class FabianUtil {
public void logIf() { public void logIf() {
if (counter.remainder(logDistance).signum() == 0) { if (counter.remainder(logDistance).signum() == 0 || isBored()) {
log(); log();
} }
} }
private boolean isBored() {
ZonedDateTime time = lastLoggedAt == null ? startTime : lastLoggedAt;
return time.until(ZonedDateTime.now(), ChronoUnit.SECONDS) >= timeLogDistance;
}
public void log() { public void log() {
Duration timePassed = getTimePassed(); Duration timePassed = getTimePassed();
System.out.println(counter + " Stück erledigt. " + formatDuration(timePassed) + " vergangen."); System.out.println(counter + " Stück erledigt. " + formatDuration(timePassed) + " vergangen.");
updateLastLoggedAt();
}
protected void updateLastLoggedAt() {
lastLoggedAt = ZonedDateTime.now();
} }
@ -163,6 +175,7 @@ public class FabianUtil {
String counterPrint = total.compareTo(BigDecimal.TEN) >= 0 ? formatNumber(counter) : counter.toString(); String counterPrint = total.compareTo(BigDecimal.TEN) >= 0 ? formatNumber(counter) : counter.toString();
System.out.println(counterPrint + " Stück von " + total + " (" + PERCENTAGE_FORMAT.format(percentage) + " %) erledigt. " System.out.println(counterPrint + " Stück von " + total + " (" + PERCENTAGE_FORMAT.format(percentage) + " %) erledigt. "
+ formatDuration(timePassed) + " vergangen" + remainingTimePart + "."); + formatDuration(timePassed) + " vergangen" + remainingTimePart + ".");
updateLastLoggedAt();
} }
} }