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_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 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 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 static final DecimalFormat LITER_FORMAT = new DecimalFormat("0.00");
|
||||||
|
|
||||||
|
private double totalLitres;
|
||||||
|
|
||||||
|
|
||||||
protected DrinkingBar(LocalTime startTime) {
|
protected DrinkingBar(LocalTime startTime) {
|
||||||
super(startTime, DEFAULT_TOTAL_TIME);
|
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
|
@Override
|
||||||
protected String fillLoadingBar(long passedMinutes, boolean progressive) {
|
protected String fillLoadingBar(long passedMinutes, boolean progressive) {
|
||||||
long effectivePassedMinutes = passedMinutes;
|
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;
|
effectivePassedMinutes = MINUTES_BEFORE_PAUSE;
|
||||||
}
|
}
|
||||||
double currentLitres = 2.0 / getTotalMinutes() * effectivePassedMinutes + 0.25;
|
double currentLitres = totalLitres / getTotalMinutes() * effectivePassedMinutes + QUARTER_LITRE;
|
||||||
double printedLitres = currentLitres - (currentLitres % 0.25);
|
double printedLitres = currentLitres - (currentLitres % QUARTER_LITRE);
|
||||||
// double currentProgressToNextStep = 100 / 0.25 * (currentLitres - printedLitres);
|
// double currentProgressToNextStep = 100 / QUARTER_LITRE * (currentLitres - printedLitres);
|
||||||
BigDecimal minutesToNextStep = getMinutesToNextStep(currentLitres);
|
BigDecimal minutesToNextStep = getMinutesToNextStep(currentLitres);
|
||||||
String progressivePart = progressive ? "\r" : "";
|
String progressivePart = progressive ? "\r" : "";
|
||||||
return progressivePart + "Aktuelles Volumen: " + LITER_FORMAT.format(printedLitres) + "L - "
|
return progressivePart + "Aktuelles Volumen: " + LITER_FORMAT.format(printedLitres) + "L - "
|
||||||
@@ -56,10 +76,11 @@ public class DrinkingBar extends AbstractLoadingBar {
|
|||||||
|
|
||||||
private BigDecimal getMinutesToNextStep(double currentLitres) {
|
private BigDecimal getMinutesToNextStep(double currentLitres) {
|
||||||
// berechne Liter benötigt bis zum nächsten 0.25er Schritt
|
// 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
|
// 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
|
// 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);
|
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 {
|
private static void handleMittagspause(BufferedReader br, WorkLoadingBar wlb) throws IOException {
|
||||||
LoadingBar.handleMittagspause(br, wlb.loadingBar);
|
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 {
|
private static void handleZapfenstreich(BufferedReader br, WorkLoadingBar wlb) throws IOException {
|
||||||
LoadingBar.handleZapfenstreich(br, wlb.loadingBar);
|
LoadingBar.handleZapfenstreich(br, wlb.loadingBar);
|
||||||
wlb.setEndTime(wlb.loadingBar.getEndTime(), true);
|
wlb.setEndTime(wlb.loadingBar.getEndTime());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -68,17 +70,16 @@ public class WorkLoadingBar extends AbstractProgressBar {
|
|||||||
LoadingBar lb = LoadingBar.getLoadingBarFromCLI(args);
|
LoadingBar lb = LoadingBar.getLoadingBarFromCLI(args);
|
||||||
var db = new DrinkingBar(lb.getStartTime());
|
var db = new DrinkingBar(lb.getStartTime());
|
||||||
var wlb = new WorkLoadingBar(lb, db);
|
var wlb = new WorkLoadingBar(lb, db);
|
||||||
wlb.setEndTime(wlb.loadingBar.getEndTime(), true);
|
wlb.setEndTime(wlb.loadingBar.getEndTime());
|
||||||
wlb.showLoadingBar();
|
wlb.showLoadingBar();
|
||||||
// wlb.showLoadingBarDebug(); // DEBUG
|
// wlb.showLoadingBarDebug(); // DEBUG
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
protected void setEndTime(LocalTime endTime, boolean finalEndTime) {
|
@Override
|
||||||
setEndTime(endTime);
|
protected void setEndTime(LocalTime endTime) {
|
||||||
if (finalEndTime) {
|
super.setEndTime(endTime);
|
||||||
drinkingBar.setEndTime(endTime);
|
drinkingBar.setEndTime(endTime);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user