From e4cb992aae34224876ee5a5848294b5e33653a13 Mon Sep 17 00:00:00 2001 From: Gerhard Hoffmann Date: Tue, 30 Jul 2024 15:39:55 +0200 Subject: [PATCH] GetTimeSteps() for payment-method degressive. introduced for Valser Alm (location: Fane). --- library/src/calculator_functions.cpp | 119 +++++++++++++++------------ 1 file changed, 65 insertions(+), 54 deletions(-) diff --git a/library/src/calculator_functions.cpp b/library/src/calculator_functions.cpp index 9073ed9..9df6563 100644 --- a/library/src/calculator_functions.cpp +++ b/library/src/calculator_functions.cpp @@ -2335,81 +2335,92 @@ QList &Calculator::GetTimeSteps(Configuration *cfg, int paymentOptionIndex, if (w.has_value()) { QVector const &vec = w.value(); - if (pop_carry_over == false) { - for (int i = 1; i <= vec.size(); ++i) { - QTime const &from = QTime::fromString(QString::fromStdString(vec[i-1].pwd_time_from), Qt::ISODate); - QString const &toStr = QString::fromStdString(vec[i-1].pwd_time_to); - QTime const &to = QTime::fromString(toStr, Qt::ISODate); + //if (pop_carry_over == false) { + for (int i = 1; i <= vec.size(); ++i) { + QTime const &from = QTime::fromString(QString::fromStdString(vec[i-1].pwd_time_from), Qt::ISODate); + QString const &toStr = QString::fromStdString(vec[i-1].pwd_time_to); + QTime const &to = QTime::fromString(toStr, Qt::ISODate); - int weekDayId = vec[i-1].pwd_period_day_in_week_id; - if (start.date().dayOfWeek() == weekDayId) { + int weekDayId = vec[i-1].pwd_period_day_in_week_id; + if (start.date().dayOfWeek() == weekDayId) { + if (DBG_LEVEL >= DBG_DEBUG) { qCritical() << "(" << __func__ << ":" << __LINE__ << ")" << weekDayId; qCritical() << "(" << __func__ << ":" << __LINE__ << ") from" << from.toString(Qt::ISODate); qCritical() << "(" << __func__ << ":" << __LINE__ << ") to" << to.toString(Qt::ISODate); qCritical() << "(" << __func__ << ":" << __LINE__ << ") start" << start.toString(Qt::ISODate); + } - if (start.time() >= from && start.time() < to) { - int runtimeInMinutes = (start.time().secsTo(to) / 60); - if (to.hour() == 23 && to.minute() == 59) { - runtimeInMinutes += 1; - } + if (start.time() >= from && start.time() < to) { + int runtimeInMinutes = (start.time().secsTo(to) / 60); + if (to.hour() == 23 && to.minute() == 59) { + runtimeInMinutes += 1; + } + + if (DBG_LEVEL >= DBG_DEBUG) { qCritical() << "(" << __func__ << ":" << __LINE__ << ") runTimeInMinutes" << runtimeInMinutes; qCritical() << "(" << __func__ << ":" << __LINE__ << ") index" << paymentOptionIndex; + } + // m_timeSteps[paymentOptionIndex] << runtimeInMinutes; - m_timeSteps[paymentOptionIndex] << runtimeInMinutes; + cfg->getPaymentOptions(paymentOptionIndex).pop_min_time = runtimeInMinutes; - cfg->getPaymentOptions(paymentOptionIndex).pop_min_time = runtimeInMinutes; - - int pop_id = vec[i-1].pwd_pop_id; - // int pwd_id = vec[i-1].pwd_id; - // int pwd_next_id = vec[i-1].pwd_next_id; + int pop_id = vec[i-1].pwd_pop_id; + // int pwd_id = vec[i-1].pwd_id; + // int pwd_next_id = vec[i-1].pwd_next_id; + if (DBG_LEVEL >= DBG_DEBUG) { qCritical() << "(" << __func__ << ":" << __LINE__ << ") pop_id" << pop_id; + } - int price = -1; - int durationId = -1; + int price = -1; + int durationId = -1; + for (auto[itr, rangeEnd] = cfg->PaymentRate.equal_range(pop_id); itr != rangeEnd; ++itr) { + durationId = itr->second.pra_payment_unit_id; + + price = itr->second.pra_price; + + auto search = cfg->Duration.find(durationId); + if (search != cfg->Duration.end()) { + ATBDuration duration = search->second; + duration.pun_duration = runtimeInMinutes; + search->second = duration; + break; + } + } + + if (price >= 0 && durationId >= 0) { + if (DBG_LEVEL >= DBG_DEBUG) { + qCritical() << "(" << __func__ << ":" << __LINE__ << ") durationId" << durationId; + qCritical() << "(" << __func__ << ":" << __LINE__ << ") price" << price; + } + + pop_id = cfg->getPaymentOptions(paymentOptionIndex).pop_id; for (auto[itr, rangeEnd] = cfg->PaymentRate.equal_range(pop_id); itr != rangeEnd; ++itr) { - durationId = itr->second.pra_payment_unit_id; - - price = itr->second.pra_price; - - auto search = cfg->Duration.find(durationId); - if (search != cfg->Duration.end()) { - ATBDuration duration = search->second; - duration.pun_duration = runtimeInMinutes; - search->second = duration; + if (durationId == itr->second.pra_payment_unit_id) { + itr->second.pra_price = price; + cfg->getPaymentOptions(paymentOptionIndex).pop_min_price = price; + qCritical() << "(" << __func__ << ":" << __LINE__ << ") park min price" << price; break; } } + } - if (price >= 0 && durationId >= 0) { - qCritical() << "(" << __func__ << ":" << __LINE__ << ") durationId" << durationId; - qCritical() << "(" << __func__ << ":" << __LINE__ << ") price" << price; + break; + } // if (start.time() >= from && start.time() < to) { + } // if (start.date().dayOfWeek() == weekDayId) { + } // for (int i = 1; i <= vec.size(); ++i) { - pop_id = cfg->getPaymentOptions(paymentOptionIndex).pop_id; - for (auto[itr, rangeEnd] = cfg->PaymentRate.equal_range(pop_id); itr != rangeEnd; ++itr) { - if (durationId == itr->second.pra_payment_unit_id) { - itr->second.pra_price = price; - break; - } - } - } + m_timeSteps[paymentOptionIndex].clear(); + int runtimeInMinutes = 0; + for (Configuration::TariffDurationType::const_iterator it = cfg->Duration.cbegin(); + it != cfg->Duration.cend(); + ++it) { + runtimeInMinutes += it->second.pun_duration; + m_timeSteps[paymentOptionIndex] << runtimeInMinutes; + } - break; - } // if (start.time() >= from && start.time() < to) { - } // if (start.date().dayOfWeek() == weekDayId) { - } // for (int i = 1; i <= vec.size(); ++i) { - - // show content: - for (Configuration::TariffDurationType::const_iterator it = cfg->Duration.cbegin(); - it != cfg->Duration.cend(); - ++it) { - qCritical() << "(" << __func__ << ":" << __LINE__ << ")" - << (*it).first << " => " << (*it).second; - } - - } // if (pop_carry_over == false) { + //} // if (pop_carry_over == false) { } // if (w.has_value()) { } else { uint16_t timeStepCompensation = 0;