Compare commits
11 Commits
c0f0648a74
...
2.1.0
| Author | SHA1 | Date | |
|---|---|---|---|
| 9d5ddfc328 | |||
| 102607b71f | |||
| 81d515eb7f | |||
| ce61e5d3b2 | |||
| b6a0f5e8af | |||
| e0223b50f9 | |||
| 690267c388 | |||
| 9c19414e5a | |||
| 3ff9883647 | |||
| 696ce644ab | |||
| 9ea2037eca |
@@ -90,6 +90,7 @@ namespace Utilities {
|
|||||||
uint32_t getMinimalParkingPrice(Configuration const *cfg, PaymentMethod methodId);
|
uint32_t getMinimalParkingPrice(Configuration const *cfg, PaymentMethod methodId);
|
||||||
uint32_t getMaximalParkingPrice(Configuration const *cfg, PaymentMethod methodId);
|
uint32_t getMaximalParkingPrice(Configuration const *cfg, PaymentMethod methodId);
|
||||||
uint32_t getFirstDurationStep(Configuration const *cfg, PaymentMethod methodId);
|
uint32_t getFirstDurationStep(Configuration const *cfg, PaymentMethod methodId);
|
||||||
|
uint32_t getTimeRangeStep(Configuration const *cfg, int step, PaymentMethod methodId);
|
||||||
BusinessHours getBusinessHours(Configuration const *cfg, PaymentMethod methodId);
|
BusinessHours getBusinessHours(Configuration const *cfg, PaymentMethod methodId);
|
||||||
uint32_t computeWeekDaysPrice(Configuration const *cfg, PaymentMethod id);
|
uint32_t computeWeekDaysPrice(Configuration const *cfg, PaymentMethod id);
|
||||||
double computeWeekDaysDurationUnit(Configuration const *cfg, PaymentMethod id);
|
double computeWeekDaysDurationUnit(Configuration const *cfg, PaymentMethod id);
|
||||||
|
|||||||
@@ -78,9 +78,13 @@ int CALCULATE_LIBRARY_API get_minimal_parkingprice(Configuration *cfg, PERMIT_TY
|
|||||||
|
|
||||||
int CALCULATE_LIBRARY_API get_maximal_parkingprice(Configuration *cfg, PERMIT_TYPE permitType) {
|
int CALCULATE_LIBRARY_API get_maximal_parkingprice(Configuration *cfg, PERMIT_TYPE permitType) {
|
||||||
int maxPrice = -1;
|
int maxPrice = -1;
|
||||||
|
static const PaymentMethod paymentMethodId = Utilities::getPaymentMethodId(cfg);
|
||||||
|
|
||||||
switch(permitType) {
|
switch(permitType) {
|
||||||
case PERMIT_TYPE::SHORT_TERM_PARKING: { // e.g. szeged (customer_281)
|
case PERMIT_TYPE::SHORT_TERM_PARKING: { // e.g. szeged (customer_281)
|
||||||
|
if (paymentMethodId == PaymentMethod::Progressive) {
|
||||||
|
maxPrice = Utilities::getMaximalParkingPrice(cfg, paymentMethodId);
|
||||||
|
} else { // PaymentMethod::Linear -> e.g. szeged
|
||||||
int const key = cfg->getPaymentOptions().pop_id;
|
int const key = cfg->getPaymentOptions().pop_id;
|
||||||
int const maxTime = cfg->getPaymentOptions().pop_max_time; // maxTime is given in minutes
|
int const maxTime = cfg->getPaymentOptions().pop_max_time; // maxTime is given in minutes
|
||||||
std::optional<QVector<ATBPaymentRate>> const &pv = cfg->getPaymentRateForKey(key);
|
std::optional<QVector<ATBPaymentRate>> const &pv = cfg->getPaymentRateForKey(key);
|
||||||
@@ -91,6 +95,7 @@ int CALCULATE_LIBRARY_API get_maximal_parkingprice(Configuration *cfg, PERMIT_TY
|
|||||||
maxPrice = qRound((maxTime * price) / 60.0f);
|
maxPrice = qRound((maxTime * price) / 60.0f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} break;
|
} break;
|
||||||
case PERMIT_TYPE::DAY_TICKET_ADULT:
|
case PERMIT_TYPE::DAY_TICKET_ADULT:
|
||||||
break;
|
break;
|
||||||
@@ -217,7 +222,9 @@ int CALCULATE_LIBRARY_API compute_next_timestep(parking_tariff_t *tariff, int cu
|
|||||||
|
|
||||||
// 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 (paymentMethodId == PaymentMethod::Steps)
|
if ((paymentMethodId == PaymentMethod::Steps) ||
|
||||||
|
// progressive tariff: e.g. Neuhauser, Kirchdorf (743)
|
||||||
|
(paymentMethodId == PaymentMethod::Progressive))
|
||||||
{
|
{
|
||||||
const QList<int> stepList = Calculator::GetInstance().GetTimeSteps(tariff);
|
const QList<int> stepList = Calculator::GetInstance().GetTimeSteps(tariff);
|
||||||
qCritical() << " compute_next_timestep() timeSteps:" << stepList;
|
qCritical() << " compute_next_timestep() timeSteps:" << stepList;
|
||||||
|
|||||||
@@ -115,7 +115,7 @@ QDateTime Calculator::GetDailyTicketDuration(Configuration* cfg, const QDateTime
|
|||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
std::string Calculator::GetDurationFromCost(Configuration* cfg,
|
std::string Calculator::GetDurationFromCost(Configuration* cfg,
|
||||||
uint8_t payment_option,
|
uint8_t payment_option,
|
||||||
char const *start_datetime, // given in local time
|
char const *startDatetimePassed, // given in local time
|
||||||
double cost,
|
double cost,
|
||||||
bool nextDay,
|
bool nextDay,
|
||||||
bool prepaid)
|
bool prepaid)
|
||||||
@@ -124,7 +124,7 @@ std::string Calculator::GetDurationFromCost(Configuration* cfg,
|
|||||||
Q_UNUSED(nextDay);
|
Q_UNUSED(nextDay);
|
||||||
|
|
||||||
// Get input date
|
// 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);
|
static const PaymentMethod paymentMethodId = Utilities::getPaymentMethodId(cfg);
|
||||||
if (paymentMethodId == PaymentMethod::Steps) {
|
if (paymentMethodId == PaymentMethod::Steps) {
|
||||||
@@ -152,44 +152,48 @@ std::string Calculator::GetDurationFromCost(Configuration* cfg,
|
|||||||
// started with Neuhauser, Kirchdorf: merge into main algo. later
|
// started with Neuhauser, Kirchdorf: merge into main algo. later
|
||||||
// for now try out some ideas
|
// 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 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(carryOverNotSet, __func__, "CARRYOVER SET (FOR KIRCHDORF)");
|
||||||
Q_ASSERT_X(prepaid, __func__, "PREPAID NOT SET (FOR KIRCHDORF)");
|
Q_ASSERT_X(prepaid, __func__, "PREPAID NOT SET (FOR KIRCHDORF)");
|
||||||
|
|
||||||
QDateTime start = QDateTime::fromString(QString(start_datetime));
|
QDateTime start_datetime = QDateTime::fromString(QString(startDatetimePassed), Qt::ISODate);
|
||||||
QDateTime end = QDateTime();
|
QDateTime start = start_datetime;
|
||||||
|
QDateTime end_datetime = QDateTime();
|
||||||
|
|
||||||
int weekdayId = -1;
|
int weekdayId = -1;
|
||||||
int weekdayIdLast = -1;
|
int weekdayIdLast = -1;
|
||||||
int timeRanges = 0;
|
int durationMinutes = Utilities::getMaximalParkingTime(cfg, paymentMethodId);
|
||||||
int durationMinutesBrutto = 0;
|
int durationMinutesBrutto = 0;
|
||||||
int durationMinutes = Utilities::getMaximalParkingPrice(cfg, paymentMethodId);
|
|
||||||
|
|
||||||
|
QDateTime current = start;
|
||||||
QDateTime current = QDateTime::fromString(QString(start_datetime), Qt::ISODate);
|
|
||||||
|
|
||||||
#define DEBUG 1
|
|
||||||
//#define DEBUG 0
|
|
||||||
|
|
||||||
#if DEBUG==1
|
|
||||||
qCritical() << "(" << __func__ << ":" << __LINE__ << ")"
|
|
||||||
<< "current" << current.time().toString(Qt::ISODate)
|
|
||||||
<< "durationMinutes" << durationMinutes
|
|
||||||
<< "durationMinutesBrutto" << durationMinutesBrutto;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
int days = 7;
|
int days = 7;
|
||||||
while (--days > 0) {
|
while (--days > 0) {
|
||||||
weekdayId = current.date().dayOfWeek();
|
weekdayId = current.date().dayOfWeek();
|
||||||
weekdayIdLast = weekdayId; // TODO: some end condition in json-file
|
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);
|
current = current.addDays(1);
|
||||||
weekdayId = current.date().dayOfWeek();
|
weekdayId = current.date().dayOfWeek();
|
||||||
if (weekdayId == weekdayIdLast) {
|
if (weekdayId == weekdayIdLast) {
|
||||||
qCritical() << "ERROR: NO VALID WORKDAY-TIMES DEFINED";
|
qCritical() << "ERROR: NO VALID WORKDAY-TIMES DEFINED";
|
||||||
return 0;
|
return QDateTime().toString(Qt::ISODate).toStdString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -205,29 +209,24 @@ std::string Calculator::GetDurationFromCost(Configuration* cfg,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (current.time() >= to) {
|
if (current.time() >= to) {
|
||||||
|
if (carryOverNotSet) {
|
||||||
|
return end_datetime.toString(Qt::ISODate).toStdString();
|
||||||
|
} else {
|
||||||
QDateTime const dt = start;
|
QDateTime const dt = start;
|
||||||
start = start.addDays(1);
|
start = start.addDays(1);
|
||||||
start.setTime(QTime(0, 0, 0));
|
start.setTime(QTime(0, 0, 0));
|
||||||
|
|
||||||
durationMinutesBrutto += dt.secsTo(start) / 60;
|
durationMinutesBrutto += dt.secsTo(start) / 60;
|
||||||
|
|
||||||
#if DEBUG==1
|
|
||||||
qCritical() << "(" << __func__ << ":" << __LINE__ << ")"
|
|
||||||
<< "start" << start.time().toString(Qt::ISODate)
|
|
||||||
<< "durationMinutes" << durationMinutes
|
|
||||||
<< "durationMinutesBrutto" << durationMinutesBrutto;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
current = start;
|
current = start;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int durationMinutesNetto = 0;
|
int durationMinutesNetto = 0;
|
||||||
uint price = cost;
|
uint price = 0;
|
||||||
|
|
||||||
if (carryOverNotSet) {
|
if (carryOverNotSet) {
|
||||||
int range = 0;
|
int range = 0;
|
||||||
@@ -259,17 +258,8 @@ std::string Calculator::GetDurationFromCost(Configuration* cfg,
|
|||||||
uint const minutesMoved = lastCurrent.secsTo(current) / 60;
|
uint const minutesMoved = lastCurrent.secsTo(current) / 60;
|
||||||
durationMinutesBrutto += minutesMoved;
|
durationMinutesBrutto += minutesMoved;
|
||||||
|
|
||||||
#if DEBUG==1
|
|
||||||
qCritical() << "(" << __func__ << ":" << __LINE__ << ")"
|
|
||||||
<< "lastCurrent" << lastCurrent.time().toString(Qt::ISODate)
|
|
||||||
<< "current" << current.time().toString(Qt::ISODate)
|
|
||||||
<< "durationMinutes" << durationMinutes
|
|
||||||
<< "durationMinutesBrutto" << durationMinutesBrutto;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (range == 1) {
|
if (range == 1) {
|
||||||
// TODO
|
start_datetime = current;
|
||||||
// start_datetime = current;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -282,15 +272,7 @@ std::string Calculator::GetDurationFromCost(Configuration* cfg,
|
|||||||
int duration = timeRange.time_range_to_in_minutes_from_start -
|
int duration = timeRange.time_range_to_in_minutes_from_start -
|
||||||
timeRange.time_range_from_in_minutes_from_start;
|
timeRange.time_range_from_in_minutes_from_start;
|
||||||
|
|
||||||
#if DEBUG==1
|
|
||||||
qCritical() << "(" << __func__ << ":" << __LINE__ << ")"
|
|
||||||
<< "duration" << duration
|
|
||||||
<< "durationMinutes" << durationMinutes
|
|
||||||
<< "durationMinutesBrutto" << durationMinutesBrutto;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (current.addSecs(duration * 60).time() <= to) {
|
if (current.addSecs(duration * 60).time() <= to) {
|
||||||
|
|
||||||
for(const auto &x: cfg->PaymentRate) {
|
for(const auto &x: cfg->PaymentRate) {
|
||||||
ATBPaymentRate const rate = x.second;
|
ATBPaymentRate const rate = x.second;
|
||||||
if (rate.pra_payment_unit_id == timeRange.time_range_payment_type_id) {
|
if (rate.pra_payment_unit_id == timeRange.time_range_payment_type_id) {
|
||||||
@@ -300,57 +282,36 @@ std::string Calculator::GetDurationFromCost(Configuration* cfg,
|
|||||||
durationMinutesBrutto += minsToCarryOver;
|
durationMinutesBrutto += minsToCarryOver;
|
||||||
current = current.addSecs(minsToCarryOver*60);
|
current = current.addSecs(minsToCarryOver*60);
|
||||||
minsToCarryOver = 0;
|
minsToCarryOver = 0;
|
||||||
|
|
||||||
#if DEBUG==1
|
|
||||||
qCritical() << "(" << __func__ << ":" << __LINE__ << ")"
|
|
||||||
<< "price" << price
|
|
||||||
<< "durationMinutes" << durationMinutes
|
|
||||||
<< "durationMinutesBrutto" << durationMinutesBrutto;
|
|
||||||
#endif
|
|
||||||
} else {
|
} else {
|
||||||
price -= (uint)rate.pra_price;
|
if (price >= cost) {
|
||||||
|
end_datetime = current;
|
||||||
|
return end_datetime.toString(Qt::ISODate).toStdString();
|
||||||
|
}
|
||||||
|
|
||||||
|
price += (uint)rate.pra_price;
|
||||||
|
|
||||||
|
if (price >= maxParkingPrice) {
|
||||||
|
price = maxParkingPrice;
|
||||||
|
}
|
||||||
|
|
||||||
durationMinutes -= duration;
|
durationMinutes -= duration;
|
||||||
durationMinutesNetto += duration;
|
durationMinutesNetto += duration;
|
||||||
durationMinutesBrutto += duration;
|
durationMinutesBrutto += duration;
|
||||||
|
|
||||||
#if DEBUG==1
|
|
||||||
qCritical() << "(" << __func__ << ":" << __LINE__ << ")"
|
|
||||||
<< "price" << price
|
|
||||||
<< "durationMinutes" << durationMinutes
|
|
||||||
<< "durationMinutesBrutto" << durationMinutesBrutto;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
current = current.addSecs(duration * 60);
|
current = current.addSecs(duration * 60);
|
||||||
|
|
||||||
if (price <= 0) {
|
if (price >= cost) {
|
||||||
|
end_datetime = current;
|
||||||
//end = start.addSecs(durationMinutesBrutto * 60);
|
return end_datetime.toString(Qt::ISODate).toStdString();
|
||||||
end = current;
|
|
||||||
|
|
||||||
#if DEBUG==1
|
|
||||||
qCritical() << "(" << __func__ << ":" << __LINE__ << ")"
|
|
||||||
<< "durationMinutesBrutto" << durationMinutesBrutto
|
|
||||||
<< "price" << price
|
|
||||||
<< "current" << current.toString(Qt::ISODate)
|
|
||||||
<< "end" << end.toString(Qt::ISODate);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return end.toString(Qt::ISODate).toStdString();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#if DEBUG==1
|
|
||||||
qCritical() << "(" << __func__ << ":" << __LINE__ << ")"
|
|
||||||
<< durationMinutes << durationMinutes;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (durationMinutes <= 0) {
|
if (durationMinutes <= 0) {
|
||||||
end = current;
|
end_datetime = current;
|
||||||
return end.toString(Qt::ISODate).toStdString();
|
return end_datetime.toString(Qt::ISODate).toStdString();
|
||||||
}
|
}
|
||||||
|
|
||||||
++timeRangeIt;
|
++timeRangeIt;
|
||||||
@@ -359,43 +320,32 @@ std::string Calculator::GetDurationFromCost(Configuration* cfg,
|
|||||||
|
|
||||||
lastCurrent = current;
|
lastCurrent = current;
|
||||||
current.setTime(to);
|
current.setTime(to);
|
||||||
int const minsLeft = lastCurrent.secsTo(current) / 60;
|
int const minsUsed = lastCurrent.secsTo(current) / 60;
|
||||||
|
|
||||||
// mod duration: possibly discard some minutes in
|
// mod duration: possibly discard some minutes in
|
||||||
// the next time-range
|
// the next time-range
|
||||||
minsToCarryOver = (durationMinutes - minsLeft) % duration;
|
minsToCarryOver = (durationMinutes - minsUsed) % duration;
|
||||||
|
|
||||||
durationMinutes -= minsLeft;
|
durationMinutes -= minsUsed;
|
||||||
durationMinutesNetto += minsLeft;
|
durationMinutesNetto += minsUsed;
|
||||||
durationMinutesBrutto += minsLeft;
|
durationMinutesBrutto += minsUsed;
|
||||||
|
|
||||||
#if DEBUG==1
|
if (minsUsed > 0) {
|
||||||
qCritical() << "(" << __func__ << ":" << __LINE__ << ")"
|
|
||||||
<< "lastCurrent" << lastCurrent.time().toString(Qt::ISODate)
|
|
||||||
<< "current" << current.time().toString(Qt::ISODate)
|
|
||||||
<< "minsLeft" << minsLeft
|
|
||||||
<< "durationMinutes" << durationMinutes
|
|
||||||
<< "durationMinutesBrutto" << durationMinutesBrutto;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (minsLeft > 0) {
|
|
||||||
for(const auto &x: cfg->PaymentRate) {
|
for(const auto &x: cfg->PaymentRate) {
|
||||||
ATBPaymentRate const rate = x.second;
|
ATBPaymentRate const rate = x.second;
|
||||||
if (rate.pra_payment_unit_id == timeRange.time_range_payment_type_id) {
|
if (rate.pra_payment_unit_id == timeRange.time_range_payment_type_id) {
|
||||||
price -= (uint)rate.pra_price;
|
price += (uint)rate.pra_price;
|
||||||
if (price <= 0) {
|
|
||||||
end = lastCurrent;
|
if (price >= maxParkingPrice) {
|
||||||
|
price = maxParkingPrice;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (price >= cost) {
|
||||||
|
end_datetime = current;
|
||||||
|
// return end_datetime.toString(Qt::ISODate).toStdString();
|
||||||
|
}
|
||||||
|
|
||||||
#if DEBUG==1
|
|
||||||
qCritical() << "(" << __func__ << ":" << __LINE__ << ")"
|
|
||||||
<< "lastCurrent" << lastCurrent.time().toString(Qt::ISODate)
|
|
||||||
<< "current" << current.time().toString(Qt::ISODate)
|
|
||||||
<< "price" << price
|
|
||||||
<< "end" << end.toString(Qt::ISODate);
|
|
||||||
#endif
|
|
||||||
// return end.toString(Qt::ISODate).toStdString();
|
|
||||||
break;
|
break;
|
||||||
} else break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -405,21 +355,13 @@ std::string Calculator::GetDurationFromCost(Configuration* cfg,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
end = current;
|
end_datetime = start.addSecs(durationMinutesBrutto * 60);
|
||||||
|
return end_datetime.toString(Qt::ISODate).toStdString();
|
||||||
#if DEBUG==1
|
|
||||||
qCritical() << "(" << __func__ << ":" << __LINE__ << ")"
|
|
||||||
<< "end" << end.toString(Qt::ISODate)
|
|
||||||
<< "durationMinutes" << durationMinutes
|
|
||||||
<< "durationMinutesBrutto" << durationMinutesBrutto;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return end.toString(Qt::ISODate).toStdString();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
end = QDateTime();
|
end_datetime = QDateTime();
|
||||||
return end.toString(Qt::ISODate).toStdString();
|
return end_datetime.toString(Qt::ISODate).toStdString();
|
||||||
}
|
}
|
||||||
|
|
||||||
Ticket t = private_GetDurationFromCost(cfg, inputDate, cost, prepaid);
|
Ticket t = private_GetDurationFromCost(cfg, inputDate, cost, prepaid);
|
||||||
@@ -604,14 +546,18 @@ double Calculator::GetCostFromDuration(Configuration* cfg,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (current.time() >= to) {
|
if (current.time() >= to) {
|
||||||
|
if (carryOverNotSet) {
|
||||||
|
end_datetime = start;
|
||||||
|
return 0;
|
||||||
|
} else {
|
||||||
QDateTime const dt = start;
|
QDateTime const dt = start;
|
||||||
start = start.addDays(1);
|
start = start.addDays(1);
|
||||||
start.setTime(QTime(0, 0, 0));
|
start.setTime(QTime(0, 0, 0));
|
||||||
|
|
||||||
durationMinutesBrutto += dt.secsTo(start) / 60;
|
durationMinutesBrutto += dt.secsTo(start) / 60;
|
||||||
current = start;
|
current = start;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -623,6 +569,7 @@ double Calculator::GetCostFromDuration(Configuration* cfg,
|
|||||||
if (carryOverNotSet) {
|
if (carryOverNotSet) {
|
||||||
int range = 0;
|
int range = 0;
|
||||||
int minsToCarryOver = 0; // from one work-time to the other on the same day
|
int minsToCarryOver = 0; // from one work-time to the other on the same day
|
||||||
|
int minsUsed = 0;
|
||||||
QDateTime lastCurrent = QDateTime();
|
QDateTime lastCurrent = QDateTime();
|
||||||
|
|
||||||
auto timeRangeIt = cfg->TimeRange.cbegin();
|
auto timeRangeIt = cfg->TimeRange.cbegin();
|
||||||
@@ -638,7 +585,6 @@ double Calculator::GetCostFromDuration(Configuration* cfg,
|
|||||||
|
|
||||||
Q_ASSERT_X(from < to, __func__, "MISCONFIGURED WORK-TIMES");
|
Q_ASSERT_X(from < to, __func__, "MISCONFIGURED WORK-TIMES");
|
||||||
|
|
||||||
|
|
||||||
if (current.time() >= to) {
|
if (current.time() >= to) {
|
||||||
continue; // try to use next available work-time
|
continue; // try to use next available work-time
|
||||||
} else
|
} else
|
||||||
@@ -664,18 +610,23 @@ double Calculator::GetCostFromDuration(Configuration* cfg,
|
|||||||
int duration = timeRange.time_range_to_in_minutes_from_start -
|
int duration = timeRange.time_range_to_in_minutes_from_start -
|
||||||
timeRange.time_range_from_in_minutes_from_start;
|
timeRange.time_range_from_in_minutes_from_start;
|
||||||
|
|
||||||
if (current.addSecs(duration * 60).time() <= to) {
|
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) {
|
for(const auto &x: cfg->PaymentRate) {
|
||||||
ATBPaymentRate const rate = x.second;
|
ATBPaymentRate const rate = x.second;
|
||||||
if (rate.pra_payment_unit_id == timeRange.time_range_payment_type_id) {
|
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;
|
|
||||||
} else {
|
|
||||||
price += (uint)rate.pra_price;
|
price += (uint)rate.pra_price;
|
||||||
|
|
||||||
durationMinutes -= duration;
|
durationMinutes -= duration;
|
||||||
@@ -683,10 +634,10 @@ double Calculator::GetCostFromDuration(Configuration* cfg,
|
|||||||
durationMinutesBrutto += duration;
|
durationMinutesBrutto += duration;
|
||||||
|
|
||||||
current = current.addSecs(duration * 60);
|
current = current.addSecs(duration * 60);
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (durationMinutes <= 0) {
|
if (durationMinutes <= 0) {
|
||||||
end_datetime = current;
|
end_datetime = current;
|
||||||
@@ -699,17 +650,19 @@ double Calculator::GetCostFromDuration(Configuration* cfg,
|
|||||||
|
|
||||||
lastCurrent = current;
|
lastCurrent = current;
|
||||||
current.setTime(to);
|
current.setTime(to);
|
||||||
int const minsLeft = lastCurrent.secsTo(current) / 60;
|
minsUsed = lastCurrent.secsTo(current) / 60;
|
||||||
|
|
||||||
// mod duration: possibly discard some minutes in
|
// mod duration: possibly discard some minutes in
|
||||||
// the next time-range
|
// the next time-range
|
||||||
minsToCarryOver = (durationMinutes - minsLeft) % duration;
|
if (durationMinutes >= minsUsed) {
|
||||||
|
minsToCarryOver = durationMinutes - minsUsed;
|
||||||
|
}
|
||||||
|
|
||||||
durationMinutes -= minsLeft;
|
durationMinutes -= minsUsed;
|
||||||
durationMinutesNetto += minsLeft;
|
durationMinutesNetto += minsUsed;
|
||||||
durationMinutesBrutto += minsLeft;
|
durationMinutesBrutto += minsUsed;
|
||||||
|
|
||||||
if (minsLeft > 0) {
|
if (minsUsed > 0) {
|
||||||
for(const auto &x: cfg->PaymentRate) {
|
for(const auto &x: cfg->PaymentRate) {
|
||||||
ATBPaymentRate const rate = x.second;
|
ATBPaymentRate const rate = x.second;
|
||||||
if (rate.pra_payment_unit_id == timeRange.time_range_payment_type_id) {
|
if (rate.pra_payment_unit_id == timeRange.time_range_payment_type_id) {
|
||||||
@@ -718,7 +671,6 @@ double Calculator::GetCostFromDuration(Configuration* cfg,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1221,6 +1173,8 @@ QList<int> Calculator::GetTimeSteps(Configuration *cfg) const {
|
|||||||
int const pop_carry_over = cfg->getPaymentOptions().pop_carry_over;
|
int const pop_carry_over = cfg->getPaymentOptions().pop_carry_over;
|
||||||
int const pop_time_step_config = cfg->getPaymentOptions().pop_time_step_config;
|
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__ << " start parking time:" << start.toString(Qt::ISODate);
|
||||||
qCritical() << __func__ << ":" << __LINE__ << " payment option id:" << pop_id;
|
qCritical() << __func__ << ":" << __LINE__ << " payment option id:" << pop_id;
|
||||||
qCritical() << __func__ << ":" << __LINE__ << "payment option carry over:" << pop_carry_over;
|
qCritical() << __func__ << ":" << __LINE__ << "payment option carry over:" << pop_carry_over;
|
||||||
@@ -1228,6 +1182,13 @@ QList<int> Calculator::GetTimeSteps(Configuration *cfg) const {
|
|||||||
if (pop_time_step_config == (int)ATBTimeStepConfig::TimeStepConfig::DYNAMIC) {
|
if (pop_time_step_config == (int)ATBTimeStepConfig::TimeStepConfig::DYNAMIC) {
|
||||||
//qCritical() << __PRETTY_FUNCTION__ << "payment option time step config:" << "TimeStepConfig::DYNAMIC";
|
//qCritical() << __PRETTY_FUNCTION__ << "payment option time step config:" << "TimeStepConfig::DYNAMIC";
|
||||||
|
|
||||||
|
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;
|
uint16_t timeStepCompensation = 0;
|
||||||
|
|
||||||
if (pop_carry_over) {
|
if (pop_carry_over) {
|
||||||
@@ -1286,6 +1247,7 @@ QList<int> Calculator::GetTimeSteps(Configuration *cfg) const {
|
|||||||
} else { // if (pop_carry_over) {
|
} else { // if (pop_carry_over) {
|
||||||
// TODO
|
// TODO
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
qCritical() << __PRETTY_FUNCTION__ << "payment option time step config:" << "TimeStepConfig::STATIC";
|
qCritical() << __PRETTY_FUNCTION__ << "payment option time step config:" << "TimeStepConfig::STATIC";
|
||||||
|
|
||||||
|
|||||||
@@ -397,6 +397,14 @@ uint32_t Utilities::getMaximalParkingPrice(Configuration const *cfg, PaymentMeth
|
|||||||
return std::max((int)cfg->PaymentOption.find(methodId)->second.pop_max_price, 0);
|
return std::max((int)cfg->PaymentOption.find(methodId)->second.pop_max_price, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint32_t Utilities::getTimeRangeStep(Configuration const *cfg, int step, PaymentMethod methodId) {
|
||||||
|
if (methodId == PaymentMethod::Progressive) {
|
||||||
|
return std::max((int)cfg->TimeRange.find(step)->second.time_range_to_in_minutes_from_start, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
uint32_t Utilities::getFirstDurationStep(Configuration const *cfg, PaymentMethod methodId) {
|
uint32_t Utilities::getFirstDurationStep(Configuration const *cfg, PaymentMethod methodId) {
|
||||||
|
|
||||||
int const popId = cfg->PaymentOption.find(methodId)->second.pop_id;
|
int const popId = cfg->PaymentOption.find(methodId)->second.pop_id;
|
||||||
|
|||||||
@@ -115,13 +115,13 @@ int main() {
|
|||||||
bool prePaid = true;
|
bool prePaid = true;
|
||||||
// bool carryOver = false;
|
// bool carryOver = false;
|
||||||
|
|
||||||
QDateTime s(QDate(2023, 11, 30), QTime());
|
QDateTime s(QDate(2024, 2, 21), QTime());
|
||||||
// QDateTime s(QDate(2023, 11, 26), QTime());
|
|
||||||
QDateTime end;
|
QDateTime end;
|
||||||
for (int duration = 35; duration <= 35; duration += 5) {
|
for (int duration = 30; duration <= 90; duration += 5) {
|
||||||
// for (int duration = 30; duration <= maxParkingTime; duration += 5) {
|
// for (int duration = 30; duration <= maxParkingTime; duration += 5) {
|
||||||
qCritical() << "";
|
qCritical() << "";
|
||||||
for (int offset = 1046; offset <= 1046; ++offset) {
|
//for (int offset = 420; offset <= 1080; ++offset) {
|
||||||
|
for (int offset = 420; offset <= 1080; ++offset) {
|
||||||
//for (int offset = 420; offset <= 1080; ++offset) {
|
//for (int offset = 420; offset <= 1080; ++offset) {
|
||||||
//if (offset > 720 && offset < 840) {
|
//if (offset > 720 && offset < 840) {
|
||||||
// continue;
|
// continue;
|
||||||
@@ -132,7 +132,7 @@ int main() {
|
|||||||
|
|
||||||
double cost = Calculator::GetInstance().GetCostFromDuration(&cfg, 1, start, end, duration, nextDay, prePaid);
|
double cost = Calculator::GetInstance().GetCostFromDuration(&cfg, 1, start, end, duration, nextDay, prePaid);
|
||||||
|
|
||||||
#if COST_FROM_DURATION==1
|
//#if COST_FROM_DURATION==0
|
||||||
double cost_soll = 30 + ((duration-30)/5 * 10);
|
double cost_soll = 30 + ((duration-30)/5 * 10);
|
||||||
uint32_t duration_ist = start.secsTo(end) / 60;
|
uint32_t duration_ist = start.secsTo(end) / 60;
|
||||||
|
|
||||||
@@ -140,7 +140,6 @@ int main() {
|
|||||||
duration_ist = duration_ist - 120;
|
duration_ist = duration_ist - 120;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
qCritical() << "****" << offset << duration << "****";
|
qCritical() << "****" << offset << duration << "****";
|
||||||
qCritical() << " firstStart :" << firstStart.toString(Qt::ISODate);
|
qCritical() << " firstStart :" << firstStart.toString(Qt::ISODate);
|
||||||
qCritical() << " start :" << start.toString(Qt::ISODate);
|
qCritical() << " start :" << start.toString(Qt::ISODate);
|
||||||
@@ -150,26 +149,39 @@ int main() {
|
|||||||
qCritical() << " cost (soll):" << cost_soll;
|
qCritical() << " cost (soll):" << cost_soll;
|
||||||
qCritical() << " cost (ist) :" << cost;
|
qCritical() << " cost (ist) :" << cost;
|
||||||
|
|
||||||
if (cost_soll != cost) {
|
// if (cost_soll != cost) {
|
||||||
qCritical() << "ERROR" << __func__ << ":" << __LINE__
|
//qCritical() << "ERROR" << __func__ << ":" << __LINE__
|
||||||
<< "cost_soll" << cost_soll << "cost_ist" << cost;
|
// << "cost_soll" << cost_soll << "cost_ist" << cost;
|
||||||
break;
|
//break;
|
||||||
}
|
// }
|
||||||
if (duration != duration_ist) {
|
// if (duration != duration_ist) {
|
||||||
//qCritical() << "ERROR" << __func__ << ":" << __LINE__
|
//qCritical() << "ERROR" << __func__ << ":" << __LINE__
|
||||||
// << "duration_soll" << duration << "duration_ist" << duration_ist;
|
// << "duration_soll" << duration << "duration_ist" << duration_ist;
|
||||||
//break;
|
//break;
|
||||||
}
|
// }
|
||||||
|
|
||||||
#else
|
//#else
|
||||||
|
start = s.addSecs(offset * 60);
|
||||||
std::string duration = Calculator::GetInstance().GetDurationFromCost(&cfg, 1,
|
std::string duration = Calculator::GetInstance().GetDurationFromCost(&cfg, 1,
|
||||||
start.toString(Qt::ISODate).toStdString().c_str(),
|
start.toString(Qt::ISODate).toStdString().c_str(),
|
||||||
cost, false, true);
|
cost, false, true);
|
||||||
|
|
||||||
|
|
||||||
|
if (end.toString(Qt::ISODate) != QString(duration.c_str())) {
|
||||||
|
//qCritical() << "ERROR" << end.toString(Qt::ISODate)
|
||||||
|
// << QString(duration.c_str());
|
||||||
|
//break;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
qCritical() << "start" << start.toString(Qt::ISODate)
|
qCritical() << "start" << start.toString(Qt::ISODate)
|
||||||
<< "cost" << cost
|
<< "cost" << cost
|
||||||
<< "until" << duration.c_str() << start.secsTo(QDateTime::fromString(duration.c_str(), Qt::ISODate)) / 60;
|
<< "until" << duration.c_str()
|
||||||
|
<< "end" << end.toString(Qt::ISODate)
|
||||||
|
<< ":" << start.secsTo(QDateTime::fromString(duration.c_str(), Qt::ISODate)) / 60
|
||||||
|
<< (end.toString(Qt::ISODate) == QString(duration.c_str()));
|
||||||
|
|
||||||
#endif // COST_FROM_DURATION
|
//#endif // COST_FROM_DURATION
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user