Compare commits

...

4 Commits

Author SHA1 Message Date
275c3ec869 compute_price_for_parking_ticket():
Pass start-date-time to parking-time-checker.
2024-09-03 11:19:23 +02:00
6d2bde1fe9 getPaymentOptionIndex():
Fix: make sure only one payment option can be chosen.
2024-09-03 11:17:31 +02:00
f02521d3c2 parseWeekDay():
for the park-time-limit checking take into account that the
 	start-date-time and end-date-time are on different days.
2024-09-03 11:15:08 +02:00
75f1c1bb76 Checking parking-time-limit:
provide start-date-time as well, because the limit counts only
	from one day to following day (e.g. Sunday to Monday or from
	holiday to next day).
2024-09-03 11:10:24 +02:00
3 changed files with 131 additions and 110 deletions

View File

@ -10,7 +10,9 @@ struct ATBTariffCarryOverSettings {
// parking time limit not violated: return false, otherwise: return true. // parking time limit not violated: return false, otherwise: return true.
using ParkingTimeLimitChecker = std::function<bool(ATBTariffCarryOverSettings const&, using ParkingTimeLimitChecker = std::function<bool(ATBTariffCarryOverSettings const&,
QDateTime const &endTime, int paymentOptionIndex)>; QDateTime const &startTime,
QDateTime const &endTime,
int paymentOptionIndex)>;
int m_duration; int m_duration;
QTime m_start; QTime m_start;
@ -24,7 +26,8 @@ struct ATBTariffCarryOverSettings {
: m_duration(0) : m_duration(0)
, m_start(QTime()) , m_start(QTime())
, m_end(QTime()) , m_end(QTime())
, m_parkingTimeLimitChecker([](ATBTariffCarryOverSettings const&, QDateTime const &, int) { return false; }) , m_parkingTimeLimitChecker([](ATBTariffCarryOverSettings const&,
QDateTime const&, QDateTime const&, int) { return false; })
, m_parking_time_limit(QTime()) , m_parking_time_limit(QTime())
, m_about_to_exceed_parking_time_limit(QTime()) {} , m_about_to_exceed_parking_time_limit(QTime()) {}
@ -41,8 +44,10 @@ struct ATBTariffCarryOverSettings {
, m_about_to_exceed_parking_time_limit(about_to_exceed_parking_time_limit) { , m_about_to_exceed_parking_time_limit(about_to_exceed_parking_time_limit) {
} }
bool parkingTimeLimitExceeded(QDateTime const &endTime, int paymentOptionIndex) const { bool parkingTimeLimitExceeded(QDateTime const &startTime,
return m_parkingTimeLimitChecker(*this, endTime, paymentOptionIndex); QDateTime const &endTime,
int paymentOptionIndex) const {
return m_parkingTimeLimitChecker(*this, startTime, endTime, paymentOptionIndex);
} }
friend QDebug operator<<(QDebug debug, ATBTariffCarryOverSettings const &co) { friend QDebug operator<<(QDebug debug, ATBTariffCarryOverSettings const &co) {

View File

@ -852,7 +852,9 @@ CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket(
for (auto[itr, rangeEnd] = tariff->WeekDays.equal_range((Qt::DayOfWeek)weekDay); itr != rangeEnd; ++itr) { for (auto[itr, rangeEnd] = tariff->WeekDays.equal_range((Qt::DayOfWeek)weekDay); itr != rangeEnd; ++itr) {
ATBWeekDay const &wd = itr->second; ATBWeekDay const &wd = itr->second;
bool const parkTimeLimitViolated = wd.getTariffCarryOverSettings().parkingTimeLimitExceeded(end_parking_time, paymentOptionIndex); bool const parkTimeLimitViolated = wd.getTariffCarryOverSettings().parkingTimeLimitExceeded(effectiveStartTime,
end_parking_time,
paymentOptionIndex);
if (parkTimeLimitViolated) { if (parkTimeLimitViolated) {
calcState.setDesc(QString("line=%1 endTime=%2: park-time-limit violated").arg(__LINE__) calcState.setDesc(QString("line=%1 endTime=%2: park-time-limit violated").arg(__LINE__)
.arg(end_parking_time.time().toString(Qt::ISODate))); .arg(end_parking_time.time().toString(Qt::ISODate)));
@ -1138,7 +1140,9 @@ CalcState CALCULATE_LIBRARY_API compute_duration_for_parking_ticket(
itr != rangeEnd; itr != rangeEnd;
++itr) { ++itr) {
ATBWeekDay const &wd = itr->second; ATBWeekDay const &wd = itr->second;
bool const parkTimeLimitViolated = wd.getTariffCarryOverSettings().parkingTimeLimitExceeded(ticketEndTime, paymentOptionIndex); bool const parkTimeLimitViolated = wd.getTariffCarryOverSettings().parkingTimeLimitExceeded(start_parking_time,
ticketEndTime,
paymentOptionIndex);
if (parkTimeLimitViolated) { if (parkTimeLimitViolated) {
calcState.setDesc(QString("line=%1 endTime=%2: park-time-limit violated").arg(__LINE__) calcState.setDesc(QString("line=%1 endTime=%2: park-time-limit violated").arg(__LINE__)
.arg(ticketEndTime.time().toString(Qt::ISODate))); .arg(ticketEndTime.time().toString(Qt::ISODate)));

View File

@ -112,7 +112,7 @@ ATBWeekDay parseWeekDay(Configuration &cfg,
for (auto l = o.MemberBegin(); l != o.MemberEnd(); ++l) { for (auto l = o.MemberBegin(); l != o.MemberEnd(); ++l) {
if (l->name.IsString()) { if (l->name.IsString()) {
QString const &member = QString::fromStdString(l->name.GetString()); QString const &member = QString::fromStdString(l->name.GetString());
if (member == "default") { if (member == "prev_day_sunday?") {
if (l->value.IsArray()) { if (l->value.IsArray()) {
auto limits = l->value.GetArray(); auto limits = l->value.GetArray();
if (limits.Size() >= 2) { if (limits.Size() >= 2) {
@ -120,23 +120,26 @@ ATBWeekDay parseWeekDay(Configuration &cfg,
parking_time_limit = QTime::fromString(QString::fromStdString(limits[1].GetString()), Qt::ISODate); parking_time_limit = QTime::fromString(QString::fromStdString(limits[1].GetString()), Qt::ISODate);
} }
parkTimeLimitChecker = [&cfg, weekDay, weekDayName](ATBTariffCarryOverSettings const& cs, parkTimeLimitChecker = [&cfg, weekDay, weekDayName](ATBTariffCarryOverSettings const& cs,
QDateTime const &endTime, QDateTime const &startTime,
int paymentOptionIndex) { QDateTime const &endTime,
if (endTime.date().dayOfWeek() == (int)weekDay) { int paymentOptionIndex) {
if (endTime.time() > cs.m_parking_time_limit) { if (startTime.date() < endTime.date()) { // start end end on different days
qCritical() << __func__ << ":" << __LINE__ if (endTime.date().dayOfWeek() == (int)weekDay) {
<< QString("ERROR time limit for end-time violated: [%1, %2 end-time=%3], but time-limit=%4") if (endTime.time() > cs.m_parking_time_limit) {
.arg(weekDayName) qCritical() << __func__ << ":" << __LINE__
.arg(endTime.date().toString(Qt::ISODate)) << QString("ERROR time limit for end-time violated: [%1, %2 end-time=%3], but time-limit=%4")
.arg(endTime.time().toString(Qt::ISODate)) .arg(weekDayName)
.arg(cs.m_parking_time_limit.toString(Qt::ISODate)); .arg(endTime.date().toString(Qt::ISODate))
return true; .arg(endTime.time().toString(Qt::ISODate))
} .arg(cs.m_parking_time_limit.toString(Qt::ISODate));
if (endTime.time() >= cs.m_about_to_exceed_parking_time_limit) { return true;
cfg.getPaymentOptions(paymentOptionIndex).pop_plus_steps = 1; }
} else { if (endTime.time() >= cs.m_about_to_exceed_parking_time_limit) {
cfg.getPaymentOptions(paymentOptionIndex).pop_plus_steps = cfg.getPaymentOptions(paymentOptionIndex).pop_plus_steps = 1;
cfg.getPaymentOptions(paymentOptionIndex).pop_plus_steps_saved; } else {
cfg.getPaymentOptions(paymentOptionIndex).pop_plus_steps =
cfg.getPaymentOptions(paymentOptionIndex).pop_plus_steps_saved;
}
} }
} }
return false; return false;
@ -151,23 +154,26 @@ ATBWeekDay parseWeekDay(Configuration &cfg,
parking_time_limit = QTime::fromString(QString::fromStdString(limits[1].GetString()), Qt::ISODate); parking_time_limit = QTime::fromString(QString::fromStdString(limits[1].GetString()), Qt::ISODate);
} }
parkTimeLimitChecker = [&cfg, weekDayName](ATBTariffCarryOverSettings const& cs, parkTimeLimitChecker = [&cfg, weekDayName](ATBTariffCarryOverSettings const& cs,
QDateTime const &endTime, QDateTime const &startTime,
int paymentOptionIndex) { QDateTime const &endTime,
if (previousDayHoliday(cfg, endTime)) { int paymentOptionIndex) {
if (endTime.time() > cs.m_parking_time_limit) { if (startTime.date() < endTime.date()) { // start end end on different days
qCritical() << __func__ << ":" << __LINE__ if (previousDayHoliday(cfg, endTime)) {
<< QString("ERROR time limit for end-time violated: [%1, %2, end-time=%3], but time-limit=%4") if (endTime.time() > cs.m_parking_time_limit) {
.arg(weekDayName) qCritical() << __func__ << ":" << __LINE__
.arg(endTime.date().toString(Qt::ISODate)) << QString("ERROR time limit for end-time violated: [%1, %2, end-time=%3], but time-limit=%4")
.arg(endTime.time().toString(Qt::ISODate)) .arg(weekDayName)
.arg(cs.m_parking_time_limit.toString(Qt::ISODate)); .arg(endTime.date().toString(Qt::ISODate))
return true; .arg(endTime.time().toString(Qt::ISODate))
} .arg(cs.m_parking_time_limit.toString(Qt::ISODate));
if (endTime.time() >= cs.m_about_to_exceed_parking_time_limit) { return true;
cfg.getPaymentOptions(paymentOptionIndex).pop_plus_steps = 1; }
} else { if (endTime.time() >= cs.m_about_to_exceed_parking_time_limit) {
cfg.getPaymentOptions(paymentOptionIndex).pop_plus_steps = cfg.getPaymentOptions(paymentOptionIndex).pop_plus_steps = 1;
cfg.getPaymentOptions(paymentOptionIndex).pop_plus_steps_saved; } else {
cfg.getPaymentOptions(paymentOptionIndex).pop_plus_steps =
cfg.getPaymentOptions(paymentOptionIndex).pop_plus_steps_saved;
}
} }
} }
return false; return false;
@ -251,21 +257,24 @@ ATBWeekDay parseWeekDay(Configuration &cfg,
} }
parkTimeLimitChecker = [&cfg, weekDay](ATBTariffCarryOverSettings const& cs, parkTimeLimitChecker = [&cfg, weekDay](ATBTariffCarryOverSettings const& cs,
QDateTime const &endTime, QDateTime const &startTime,
int paymentOptionIndex) { QDateTime const &endTime,
if (endTime.date().dayOfWeek() == (int)weekDay) { int paymentOptionIndex) {
if (endTime.time() > cs.m_parking_time_limit) { if (startTime.date() < endTime.date()) { // start end end on different days
qCritical() << __func__ << ":" << __LINE__ if (endTime.date().dayOfWeek() == (int)weekDay) {
<< QString("ERROR time limit for end-time violated: end-time=%1, but time-limit=%2") if (endTime.time() > cs.m_parking_time_limit) {
.arg(endTime.time().toString(Qt::ISODate)) qCritical() << __func__ << ":" << __LINE__
.arg(cs.m_parking_time_limit.toString(Qt::ISODate)); << QString("ERROR time limit for end-time violated: end-time=%1, but time-limit=%2")
return true; .arg(endTime.time().toString(Qt::ISODate))
} .arg(cs.m_parking_time_limit.toString(Qt::ISODate));
if (endTime.time() >= cs.m_about_to_exceed_parking_time_limit) { return true;
cfg.getPaymentOptions(paymentOptionIndex).pop_plus_steps = 1; }
} else { if (endTime.time() >= cs.m_about_to_exceed_parking_time_limit) {
cfg.getPaymentOptions(paymentOptionIndex).pop_plus_steps = cfg.getPaymentOptions(paymentOptionIndex).pop_plus_steps = 1;
cfg.getPaymentOptions(paymentOptionIndex).pop_plus_steps_saved; } else {
cfg.getPaymentOptions(paymentOptionIndex).pop_plus_steps =
cfg.getPaymentOptions(paymentOptionIndex).pop_plus_steps_saved;
}
} }
} }
return false; return false;
@ -280,21 +289,24 @@ ATBWeekDay parseWeekDay(Configuration &cfg,
} }
} }
parkTimeLimitChecker = [&cfg](ATBTariffCarryOverSettings const& cs, parkTimeLimitChecker = [&cfg](ATBTariffCarryOverSettings const& cs,
QDateTime const &endTime, QDateTime const &startTime,
int paymentOptionIndex) { QDateTime const &endTime,
if (previousDayHoliday(cfg, endTime)) { int paymentOptionIndex) {
if (endTime.time() > cs.m_parking_time_limit) { if (startTime.date() < endTime.date()) { // start end end on different days
qCritical() << __func__ << ":" << __LINE__ if (previousDayHoliday(cfg, endTime)) {
<< QString("ERROR time limit for end-time violated: end-time=%1, but time-limit=%2") if (endTime.time() > cs.m_parking_time_limit) {
.arg(endTime.time().toString(Qt::ISODate)) qCritical() << __func__ << ":" << __LINE__
.arg(cs.m_parking_time_limit.toString(Qt::ISODate)); << QString("ERROR time limit for end-time violated: end-time=%1, but time-limit=%2")
return true; .arg(endTime.time().toString(Qt::ISODate))
} .arg(cs.m_parking_time_limit.toString(Qt::ISODate));
if (endTime.time() >= cs.m_about_to_exceed_parking_time_limit) { return true;
cfg.getPaymentOptions(paymentOptionIndex).pop_plus_steps = 1; }
} else { if (endTime.time() >= cs.m_about_to_exceed_parking_time_limit) {
cfg.getPaymentOptions(paymentOptionIndex).pop_plus_steps = cfg.getPaymentOptions(paymentOptionIndex).pop_plus_steps = 1;
cfg.getPaymentOptions(paymentOptionIndex).pop_plus_steps_saved; } else {
cfg.getPaymentOptions(paymentOptionIndex).pop_plus_steps =
cfg.getPaymentOptions(paymentOptionIndex).pop_plus_steps_saved;
}
} }
} }
return false; return false;
@ -1523,7 +1535,6 @@ int Configuration::getPaymentOptionIndex(PERMIT_TYPE permitType) const {
int getPaymentOptionIndex(Configuration const &cfg) { int getPaymentOptionIndex(Configuration const &cfg) {
int const numOptions = cfg.getAllPaymentOptions().size(); int const numOptions = cfg.getAllPaymentOptions().size();
for (int opt=0; opt < numOptions; ++opt) { for (int opt=0; opt < numOptions; ++opt) {
@ -1536,48 +1547,48 @@ int getPaymentOptionIndex(Configuration const &cfg) {
QDateTime const dt = QDateTime::currentDateTime(); QDateTime const dt = QDateTime::currentDateTime();
int const dayOfWeek = dt.date().dayOfWeek(); int const dayOfWeek = dt.date().dayOfWeek();
switch (dayOfWeek) {
case (int)Qt::Monday: {
if (pop_business_hours & BusinessHours::MON) {
return opt;
}
} break;
case (int)Qt::Tuesday: {
if (pop_business_hours & BusinessHours::TUE) {
return opt;
}
} break;
case (int)Qt::Wednesday: {
if (pop_business_hours & BusinessHours::WED) {
return opt;
}
} break;
case (int)Qt::Thursday: {
if (pop_business_hours & BusinessHours::THU) {
return opt;
}
} break;
case (int)Qt::Friday: {
if (pop_business_hours & BusinessHours::FRI) {
return opt;
}
} break;
case (int)Qt::Saturday: {
if (pop_business_hours & BusinessHours::SAT) {
return opt;
}
} break;
case (int)Qt::Sunday: {
if (pop_business_hours & BusinessHours::SUN) {
return opt;
}
} break;
}
if (isHoliday(cfg, dt)) { if (isHoliday(cfg, dt)) {
if (pop_business_hours & BusinessHours::OFFICIAL_HOLIDAY) { if (pop_business_hours & BusinessHours::OFFICIAL_HOLIDAY) {
return opt; return opt;
} }
} else {
switch (dayOfWeek) {
case (int)Qt::Monday: {
if (pop_business_hours & BusinessHours::MON) {
return opt;
}
} break;
case (int)Qt::Tuesday: {
if (pop_business_hours & BusinessHours::TUE) {
return opt;
}
} break;
case (int)Qt::Wednesday: {
if (pop_business_hours & BusinessHours::WED) {
return opt;
}
} break;
case (int)Qt::Thursday: {
if (pop_business_hours & BusinessHours::THU) {
return opt;
}
} break;
case (int)Qt::Friday: {
if (pop_business_hours & BusinessHours::FRI) {
return opt;
}
} break;
case (int)Qt::Saturday: {
if (pop_business_hours & BusinessHours::SAT) {
return opt;
}
} break;
case (int)Qt::Sunday: {
if (pop_business_hours & BusinessHours::SUN) {
return opt;
}
} break;
}
} }
} }
@ -1841,6 +1852,7 @@ Configuration::getWeekDayWorkTime(QTime const &time, Qt::DayOfWeek dayOfWeek) {
bool isHoliday(Configuration const &cfg, QDateTime const &t) { bool isHoliday(Configuration const &cfg, QDateTime const &t) {
int const weekDay = t.date().dayOfWeek(); int const weekDay = t.date().dayOfWeek();
for (auto[iter, rEnd] = cfg.WeekDays.equal_range(static_cast<Qt::DayOfWeek>(weekDay)); for (auto[iter, rEnd] = cfg.WeekDays.equal_range(static_cast<Qt::DayOfWeek>(weekDay));
iter != rEnd; iter != rEnd;
++iter) { ++iter) {