From c153652b3d968ee03a5adacc6c1b946a746672ae Mon Sep 17 00:00:00 2001 From: Gerhard Hoffmann Date: Tue, 16 Jul 2024 16:50:11 +0200 Subject: [PATCH] compute_next_timestep(): allow some tolerance for first time-step --- library/src/calculate_price.cpp | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/library/src/calculate_price.cpp b/library/src/calculate_price.cpp index 347d6ce..938f379 100644 --- a/library/src/calculate_price.cpp +++ b/library/src/calculate_price.cpp @@ -372,8 +372,31 @@ int CALCULATE_LIBRARY_API compute_next_timestep(parking_tariff_t *tariff, int cu // progressive tariff: e.g. Neuhauser, Kirchdorf (743) (paymentMethodId == PaymentMethod::Progressive)) { - const QList stepList = Calculator::GetInstance().GetTimeSteps(tariff); - qCritical() << " compute_next_timestep() timeSteps:" << stepList; + QList &stepList = Calculator::GetInstance().GetTimeSteps(tariff); + int const size = stepList.size(); + if (size == 0) { + qCritical() << "compute_next_timestep() *ERROR empty step-list*"; + return currentTimeMinutes; + } + + qCritical() << " compute_next_timestep() first time step:" << stepList[0]; + qCritical() << " compute_next_timestep() timeSteps:" << stepList; + qCritical() << " compute_next_timestep() currentTimeInMinutes:" << currentTimeMinutes; + + // 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);