GetTimeSteps(): compute minimal parking time and set pop_min_time.

This commit is contained in:
Gerhard Hoffmann 2024-01-22 13:31:00 +01:00
parent 15700a363d
commit 33731faba9

View File

@ -695,72 +695,86 @@ Ticket Calculator::private_GetDurationFromCost(Configuration *cfg,
cost, Ticket::s[VALID]); cost, Ticket::s[VALID]);
} }
QList<int> Calculator::GetTimeSteps(Configuration *cfg) const { QList<int> Calculator::GetTimeSteps(Configuration *cfg, quint64 startInMinutes) const {
QList<int> timeSteps; static QList<int> timeSteps;
int const pop_id = cfg->getPaymentOptions().pop_id; if (timeSteps.size() == 0) {
int const pop_carry_over = cfg->getPaymentOptions().pop_carry_over; int const pop_id = cfg->getPaymentOptions().pop_id;
int const pop_time_step_config = cfg->getPaymentOptions().pop_time_step_config; int const pop_carry_over = cfg->getPaymentOptions().pop_carry_over;
int const pop_time_step_config = cfg->getPaymentOptions().pop_time_step_config;
if (pop_time_step_config == (int)ATBTimeStepConfig::TimeStepConfig::DYNAMIC) { qCritical() << " payment option id:" << pop_id;
if (pop_carry_over) { qCritical() << " payment option carry over:" << pop_carry_over;
int const pop_carry_over_time_range_id = cfg->getPaymentOptions().pop_carry_over_time_range_id; qCritical() << "payment option time step config:" << pop_time_step_config;
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_time_step_config == (int)ATBTimeStepConfig::TimeStepConfig::DYNAMIC) {
if (carryOverTimeRangeFrom == QTime(0, 0, 0)) { QDateTime start;
for (auto[itr, rangeEnd] = cfg->PaymentRate.equal_range(pop_id); itr != rangeEnd; ++itr) { start.setSecsSinceEpoch(startInMinutes * 60);
int const durationId = itr->second.pra_payment_unit_id; uint16_t timeStepCompensation = 0;
auto search = cfg->Duration.find(durationId);
if (search != cfg->Duration.end()) {
ATBDuration duration = search->second;
if (durationId == 1) {
//duration.pun_duration_min = search->second.pun_duration_min;
//duration.pun_duration_max = search->second.pun_duration_max;
QDateTime carryOver = m_start; if (pop_carry_over) {
carryOver = carryOver.addDays(1); int const pop_carry_over_time_range_id = cfg->getPaymentOptions().pop_carry_over_time_range_id;
carryOver.setTime(QTime(0, 0, 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;
int const timeStep = std::ceil(m_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) {
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;
}
qCritical() << "configured minimal parking time:" << cfg->getPaymentOptions().pop_min_time;
// set dynamic minimal parking time
cfg->getPaymentOptions().pop_min_time = timeStep;
qCritical() << " computed minimal parking time:" << cfg->getPaymentOptions().pop_min_time;
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;;
} }
duration.pun_duration = timeStep;
m_timeStepCompensation = duration.pun_duration_max - duration.pun_duration; cfg->Duration.erase(search);
timeSteps << duration.pun_duration; cfg->Duration.insert(pair<int, ATBDuration>(duration.pun_id, duration));
} else {
duration.pun_duration = duration.pun_duration_max - m_timeStepCompensation; } else { // if (search != cfg->Duration.end()) {
timeSteps << duration.pun_duration;; // 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 // TODO
} }
} else { // if (carryOverTimeRangeFrom == carryOverTimeRangeTo) { } else { // if (pop_carry_over) {
// TODO // TODO
} }
} else { // if (pop_carry_over) { } else {
// TODO for (auto[itr, rangeEnd] = cfg->PaymentRate.equal_range(pop_id); itr != rangeEnd; ++itr)
} {
} else { int const durationId = itr->second.pra_payment_unit_id;
for (auto[itr, rangeEnd] = cfg->PaymentRate.equal_range(pop_id); itr != rangeEnd; ++itr) int const durationUnit = cfg->Duration.find(durationId)->second.pun_duration;
{ timeSteps << durationUnit;
int const durationId = itr->second.pra_payment_unit_id; }
int const durationUnit = cfg->Duration.find(durationId)->second.pun_duration;
timeSteps << durationUnit;
} }
} }