more elegant handling of pre-lunch-time/ shorter total times in general
This commit is contained in:
@@ -20,11 +20,31 @@ public class DrinkingBar extends AbstractLoadingBar {
|
||||
private static final int MINUTES_BEFORE_PAUSE = 4 * CommonTools.MINS_PER_HOUR + MINS_PER_HALF_HOUR;
|
||||
private static final int MINUTES_WITH_PAUSE = 6 * CommonTools.MINS_PER_HOUR;
|
||||
private static final int DEFAULT_TOTAL_TIME = 8 * CommonTools.MINS_PER_HOUR + MINS_PER_HALF_HOUR;
|
||||
private static final double DEFAULT_TOTAL_LITRES = 2.0;
|
||||
private static final double QUARTER_LITRE = 0.25;
|
||||
private static final DecimalFormat LITER_FORMAT = new DecimalFormat("0.00");
|
||||
|
||||
private double totalLitres;
|
||||
|
||||
|
||||
protected DrinkingBar(LocalTime startTime) {
|
||||
super(startTime, DEFAULT_TOTAL_TIME);
|
||||
this.totalLitres = DEFAULT_TOTAL_LITRES;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void setEndTime(LocalTime endTime) {
|
||||
super.setEndTime(endTime);
|
||||
// correct necessary litres to drink based on the end time.
|
||||
// lower the volume in quarter litre steps
|
||||
double calcTotalLitres = DEFAULT_TOTAL_LITRES;
|
||||
double totalLitresFromMinutes = calcTotalLitres / DEFAULT_TOTAL_TIME * getTotalMinutes();
|
||||
do {
|
||||
calcTotalLitres -= QUARTER_LITRE;
|
||||
} while (calcTotalLitres >= totalLitresFromMinutes);
|
||||
// add quarter since we always did a step "too many", due to the do ... while loop
|
||||
this.totalLitres = calcTotalLitres + QUARTER_LITRE;
|
||||
}
|
||||
|
||||
|
||||
@@ -40,12 +60,12 @@ public class DrinkingBar extends AbstractLoadingBar {
|
||||
@Override
|
||||
protected String fillLoadingBar(long passedMinutes, boolean progressive) {
|
||||
long effectivePassedMinutes = passedMinutes;
|
||||
if (passedMinutes > MINUTES_BEFORE_PAUSE && passedMinutes <= MINUTES_WITH_PAUSE) {
|
||||
if (getTotalMinutes() > MINUTES_WITH_PAUSE && passedMinutes > MINUTES_BEFORE_PAUSE && passedMinutes <= MINUTES_WITH_PAUSE) {
|
||||
effectivePassedMinutes = MINUTES_BEFORE_PAUSE;
|
||||
}
|
||||
double currentLitres = 2.0 / getTotalMinutes() * effectivePassedMinutes + 0.25;
|
||||
double printedLitres = currentLitres - (currentLitres % 0.25);
|
||||
// double currentProgressToNextStep = 100 / 0.25 * (currentLitres - printedLitres);
|
||||
double currentLitres = totalLitres / getTotalMinutes() * effectivePassedMinutes + QUARTER_LITRE;
|
||||
double printedLitres = currentLitres - (currentLitres % QUARTER_LITRE);
|
||||
// double currentProgressToNextStep = 100 / QUARTER_LITRE * (currentLitres - printedLitres);
|
||||
BigDecimal minutesToNextStep = getMinutesToNextStep(currentLitres);
|
||||
String progressivePart = progressive ? "\r" : "";
|
||||
return progressivePart + "Aktuelles Volumen: " + LITER_FORMAT.format(printedLitres) + "L - "
|
||||
@@ -56,10 +76,11 @@ public class DrinkingBar extends AbstractLoadingBar {
|
||||
|
||||
private BigDecimal getMinutesToNextStep(double currentLitres) {
|
||||
// berechne Liter benötigt bis zum nächsten 0.25er Schritt
|
||||
double litresToNextStep = 0.25 - (currentLitres % 0.25);
|
||||
double litresToNextStep = QUARTER_LITRE - (currentLitres % QUARTER_LITRE);
|
||||
// berechne Minuten benötigt für 1 Liter
|
||||
double minutesPerLitre = getTotalMinutes() / 2.0;
|
||||
double minutesPerLitre = getTotalMinutes() / totalLitres;
|
||||
// berechne Minuten benötigt bis zum nächsten 0.25er Schritt
|
||||
// + 1 since we only show minutes and have to adjust for the "ignored" seconds
|
||||
return BigDecimal.valueOf((minutesPerLitre * litresToNextStep) + 1);
|
||||
}
|
||||
}
|
||||
|
@@ -54,13 +54,15 @@ public class WorkLoadingBar extends AbstractProgressBar {
|
||||
|
||||
private static void handleMittagspause(BufferedReader br, WorkLoadingBar wlb) throws IOException {
|
||||
LoadingBar.handleMittagspause(br, wlb.loadingBar);
|
||||
wlb.setEndTime(wlb.loadingBar.getEndTime(), false);
|
||||
// FSFIXME add functionality that regards this end time as lunch time (thus making the 30 mins pause right before the end).
|
||||
// it can maybe save that end time and when setting the final end time, making the 30 mins pause prevEndTime + lunchDuration.
|
||||
wlb.setEndTime(wlb.loadingBar.getEndTime());
|
||||
}
|
||||
|
||||
|
||||
private static void handleZapfenstreich(BufferedReader br, WorkLoadingBar wlb) throws IOException {
|
||||
LoadingBar.handleZapfenstreich(br, wlb.loadingBar);
|
||||
wlb.setEndTime(wlb.loadingBar.getEndTime(), true);
|
||||
wlb.setEndTime(wlb.loadingBar.getEndTime());
|
||||
}
|
||||
|
||||
|
||||
@@ -68,18 +70,17 @@ public class WorkLoadingBar extends AbstractProgressBar {
|
||||
LoadingBar lb = LoadingBar.getLoadingBarFromCLI(args);
|
||||
var db = new DrinkingBar(lb.getStartTime());
|
||||
var wlb = new WorkLoadingBar(lb, db);
|
||||
wlb.setEndTime(wlb.loadingBar.getEndTime(), true);
|
||||
wlb.setEndTime(wlb.loadingBar.getEndTime());
|
||||
wlb.showLoadingBar();
|
||||
// wlb.showLoadingBarDebug(); // DEBUG
|
||||
}
|
||||
|
||||
|
||||
protected void setEndTime(LocalTime endTime, boolean finalEndTime) {
|
||||
setEndTime(endTime);
|
||||
if (finalEndTime) {
|
||||
@Override
|
||||
protected void setEndTime(LocalTime endTime) {
|
||||
super.setEndTime(endTime);
|
||||
drinkingBar.setEndTime(endTime);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
|
Reference in New Issue
Block a user