save experimental
This commit is contained in:
@@ -115,8 +115,8 @@ QDateTime Calculator::GetDailyTicketDuration(Configuration* cfg, const QDateTime
|
||||
/// <inheritdoc/>
|
||||
std::string Calculator::GetDurationFromCost(Configuration* cfg,
|
||||
uint8_t payment_option,
|
||||
char const* start_datetime, // given in local time
|
||||
double price,
|
||||
char const *startDatetimePassed, // given in local time
|
||||
double cost,
|
||||
bool nextDay,
|
||||
bool prepaid)
|
||||
{
|
||||
@@ -124,14 +124,14 @@ std::string Calculator::GetDurationFromCost(Configuration* cfg,
|
||||
Q_UNUSED(nextDay);
|
||||
|
||||
// Get input date
|
||||
QDateTime inputDate = QDateTime::fromString(start_datetime,Qt::ISODate);
|
||||
QDateTime inputDate = QDateTime::fromString(startDatetimePassed,Qt::ISODate);
|
||||
|
||||
static const PaymentMethod paymentMethodId = Utilities::getPaymentMethodId(cfg);
|
||||
if (paymentMethodId == PaymentMethod::Steps) {
|
||||
if (tariffIs24_7(cfg)) {
|
||||
// use tariff with structure as for instance Schoenau, Koenigsee:
|
||||
// without given YearPeriod, SpecialDays and SpecialDaysWorktime
|
||||
inputDate = inputDate.addSecs(GetDurationForPrice(cfg, price) * 60);
|
||||
inputDate = inputDate.addSecs(GetDurationForPrice(cfg, cost) * 60);
|
||||
return inputDate.toString(Qt::ISODate).toStdString();
|
||||
} else {
|
||||
if (Utilities::IsYearPeriodActive(cfg, inputDate)) {
|
||||
@@ -147,9 +147,226 @@ std::string Calculator::GetDurationFromCost(Configuration* cfg,
|
||||
return "";
|
||||
}
|
||||
}
|
||||
} else
|
||||
if (paymentMethodId == PaymentMethod::Progressive) {
|
||||
// started with Neuhauser, Kirchdorf: merge into main algo. later
|
||||
// for now try out some ideas
|
||||
|
||||
// started with Neuhauser, Kirchdorf: merge into main algo. later
|
||||
// for now try out some ideas
|
||||
|
||||
static const bool carryOverNotSet = Utilities::isCarryOverNotSet(cfg, paymentMethodId);
|
||||
static const uint minParkingPrice = Utilities::getMinimalParkingPrice(cfg, paymentMethodId);
|
||||
static const uint maxParkingPrice = Utilities::getMaximalParkingPrice(cfg, paymentMethodId);
|
||||
|
||||
if (cost < minParkingPrice) {
|
||||
qCritical() << QString("ERROR: COST < MIN_PARKING_PRICE (%1 < %2)").arg(cost).arg(minParkingPrice);
|
||||
return QDateTime().toString(Qt::ISODate).toStdString();
|
||||
}
|
||||
|
||||
if (cost > maxParkingPrice) {
|
||||
qCritical() << QString("WARN: COST > MAX_PARKING_PRICE (%1 > %2)").arg(cost).arg(maxParkingPrice);
|
||||
cost = maxParkingPrice;
|
||||
}
|
||||
|
||||
Q_ASSERT_X(carryOverNotSet, __func__, "CARRYOVER SET (FOR KIRCHDORF)");
|
||||
Q_ASSERT_X(prepaid, __func__, "PREPAID NOT SET (FOR KIRCHDORF)");
|
||||
|
||||
QDateTime start_datetime = QDateTime::fromString(QString(startDatetimePassed), Qt::ISODate);
|
||||
QDateTime start = start_datetime;
|
||||
QDateTime end_datetime = QDateTime();
|
||||
|
||||
int weekdayId = -1;
|
||||
int weekdayIdLast = -1;
|
||||
int durationMinutes = Utilities::getMaximalParkingTime(cfg, paymentMethodId);
|
||||
int durationMinutesBrutto = 0;
|
||||
|
||||
QDateTime current = start;
|
||||
|
||||
int days = 7;
|
||||
while (--days > 0) {
|
||||
weekdayId = current.date().dayOfWeek();
|
||||
weekdayIdLast = weekdayId; // TODO: some end condition in json-file
|
||||
|
||||
while (cfg->WeekDaysWorktime.count(weekdayId) == 0) {
|
||||
current = current.addDays(1);
|
||||
weekdayId = current.date().dayOfWeek();
|
||||
if (weekdayId == weekdayIdLast) {
|
||||
qCritical() << "ERROR: NO VALID WORKDAY-TIMES DEFINED";
|
||||
return QDateTime().toString(Qt::ISODate).toStdString();
|
||||
}
|
||||
}
|
||||
|
||||
using WTIterator = std::multimap<int, ATBWeekDaysWorktime>::const_iterator;
|
||||
std::pair<WTIterator, WTIterator> p = cfg->WeekDaysWorktime.equal_range(weekdayId);
|
||||
|
||||
QTime to = QTime(0, 0, 0);
|
||||
for (WTIterator itr = p.first; itr != p.second; ++itr) {
|
||||
QTime const &t = Utilities::WeekDaysWorkTimeUntil(itr);
|
||||
|
||||
if (to < t) {
|
||||
to = t;
|
||||
}
|
||||
}
|
||||
|
||||
if (current.time() >= to) {
|
||||
if (carryOverNotSet) {
|
||||
return end_datetime.toString(Qt::ISODate).toStdString();
|
||||
} else {
|
||||
QDateTime const dt = start;
|
||||
start = start.addDays(1);
|
||||
start.setTime(QTime(0, 0, 0));
|
||||
|
||||
durationMinutesBrutto += dt.secsTo(start) / 60;
|
||||
current = start;
|
||||
}
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
int durationMinutesNetto = 0;
|
||||
uint price = 0;
|
||||
|
||||
if (carryOverNotSet) {
|
||||
int range = 0;
|
||||
int minsToCarryOver = 0; // from one work-time to the other on the same day
|
||||
int minsUsed = 0;
|
||||
QDateTime lastCurrent = QDateTime();
|
||||
|
||||
auto timeRangeIt = cfg->TimeRange.cbegin();
|
||||
for (; timeRangeIt != cfg->TimeRange.cend(); ++timeRangeIt) {
|
||||
using WTIterator = std::multimap<int, ATBWeekDaysWorktime>::const_iterator;
|
||||
std::pair<WTIterator, WTIterator> p = cfg->WeekDaysWorktime.equal_range(weekdayId);
|
||||
|
||||
for (WTIterator itr = p.first; itr != p.second; ++itr) {
|
||||
++range;
|
||||
|
||||
QTime const &from = Utilities::WeekDaysWorkTimeFrom(itr);
|
||||
QTime const &to = Utilities::WeekDaysWorkTimeUntil(itr);
|
||||
|
||||
Q_ASSERT_X(from < to, __func__, "MISCONFIGURED WORK-TIMES");
|
||||
|
||||
if (current.time() >= to) {
|
||||
continue; // try to use next available work-time
|
||||
} else
|
||||
if (current.time() <= from) {
|
||||
if (prepaid) {
|
||||
lastCurrent = current;
|
||||
current.setTime(from); // move current forward (range==1),
|
||||
// as prepaid is set
|
||||
uint const minutesMoved = lastCurrent.secsTo(current) / 60;
|
||||
durationMinutesBrutto += minutesMoved;
|
||||
|
||||
if (range == 1) {
|
||||
start_datetime = current;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
while (timeRangeIt != cfg->TimeRange.cend()) {
|
||||
ATBTimeRange timeRange = timeRangeIt->second;
|
||||
|
||||
timeRange.computeQTimes(current.time());
|
||||
|
||||
int duration = timeRange.time_range_to_in_minutes_from_start -
|
||||
timeRange.time_range_from_in_minutes_from_start;
|
||||
|
||||
if (minsUsed > 0) {
|
||||
duration -= minsUsed;
|
||||
minsUsed = 0;
|
||||
}
|
||||
|
||||
if (current.addSecs(duration * 60).time() <= to) {
|
||||
if (minsToCarryOver > 0) { // the price for this time range
|
||||
// has been is paid already
|
||||
durationMinutes -= duration;
|
||||
durationMinutesNetto += duration;
|
||||
durationMinutesBrutto += duration;
|
||||
current = current.addSecs(duration*60);
|
||||
minsToCarryOver = 0;
|
||||
} else {
|
||||
for(const auto &x: cfg->PaymentRate) {
|
||||
ATBPaymentRate const rate = x.second;
|
||||
if (rate.pra_payment_unit_id == timeRange.time_range_payment_type_id) {
|
||||
price += (uint)rate.pra_price;
|
||||
|
||||
if (price >= maxParkingPrice) {
|
||||
price = maxParkingPrice;
|
||||
}
|
||||
|
||||
durationMinutes -= duration;
|
||||
durationMinutesNetto += duration;
|
||||
durationMinutesBrutto += duration;
|
||||
|
||||
current = current.addSecs(duration * 60);
|
||||
|
||||
if (price >= cost) {
|
||||
end_datetime = current;
|
||||
return end_datetime.toString(Qt::ISODate).toStdString();
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (durationMinutes <= 0) {
|
||||
end_datetime = current;
|
||||
return end_datetime.toString(Qt::ISODate).toStdString();
|
||||
}
|
||||
|
||||
++timeRangeIt;
|
||||
|
||||
} else {
|
||||
|
||||
lastCurrent = current;
|
||||
current.setTime(to);
|
||||
minsUsed = lastCurrent.secsTo(current) / 60;
|
||||
|
||||
// mod duration: possibly discard some minutes in
|
||||
// the next time-range
|
||||
if (durationMinutes >= minsUsed) {
|
||||
minsToCarryOver = durationMinutes - minsUsed;
|
||||
}
|
||||
|
||||
durationMinutes -= minsUsed;
|
||||
durationMinutesNetto += minsUsed;
|
||||
durationMinutesBrutto += minsUsed;
|
||||
|
||||
if (minsUsed > 0) {
|
||||
for(const auto &x: cfg->PaymentRate) {
|
||||
ATBPaymentRate const rate = x.second;
|
||||
if (rate.pra_payment_unit_id == timeRange.time_range_payment_type_id) {
|
||||
price += (uint)rate.pra_price;
|
||||
|
||||
if (price >= maxParkingPrice) {
|
||||
price = maxParkingPrice;
|
||||
}
|
||||
|
||||
if (price >= cost) {
|
||||
end_datetime = current;
|
||||
// return end_datetime.toString(Qt::ISODate).toStdString();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
end_datetime = start.addSecs(durationMinutesBrutto * 60);
|
||||
return end_datetime.toString(Qt::ISODate).toStdString();
|
||||
}
|
||||
}
|
||||
|
||||
end_datetime = QDateTime();
|
||||
return end_datetime.toString(Qt::ISODate).toStdString();
|
||||
}
|
||||
|
||||
Ticket t = private_GetDurationFromCost(cfg, inputDate, price, prepaid);
|
||||
Ticket t = private_GetDurationFromCost(cfg, inputDate, cost, prepaid);
|
||||
|
||||
// qCritical().noquote() << t;
|
||||
|
||||
@@ -279,9 +496,11 @@ double Calculator::GetCostFromDuration(Configuration* cfg,
|
||||
end_datetime.setTime(cs.getAllowedTimeRange().getTimeUntil());
|
||||
return cost;
|
||||
}
|
||||
} else {
|
||||
// it might be that in such a case even prepaid ("vorkauf")
|
||||
// is not allowed at any moment
|
||||
}
|
||||
|
||||
qCritical() << __PRETTY_FUNCTION__ << "NOT YET IMPLEMENTED";
|
||||
qCritical() << "(" << __func__ << ":" << __LINE__ << ")" << "NOT YET IMPLEMENTED";
|
||||
end_datetime = QDateTime();
|
||||
return 0;
|
||||
}
|
||||
@@ -299,34 +518,18 @@ double Calculator::GetCostFromDuration(Configuration* cfg,
|
||||
|
||||
QDateTime start = start_datetime;
|
||||
|
||||
#define DEBUG 0
|
||||
#if DEBUG==1
|
||||
qCritical() << "start" << start.toString(Qt::ISODate) << durationMinutes;
|
||||
#endif
|
||||
int weekdayId = -1;
|
||||
int weekdayIdLast = -1;
|
||||
int timeRanges = 0;
|
||||
int durationMinutesBrutto = 0;
|
||||
|
||||
QDateTime current = start;
|
||||
|
||||
//if ((durationMinutes % 5) != 0) {
|
||||
// qCritical() << "ERROR DURATION (" << durationMinutes
|
||||
// << ") NOT A MULTIPLE Of 5";
|
||||
//}
|
||||
|
||||
int days = 7;
|
||||
while (--days > 0) {
|
||||
|
||||
#if DEBUG==1
|
||||
qCritical() << "(" << __func__ << ":" << __LINE__ << ")"
|
||||
<< "start" << start.toString(Qt::ISODate)
|
||||
<< "current" << current.toString(Qt::ISODate);
|
||||
#endif
|
||||
weekdayId = current.date().dayOfWeek();
|
||||
weekdayIdLast = weekdayId; // TODO: some end condition in json-file
|
||||
|
||||
while ((timeRanges = cfg->WeekDaysWorktime.count(weekdayId)) == 0) {
|
||||
while (cfg->WeekDaysWorktime.count(weekdayId) == 0) {
|
||||
current = current.addDays(1);
|
||||
weekdayId = current.date().dayOfWeek();
|
||||
if (weekdayId == weekdayIdLast) {
|
||||
@@ -335,11 +538,6 @@ double Calculator::GetCostFromDuration(Configuration* cfg,
|
||||
}
|
||||
}
|
||||
|
||||
#if DEBUG==1
|
||||
qCritical() << "(" << __func__ << ":" << __LINE__ << ")"
|
||||
<< "current" << current.toString(Qt::ISODate);
|
||||
#endif
|
||||
|
||||
using WTIterator = std::multimap<int, ATBWeekDaysWorktime>::const_iterator;
|
||||
std::pair<WTIterator, WTIterator> p = cfg->WeekDaysWorktime.equal_range(weekdayId);
|
||||
|
||||
@@ -347,235 +545,169 @@ double Calculator::GetCostFromDuration(Configuration* cfg,
|
||||
for (WTIterator itr = p.first; itr != p.second; ++itr) {
|
||||
QTime const &t = Utilities::WeekDaysWorkTimeUntil(itr);
|
||||
|
||||
#if DEBUG==1
|
||||
qCritical() << "(" << __func__ << ":" << __LINE__ << ")"
|
||||
<< "current" << current.time().toString(Qt::ISODate)
|
||||
<< "t" << t.toString(Qt::ISODate)
|
||||
<< "to" << to.toString(Qt::ISODate);
|
||||
#endif
|
||||
|
||||
if (to < t) {
|
||||
to = t;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (current.time() >= to) {
|
||||
QDateTime const dt = start;
|
||||
start = start.addDays(1);
|
||||
start.setTime(QTime(0, 0, 0));
|
||||
if (carryOverNotSet) {
|
||||
end_datetime = start;
|
||||
return 0;
|
||||
} else {
|
||||
QDateTime const dt = start;
|
||||
start = start.addDays(1);
|
||||
start.setTime(QTime(0, 0, 0));
|
||||
|
||||
durationMinutesBrutto += dt.secsTo(start) / 60;
|
||||
current = start;
|
||||
durationMinutesBrutto += dt.secsTo(start) / 60;
|
||||
current = start;
|
||||
}
|
||||
} else {
|
||||
|
||||
#if DEBUG==1
|
||||
qCritical() << "(" << __func__ << ":" << __LINE__ << ")"
|
||||
<< "current" << current.toString(Qt::ISODate)
|
||||
<< "durationMinutesBrutto" << durationMinutesBrutto;
|
||||
#endif
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
#if DEBUG==1
|
||||
qCritical() << "(" << __func__ << ":" << __LINE__ << ")"
|
||||
<< "timeRanges" << timeRanges << weekdayId
|
||||
<< "durationMinutesBrutto" << durationMinutesBrutto
|
||||
<< "start" << start.toString(Qt::ISODate)
|
||||
<< "current" << current.toString(Qt::ISODate);
|
||||
#endif
|
||||
|
||||
int durationMinutesNetto = 0;
|
||||
uint price = 0;
|
||||
|
||||
if (carryOverNotSet) {
|
||||
int range = 0;
|
||||
int minsToCarryOver = 0; // from one work-time to the other on the same day
|
||||
int minsUsed = 0;
|
||||
QDateTime lastCurrent = QDateTime();
|
||||
|
||||
auto timeRangeIt = cfg->TimeRange.cbegin();
|
||||
for (; timeRangeIt != cfg->TimeRange.cend(); ++timeRangeIt) {
|
||||
using WTIterator = std::multimap<int, ATBWeekDaysWorktime>::const_iterator;
|
||||
std::pair<WTIterator, WTIterator> p = cfg->WeekDaysWorktime.equal_range(weekdayId);
|
||||
using WTIterator = std::multimap<int, ATBWeekDaysWorktime>::const_iterator;
|
||||
std::pair<WTIterator, WTIterator> p = cfg->WeekDaysWorktime.equal_range(weekdayId);
|
||||
|
||||
for (WTIterator itr = p.first; itr != p.second; ++itr) {
|
||||
++range;
|
||||
for (WTIterator itr = p.first; itr != p.second; ++itr) {
|
||||
++range;
|
||||
|
||||
QTime const &from = Utilities::WeekDaysWorkTimeFrom(itr);
|
||||
QTime const &to = Utilities::WeekDaysWorkTimeUntil(itr);
|
||||
QTime const &from = Utilities::WeekDaysWorkTimeFrom(itr);
|
||||
QTime const &to = Utilities::WeekDaysWorkTimeUntil(itr);
|
||||
|
||||
Q_ASSERT_X(from < to, __func__, "MISCONFIGURED WORK-TIMES");
|
||||
Q_ASSERT_X(from < to, __func__, "MISCONFIGURED WORK-TIMES");
|
||||
|
||||
if (current.time() >= to) {
|
||||
continue; // try to use next available work-time
|
||||
} else
|
||||
if (current.time() <= from) {
|
||||
if (prepaid) {
|
||||
lastCurrent = current;
|
||||
current.setTime(from); // move current forward (range==1),
|
||||
// as prepaid is set
|
||||
uint const minutesMoved = lastCurrent.secsTo(current) / 60;
|
||||
durationMinutesBrutto += minutesMoved;
|
||||
|
||||
if (current.time() >= to) {
|
||||
#if DEBUG==1
|
||||
qCritical() << "(" << __func__ << ":" << __LINE__ << ")"
|
||||
<< "current" << current.toString(Qt::ISODate)
|
||||
<< "from" << from.toString(Qt::ISODate)
|
||||
<< "to" << to.toString(Qt::ISODate);
|
||||
#endif
|
||||
continue; // try to use next available work-time
|
||||
} else
|
||||
if (current.time() <= from) {
|
||||
if (prepaid) {
|
||||
lastCurrent = current;
|
||||
current.setTime(from); // move current forward (range==1),
|
||||
// as prepaid is set
|
||||
uint const minutesMoved = lastCurrent.secsTo(current) / 60;
|
||||
#if DEBUG==1
|
||||
qCritical() << "(" << __func__ << ":" << __LINE__ << ")"
|
||||
<< "current" << current.toString(Qt::ISODate)
|
||||
<< "lastCurrent" << lastCurrent.toString(Qt::ISODate)
|
||||
<< "minutesMoved" << minutesMoved
|
||||
<< "durationMinutes" << durationMinutes;
|
||||
#endif
|
||||
durationMinutesBrutto += minutesMoved;
|
||||
|
||||
if (range == 1) {
|
||||
start_datetime = current;
|
||||
}
|
||||
if (range == 1) {
|
||||
start_datetime = current;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#if DEBUG==1
|
||||
qCritical() << "(" << __func__ << ":" << __LINE__ << ")"
|
||||
<< "from" << from.toString(Qt::ISODate)
|
||||
<< "to" << to.toString(Qt::ISODate)
|
||||
for (auto timeRangeIt = cfg->TimeRange.cbegin(); timeRangeIt != cfg->TimeRange.cend(); ++timeRangeIt) {
|
||||
|
||||
ATBTimeRange timeRange = timeRangeIt->second;
|
||||
|
||||
timeRange.computeQTimes(current.time());
|
||||
|
||||
int duration = timeRange.time_range_to_in_minutes_from_start -
|
||||
timeRange.time_range_from_in_minutes_from_start;
|
||||
|
||||
qCritical() << __func__ << ":" << __LINE__
|
||||
<< "current" << current.toString(Qt::ISODate)
|
||||
<< "durationMinutes" << durationMinutes;
|
||||
#endif
|
||||
<< "duration" << duration
|
||||
<< "minsUsed" << minsUsed
|
||||
<< "minsToCarryOver" << minsToCarryOver;
|
||||
|
||||
while (timeRangeIt != cfg->TimeRange.cend()) {
|
||||
ATBTimeRange timeRange = timeRangeIt->second;
|
||||
|
||||
timeRange.computeQTimes(current.time());
|
||||
//if (minsUsed > 0) {
|
||||
// duration -= minsUsed;
|
||||
// minsUsed = 0;
|
||||
//}
|
||||
|
||||
int duration = timeRange.time_range_to_in_minutes_from_start -
|
||||
timeRange.time_range_from_in_minutes_from_start;
|
||||
|
||||
#if DEBUG==1
|
||||
qCritical() << "(" << __func__ << ":" << __LINE__ << ")"
|
||||
<< "duration" << duration << timeRange.time_range_id
|
||||
<< "current" << current.toString(Qt::ISODate)
|
||||
<< "minsToCarryOver" << minsToCarryOver
|
||||
<< "durationMinutes" << durationMinutes;
|
||||
#endif
|
||||
|
||||
if (current.addSecs(duration * 60).time() <= to) {
|
||||
|
||||
for(const auto &x: cfg->PaymentRate) {
|
||||
ATBPaymentRate const rate = x.second;
|
||||
if (rate.pra_payment_unit_id == timeRange.time_range_payment_type_id) {
|
||||
if (minsToCarryOver > 0) {
|
||||
durationMinutes -= minsToCarryOver;
|
||||
durationMinutesNetto += minsToCarryOver;
|
||||
durationMinutesBrutto += minsToCarryOver;
|
||||
current = current.addSecs(minsToCarryOver*60);
|
||||
minsToCarryOver = 0;
|
||||
#if DEBUG==1
|
||||
qCritical() << "(" << __func__ << ":" << __LINE__ << ")"
|
||||
<< "durationMinutes" << durationMinutes
|
||||
<< "durationMinutesNetto" << durationMinutesNetto
|
||||
<< "durationMinutesBrutto" << durationMinutesBrutto
|
||||
<< "current" << current.toString(Qt::ISODate);
|
||||
#endif
|
||||
} else {
|
||||
if (current.addSecs(duration * 60).time() <= to) {
|
||||
if (minsToCarryOver > 0) { // the price for this time range
|
||||
// has been is paid already
|
||||
if (minsUsed == 0) {
|
||||
for(const auto &x: cfg->PaymentRate) {
|
||||
ATBPaymentRate const rate = x.second;
|
||||
if (rate.pra_payment_unit_id == timeRange.time_range_payment_type_id) {
|
||||
price += (uint)rate.pra_price;
|
||||
|
||||
durationMinutes -= duration;
|
||||
durationMinutesNetto += duration;
|
||||
durationMinutesBrutto += duration;
|
||||
|
||||
#if DEBUG==1
|
||||
qCritical() << "(" << __func__ << ":" << __LINE__ << ")"
|
||||
<< "duration" << duration
|
||||
<< "durationMinutes" << durationMinutes
|
||||
<< "durationMinutesNetto" << durationMinutesNetto
|
||||
<< "durationMinutesBrutto" << durationMinutesBrutto;
|
||||
#endif
|
||||
|
||||
current = current.addSecs(duration * 60);
|
||||
|
||||
#if DEBUG==1
|
||||
qCritical() << "(" << __func__ << ":" << __LINE__ << ")"
|
||||
<< "current" << current.toString(Qt::ISODate)
|
||||
<< "price" << price;
|
||||
#endif
|
||||
}
|
||||
if (durationMinutes <= 0) {
|
||||
end_datetime = current;
|
||||
return price;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (durationMinutes <= 0) {
|
||||
end_datetime = current;
|
||||
#if DEBUG==1
|
||||
qCritical() << "(" << __func__ << ":" << __LINE__ << ")"
|
||||
<< "duration" << durationMinutesNetto << ", price" << price
|
||||
<< current.toString(Qt::ISODate)
|
||||
<< end_datetime.toString(Qt::ISODate);
|
||||
#endif
|
||||
return price;
|
||||
}
|
||||
|
||||
++timeRangeIt;
|
||||
|
||||
} else {
|
||||
|
||||
lastCurrent = current;
|
||||
current.setTime(to);
|
||||
int const minsLeft = lastCurrent.secsTo(current) / 60;
|
||||
|
||||
// mod duration: possibly discard some minutes in
|
||||
// the next time-range
|
||||
minsToCarryOver = (durationMinutes - minsLeft) % duration;
|
||||
|
||||
durationMinutes -= minsLeft;
|
||||
durationMinutesNetto += minsLeft;
|
||||
durationMinutesBrutto += minsLeft;
|
||||
|
||||
#if DEBUG==1
|
||||
qCritical() << "(" << __func__ << ":" << __LINE__ << ")"
|
||||
<< "lastCurrent" << lastCurrent.toString(Qt::ISODate)
|
||||
<< "current" << current.toString(Qt::ISODate)
|
||||
<< "minsLeft" << minsLeft;
|
||||
qCritical() << "(" << __func__ << ":" << __LINE__ << ")"
|
||||
<< "duration" << duration
|
||||
<< "durationMinutes" << durationMinutes
|
||||
<< "durationMinutesNetto" << durationMinutesNetto
|
||||
<< "durationMinutesBrutto" << durationMinutesBrutto
|
||||
<< "minsToCarryOver" << minsToCarryOver;
|
||||
#endif
|
||||
|
||||
if (minsLeft > 0) {
|
||||
for(const auto &x: cfg->PaymentRate) {
|
||||
ATBPaymentRate const rate = x.second;
|
||||
if (rate.pra_payment_unit_id == timeRange.time_range_payment_type_id) {
|
||||
price += (uint)rate.pra_price;
|
||||
#if DEBUG==1
|
||||
qCritical() << "(" << __func__ << ":" << __LINE__ << ")"
|
||||
<< "price" << price;
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
durationMinutes -= duration;
|
||||
durationMinutesNetto += duration;
|
||||
durationMinutesBrutto += duration;
|
||||
current = current.addSecs(duration*60);
|
||||
minsToCarryOver = 0;
|
||||
}
|
||||
} else {
|
||||
for(const auto &x: cfg->PaymentRate) {
|
||||
ATBPaymentRate const rate = x.second;
|
||||
if (rate.pra_payment_unit_id == timeRange.time_range_payment_type_id) {
|
||||
price += (uint)rate.pra_price;
|
||||
|
||||
break;
|
||||
durationMinutes -= duration;
|
||||
durationMinutesNetto += duration;
|
||||
durationMinutesBrutto += duration;
|
||||
|
||||
current = current.addSecs(duration * 60);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (durationMinutes <= 0) {
|
||||
end_datetime = current;
|
||||
return price;
|
||||
}
|
||||
|
||||
//++timeRangeIt;
|
||||
|
||||
} else {
|
||||
|
||||
lastCurrent = current;
|
||||
current.setTime(to);
|
||||
minsUsed = lastCurrent.secsTo(current) / 60;
|
||||
|
||||
// mod duration: possibly discard some minutes in
|
||||
// the next time-range
|
||||
if (durationMinutes >= minsUsed) {
|
||||
minsToCarryOver = durationMinutes - minsUsed;
|
||||
}
|
||||
|
||||
durationMinutes -= minsUsed;
|
||||
durationMinutesNetto += minsUsed;
|
||||
durationMinutesBrutto += minsUsed;
|
||||
|
||||
if (minsUsed > 0) {
|
||||
for(const auto &x: cfg->PaymentRate) {
|
||||
ATBPaymentRate const rate = x.second;
|
||||
if (rate.pra_payment_unit_id == timeRange.time_range_payment_type_id) {
|
||||
price += (uint)rate.pra_price;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
// break;
|
||||
}
|
||||
}
|
||||
} // for (WTIterator itr = p.first; itr != p.second; ++itr) {
|
||||
|
||||
end_datetime = start.addSecs(durationMinutesBrutto * 60);
|
||||
#if DEBUG==1
|
||||
qCritical() << "(" << __func__ << ":" << __LINE__ << ")"
|
||||
<< "duration" << durationMinutesNetto
|
||||
<< ", price" << std::max(price, minParkingPrice)
|
||||
<< start.toString(Qt::ISODate)
|
||||
<< end_datetime.toString(Qt::ISODate);
|
||||
#endif
|
||||
return std::max(price, minParkingPrice);
|
||||
}
|
||||
}
|
||||
@@ -1072,6 +1204,8 @@ QList<int> Calculator::GetTimeSteps(Configuration *cfg) const {
|
||||
int const pop_carry_over = cfg->getPaymentOptions().pop_carry_over;
|
||||
int const pop_time_step_config = cfg->getPaymentOptions().pop_time_step_config;
|
||||
|
||||
static PaymentMethod const paymentMethodId = Utilities::getPaymentMethodId(cfg);
|
||||
|
||||
qCritical() << __func__ << ":" << __LINE__ << " start parking time:" << start.toString(Qt::ISODate);
|
||||
qCritical() << __func__ << ":" << __LINE__ << " payment option id:" << pop_id;
|
||||
qCritical() << __func__ << ":" << __LINE__ << "payment option carry over:" << pop_carry_over;
|
||||
@@ -1079,63 +1213,71 @@ QList<int> Calculator::GetTimeSteps(Configuration *cfg) const {
|
||||
if (pop_time_step_config == (int)ATBTimeStepConfig::TimeStepConfig::DYNAMIC) {
|
||||
//qCritical() << __PRETTY_FUNCTION__ << "payment option time step config:" << "TimeStepConfig::DYNAMIC";
|
||||
|
||||
uint16_t timeStepCompensation = 0;
|
||||
if (paymentMethodId == PaymentMethod::Progressive) { // e.g. neuhauser kirchdorf (743)
|
||||
std::size_t const s = cfg->TimeRange.size();
|
||||
for (std::size_t id = 1; id <= s; ++id) {
|
||||
int const step = Utilities::getTimeRangeStep(cfg, id, paymentMethodId);
|
||||
m_timeSteps.append(step);
|
||||
}
|
||||
} else {
|
||||
uint16_t timeStepCompensation = 0;
|
||||
|
||||
if (pop_carry_over) {
|
||||
int const pop_carry_over_time_range_id = cfg->getPaymentOptions().pop_carry_over_time_range_id;
|
||||
QTime const carryOverTimeRangeFrom = cfg->TimeRange.find(pop_carry_over_time_range_id)->second.time_range_from;
|
||||
QTime const carryOverTimeRangeTo = cfg->TimeRange.find(pop_carry_over_time_range_id)->second.time_range_to;
|
||||
if (pop_carry_over) {
|
||||
int const pop_carry_over_time_range_id = cfg->getPaymentOptions().pop_carry_over_time_range_id;
|
||||
QTime const carryOverTimeRangeFrom = cfg->TimeRange.find(pop_carry_over_time_range_id)->second.time_range_from;
|
||||
QTime const carryOverTimeRangeTo = cfg->TimeRange.find(pop_carry_over_time_range_id)->second.time_range_to;
|
||||
|
||||
if (carryOverTimeRangeFrom.secsTo(carryOverTimeRangeTo) <= 60) { // carry over time point, usually 00:00:00
|
||||
if (carryOverTimeRangeFrom == QTime(0, 0, 0)) {
|
||||
for (auto[itr, rangeEnd] = cfg->PaymentRate.equal_range(pop_id); itr != rangeEnd; ++itr) {
|
||||
int const durationId = itr->second.pra_payment_unit_id;
|
||||
auto search = cfg->Duration.find(durationId);
|
||||
if (search != cfg->Duration.end()) {
|
||||
ATBDuration duration = search->second;
|
||||
if (durationId == 1) {
|
||||
QDateTime carryOver = start;
|
||||
carryOver = carryOver.addDays(1);
|
||||
carryOver.setTime(QTime(0, 0, 0));
|
||||
if (carryOverTimeRangeFrom.secsTo(carryOverTimeRangeTo) <= 60) { // carry over time point, usually 00:00:00
|
||||
if (carryOverTimeRangeFrom == QTime(0, 0, 0)) {
|
||||
for (auto[itr, rangeEnd] = cfg->PaymentRate.equal_range(pop_id); itr != rangeEnd; ++itr) {
|
||||
int const durationId = itr->second.pra_payment_unit_id;
|
||||
auto search = cfg->Duration.find(durationId);
|
||||
if (search != cfg->Duration.end()) {
|
||||
ATBDuration duration = search->second;
|
||||
if (durationId == 1) {
|
||||
QDateTime carryOver = start;
|
||||
carryOver = carryOver.addDays(1);
|
||||
carryOver.setTime(QTime(0, 0, 0));
|
||||
|
||||
int const timeStep = std::ceil(start.secsTo(carryOver) / 60.0);
|
||||
if (timeStep < duration.pun_duration_min || timeStep > duration.pun_duration_max) {
|
||||
qCritical()
|
||||
<< QString("ERROR timeStep (%1) < durationMin (%2) || timeStep (%3)) > durationMax (%4)")
|
||||
.arg(timeStep).arg(duration.pun_duration_min)
|
||||
.arg(timeStep).arg(duration.pun_duration_max);
|
||||
break;
|
||||
int const timeStep = std::ceil(start.secsTo(carryOver) / 60.0);
|
||||
if (timeStep < duration.pun_duration_min || timeStep > duration.pun_duration_max) {
|
||||
qCritical()
|
||||
<< QString("ERROR timeStep (%1) < durationMin (%2) || timeStep (%3)) > durationMax (%4)")
|
||||
.arg(timeStep).arg(duration.pun_duration_min)
|
||||
.arg(timeStep).arg(duration.pun_duration_max);
|
||||
break;
|
||||
}
|
||||
qCritical() << __PRETTY_FUNCTION__ << "configured minimal parking time:" << cfg->getPaymentOptions().pop_min_time;
|
||||
|
||||
// set dynamic minimal parking time
|
||||
cfg->getPaymentOptions().pop_min_time = timeStep;
|
||||
|
||||
qCritical() << __PRETTY_FUNCTION__ << " computed minimal parking time:" << cfg->getPaymentOptions().pop_min_time;
|
||||
|
||||
duration.pun_duration = timeStep;
|
||||
timeStepCompensation = duration.pun_duration_max - duration.pun_duration;
|
||||
m_timeSteps << duration.pun_duration;
|
||||
} else {
|
||||
duration.pun_duration = duration.pun_duration_max - timeStepCompensation;
|
||||
m_timeSteps << duration.pun_duration;;
|
||||
}
|
||||
qCritical() << __PRETTY_FUNCTION__ << "configured minimal parking time:" << cfg->getPaymentOptions().pop_min_time;
|
||||
|
||||
// set dynamic minimal parking time
|
||||
cfg->getPaymentOptions().pop_min_time = timeStep;
|
||||
cfg->Duration.erase(search);
|
||||
cfg->Duration.insert(pair<int, ATBDuration>(duration.pun_id, duration));
|
||||
|
||||
qCritical() << __PRETTY_FUNCTION__ << " computed minimal parking time:" << cfg->getPaymentOptions().pop_min_time;
|
||||
|
||||
duration.pun_duration = timeStep;
|
||||
timeStepCompensation = duration.pun_duration_max - duration.pun_duration;
|
||||
m_timeSteps << duration.pun_duration;
|
||||
} else {
|
||||
duration.pun_duration = duration.pun_duration_max - timeStepCompensation;
|
||||
m_timeSteps << duration.pun_duration;;
|
||||
} else { // if (search != cfg->Duration.end()) {
|
||||
// TODO
|
||||
}
|
||||
|
||||
cfg->Duration.erase(search);
|
||||
cfg->Duration.insert(pair<int, ATBDuration>(duration.pun_id, duration));
|
||||
|
||||
} else { // if (search != cfg->Duration.end()) {
|
||||
// TODO
|
||||
}
|
||||
} else { // if (carryOverTimeRangeFrom == QTime(0, 0, 0)) {
|
||||
// TODO
|
||||
}
|
||||
} else { // if (carryOverTimeRangeFrom == QTime(0, 0, 0)) {
|
||||
} else { // if (carryOverTimeRangeFrom == carryOverTimeRangeTo) {
|
||||
// TODO
|
||||
}
|
||||
} else { // if (carryOverTimeRangeFrom == carryOverTimeRangeTo) {
|
||||
} else { // if (pop_carry_over) {
|
||||
// TODO
|
||||
}
|
||||
} else { // if (pop_carry_over) {
|
||||
// TODO
|
||||
}
|
||||
} else {
|
||||
qCritical() << __PRETTY_FUNCTION__ << "payment option time step config:" << "TimeStepConfig::STATIC";
|
||||
@@ -1308,6 +1450,18 @@ Calculator::GetDailyTicketPrice(Configuration* cfg,
|
||||
case PERMIT_TYPE::INVALID:
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
// for projects which have not defined a daily ticket in their
|
||||
// tariff-files (e.g. szeged)
|
||||
price.netto = cfg->getPaymentOptions().pop_daily_card_price;
|
||||
|
||||
qCritical() << "( GetDailyTicketPrice():" << __LINE__ << ")";
|
||||
qCritical() << " start:" << startDatetime.toString(Qt::ISODate);
|
||||
qCritical() << " workTime from:" << QTime::fromString(QString(wt.pwd_time_from.c_str()), Qt::ISODate);
|
||||
qCritical() << " workTime to:" << QTime::fromString(QString(wt.pwd_time_to.c_str()), Qt::ISODate);
|
||||
qCritical() << "daily_ticket_card_price:" << price.netto;
|
||||
|
||||
value = value.value_or(price);
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user