Compare commits

..

12 Commits

Author SHA1 Message Date
dffc6e2a03 Minor: removed some debug output. 2024-09-11 11:56:06 +02:00
f9cc3af473 ParseJson():
Add parsing of "pop_apply_carry_over_to_ticket_endtime".
2024-09-11 11:55:03 +02:00
9dd0108731 ParseJson():
Add parsing for prepaid-options.
2024-09-11 11:54:16 +02:00
fa10ea4b89 compute_price_for_parking_ticket():
In case parking-time-limit is violated, return with an error.

	Commented out: use another possiblity: cut max-parking-time
	so that parking-time-limit is not violated.
2024-09-11 11:49:31 +02:00
05f03a623b compute_price_for_parking_ticket():
If after crossing a carry-over-time range (taking several days)
	check if we have to carry over again on the target day.
2024-09-11 11:47:50 +02:00
03e9076962 compute_price_for_parking_ticket():
Minor: add some debug output.
2024-09-11 11:46:36 +02:00
5dbd3645c6 compute_price_for_parking_ticket():
Fetch prepaid-option-id (possibly recalculating it depending
	on year-period), and fetch associated prepaid-options.
2024-09-11 11:44:09 +02:00
d21f69cb9b get_maximal_parkingprice():
Fetch maxPrice directly instead of using utility function.
2024-09-11 11:42:15 +02:00
e38a1bfe12 Add default constructor, update debug output. 2024-09-11 11:40:19 +02:00
f38a8d528c Minor: add getters for parking-time-limit. 2024-09-11 11:39:16 +02:00
08a593eb12 Add 'pop_apply_carry_over_to_ticket_endtime':
If ticket-end-time exactly hits the start of a carry-over-time-range,
	the move to the end of the carry-over-time-range, even if this
	were not strictly necessary.
2024-09-11 11:36:57 +02:00
f322d30e36 Add default constructor, fix debug output. 2024-09-11 11:35:17 +02:00
6 changed files with 182 additions and 24 deletions

View File

@ -44,6 +44,7 @@ public:
pop_plus_steps_saved = 1;
pop_minus_steps = 1; // -: jump <x=1> steps backward
pop_allow_overpay = false;
pop_apply_carry_over_to_ticket_endtime = false;
}
int pop_id;
@ -77,6 +78,7 @@ public:
int pop_plus_steps_saved;
int pop_minus_steps;
bool pop_allow_overpay;
bool pop_apply_carry_over_to_ticket_endtime;
struct ATBMaxDateTime {
int direction;

View File

@ -15,6 +15,19 @@ struct ATBCarryOver {
int id;
explicit ATBCarryOver()
: id(-1) {
for (int i = 0 ; i < 8; ++i) {
carryover[i].day = -1;
carryover[i].seemless = false;
carryover[i].never = false;
carryover[i].static_start = QTime(23, 59, 59);
carryover[i].static_end = QTime(0, 0, 0);
carryover[i].duration = -1;
}
}
friend QDebug operator<<(QDebug debug, ATBCarryOver const &co) {
QDebugStateSaver saver(debug);
@ -31,21 +44,21 @@ struct ATBCarryOver {
<< " day: " << co.carryover[(int)Qt::Tuesday].day << "\n"
<< " static_start: " << co.carryover[(int)Qt::Tuesday].static_start.toString(Qt::ISODate) << "\n"
<< " static_end: " << co.carryover[(int)Qt::Tuesday].static_end.toString(Qt::ISODate) << "\n"
<< " duration: " << co.carryover[(int)Qt::Monday].duration << "\n"
<< " duration: " << co.carryover[(int)Qt::Tuesday].duration << "\n"
<< " anytime: " << co.carryover[(int)Qt::Tuesday].seemless << "\n"
<< " never: " << co.carryover[(int)Qt::Tuesday].never << "\n"
<< " **** Wednesday **** \n"
<< " day: " << co.carryover[(int)Qt::Wednesday].day << "\n"
<< " static_start: " << co.carryover[(int)Qt::Wednesday].static_start.toString(Qt::ISODate) << "\n"
<< " static_end: " << co.carryover[(int)Qt::Wednesday].static_end.toString(Qt::ISODate) << "\n"
<< " duration: " << co.carryover[(int)Qt::Monday].duration << "\n"
<< " duration: " << co.carryover[(int)Qt::Wednesday].duration << "\n"
<< " anytime: " << co.carryover[(int)Qt::Wednesday].seemless << "\n"
<< " never: " << co.carryover[(int)Qt::Wednesday].never << "\n"
<< " **** Thursday **** \n"
<< " day: " << co.carryover[(int)Qt::Thursday].day << "\n"
<< " static_start: " << co.carryover[(int)Qt::Thursday].static_start.toString(Qt::ISODate) << "\n"
<< " static_end: " << co.carryover[(int)Qt::Thursday].static_end.toString(Qt::ISODate) << "\n"
<< " duration: " << co.carryover[(int)Qt::Monday].duration << "\n"
<< " duration: " << co.carryover[(int)Qt::Thursday].duration << "\n"
<< " anytime: " << co.carryover[(int)Qt::Thursday].seemless << "\n"
<< " never: " << co.carryover[(int)Qt::Thursday].never << "\n"
<< " **** Friday **** \n"
@ -58,14 +71,14 @@ struct ATBCarryOver {
<< " day: " << co.carryover[(int)Qt::Saturday].day << "\n"
<< " static_start: " << co.carryover[(int)Qt::Saturday].static_start.toString(Qt::ISODate) << "\n"
<< " static_end: " << co.carryover[(int)Qt::Saturday].static_end.toString(Qt::ISODate) << "\n"
<< " duration: " << co.carryover[(int)Qt::Monday].duration << "\n"
<< " duration: " << co.carryover[(int)Qt::Saturday].duration << "\n"
<< " anytime: " << co.carryover[(int)Qt::Saturday].seemless << "\n"
<< " never: " << co.carryover[(int)Qt::Saturday].never << "\n"
<< " **** Sunday **** \n"
<< " day: " << co.carryover[(int)Qt::Sunday].day << "\n"
<< " static_start: " << co.carryover[(int)Qt::Sunday].static_start.toString(Qt::ISODate) << "\n"
<< " static_end: " << co.carryover[(int)Qt::Sunday].static_end.toString(Qt::ISODate) << "\n"
<< " duration: " << co.carryover[(int)Qt::Monday].duration << "\n"
<< " duration: " << co.carryover[(int)Qt::Sunday].duration << "\n"
<< " anytime: " << co.carryover[(int)Qt::Sunday].seemless << "\n"
<< " never: " << co.carryover[(int)Qt::Sunday].never << "\n";

View File

@ -50,6 +50,9 @@ struct ATBTariffCarryOverSettings {
return m_parkingTimeLimitChecker(*this, startTime, endTime, paymentOptionIndex);
}
QTime const &parkingTimeLimit() const { return m_parking_time_limit; }
QTime &parkingTimeLimit() { return m_parking_time_limit; }
friend QDebug operator<<(QDebug debug, ATBTariffCarryOverSettings const &co) {
QDebugStateSaver saver(debug);

View File

@ -5,13 +5,34 @@
#include <QString>
struct ATBPrepaid {
explicit ATBPrepaid() = default;
int id;
bool anytime;
bool never;
QTime static_start;
QTime static_end;
struct week {
int day;
QTime static_start;
QTime static_end;
int duration;
} prepaid[8];
explicit ATBPrepaid()
: id(-1)
, anytime(false)
, never(false)
, static_start(QTime(23, 59, 59))
, static_end(QTime(0, 0, 0)) {
for (int i = 0 ; i < 8; ++i) {
prepaid[i].day = -1;
prepaid[i].static_start = QTime(23, 59, 59);
prepaid[i].static_end = QTime(0, 0, 0);
prepaid[i].duration = -1;
}
}
friend QDebug operator<<(QDebug debug, ATBPrepaid const &pp) {
QDebugStateSaver saver(debug);
@ -20,7 +41,41 @@ struct ATBPrepaid {
<< " static_start: " << pp.static_start.toString(Qt::ISODate) << "\n"
<< " static_end: " << pp.static_end.toString(Qt::ISODate) << "\n"
<< " anytime: " << pp.anytime << "\n"
<< " never: " << pp.never << "\n";
<< " never: " << pp.never << "\n"
<< " **** Monday **** \n"
<< " day: " << pp.prepaid[(int)Qt::Monday].day << "\n"
<< " static_start: " << pp.prepaid[(int)Qt::Monday].static_start.toString(Qt::ISODate) << "\n"
<< " static_end: " << pp.prepaid[(int)Qt::Monday].static_end.toString(Qt::ISODate) << "\n"
<< " duration: " << pp.prepaid[(int)Qt::Monday].duration << "\n"
<< " **** Tuesday **** \n"
<< " day: " << pp.prepaid[(int)Qt::Tuesday].day << "\n"
<< " static_start: " << pp.prepaid[(int)Qt::Tuesday].static_start.toString(Qt::ISODate) << "\n"
<< " static_end: " << pp.prepaid[(int)Qt::Tuesday].static_end.toString(Qt::ISODate) << "\n"
<< " duration: " << pp.prepaid[(int)Qt::Tuesday].duration << "\n"
<< " **** Wednesday **** \n"
<< " day: " << pp.prepaid[(int)Qt::Wednesday].day << "\n"
<< " static_start: " << pp.prepaid[(int)Qt::Wednesday].static_start.toString(Qt::ISODate) << "\n"
<< " static_end: " << pp.prepaid[(int)Qt::Wednesday].static_end.toString(Qt::ISODate) << "\n"
<< " duration: " << pp.prepaid[(int)Qt::Wednesday].duration << "\n"
<< " **** Thursday **** \n"
<< " day: " << pp.prepaid[(int)Qt::Thursday].day << "\n"
<< " static_start: " << pp.prepaid[(int)Qt::Thursday].static_start.toString(Qt::ISODate) << "\n"
<< " static_end: " << pp.prepaid[(int)Qt::Thursday].static_end.toString(Qt::ISODate) << "\n"
<< " duration: " << pp.prepaid[(int)Qt::Thursday].duration << "\n"
<< " **** Friday **** \n"
<< " day: " << pp.prepaid[(int)Qt::Friday].day << "\n"
<< " static_start: " << pp.prepaid[(int)Qt::Friday].static_start.toString(Qt::ISODate) << "\n"
<< " static_end: " << pp.prepaid[(int)Qt::Friday].static_end.toString(Qt::ISODate) << "\n"
<< " **** Saturday **** \n"
<< " day: " << pp.prepaid[(int)Qt::Saturday].day << "\n"
<< " static_start: " << pp.prepaid[(int)Qt::Saturday].static_start.toString(Qt::ISODate) << "\n"
<< " static_end: " << pp.prepaid[(int)Qt::Saturday].static_end.toString(Qt::ISODate) << "\n"
<< " duration: " << pp.prepaid[(int)Qt::Saturday].duration << "\n"
<< " **** Sunday **** \n"
<< " day: " << pp.prepaid[(int)Qt::Sunday].day << "\n"
<< " static_start: " << pp.prepaid[(int)Qt::Sunday].static_start.toString(Qt::ISODate) << "\n"
<< " static_end: " << pp.prepaid[(int)Qt::Sunday].static_end.toString(Qt::ISODate) << "\n"
<< " duration: " << pp.prepaid[(int)Qt::Sunday].duration << "\n";
return debug;
}

View File

@ -337,7 +337,9 @@ int CALCULATE_LIBRARY_API get_maximal_parkingprice(Configuration *cfg,
switch(permitType) {
case PERMIT_TYPE::SHORT_TERM_PARKING: { // e.g. szeged (customer_281)
if (paymentMethodId == PaymentMethod::Progressive || paymentMethodId == PaymentMethod::Steps) {
maxPrice = Utilities::getMaximalParkingPrice(cfg, paymentMethodId);
//maxPrice = Utilities::getMaximalParkingPrice(cfg, paymentMethodId);
ATBPaymentOption const &po = cfg->getPaymentOptions(paymentOptionIndex);
maxPrice = po.pop_max_price; // maxTime is given in minutes
} else { // PaymentMethod::Linear -> e.g. szeged
int const key = cfg->getPaymentOptions(paymentOptionIndex).pop_id;
int const maxTime = cfg->getPaymentOptions(paymentOptionIndex).pop_max_time; // maxTime is given in minutes
@ -803,20 +805,22 @@ CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket(
int weekDay = start_parking_time.date().dayOfWeek();
int pop_carry_over_option_id = tariff->getPaymentOptions(paymentOptionIndex).pop_carry_over_option_id;
qCritical() << __func__ << __LINE__ << "configured carry-over-id" << pop_carry_over_option_id;
int pop_prepaid_option_id = tariff->getPaymentOptions(paymentOptionIndex).pop_prepaid_option_id;
std::optional<ATBPeriodYear> yperiod = Utilities::GetYearPeriodActive(tariff, start_parking_time);
if (yperiod.has_value()) {
ATBPeriodYear const &period = yperiod.value();
pop_carry_over_option_id = period.pye_id;
qCritical() << __func__ << __LINE__ << "re-computed carry-over-id" << pop_carry_over_option_id;
pop_prepaid_option_id = period.pye_id;
qCritical() << __func__ << ":" << __LINE__ << "re-computed carry-over-id" << pop_carry_over_option_id;
qCritical() << __func__ << ":" << __LINE__ << " re-computed prepaid-id" << pop_prepaid_option_id;
}
QTime const carryOverStart = tariff->TariffCarryOverOptions.find(pop_carry_over_option_id)->second.carryover[weekDay].static_start;
int const carryOverDuration = tariff->TariffCarryOverOptions.find(pop_carry_over_option_id)->second.carryover[weekDay].duration;
QTime carryOverStart = tariff->TariffCarryOverOptions.find(pop_carry_over_option_id)->second.carryover[weekDay].static_start;
int carryOverDuration = tariff->TariffCarryOverOptions.find(pop_carry_over_option_id)->second.carryover[weekDay].duration;
qCritical() << __func__ << __LINE__ << "carryOverStart" << carryOverStart.toString(Qt::ISODate);
qCritical() << __func__ << __LINE__ << "carryOverDuration" << carryOverDuration;
qCritical() << __func__ << ":" << __LINE__ << " carryOverStart" << carryOverStart.toString(Qt::ISODate);
qCritical() << __func__ << ":" << __LINE__ << "carryOverDuration" << carryOverDuration;
// handle prepaid option
QDateTime effectiveStartTime(start_parking_time);
@ -825,17 +829,23 @@ CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket(
if (prepaidOption.has_value()) {
ATBPrepaid const &p = prepaidOption.value();
if (p.never) {
qCritical() << __func__ << __LINE__ << "prepaid: no";
qCritical() << __func__ << ":" << __LINE__ << "prepaid: no";
} else {
if (start_parking_time.time() < p.static_end) { // static_end: e.g. 08:00:00
effectiveStartTime.setTime(p.static_end);
qCritical() << __func__ << ":" << __LINE__ << " prepaidStart" << p.prepaid[weekDay].static_start.toString(Qt::ISODate);
qCritical() << __func__ << ":" << __LINE__ << " prepaidEnd" << p.prepaid[weekDay].static_end.toString(Qt::ISODate);
qCritical() << __func__ << ":" << __LINE__ << "prepaid duration" << p.prepaid[weekDay].duration;
if (start_parking_time.time() < p.prepaid[weekDay].static_end) { // static_end: e.g. 08:00:00
effectiveStartTime.setTime(p.prepaid[weekDay].static_end);
} else
if (start_parking_time.time() > p.static_start) { // static_start: e.g. 22:00:00
effectiveStartTime.setTime(p.static_start);
if (start_parking_time.time() > p.prepaid[weekDay].static_start) { // static_start: e.g. 22:00:00
effectiveStartTime.setTime(p.prepaid[weekDay].static_start);
}
}
}
qCritical() << __func__ << ":" << __LINE__ << "effectiveStartTime:" << effectiveStartTime.toString(Qt::ISODate);
// handle carry over
int minutesUntilCarryOver = effectiveStartTime.time().secsTo(carryOverStart) / 60;
if (netto_parking_time > minutesUntilCarryOver) {
@ -848,13 +858,32 @@ CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket(
end_parking_time = effectiveStartTime.addSecs(netto_parking_time*60);
}
qCritical() << __func__ << ":" << __LINE__ << "end-parking-time:" << end_parking_time.toString(Qt::ISODate);
weekDay = end_parking_time.date().dayOfWeek();
// musste man in einer schleife machen
carryOverStart = tariff->TariffCarryOverOptions.find(pop_carry_over_option_id)->second.carryover[weekDay].static_start;
carryOverDuration = tariff->TariffCarryOverOptions.find(pop_carry_over_option_id)->second.carryover[weekDay].duration;
if (end_parking_time.time() > carryOverStart) {
end_parking_time = end_parking_time.addSecs(carryOverDuration * 60);
} else
if (end_parking_time.time() == carryOverStart) {
qCritical() << __func__ << ":" << __LINE__ << "end-parking-time:" << end_parking_time.toString(Qt::ISODate);
qCritical() << __func__ << ":" << __LINE__ << " carryOverStart" << carryOverStart.toString(Qt::ISODate);
ATBPaymentOption const &po = tariff->getPaymentOptions(paymentOptionIndex);
if (po.pop_apply_carry_over_to_ticket_endtime) {
end_parking_time = end_parking_time.addSecs(carryOverDuration * 60);
qCritical() << __func__ << ":" << __LINE__ << "end-parking-time:" << end_parking_time.toString(Qt::ISODate);
}
}
end_parking_time.setTime(QTime(end_parking_time.time().hour(),
end_parking_time.time().minute(), 0));
qCritical() << __func__ << ":" << __LINE__ << "end-parking-time:" << end_parking_time.toString(Qt::ISODate);
weekDay = end_parking_time.date().dayOfWeek();
qCritical() << __func__ << ":" << __LINE__ << " week-day:" << weekDay;
for (auto[itr, rangeEnd] = tariff->WeekDays.equal_range((Qt::DayOfWeek)weekDay); itr != rangeEnd; ++itr) {
ATBWeekDay const &wd = itr->second;
@ -862,12 +891,14 @@ CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket(
end_parking_time,
paymentOptionIndex);
if (parkTimeLimitViolated) {
//QTime const &tlimit = wd.getTariffCarryOverSettings().parkingTimeLimit();
//end_parking_time.setTime(tlimit);
calcState.setDesc(QString("line=%1 endTime=%2: park-time-limit violated").arg(__LINE__)
.arg(end_parking_time.time().toString(Qt::ISODate)));
return calcState.set(CalcState::State::ABOVE_MAX_PARKING_TIME);
}
}
} else {
cost = Calculator::GetInstance().GetCostFromDuration(
tariff,
@ -1152,6 +1183,9 @@ CalcState CALCULATE_LIBRARY_API compute_duration_for_parking_ticket(
ticketEndTime,
paymentOptionIndex);
if (parkTimeLimitViolated) {
//QTime const &tlimit = wd.getTariffCarryOverSettings().parkingTimeLimit();
//ticketEndTime.setTime(tlimit);
calcState.setDesc(QString("line=%1 endTime=%2: park-time-limit violated").arg(__LINE__)
.arg(ticketEndTime.time().toString(Qt::ISODate)));
return calcState.set(CalcState::State::ABOVE_MAX_PARKING_TIME);

View File

@ -591,6 +591,49 @@ bool Configuration::ParseJson(Configuration* cfg, const char* json)
QTime const &t = QTime::fromString(k->value.GetString(), Qt::ISODate);
TariffPrepaidOption.static_end = t;
}
} else
if (QString(inner_obj_name) == QString("prepaid_week")) {
if (k->value.IsArray()) {
auto days = k->value.GetArray();
for (rapidjson::SizeType j=0; j < days.Size(); ++j) {
if (days[j].IsObject()) {
auto weekday = days[j].GetObject();
for (auto w = weekday.MemberBegin(); w != weekday.MemberEnd(); ++w) {
int day = j+1; // 8 entries
TariffPrepaidOption.prepaid[day].day = 0;
QString member(QString::fromStdString(w->name.GetString()));
if (member == "prepaid_day") {
if (w->value.IsInt()) {
rapidjson::SizeType const d = w->value.GetInt();
if (d != (j+1)) {
qCritical() << "ERROR: misconfigured jsonfile" << d << "!=" << (j+1);
}
TariffPrepaidOption.prepaid[day].day = day;
}
} else
if (member == "prepaid_duration") {
if (w->value.IsInt()) {
TariffPrepaidOption.prepaid[day].duration = w->value.GetInt();
}
} else
if (member == "prepaid_static_start") {
if (w->value.IsString()) {
QTime const &t = QTime::fromString(w->value.GetString(), Qt::ISODate);
TariffPrepaidOption.prepaid[day].static_start = t;
}
} else
if (member == "prepaid_static_end") {
if (w->value.IsString()) {
QTime const &t = QTime::fromString(w->value.GetString(), Qt::ISODate);
TariffPrepaidOption.prepaid[day].static_end = t;
}
}
}
}
}
}
}
} break;
case MemberType::InterpolationType: {
@ -941,6 +984,10 @@ bool Configuration::ParseJson(Configuration* cfg, const char* json)
if (k->value.IsBool()) {
this->currentPaymentOptions.last().pop_allow_overpay = k->value.GetBool();
}
} else if (strcmp(inner_obj_name, "pop_apply_carry_over_to_ticket_endtime") == 0) {
if (k->value.IsBool()) {
this->currentPaymentOptions.last().pop_apply_carry_over_to_ticket_endtime = k->value.GetBool();
}
} else if (strcmp(inner_obj_name, "pop_payment_method_id") == 0) {
this->currentPaymentOptions.last().pop_payment_method_id = k->value.GetInt();
} else if (strcmp(inner_obj_name, "pop_day_end_time") == 0) {
@ -1430,7 +1477,6 @@ bool Configuration::isDayIncludedAsSpecialDay(uint64_t businessHours, QDateTime
if (isSpecialDay(dt)) {
bool const &r = ((businessHours & BusinessHours::OFFICIAL_HOLIDAY) == BusinessHours::OFFICIAL_HOLIDAY);
qCritical() << "XXXXXXXXXXXXXXXXXX r" << r << businessHours;
return r;
}
@ -1537,6 +1583,8 @@ int getPaymentOptionIndex(Configuration const &cfg, QDateTime const &dt) {
int const numOptions = cfg.getAllPaymentOptions().size();
// qCritical() << __func__ << ":" << __LINE__ << "numOptions" << numOptions;
for (int opt=0; opt < numOptions; ++opt) {
uint64_t const pop_business_hours = cfg.getPaymentOptions(opt).pop_business_hours;
@ -1547,6 +1595,8 @@ int getPaymentOptionIndex(Configuration const &cfg, QDateTime const &dt) {
// QDateTime const dt = QDateTime::currentDateTime();
int const dayOfWeek = dt.date().dayOfWeek();
// qCritical() << __func__ << ":" << __LINE__ << "dayOfWeek" << dayOfWeek;
if (isHoliday(cfg, dt)) {
if (pop_business_hours & BusinessHours::OFFICIAL_HOLIDAY) {
return opt;
@ -1585,6 +1635,7 @@ int getPaymentOptionIndex(Configuration const &cfg, QDateTime const &dt) {
} break;
case (int)Qt::Sunday: {
if (pop_business_hours & BusinessHours::SUN) {
qCritical() << __func__ << ":" << __LINE__ << "opt" << opt;
return opt;
}
} break;