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);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user