GetTimeSteps(): compute time step only once, when calling get_minimal_parkingprice().

Otherwise use timeSteps-member in Calculator.
This commit is contained in:
Gerhard Hoffmann 2024-01-23 10:53:26 +01:00
parent 9af39fa83f
commit ac45ebb926

View File

@ -696,7 +696,10 @@ Ticket Calculator::private_GetDurationFromCost(Configuration *cfg,
} }
QList<int> Calculator::GetTimeSteps(Configuration *cfg) const { QList<int> Calculator::GetTimeSteps(Configuration *cfg) const {
QList<int> timeSteps; if (m_timeSteps.size() > 0) {
//qCritical() << __PRETTY_FUNCTION__ << "timeSteps:" << m_timeSteps;
return m_timeSteps;
}
QDateTime start = QDateTime::currentDateTime(); QDateTime start = QDateTime::currentDateTime();
start.setTime(QTime(start.time().hour(), start.time().minute(), 0)); start.setTime(QTime(start.time().hour(), start.time().minute(), 0));
@ -705,12 +708,12 @@ 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;
qCritical() << " start parking time:" << start.toString(Qt::ISODate); qCritical() << __PRETTY_FUNCTION__ << " start parking time:" << start.toString(Qt::ISODate);
qCritical() << " payment option id:" << pop_id; qCritical() << __PRETTY_FUNCTION__ << " payment option id:" << pop_id;
qCritical() << " payment option carry over:" << pop_carry_over; qCritical() << __PRETTY_FUNCTION__ << " payment option carry over:" << pop_carry_over;
if (pop_time_step_config == (int)ATBTimeStepConfig::TimeStepConfig::DYNAMIC) { if (pop_time_step_config == (int)ATBTimeStepConfig::TimeStepConfig::DYNAMIC) {
qCritical() << "payment option time step config:" << "TimeStepConfig::DYNAMIC"; //qCritical() << __PRETTY_FUNCTION__ << "payment option time step config:" << "TimeStepConfig::DYNAMIC";
uint16_t timeStepCompensation = 0; uint16_t timeStepCompensation = 0;
@ -739,19 +742,19 @@ QList<int> Calculator::GetTimeSteps(Configuration *cfg) const {
.arg(timeStep).arg(duration.pun_duration_max); .arg(timeStep).arg(duration.pun_duration_max);
break; break;
} }
qCritical() << "configured minimal parking time:" << cfg->getPaymentOptions().pop_min_time; qCritical() << __PRETTY_FUNCTION__ << "configured minimal parking time:" << cfg->getPaymentOptions().pop_min_time;
// set dynamic minimal parking time // set dynamic minimal parking time
cfg->getPaymentOptions().pop_min_time = timeStep; cfg->getPaymentOptions().pop_min_time = timeStep;
qCritical() << " computed minimal parking time:" << cfg->getPaymentOptions().pop_min_time; qCritical() << __PRETTY_FUNCTION__ << " computed minimal parking time:" << cfg->getPaymentOptions().pop_min_time;
duration.pun_duration = timeStep; duration.pun_duration = timeStep;
timeStepCompensation = duration.pun_duration_max - duration.pun_duration; timeStepCompensation = duration.pun_duration_max - duration.pun_duration;
timeSteps << duration.pun_duration; m_timeSteps << duration.pun_duration;
} else { } else {
duration.pun_duration = duration.pun_duration_max - timeStepCompensation; duration.pun_duration = duration.pun_duration_max - timeStepCompensation;
timeSteps << duration.pun_duration;; m_timeSteps << duration.pun_duration;;
} }
cfg->Duration.erase(search); cfg->Duration.erase(search);
@ -771,17 +774,19 @@ QList<int> Calculator::GetTimeSteps(Configuration *cfg) const {
// TODO // TODO
} }
} else { } else {
qCritical() << "payment option time step config:" << "TimeStepConfig::STATIC"; qCritical() << __PRETTY_FUNCTION__ << "payment option time step config:" << "TimeStepConfig::STATIC";
for (auto[itr, rangeEnd] = cfg->PaymentRate.equal_range(pop_id); itr != rangeEnd; ++itr) for (auto[itr, rangeEnd] = cfg->PaymentRate.equal_range(pop_id); itr != rangeEnd; ++itr)
{ {
int const durationId = itr->second.pra_payment_unit_id; int const durationId = itr->second.pra_payment_unit_id;
int const durationUnit = cfg->Duration.find(durationId)->second.pun_duration; int const durationUnit = cfg->Duration.find(durationId)->second.pun_duration;
timeSteps << durationUnit; m_timeSteps << durationUnit;
} }
} }
return timeSteps; Critical() << __PRETTY_FUNCTION__ << "NEW timeSteps:" << m_timeSteps;
return m_timeSteps;
} }
uint32_t Calculator::GetPriceForTimeStep(Configuration *cfg, int timeStep) const { uint32_t Calculator::GetPriceForTimeStep(Configuration *cfg, int timeStep) const {