Compare commits
No commits in common. "71daaaff157268ca373c4dbd7ebdc6fb513ddd11" and "4fc5648c4ff3ad0bfd12acda567a365eb0b15cca" have entirely different histories.
71daaaff15
...
4fc5648c4f
@ -1,8 +1,6 @@
|
||||
package de.vorsorge.theo.util;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.math.BigDecimal;
|
||||
import java.math.MathContext;
|
||||
import java.math.RoundingMode;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
@ -10,7 +8,6 @@ import java.text.DecimalFormat;
|
||||
import java.time.Duration;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class FabianUtil {
|
||||
|
||||
@ -68,69 +65,54 @@ public class FabianUtil {
|
||||
}
|
||||
|
||||
|
||||
protected synchronized BigDecimal getCounter() {
|
||||
protected BigDecimal getCounter() {
|
||||
return counter;
|
||||
}
|
||||
|
||||
|
||||
protected synchronized int getTimeLogDistance() {
|
||||
return timeLogDistance;
|
||||
}
|
||||
|
||||
|
||||
public synchronized void tickAndLog() {
|
||||
public void tickAndLog() {
|
||||
tick();
|
||||
logIf();
|
||||
}
|
||||
|
||||
|
||||
protected synchronized void tick() {
|
||||
protected void tick() {
|
||||
counter = counter.add(BigDecimal.ONE);
|
||||
}
|
||||
|
||||
|
||||
public synchronized void logAndTick() {
|
||||
public void logAndTick() {
|
||||
logIf();
|
||||
tick();
|
||||
}
|
||||
|
||||
|
||||
public synchronized void logIf() {
|
||||
if (shouldLog()) {
|
||||
public void logIf() {
|
||||
if (counter.remainder(logDistance).signum() == 0 || isBored()) {
|
||||
log();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected synchronized boolean shouldLog() {
|
||||
return counter.remainder(logDistance).signum() == 0 || isBored();
|
||||
}
|
||||
|
||||
|
||||
private synchronized boolean isBored() {
|
||||
return getTimeSinceLastLogged() >= timeLogDistance;
|
||||
}
|
||||
|
||||
|
||||
protected synchronized long getTimeSinceLastLogged() {
|
||||
private boolean isBored() {
|
||||
ZonedDateTime time = lastLoggedAt == null ? startTime : lastLoggedAt;
|
||||
return time.until(ZonedDateTime.now(), ChronoUnit.SECONDS);
|
||||
return time.until(ZonedDateTime.now(), ChronoUnit.SECONDS) >= timeLogDistance;
|
||||
}
|
||||
|
||||
|
||||
public synchronized void log() {
|
||||
public void log() {
|
||||
Duration timePassed = getTimePassed();
|
||||
System.out.println(counter + " Stück erledigt. " + formatDuration(timePassed) + " vergangen.");
|
||||
updateLastLoggedAt();
|
||||
}
|
||||
|
||||
|
||||
protected synchronized void updateLastLoggedAt() {
|
||||
protected void updateLastLoggedAt() {
|
||||
lastLoggedAt = ZonedDateTime.now();
|
||||
}
|
||||
|
||||
|
||||
protected synchronized Duration getTimePassed() {
|
||||
protected Duration getTimePassed() {
|
||||
return Duration.ofSeconds(startTime.until(ZonedDateTime.now(), ChronoUnit.SECONDS));
|
||||
}
|
||||
|
||||
@ -145,7 +127,7 @@ public class FabianUtil {
|
||||
}
|
||||
|
||||
|
||||
public synchronized void logFinal() {
|
||||
public void logFinal() {
|
||||
Duration timePassed = getTimePassed();
|
||||
System.out.println(counter + " Stück (100 %) erledigt. " + formatDuration(timePassed) + " vergangen.");
|
||||
}
|
||||
@ -176,21 +158,16 @@ public class FabianUtil {
|
||||
|
||||
|
||||
@Override
|
||||
protected synchronized boolean shouldLog() {
|
||||
return super.shouldLog() && getCounter().compareTo(total) <= 0;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public synchronized void log() {
|
||||
public void log() {
|
||||
BigDecimal counter = getCounter();
|
||||
BigDecimal percentage = BigDecimal.valueOf(100).divide(total, MathContext.DECIMAL64).multiply(counter);
|
||||
BigDecimal percentage = BigDecimal.valueOf(100).divide(total, 15, RoundingMode.HALF_UP).multiply(counter);
|
||||
|
||||
Duration timePassed = getTimePassed();
|
||||
|
||||
String remainingTimePart = "";
|
||||
if (counter.signum() != 0) {
|
||||
BigDecimal secondsPassed = BigDecimal.valueOf(timePassed.getSeconds());
|
||||
BigDecimal totalSeconds = secondsPassed.divide(counter, MathContext.DECIMAL64).multiply(total);
|
||||
BigDecimal totalSeconds = secondsPassed.divide(counter, 15, RoundingMode.HALF_UP).multiply(total);
|
||||
BigDecimal secondsToGo = totalSeconds.subtract(secondsPassed);
|
||||
Duration timeToGo = Duration.of(secondsToGo.longValue(), ChronoUnit.SECONDS);
|
||||
remainingTimePart = ", " + formatDuration(timeToGo) + " verbleibend";
|
||||
@ -201,25 +178,6 @@ public class FabianUtil {
|
||||
+ formatDuration(timePassed) + " vergangen" + remainingTimePart + ".");
|
||||
updateLastLoggedAt();
|
||||
}
|
||||
|
||||
|
||||
public void logContinuouslyTimeBased() {
|
||||
new Thread(this::logTimeBased).start();
|
||||
}
|
||||
|
||||
|
||||
private synchronized void logTimeBased() {
|
||||
while (getCounter().compareTo(total) != 0) {
|
||||
logIf();
|
||||
long timeSinceLastLogged = getTimeSinceLastLogged();
|
||||
try {
|
||||
TimeUnit.SECONDS.sleep(timeSinceLastLogged - getTimeLogDistance());
|
||||
} catch (InterruptedException ie) {
|
||||
Thread.currentThread().interrupt();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,5 +1,3 @@
|
||||
import java.math.BigDecimal;
|
||||
import java.math.MathContext;
|
||||
import java.text.DecimalFormat;
|
||||
import java.time.LocalTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
@ -21,12 +19,11 @@ public class LoadingBar {
|
||||
private static final DecimalFormat PERCENTAGE_FORMAT = new DecimalFormat("00.00");
|
||||
private static final int MIN_LUNCH_DURATION = 30;
|
||||
private static final LocalTime LATEST_LUNCH_TIME = LocalTime.of(13, 30);
|
||||
private static final long DEFAULT_NUMBER_WORK_MINS_BEFORE_LUNCH = 5L * 60;
|
||||
private static final int MAX_NUMBER_WORK_MINS_WITHOUT_LUNCH = 6 * 60;
|
||||
private static final long MAX_NUMBER_WORK_MINS = 8L * 60;
|
||||
private static final int MINS_PER_HOUR = 60;
|
||||
private static final long DEFAULT_NUMBER_WORK_MINS_BEFORE_LUNCH = 5L * MINS_PER_HOUR;
|
||||
private static final int MAX_NUMBER_WORK_MINS_WITHOUT_LUNCH = 6 * MINS_PER_HOUR;
|
||||
private static final long MAX_NUMBER_WORK_MINS = 8L * MINS_PER_HOUR;
|
||||
private static final int LINE_LENGTH = 100;
|
||||
private static final MathContext MC_INTEGER = new MathContext(1, RoundingMode.HALF_EVEN);
|
||||
|
||||
|
||||
private enum DaySection {
|
||||
@ -336,11 +333,9 @@ public class LoadingBar {
|
||||
|
||||
|
||||
private static String fillLoadingBar(long initialMinutes, long passedMinutes, boolean progressive) {
|
||||
BigDecimal wholePercentage = BigDecimal.valueOf(100)
|
||||
.divide(BigDecimal.valueOf(initialMinutes), MathContext.DECIMAL64)
|
||||
.multiply(BigDecimal.valueOf(passedMinutes));
|
||||
double wholePercentage = ((double) passedMinutes / initialMinutes) * 100;
|
||||
long remainingMinutes = initialMinutes - passedMinutes;
|
||||
int numberOfEquals = wholePercentage.intValue();
|
||||
int numberOfEquals = (int) wholePercentage;
|
||||
var sb = new StringBuilder("[");
|
||||
for (int i = 0; i < LINE_LENGTH; i++) {
|
||||
if (i < numberOfEquals) {
|
||||
@ -359,9 +354,6 @@ public class LoadingBar {
|
||||
|
||||
|
||||
private static String minutesToTimeString(long minutes) {
|
||||
var minutesBD = BigDecimal.valueOf(minutes);
|
||||
int hours = minutesBD.divide(BigDecimal.valueOf(MINS_PER_HOUR), MC_INTEGER).intValue();
|
||||
int rest_minutes = minutesBD.remainder(BigDecimal.valueOf(MINS_PER_HOUR), MC_INTEGER).intValue();
|
||||
return LocalTime.of(hours, rest_minutes).format(TIME_FORMATTER);
|
||||
return LocalTime.of((int) minutes / MINS_PER_HOUR, (int) minutes % MINS_PER_HOUR).format(TIME_FORMATTER);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user