Allow some tolerance when looking for a match for the first time-step

This commit is contained in:
Gerhard Hoffmann 2024-07-13 13:55:24 +02:00
parent a7f3477752
commit dda04434fc

View File

@ -344,7 +344,7 @@ int CALCULATE_LIBRARY_API compute_next_timestep(parking_tariff_t *tariff, int cu
qCritical() << " compute_next_timestep() currentTimeMinutes: " << currentTimeMinutes;
qCritical() << " compute_next_timestep() up/down (1=up, 0=down): " << UpDown;
Configuration *cfg = tariff;
Configuration const *cfg = tariff;
// compute payment method id (e.g. Linear=3, Steps=4)
PaymentMethod const paymentMethodId = Utilities::getPaymentMethodId(cfg);
@ -372,71 +372,39 @@ int CALCULATE_LIBRARY_API compute_next_timestep(parking_tariff_t *tariff, int cu
// progressive tariff: e.g. Neuhauser, Kirchdorf (743)
(paymentMethodId == PaymentMethod::Progressive))
{
QVector<QList<int>> stepListVec;
QList<int> const timeSteps = Calculator::GetInstance().GetTimeSteps(tariff);
qCritical() << " compute_next_timestep() time-steps: " << timeSteps;
int paymentOptionIndex = 0;
int const pop_time_step_config = tariff->getPaymentOptions(paymentOptionIndex).pop_time_step_config;
if (pop_time_step_config == (int)ATBTimeStepConfig::TimeStepConfig::DYNAMIC) {
QList<int> lst;
for (int index = 0; index < 5; ++index) {
lst.clear();
QListIterator<int> i(timeSteps);
while (i.hasNext()) {
switch (index) {
case 0:
lst.append(i.next());
break;
case 1:
lst.append(i.next() - 2);
break;
case 2:
lst.append(i.next() - 1);
break;
case 3:
lst.append(i.next() + 1);
break;
case 4:
lst.append(i.next() + 2);
break;
default:;
}
}
qCritical() << " compute_next_timestep() " << index << "list of time-steps" << lst;
stepListVec.append(lst);
}
}
int stepListIndex = -1;
for (int index = 0; index < stepListVec.size(); ++index) {
if (stepListVec[index].indexOf(currentTimeMinutes) != -1) {
stepListIndex = index;
break;
}
}
if (stepListIndex == -1) {
qCritical() << "compute_next_timestep() *NO STEP INDEX* for currentTimeMinutes (" << currentTimeMinutes << ")";
QList<int> &stepList = Calculator::GetInstance().GetTimeSteps(tariff);
int const size = stepList.size();
if (size == 0) {
qCritical() << "compute_next_timestep() *ERROR empty step-list*";
return currentTimeMinutes;
}
QList<int> const &stepList = stepListVec[stepListIndex];
qCritical() << " compute_next_timestep() index:" << stepListIndex;
qCritical() << " compute_next_timestep() timeSteps:" << stepList;
qCritical() << " compute_next_timestep() first time step:" << stepList[0];
qCritical() << " compute_next_timestep() timeSteps:" << stepList;
qCritical() << " compute_next_timestep() currentTimeInMinutes:" << currentTimeMinutes;
int const currentStepIndex = stepList.indexOf(currentTimeMinutes); // must be currentStepIndex != -1
// consider time shift: the step-list might have been computed at a
// slightly different time point
int maxStep = -1;
if (size >= 2) {
maxStep = stepList[1] - stepList[0];
}
int tolerance = (maxStep == -1) ? 5 : std::min(maxStep, 5);
if (std::abs(stepList[0] - currentTimeMinutes) <= tolerance) {
qCritical().noquote()
<< QString(" compute_next_timestep() correction stepList[0]=%1 -> %2:")
.arg(stepList[0]).arg(currentTimeMinutes);
stepList[0] = currentTimeMinutes;
qCritical() << " compute_next_timestep() NEW timeSteps:" << stepList;
}
int currentStepIndex = stepList.indexOf(currentTimeMinutes);
if (currentStepIndex == -1) {
qCritical() << "compute_next_timestep() *NO STEP* for currentTimeMinutes (" << currentTimeMinutes << ")";
return currentTimeMinutes;
}
cfg->getPaymentOptions(paymentOptionIndex).pop_min_time = stepList.first();
if (UpDown == 1) { // UP
if (stepList[currentStepIndex] == stepList.last()) {
qCritical() << "compute_next_timestep() *NO NEXT STEP* for currentTimeMinutes (" << currentTimeMinutes << ")";