Added changes for Schnals

This commit is contained in:
Gerhard Hoffmann 2024-07-19 14:10:07 +02:00
parent 2a89f90745
commit 977356040c

View File

@ -5,6 +5,7 @@
#include "tariff_time_range.h" #include "tariff_time_range.h"
#include "ticket.h" #include "ticket.h"
#include "tariff_global_defines.h" #include "tariff_global_defines.h"
#include "tariff_prepaid.h"
#include <sstream> #include <sstream>
#include <algorithm> #include <algorithm>
@ -2090,6 +2091,9 @@ QList<int> Calculator::GetPriceSteps(Configuration * /*cfg*/) const {
return QList<int>(); return QList<int>();
} }
#define DEBUG_GET_TIME_STEPS (1)
QList<int> &Calculator::GetTimeSteps(Configuration *cfg, int paymentOptionIndex) const { QList<int> &Calculator::GetTimeSteps(Configuration *cfg, int paymentOptionIndex) const {
qCritical() << "(" << __func__ << ":" << __LINE__ << ") paymentOptionIndex:" << paymentOptionIndex; qCritical() << "(" << __func__ << ":" << __LINE__ << ") paymentOptionIndex:" << paymentOptionIndex;
@ -2107,12 +2111,14 @@ QList<int> &Calculator::GetTimeSteps(Configuration *cfg, int paymentOptionIndex)
int const pop_id = cfg->getPaymentOptions(paymentOptionIndex).pop_id; int const pop_id = cfg->getPaymentOptions(paymentOptionIndex).pop_id;
int const pop_carry_over = cfg->getPaymentOptions(paymentOptionIndex).pop_carry_over; int const pop_carry_over = cfg->getPaymentOptions(paymentOptionIndex).pop_carry_over;
int const pop_time_step_config = cfg->getPaymentOptions(paymentOptionIndex).pop_time_step_config; int const pop_time_step_config = cfg->getPaymentOptions(paymentOptionIndex).pop_time_step_config;
int const pop_prepaid_option_id = cfg->getPaymentOptions(paymentOptionIndex).pop_prepaid_option_id;
static PaymentMethod const paymentMethodId = Utilities::getPaymentMethodId(cfg); static PaymentMethod const paymentMethodId = Utilities::getPaymentMethodId(cfg);
qCritical() << "(" << __func__ << ":" << __LINE__ << ") start parking time:" << start.toString(Qt::ISODate); qCritical() << "(" << __func__ << ":" << __LINE__ << ") start parking time:" << start.toString(Qt::ISODate);
qCritical() << "(" << __func__ << ":" << __LINE__ << ") payment option id:" << pop_id; qCritical() << "(" << __func__ << ":" << __LINE__ << ") payment option id:" << pop_id;
qCritical() << "(" << __func__ << ":" << __LINE__ << ") payment option carry over:" << pop_carry_over; qCritical() << "(" << __func__ << ":" << __LINE__ << ") time step configuration:" << pop_time_step_config;
qCritical() << "(" << __func__ << ":" << __LINE__ << ") prepaid option id:" << pop_prepaid_option_id;
if (pop_time_step_config == (int)ATBTimeStepConfig::TimeStepConfig::DYNAMIC) { if (pop_time_step_config == (int)ATBTimeStepConfig::TimeStepConfig::DYNAMIC) {
//qCritical() << __PRETTY_FUNCTION__ << "payment option time step config:" << "TimeStepConfig::DYNAMIC"; //qCritical() << __PRETTY_FUNCTION__ << "payment option time step config:" << "TimeStepConfig::DYNAMIC";
@ -2126,11 +2132,15 @@ QList<int> &Calculator::GetTimeSteps(Configuration *cfg, int paymentOptionIndex)
} else { } else {
uint16_t timeStepCompensation = 0; uint16_t timeStepCompensation = 0;
qCritical() << "(" << __func__ << ":" << __LINE__ << ") payment option carry over:" << pop_carry_over;
if (pop_carry_over) { if (pop_carry_over) {
int const pop_carry_over_time_range_id = cfg->getPaymentOptions(paymentOptionIndex).pop_carry_over_time_range_id; int const pop_carry_over_time_range_id = cfg->getPaymentOptions(paymentOptionIndex).pop_carry_over_time_range_id;
QTime const carryOverTimeRangeFrom = cfg->TimeRange.find(pop_carry_over_time_range_id)->second.time_range_from; 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; QTime const carryOverTimeRangeTo = cfg->TimeRange.find(pop_carry_over_time_range_id)->second.time_range_to;
qCritical() << "(" << __func__ << ":" << __LINE__ << ") carry over time range id:" << pop_carry_over_time_range_id;
if (carryOverTimeRangeFrom.secsTo(carryOverTimeRangeTo) <= 60) { // carry over time point, usually 00:00:00 if (carryOverTimeRangeFrom.secsTo(carryOverTimeRangeTo) <= 60) { // carry over time point, usually 00:00:00
if (carryOverTimeRangeFrom == QTime(0, 0, 0)) { if (carryOverTimeRangeFrom == QTime(0, 0, 0)) {
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) {
@ -2163,7 +2173,7 @@ QList<int> &Calculator::GetTimeSteps(Configuration *cfg, int paymentOptionIndex)
m_timeSteps[paymentOptionIndex] << duration.pun_duration; m_timeSteps[paymentOptionIndex] << duration.pun_duration;
} else { } else {
duration.pun_duration = duration.pun_duration_max - timeStepCompensation; duration.pun_duration = duration.pun_duration_max - timeStepCompensation;
m_timeSteps[paymentOptionIndex] << duration.pun_duration;; m_timeSteps[paymentOptionIndex] << duration.pun_duration;
} }
cfg->Duration.erase(search); cfg->Duration.erase(search);
@ -2174,7 +2184,157 @@ QList<int> &Calculator::GetTimeSteps(Configuration *cfg, int paymentOptionIndex)
} }
} }
} else { // if (carryOverTimeRangeFrom == QTime(0, 0, 0)) { } else { // if (carryOverTimeRangeFrom == QTime(0, 0, 0)) {
// TODO qCritical() << "(" << __func__ << ":" << __LINE__ << ") carry over time range from:" << carryOverTimeRangeFrom.toString(Qt::ISODate);
qCritical() << "(" << __func__ << ":" << __LINE__ << ") carry over time range to:" << carryOverTimeRangeTo.toString(Qt::ISODate);
m_timeSteps[paymentOptionIndex].clear();
std::optional<QDateTime> adaptedStart = cfg->adaptStart(start, pop_prepaid_option_id);
if (adaptedStart) {
start = adaptedStart.value();
} else {
// TODO
}
int const start_time = start.time().hour() * 60 + start.time().minute();
for (auto[itr, rangeEnd] = cfg->PaymentRate.equal_range(pop_id); itr != rangeEnd; ++itr) {
int const durationId = itr->second.pra_payment_unit_id;
// int const price = itr->second.pra_price;
auto search = cfg->Duration.find(durationId);
if (search != cfg->Duration.end()) {
ATBDuration duration = search->second;
if (duration.pun_interpolation_id == -1) {
// should never happen -> misconfigured tariff-file
qCritical() << "(" << __func__ << ":" << __LINE__ << ") ERROR pun_interpolation not set!";
qCritical() << "(" << __func__ << ":" << __LINE__ << ") See for instance customer_505/6";
break;
}
std::optional<ATBInterpolation> ipolCheck = cfg->getInterpolationType(duration.pun_interpolation_id);
if (ipolCheck) {
ATBInterpolation interpolation = ipolCheck.value();
if (duration.pun_interpolation_id == (int)ATBInterpolation::DYNAMIC_ABSTRACT_TIMEPOINT_AND_STATIC_END_TIME) {
//qCritical() << "(" << __func__ << ":" << __LINE__ << ") pun_id:" << duration.pun_id;
int const end_time = interpolation.dynamic_end.hour() * 60 + interpolation.dynamic_end.minute();
//qCritical() << "(" << __func__ << ":" << __LINE__ << ") pun_duration:" << duration.pun_duration;
//qCritical() << "(" << __func__ << ":" << __LINE__ << ") pun_interpolation:" << duration.pun_interpolation_id;
//qCritical() << "(" << __func__ << ":" << __LINE__ << ") interpolation dynamic end:" << interpolation.dynamic_end.toString(Qt::ISODate);
// qCritical() << "(" << __func__ << ":" << __LINE__ << ") interpolation dynamic end time:" << end_time;
QDateTime carryOver = start;
carryOver.setTime(interpolation.dynamic_end);
int pop_min_time = cfg->getPaymentOptions(paymentOptionIndex).pop_min_time;
int nextTimeStep = start_time + duration.pun_duration;
int rest = end_time - nextTimeStep;
if (nextTimeStep <= end_time) {
if (durationId == 1) {
#if DEBUG_GET_TIME_STEPS==1
qCritical() << "(" << __func__ << ":" << __LINE__ << ") pun_id:" << duration.pun_id;
qCritical() << "(" << __func__ << ":" << __LINE__ << ") pun_duration:" << duration.pun_duration;
qCritical() << "(" << __func__ << ":" << __LINE__ << ") pun_interpolation:" << duration.pun_interpolation_id;
qCritical() << "(" << __func__ << ":" << __LINE__ << ") interpolation dynamic end:" << interpolation.dynamic_end.toString(Qt::ISODate);
#endif
int const timeStep = nextTimeStep;
qCritical() << "(" << __func__ << ":" << __LINE__ << ") time step:" << timeStep;
if (timeStep < duration.pun_duration_min || timeStep > duration.pun_duration_max) {
qCritical() << "(" << __func__ << ":" << __LINE__ << ")"
<< 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() << "(" << __func__ << ":" << __LINE__ << ") configured minimal parking time:" << cfg->getPaymentOptions(paymentOptionIndex).pop_min_time;
// set dynamic minimal parking time
cfg->getPaymentOptions(paymentOptionIndex).pop_min_time = timeStep;
qCritical() << "(" << __func__ << ":" << __LINE__ << ") computed minimal parking time:" << cfg->getPaymentOptions(paymentOptionIndex).pop_min_time;
duration.pun_duration = timeStep;
timeStepCompensation = end_time - start_time;
if (duration.pun_duration > 0) {
m_timeSteps[paymentOptionIndex] << duration.pun_duration;
}
#if DEBUG_GET_TIME_STEPS==1
// timeStepComp: added to (otherwise static) time-steps
qCritical() << "(" << __func__ << ":" << __LINE__ << ") duration.pun_duration_max:" << duration.pun_duration_max;
qCritical() << "(" << __func__ << ":" << __LINE__ << ") duration.pun_duration:" << duration.pun_duration;
qCritical() << "(" << __func__ << ":" << __LINE__ << ") time step compensation:" << timeStepCompensation;
#endif
} else {
duration.pun_duration = nextTimeStep;
#if DEBUG_GET_TIME_STEPS==1
QTime nextTime(0, 0, 0);
nextTime = nextTime.addSecs(duration.pun_duration * 60);
qCritical() << "(" << __func__ << ":" << __LINE__ << ") next time step:" << nextTime.toString(Qt::ISODate);
#endif
if (duration.pun_duration > 0) {
m_timeSteps[paymentOptionIndex] << duration.pun_duration;
}
}
} else
if (rest > 0) {
// last time step before swicthing to dayticket (see Schnals 505/506)
duration.pun_duration = duration.pun_duration_max;
#if DEBUG_GET_TIME_STEPS==1
QTime nextTime(0, 0, 0);
nextTime = nextTime.addSecs(duration.pun_duration * 60);
qCritical() << "(" << __func__ << ":" << __LINE__ << ") next time step:" << nextTime.toString(Qt::ISODate);
qCritical() << "(" << __func__ << ":" << __LINE__ << ") pun id:" << duration.pun_id;
qCritical() << "(" << __func__ << ":" << __LINE__ << ") pun duration:" << duration.pun_duration;
#endif
if (duration.pun_duration > 0) {
m_timeSteps[paymentOptionIndex] << duration.pun_duration;
}
}
cfg->Duration.erase(search);
cfg->Duration.insert(pair<int, ATBDuration>(duration.pun_id, duration));
} else
if (duration.pun_interpolation_id == (int)ATBInterpolation::NO_INTERPOLATION) {
#if DEBUG_GET_TIME_STEPS==1
qCritical() << "(" << __func__ << ":" << __LINE__ << ") pun_id:" << duration.pun_id;
qCritical() << "(" << __func__ << ":" << __LINE__ << ") pun duration_max:" << duration.pun_duration_max;
qCritical() << "(" << __func__ << ":" << __LINE__ << ") pun duration:" << duration.pun_duration;
qCritical() << "(" << __func__ << ":" << __LINE__ << ") time step compensation:" << timeStepCompensation;
#endif
duration.pun_duration += start_time + timeStepCompensation;
m_timeSteps[paymentOptionIndex] << duration.pun_duration;
cfg->Duration.erase(search);
cfg->Duration.insert(pair<int, ATBDuration>(duration.pun_id, duration));
} else {
cfg->Duration.erase(search);
}
}
}
}
} }
} else { // if (carryOverTimeRangeFrom == carryOverTimeRangeTo) { } else { // if (carryOverTimeRangeFrom == carryOverTimeRangeTo) {
// TODO // TODO
@ -2203,9 +2363,22 @@ QList<int> &Calculator::GetTimeSteps(Configuration *cfg, int paymentOptionIndex)
qCritical() << "(" << __func__ << ":" << __LINE__ << ") NEW timeSteps:" << m_timeSteps; qCritical() << "(" << __func__ << ":" << __LINE__ << ") NEW timeSteps:" << m_timeSteps;
#if DEBUG_GET_TIME_STEPS==1
for (int i = 0; i < m_timeSteps[paymentOptionIndex].size(); ++i) {
QDateTime nextTime = start;
nextTime.setTime(QTime(0, 0, 0));
nextTime = nextTime.addSecs(m_timeSteps[paymentOptionIndex][i] * 60);
qCritical() << "(" << __func__ << ":" << __LINE__ << ") step"
<< i << m_timeSteps[0][i] << "->" << nextTime.toString(Qt::ISODate);
}
#endif
return m_timeSteps[paymentOptionIndex]; return m_timeSteps[paymentOptionIndex];
} }
#undef DEBUG_GET_TIME_STEPS
uint32_t Calculator::GetPriceForTimeStep(Configuration *cfg, int timeStep, int paymentOptionIndex) const { uint32_t Calculator::GetPriceForTimeStep(Configuration *cfg, int timeStep, int paymentOptionIndex) const {
int const pop_id = cfg->getPaymentOptions(paymentOptionIndex).pop_id; int const pop_id = cfg->getPaymentOptions(paymentOptionIndex).pop_id;