Implement get_minimal_parkingtime() and get_time_steps().

This commit is contained in:
Gerhard Hoffmann 2024-01-22 15:41:20 +01:00
parent 0ce630dfa3
commit b43fa274bd
3 changed files with 73 additions and 66 deletions

View File

@ -44,7 +44,7 @@ public:
// helper function to find time steps for a tariff with PaymentMethod::Steps // helper function to find time steps for a tariff with PaymentMethod::Steps
// (e.g. Schoenau/Koenigsee) // (e.g. Schoenau/Koenigsee)
// //
QList<int> GetTimeSteps(Configuration *cfg, quint64 startInMinutes = QDateTime::currentSecsSinceEpoch() / 60) const; QList<int> GetTimeSteps(Configuration *cfg) const;
QList<int> GetSteps(Configuration *cfg) const { return GetTimeSteps(cfg); } QList<int> GetSteps(Configuration *cfg) const { return GetTimeSteps(cfg); }
// additional helper functions // additional helper functions

View File

@ -12,8 +12,15 @@
static Calculator calculator; static Calculator calculator;
QList<int> CALCULATE_LIBRARY_API get_time_steps(Configuration *cfg, qint64 startInMinutes) { QList<int> CALCULATE_LIBRARY_API get_time_steps(Configuration *cfg) {
return calculator.GetTimeSteps(cfg, startInMinutes); return calculator.GetTimeSteps(cfg);
}
int CALCULATE_LIBRARY_API get_minimum_parkingtime(Configuration *cfg) {
// get_time_steps() possibly re-computes pop_min_time: see
// calculator.GetTimeSteps()
get_time_steps(cfg);
return qRound(cfg->getPaymentOptions().pop_min_time);
} }
int CALCULATE_LIBRARY_API get_zone_nr(int zone) int CALCULATE_LIBRARY_API get_zone_nr(int zone)

View File

@ -695,86 +695,86 @@ Ticket Calculator::private_GetDurationFromCost(Configuration *cfg,
cost, Ticket::s[VALID]); cost, Ticket::s[VALID]);
} }
QList<int> Calculator::GetTimeSteps(Configuration *cfg, quint64 startInMinutes) const { QList<int> Calculator::GetTimeSteps(Configuration *cfg) const {
static QList<int> timeSteps; QList<int> timeSteps;
if (timeSteps.size() == 0) { QDateTime start = QDateTime::currentDateTime();
int const pop_id = cfg->getPaymentOptions().pop_id; start.setTime(QTime(start.time().hour(), start.time().minute(), 0));
int const pop_carry_over = cfg->getPaymentOptions().pop_carry_over;
int const pop_time_step_config = cfg->getPaymentOptions().pop_time_step_config;
qCritical() << " payment option id:" << pop_id; int const pop_id = cfg->getPaymentOptions().pop_id;
qCritical() << " payment option carry over:" << pop_carry_over; int const pop_carry_over = cfg->getPaymentOptions().pop_carry_over;
qCritical() << "payment option time step config:" << pop_time_step_config; int const pop_time_step_config = cfg->getPaymentOptions().pop_time_step_config;
if (pop_time_step_config == (int)ATBTimeStepConfig::TimeStepConfig::DYNAMIC) { qCritical() << " start parking time:" << start.toString(Qt::ISODate);
QDateTime start; qCritical() << " payment option id:" << pop_id;
start.setSecsSinceEpoch(startInMinutes * 60); qCritical() << " payment option carry over:" << pop_carry_over;
uint16_t timeStepCompensation = 0; qCritical() << "payment option time step config:" << pop_time_step_config;
if (pop_carry_over) { if (pop_time_step_config == (int)ATBTimeStepConfig::TimeStepConfig::DYNAMIC) {
int const pop_carry_over_time_range_id = cfg->getPaymentOptions().pop_carry_over_time_range_id; uint16_t timeStepCompensation = 0;
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 (pop_carry_over) {
if (carryOverTimeRangeFrom == QTime(0, 0, 0)) { int const pop_carry_over_time_range_id = cfg->getPaymentOptions().pop_carry_over_time_range_id;
for (auto[itr, rangeEnd] = cfg->PaymentRate.equal_range(pop_id); itr != rangeEnd; ++itr) { QTime const carryOverTimeRangeFrom = cfg->TimeRange.find(pop_carry_over_time_range_id)->second.time_range_from;
int const durationId = itr->second.pra_payment_unit_id; QTime const carryOverTimeRangeTo = cfg->TimeRange.find(pop_carry_over_time_range_id)->second.time_range_to;
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 (carryOverTimeRangeFrom.secsTo(carryOverTimeRangeTo) <= 60) { // carry over time point, usually 00:00:00
if (timeStep < duration.pun_duration_min || timeStep > duration.pun_duration_max) { if (carryOverTimeRangeFrom == QTime(0, 0, 0)) {
qCritical() for (auto[itr, rangeEnd] = cfg->PaymentRate.equal_range(pop_id); itr != rangeEnd; ++itr) {
<< QString("ERROR timeStep (%1) < durationMin (%2) || timeStep (%3)) > durationMax (%4)") int const durationId = itr->second.pra_payment_unit_id;
.arg(timeStep).arg(duration.pun_duration_min) auto search = cfg->Duration.find(durationId);
.arg(timeStep).arg(duration.pun_duration_max); if (search != cfg->Duration.end()) {
break; ATBDuration duration = search->second;
} if (durationId == 1) {
qCritical() << "configured minimal parking time:" << cfg->getPaymentOptions().pop_min_time; QDateTime carryOver = start;
carryOver = carryOver.addDays(1);
carryOver.setTime(QTime(0, 0, 0));
// set dynamic minimal parking time int const timeStep = std::ceil(start.secsTo(carryOver) / 60.0);
cfg->getPaymentOptions().pop_min_time = timeStep; if (timeStep < duration.pun_duration_min || timeStep > duration.pun_duration_max) {
qCritical()
qCritical() << " computed minimal parking time:" << cfg->getPaymentOptions().pop_min_time; << QString("ERROR timeStep (%1) < durationMin (%2) || timeStep (%3)) > durationMax (%4)")
.arg(timeStep).arg(duration.pun_duration_min)
duration.pun_duration = timeStep; .arg(timeStep).arg(duration.pun_duration_max);
timeStepCompensation = duration.pun_duration_max - duration.pun_duration; break;
timeSteps << duration.pun_duration;
} else {
duration.pun_duration = duration.pun_duration_max - timeStepCompensation;
timeSteps << duration.pun_duration;;
} }
qCritical() << "configured minimal parking time:" << cfg->getPaymentOptions().pop_min_time;
cfg->Duration.erase(search); // set dynamic minimal parking time
cfg->Duration.insert(pair<int, ATBDuration>(duration.pun_id, duration)); cfg->getPaymentOptions().pop_min_time = timeStep;
} else { // if (search != cfg->Duration.end()) { qCritical() << " computed minimal parking time:" << cfg->getPaymentOptions().pop_min_time;
// TODO
duration.pun_duration = timeStep;
timeStepCompensation = duration.pun_duration_max - duration.pun_duration;
timeSteps << duration.pun_duration;
} else {
duration.pun_duration = duration.pun_duration_max - timeStepCompensation;
timeSteps << duration.pun_duration;;
} }
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 == carryOverTimeRangeTo) { } else { // if (carryOverTimeRangeFrom == QTime(0, 0, 0)) {
// TODO // TODO
} }
} else { // if (pop_carry_over) { } else { // if (carryOverTimeRangeFrom == carryOverTimeRangeTo) {
// TODO // TODO
} }
} else { } else { // if (pop_carry_over) {
for (auto[itr, rangeEnd] = cfg->PaymentRate.equal_range(pop_id); itr != rangeEnd; ++itr) // TODO
{ }
int const durationId = itr->second.pra_payment_unit_id; } else {
int const durationUnit = cfg->Duration.find(durationId)->second.pun_duration; for (auto[itr, rangeEnd] = cfg->PaymentRate.equal_range(pop_id); itr != rangeEnd; ++itr)
timeSteps << durationUnit; {
} int const durationId = itr->second.pra_payment_unit_id;
int const durationUnit = cfg->Duration.find(durationId)->second.pun_duration;
timeSteps << durationUnit;
} }
} }