Mainly removed debug output. Regression tests with szeged looking good.

This commit is contained in:
Gerhard Hoffmann 2023-12-05 17:31:56 +01:00
parent de7a63bc2a
commit 9d220df52e

View File

@ -140,7 +140,7 @@ std::string Calculator::GetDurationFromCost(Configuration* cfg,
Ticket t = private_GetDurationFromCost(cfg, inputDate, price, prepaid); Ticket t = private_GetDurationFromCost(cfg, inputDate, price, prepaid);
qCritical().noquote() << t; // qCritical().noquote() << t;
// TODO: im fehlerfall // TODO: im fehlerfall
return t.getValidUntil().toString(Qt::ISODate).toStdString(); return t.getValidUntil().toString(Qt::ISODate).toStdString();
@ -207,7 +207,7 @@ double Calculator::GetCostFromDuration(Configuration* cfg,
durationMinutes, durationMinutes,
prepaid); prepaid);
if (t) { if (t) {
qCritical().noquote() << t; // qCritical().noquote() << t;
} }
end_datetime = t.getValidUntil(); end_datetime = t.getValidUntil();
@ -324,8 +324,6 @@ Ticket Calculator::private_GetCostFromDuration(Configuration const* cfg,
for (current = start; durationMinutes > 0; current = current.addDays(1)) { for (current = start; durationMinutes > 0; current = current.addDays(1)) {
int const weekdayId = current.date().dayOfWeek(); int const weekdayId = current.date().dayOfWeek();
qCritical() << "current" << current.toString(Qt::ISODate) << weekdayId;
specialDayId = -1; specialDayId = -1;
// find worktime ranges for the current day // find worktime ranges for the current day
@ -367,28 +365,27 @@ Ticket Calculator::private_GetCostFromDuration(Configuration const* cfg,
QTime const &lastWorktimeTo = worktime[ranges-1].getTimeUntil(); QTime const &lastWorktimeTo = worktime[ranges-1].getTimeUntil();
// find worktime range to start with // find worktime range to start with
int currentRange = 0; int currentRange = 0;
if (!isSpecialDay) { if (!isSpecialDay) {
if (start != current) { // on next day if (start != current) { // on next day
current.setTime(worktime[currentRange].getTimeFrom()); current.setTime(worktime[currentRange].getTimeFrom());
} else { } else {
// check if inputDate is located inside a valid worktime-range... // check if inputDate is located inside a valid worktime-range...
currentRange = findWorkTimeRange(current, worktime, ranges); if ((currentRange = findWorkTimeRange(current, worktime, ranges)) == -1) {
if (currentRange == -1) { // no... if (!prepaid && carryOverNotSet) { // parking is not allowed
if (!prepaid) { // parking is not allowed
return Ticket(start, QDateTime(), durationMinutesNetto, 0, return Ticket(start, QDateTime(), durationMinutesNetto, 0,
0, Ticket::s[INVALID_FROM_DATETIME]); 0, Ticket::s[INVALID_FROM_DATETIME]);
} }
// find the next worktime-range (on the same day), and start from there // find the next worktime-range (on the same day), and start from there
currentRange = findNextWorkTimeRange(current, worktime, ranges); if ((currentRange = findNextWorkTimeRange(current, worktime, ranges)) == -1) {
end = current;
continue;
}
current.setTime(worktime[currentRange].getTimeFrom()); current.setTime(worktime[currentRange].getTimeFrom());
} }
} }
} }
qCritical() << "current" << current.toString(Qt::ISODate) << currentRange;
for (int w = currentRange; w < ranges; ++w, ++totalTimeRanges) { for (int w = currentRange; w < ranges; ++w, ++totalTimeRanges) {
if (durationMinutes > 0) { if (durationMinutes > 0) {
QTime const &worktime_from = worktime[w].getTimeFrom(); QTime const &worktime_from = worktime[w].getTimeFrom();
@ -400,13 +397,7 @@ Ticket Calculator::private_GetCostFromDuration(Configuration const* cfg,
current.setTime(worktime_from); current.setTime(worktime_from);
} }
qCritical() << "worktime_from" << worktime_from;
qCritical() << "worktime_to" << worktime_to;
qCritical() << "current" << current.toString(Qt::ISODate);
if (price == 0) { if (price == 0) {
// inputDate = inputDate.addDays(1);
// inputDate.setTime(worktime_from);
end = current; end = current;
current.setTime(QTime()); current.setTime(QTime());
continue; continue;
@ -458,7 +449,6 @@ Ticket Calculator::private_GetCostFromDuration(Configuration const* cfg,
durationMinutes -= 1; durationMinutes -= 1;
//costFromDuration += price_per_unit; //costFromDuration += price_per_unit;
costFromDuration += price; costFromDuration += price;
qCritical() << "current" << current.toString(Qt::ISODate) << durationMinutes << costFromDuration;
} else break; } else break;
} }
} // while(durationMinutes > 0) { } // while(durationMinutes > 0) {
@ -468,12 +458,9 @@ Ticket Calculator::private_GetCostFromDuration(Configuration const* cfg,
int durationMinutesBrutto = start.secsTo(end) / 60; int durationMinutesBrutto = start.secsTo(end) / 60;
qCritical() << "start" << start.toString(Qt::ISODate) << "end" << end
<< llround(Utilities::CalculatePricePerUnit(costFromDuration, durationUnit));
return return
Ticket(start, end, durationMinutesNetto, durationMinutesBrutto, Ticket(start, end, durationMinutesNetto, durationMinutesBrutto,
llround(Utilities::CalculatePricePerUnit(costFromDuration, durationUnit)), ceil(Utilities::CalculatePricePerUnit(costFromDuration, durationUnit)),
Ticket::s[VALID]); Ticket::s[VALID]);
} }
@ -485,8 +472,6 @@ Ticket Calculator::private_GetDurationFromCost(Configuration *cfg,
// Get input date // Get input date
QDateTime current = start; QDateTime current = start;
qCritical() << "current" << current.toString(Qt::ISODate);
// use tariff with structure as for instance Schnau, Koenigsee: // use tariff with structure as for instance Schnau, Koenigsee:
// without given YearPeriod, SpecialDays and SpecialDaysWorktime // without given YearPeriod, SpecialDays and SpecialDaysWorktime
if (cfg->YearPeriod.size() == 0 if (cfg->YearPeriod.size() == 0
@ -526,22 +511,18 @@ Ticket Calculator::private_GetDurationFromCost(Configuration *cfg,
return Ticket(); return Ticket();
} }
qCritical() << "current" << current.toString(Qt::ISODate);
uint32_t durationMinutesNetto = 0; uint32_t durationMinutesNetto = 0;
int moneyLeft = cost; double moneyLeft = cost;
uint32_t durationUnit = 1; double durationUnit = 1;
int specialDayId = -1; int specialDayId = -1;
bool isSpecialDay = false; bool isSpecialDay = false;
QDateTime end = start; QDateTime end = start;
int totalTimeRanges = 0; int totalTimeRanges = 0;
uint32_t price = 0; double price = 0;
for (current = start; moneyLeft > 0; current = current.addDays(1), moneyLeft /= durationUnit) { for (current = start; moneyLeft > 0 && moneyLeft >= price; current = current.addDays(1)) {
int const weekdayId = current.date().dayOfWeek(); int const weekdayId = current.date().dayOfWeek();
qCritical() << "current" << current.toString(Qt::ISODate) << weekdayId;
specialDayId = -1; specialDayId = -1;
// find worktime ranges for the current day // find worktime ranges for the current day
@ -549,9 +530,12 @@ Ticket Calculator::private_GetDurationFromCost(Configuration *cfg,
QScopedArrayPointer<TariffTimeRange> worktime(new TariffTimeRange[timeRanges]); QScopedArrayPointer<TariffTimeRange> worktime(new TariffTimeRange[timeRanges]);
int ranges = 0; int ranges = 0;
if((isSpecialDay = Utilities::CheckSpecialDay(cfg, current, &specialDayId, &price))) { uint32_t p = 0;
if((isSpecialDay = Utilities::CheckSpecialDay(cfg, current, &specialDayId, &p))) {
// Set special day price: // Set special day price:
durationUnit = specialDaysDurationUnit; durationUnit = specialDaysDurationUnit;
price = p / durationUnit;
price = std::round(price * 1000.0) / 1000.0;
worktime[ranges].setTimeRange(SpecialDaysWorkTimeFrom(cfg, specialDayId), worktime[ranges].setTimeRange(SpecialDaysWorkTimeFrom(cfg, specialDayId),
SpecialDaysWorkTimeUntil(cfg, specialDayId)); SpecialDaysWorkTimeUntil(cfg, specialDayId));
ranges = 1; ranges = 1;
@ -561,10 +545,12 @@ Ticket Calculator::private_GetDurationFromCost(Configuration *cfg,
// the computation the price is divided by durationUnit. // the computation the price is divided by durationUnit.
price = weekDaysPrice; price = weekDaysPrice;
durationUnit = weekDaysDurationUnit; durationUnit = weekDaysDurationUnit;
price /= durationUnit;
price = std::round(price * 1000.0) / 1000.0; // round to 3 decimals
// If no working day found, skip it (epsecially Sundays!) // If no working day found, skip it (epsecially Sundays!)
if (cfg->WeekDaysWorktime.count(weekdayId) <= 0) { if (cfg->WeekDaysWorktime.count(weekdayId) <= 0) {
qDebug() << "No workday found, trying to find next available day"; // qDebug() << "No workday found, trying to find next available day";
end = current; end = current;
current.setTime(QTime()); // start at midnight on the next day current.setTime(QTime()); // start at midnight on the next day
continue; continue;
@ -580,33 +566,30 @@ Ticket Calculator::private_GetDurationFromCost(Configuration *cfg,
} }
} }
moneyLeft *= durationUnit;
QTime const &lastWorktimeTo = worktime[ranges-1].getTimeUntil(); QTime const &lastWorktimeTo = worktime[ranges-1].getTimeUntil();
// find worktime range to start with // find worktime range to start with
int currentRange = 0; int currentRange = 0;
if (!isSpecialDay) { if (!isSpecialDay) {
if (start != current) { // on next day if (start != current) { // on next day
current.setTime(worktime[currentRange].getTimeFrom()); current.setTime(worktime[currentRange].getTimeFrom());
} else { } else {
// check if inputDate is located inside a valid worktime-range... // check if inputDate is located inside a valid worktime-range...
currentRange = findWorkTimeRange(current, worktime, ranges); if ((currentRange = findWorkTimeRange(current, worktime, ranges)) == -1) {
if (currentRange == -1) { // no... if (!prepaid && carryOverNotSet) { // parking is not allowed
if (!prepaid) { // parking is not allowed
return Ticket(start, QDateTime(), durationMinutesNetto, 0, return Ticket(start, QDateTime(), durationMinutesNetto, 0,
0, Ticket::s[INVALID_FROM_DATETIME]); 0, Ticket::s[INVALID_FROM_DATETIME]);
} }
// find the next worktime-range (on the same day), and start from there // find the next worktime-range (on the same day), and start from there
currentRange = findNextWorkTimeRange(current, worktime, ranges); if ((currentRange = findNextWorkTimeRange(current, worktime, ranges)) == -1) {
end = current;
continue;
}
current.setTime(worktime[currentRange].getTimeFrom()); current.setTime(worktime[currentRange].getTimeFrom());
} }
} }
} }
qCritical() << "current" << current.toString(Qt::ISODate) << currentRange;
for (int w = currentRange; w < ranges; ++w, ++totalTimeRanges) { for (int w = currentRange; w < ranges; ++w, ++totalTimeRanges) {
if (moneyLeft > 0) { if (moneyLeft > 0) {
QTime const &worktime_from = worktime[w].getTimeFrom(); QTime const &worktime_from = worktime[w].getTimeFrom();
@ -618,10 +601,6 @@ Ticket Calculator::private_GetDurationFromCost(Configuration *cfg,
current.setTime(worktime_from); current.setTime(worktime_from);
} }
qCritical() << "worktime_from" << worktime_from;
qCritical() << "worktime_to" << worktime_to;
qCritical() << "current" << current.toString(Qt::ISODate);
if (price == 0) { if (price == 0) {
// inputDate = inputDate.addDays(1); // inputDate = inputDate.addDays(1);
// inputDate.setTime(worktime_from); // inputDate.setTime(worktime_from);
@ -655,7 +634,7 @@ Ticket Calculator::private_GetDurationFromCost(Configuration *cfg,
} }
} }
while(moneyLeft > 0) { while(moneyLeft >= price) {
// Check for active year period // Check for active year period
if (!IsYearPeriodActive(cfg, current)) { if (!IsYearPeriodActive(cfg, current)) {
return Ticket(); return Ticket();
@ -675,13 +654,11 @@ Ticket Calculator::private_GetDurationFromCost(Configuration *cfg,
} else { } else {
if(current.time() < worktime_to) { if(current.time() < worktime_to) {
// Increment input date minutes for each monetary unit // Increment input date minutes for each monetary unit
durationMinutesNetto +=1;
moneyLeft -= price;
moneyLeft = std::round(moneyLeft * 1000.0) / 1000.0;
current = current.addSecs(60); current = current.addSecs(60);
end = current; end = current;
if(price > 0) {
durationMinutesNetto +=1;
}
moneyLeft -= price;
qCritical() << "current" << current.toString(Qt::ISODate) << "moneyLeft" << moneyLeft;
} else break; } else break;
} }
} // while(durationMinutes > 0) { } // while(durationMinutes > 0) {
@ -691,8 +668,8 @@ Ticket Calculator::private_GetDurationFromCost(Configuration *cfg,
int durationMinutesBrutto = start.secsTo(end) / 60; int durationMinutesBrutto = start.secsTo(end) / 60;
qCritical() << "start" << start.toString(Qt::ISODate) << "end" //qCritical() << "start" << start.toString(Qt::ISODate) << "end"
<< end.toString(Qt::ISODate) << durationMinutesBrutto; // << end.toString(Qt::ISODate) << durationMinutesBrutto;
return return
Ticket(start, end, durationMinutesNetto, durationMinutesBrutto, Ticket(start, end, durationMinutesNetto, durationMinutesBrutto,