compute_next_time_step():
Added handling with pop_plus_steps/pop_minus_steps: '+' usually takes more than one time step. '-' is usually 1. Changed behaviour when current time is not found in the list of time steps: Search for the entry with the smallest distance to 'current time'. If the distance is smaller than 3 minutes, then use 'current time' as new entry in the list of time steps.
This commit is contained in:
parent
f0677374ec
commit
cde490bab2
@ -3,6 +3,8 @@
|
||||
#include "calculator_functions.h"
|
||||
#include "payment_option.h"
|
||||
#include "utilities.h"
|
||||
#include "tariff_global_defines.h"
|
||||
#include "period_year.h"
|
||||
|
||||
#include <QFile>
|
||||
#include <QFileInfo>
|
||||
@ -462,8 +464,8 @@ int CALCULATE_LIBRARY_API compute_next_timestep(parking_tariff_t *tariff, int cu
|
||||
int UpDown, PermitType const &permitType)
|
||||
{
|
||||
|
||||
qCritical() << " compute_next_timestep() currentTimeMinutes: " << currentTimeMinutes;
|
||||
qCritical() << " compute_next_timestep() up/down (1=up, 0=down): " << UpDown;
|
||||
qCritical() << __LINE__ << "compute_next_timestep() currentTimeMinutes: " << currentTimeMinutes;
|
||||
qCritical() << __LINE__ << "compute_next_timestep() up/down (1=up, 0=down): " << UpDown;
|
||||
|
||||
// FIXME
|
||||
//std::optional<ATBPaymentOption> paymentOption = tariff->getPaymentOptionForKey(permitType.get());
|
||||
@ -473,7 +475,12 @@ int CALCULATE_LIBRARY_API compute_next_timestep(parking_tariff_t *tariff, int cu
|
||||
//}
|
||||
|
||||
int const paymentOptionIndex = tariff->getPaymentOptionIndex(permitType);
|
||||
qCritical() << " compute_next_timestep() payment option index: " << paymentOptionIndex;
|
||||
int const &pop_plus_steps = tariff->getPaymentOptions(paymentOptionIndex).pop_plus_steps;
|
||||
int const &pop_minus_steps = tariff->getPaymentOptions(paymentOptionIndex).pop_minus_steps;
|
||||
|
||||
qCritical() << __LINE__ << "compute_next_timestep() payment option index: " << paymentOptionIndex;
|
||||
qCritical() << __LINE__ << "compute_next_timestep() plus steps: " << pop_plus_steps;
|
||||
qCritical() << __LINE__ << "compute_next_timestep() minus steps: " << pop_minus_steps;
|
||||
|
||||
Configuration const *cfg = tariff;
|
||||
|
||||
@ -481,19 +488,19 @@ int CALCULATE_LIBRARY_API compute_next_timestep(parking_tariff_t *tariff, int cu
|
||||
PaymentMethod const paymentMethodId = Utilities::getPaymentMethodId(cfg);
|
||||
switch (paymentMethodId) {
|
||||
case PaymentMethod::Progressive:
|
||||
qCritical() << __LINE__ << " compute_next_timestep() paymentMethodId: Progressive";
|
||||
qCritical() << __LINE__ << "compute_next_timestep() paymentMethodId: Progressive";
|
||||
break;
|
||||
case PaymentMethod::Degressive:
|
||||
qCritical() << __LINE__ << " compute_next_timestep() paymentMethodId: Degressive";
|
||||
qCritical() << __LINE__ << "compute_next_timestep() paymentMethodId: Degressive";
|
||||
break;
|
||||
case PaymentMethod::Linear:
|
||||
qCritical() << __LINE__ << " compute_next_timestep() paymentMethodId: Linear";
|
||||
qCritical() << __LINE__ << "compute_next_timestep() paymentMethodId: Linear";
|
||||
break;
|
||||
case PaymentMethod::Steps:
|
||||
qCritical() << __LINE__ << " compute_next_timestep() paymentMethodId: Steps";
|
||||
qCritical() << __LINE__ << "compute_next_timestep() paymentMethodId: Steps";
|
||||
break;
|
||||
case PaymentMethod::Undefined:
|
||||
qCritical() << __LINE__ << " compute_next_timestep() paymentMethodId: Undefined";
|
||||
qCritical() << __LINE__ << "compute_next_timestep() paymentMethodId: Undefined";
|
||||
break;
|
||||
}
|
||||
|
||||
@ -502,9 +509,8 @@ int CALCULATE_LIBRARY_API compute_next_timestep(parking_tariff_t *tariff, int cu
|
||||
if ((paymentMethodId == PaymentMethod::Steps) ||
|
||||
// progressive tariff: e.g. Neuhauser, Kirchdorf (743)
|
||||
(paymentMethodId == PaymentMethod::Progressive))
|
||||
// (paymentMethodId == PaymentMethod::Degressive)) degressive tariff: e.g. Fuchs Technik (500)
|
||||
{
|
||||
// int paymentOptionIndex = 1;
|
||||
|
||||
QList<int> &stepList = Calculator::GetInstance().GetTimeSteps(tariff, paymentOptionIndex);
|
||||
int const size = stepList.size();
|
||||
if (size == 0) {
|
||||
@ -512,52 +518,94 @@ int CALCULATE_LIBRARY_API compute_next_timestep(parking_tariff_t *tariff, int cu
|
||||
return currentTimeMinutes;
|
||||
}
|
||||
|
||||
qCritical() << " compute_next_timestep() first time step:" << stepList[0];
|
||||
qCritical() << " compute_next_timestep() timeSteps:" << stepList;
|
||||
qCritical() << " compute_next_timestep() currentTimeInMinutes:" << currentTimeMinutes;
|
||||
qCritical() << __LINE__ << "compute_next_timestep() first time step:" << stepList[0];
|
||||
qCritical() << __LINE__ << "compute_next_timestep() timeSteps:" << stepList;
|
||||
qCritical() << __LINE__ << "compute_next_timestep() currentTimeInMinutes:" << currentTimeMinutes;
|
||||
|
||||
// consider time shift: the step-list might have been computed at a
|
||||
// slightly different time point
|
||||
|
||||
int currentStepIndex = stepList.indexOf(currentTimeMinutes);
|
||||
if (currentStepIndex == -1) {
|
||||
unsigned minimalDistance = ~0;
|
||||
int j = -1;
|
||||
for (int i = 0; i < stepList.size(); ++i) {
|
||||
unsigned distance = std::abs(stepList[i] - currentTimeMinutes);
|
||||
if (distance < minimalDistance) {
|
||||
minimalDistance = distance;
|
||||
j = i;
|
||||
}
|
||||
}
|
||||
// max. tolerance set to 3 minutes
|
||||
unsigned const tolerance = std::min(minimalDistance, (unsigned)(3));
|
||||
if (j != -1) {
|
||||
stepList[j] = currentTimeMinutes;
|
||||
}
|
||||
}
|
||||
|
||||
#if 0
|
||||
int maxStep = -1;
|
||||
if (size >= 2) {
|
||||
maxStep = stepList[1] - stepList[0];
|
||||
}
|
||||
int tolerance = (maxStep == -1) ? 5 : std::min(maxStep, 5);
|
||||
// max. tolerance set to 5 minutes
|
||||
int const tolerance = (maxStep == -1) ? 5 : std::min(maxStep, 5);
|
||||
for (int i=0; i < stepList.size(); ++i) {
|
||||
if (std::abs(stepList[i] - currentTimeMinutes) <= tolerance) {
|
||||
qCritical().noquote()
|
||||
<< QString(" compute_next_timestep() correction stepList[%1]=%2 -> %3:")
|
||||
<< __LINE__ << QString("compute_next_timestep() correction stepList[%1]=%2 -> %3:")
|
||||
.arg(i).arg(stepList[0]).arg(currentTimeMinutes);
|
||||
stepList[i] = currentTimeMinutes;
|
||||
qCritical() << " compute_next_timestep() NEW timeSteps:" << stepList;
|
||||
qCritical() << __LINE__ << "compute_next_timestep() NEW timeSteps:" << stepList;
|
||||
}
|
||||
}
|
||||
|
||||
int currentStepIndex = stepList.indexOf(currentTimeMinutes);
|
||||
#endif
|
||||
|
||||
currentStepIndex = stepList.indexOf(currentTimeMinutes);
|
||||
qCritical() << __LINE__ << "compute_next_timestep() currentStepIndex (" << currentStepIndex << ")";
|
||||
|
||||
if (currentStepIndex == -1) {
|
||||
qCritical() << "compute_next_timestep() *NO STEP* for currentTimeMinutes (" << currentTimeMinutes << ")";
|
||||
qCritical() << __LINE__ << "compute_next_timestep() *NO STEP* for currentTimeMinutes (" << currentTimeMinutes << ")";
|
||||
return currentTimeMinutes;
|
||||
}
|
||||
|
||||
if (UpDown == 1) { // UP
|
||||
if (stepList[currentStepIndex] == stepList.last()) {
|
||||
qCritical() << "compute_next_timestep() *NO NEXT STEP* for currentTimeMinutes (" << currentTimeMinutes << ")";
|
||||
qCritical() << __LINE__ << "compute_next_timestep() *NO NEXT STEP* for currentTimeMinutes (" << currentTimeMinutes << ")";
|
||||
return currentTimeMinutes;
|
||||
}
|
||||
else {
|
||||
qCritical() << " compute_next_timestep() return next time step:" << stepList[currentStepIndex + 1];
|
||||
return stepList[currentStepIndex + 1];
|
||||
int const rest = currentStepIndex % pop_plus_steps;
|
||||
|
||||
if (rest) {
|
||||
currentStepIndex -= rest;
|
||||
}
|
||||
|
||||
qCritical() << __LINE__ << "compute_next_timestep() currentStepIndex (" << currentStepIndex << ")";
|
||||
|
||||
int const nextStepIndex = currentStepIndex + pop_plus_steps;
|
||||
|
||||
qCritical() << __LINE__ << "compute_next_timestep() next step index:" << nextStepIndex;
|
||||
if (nextStepIndex >= 0 && nextStepIndex < stepList.size()) {
|
||||
qCritical() << __LINE__ << "compute_next_timestep() return next time step:" << stepList[nextStepIndex];
|
||||
return stepList[nextStepIndex];
|
||||
}
|
||||
}
|
||||
}
|
||||
if (UpDown == 0) { // DOWN
|
||||
if (stepList[currentStepIndex] == stepList.first()) {
|
||||
qCritical() << "compute_next_timestep() *NO PREVIOUS STEP* for currentTimeMinutes (" << currentTimeMinutes << ")";
|
||||
qCritical() << __LINE__ << "compute_next_timestep() *NO PREVIOUS STEP* for currentTimeMinutes (" << currentTimeMinutes << ")";
|
||||
return currentTimeMinutes;
|
||||
}
|
||||
else {
|
||||
qCritical() << " compute_next_timestep() return next time step:" << stepList[currentStepIndex - 1];
|
||||
return stepList[currentStepIndex - 1];
|
||||
int const nextStepIndex = currentStepIndex - pop_minus_steps;
|
||||
qCritical() << __LINE__ << "compute_next_timestep() next step index:" << nextStepIndex;
|
||||
if (nextStepIndex >= 0 && nextStepIndex < stepList.size()) {
|
||||
qCritical() << __LINE__ << "compute_next_timestep() return next time step:" << stepList[nextStepIndex];
|
||||
return stepList[nextStepIndex];
|
||||
}
|
||||
}
|
||||
}
|
||||
} else
|
||||
|
Loading…
Reference in New Issue
Block a user