Add compute_next_timestep() computing timesteps if PaymentMethod = Steps.
Add additional code for computing time steps dynamically if PaymentMethod = Linear.
This commit is contained in:
parent
5b8d9c62cc
commit
b9a7c04db9
@ -2,6 +2,7 @@
|
||||
#include "configuration.h"
|
||||
#include "calculator_functions.h"
|
||||
#include "payment_option.h"
|
||||
#include "utilities.h"
|
||||
|
||||
#include <QFile>
|
||||
#include <QFileInfo>
|
||||
@ -92,6 +93,77 @@ void CALCULATE_LIBRARY_API free_tariff(parking_tariff_t *tariff) {
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// UpDown 1 -> up; 0 -> down
|
||||
int CALCULATE_LIBRARY_API compute_next_timestep(parking_tariff_t *tariff, int currentTimeMinutes, int UpDown)
|
||||
{
|
||||
// use tariff with structure as for instance Schnau, Koenigsee:
|
||||
// without given YearPeriod, SpecialDays and SpecialDaysWorktime
|
||||
if (tariff->YearPeriod.size() == 0
|
||||
&& tariff->SpecialDays.size() == 0
|
||||
&& tariff->SpecialDaysWorktime.size() == 0)
|
||||
{
|
||||
static const QList<int> stepList = calculator.GetTimeSteps(tariff);
|
||||
|
||||
int currentStepIndex = stepList.indexOf(currentTimeMinutes);
|
||||
|
||||
if (currentStepIndex == -1) {
|
||||
qCritical() << "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 << ")";
|
||||
return currentTimeMinutes;
|
||||
}
|
||||
else {
|
||||
return stepList[currentStepIndex + 1];
|
||||
}
|
||||
}
|
||||
if (UpDown == 0) { // DOWN
|
||||
if (stepList[currentStepIndex] == stepList.first()) {
|
||||
qCritical() << "compute_next_timestep() *NO PREVIOUS STEP* for currentTimeMinutes (" << currentTimeMinutes << ")";
|
||||
return currentTimeMinutes;
|
||||
}
|
||||
else {
|
||||
return stepList[currentStepIndex - 1];
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Configuration const *cfg = tariff;
|
||||
|
||||
// currentTimeMinutes is the number of minutes actually used. This
|
||||
// value is an offset from the start time and cannot be used as a
|
||||
// QDateTime.
|
||||
|
||||
qCritical() << "compute_next_timestep() currentTimeMinutes:" << currentTimeMinutes;
|
||||
|
||||
// compute payment method id (e.g. Linear=3, Steps=4)
|
||||
PaymentMethod paymentMethodId = Utilities::getPaymentMethodId(cfg);
|
||||
qCritical() << " compute_next_timestep() paymentMethodId:" << paymentMethodId;
|
||||
|
||||
// get minimal and maximal parking times
|
||||
int const minParkingTime = Utilities::getMinimalParkingTime(cfg, paymentMethodId);
|
||||
int const maxParkingTime = Utilities::getMaximalParkingTime(cfg, paymentMethodId);
|
||||
|
||||
qCritical() << " compute_next_timestep() maxParkingTime:" << paymentMethodId;
|
||||
qCritical() << " compute_next_timestep() minParkingTime:" << paymentMethodId;
|
||||
|
||||
// use the first (i.e. main duration step contained in the tariff json-file)
|
||||
int firstDurationStep = Utilities::getFirstDurationStep(cfg, paymentMethodId);
|
||||
qCritical() << " compute_next_timestep() firstDurationStep:" << paymentMethodId;
|
||||
|
||||
int nextTimeStep = currentTimeMinutes + firstDurationStep;
|
||||
if (currentTimeMinutes >= minParkingTime && nextTimeStep <= maxParkingTime) {
|
||||
qCritical() << " compute_next_timestep() nextTimeStep:" << nextTimeStep;
|
||||
return nextTimeStep;
|
||||
}
|
||||
}
|
||||
|
||||
qCritical() << "compute_next_timestep() *CAN NOT COMPUTE* for currentTimeMinutes (" << currentTimeMinutes << ")";
|
||||
return currentTimeMinutes;
|
||||
}
|
||||
|
||||
// this is currently not used
|
||||
CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket(
|
||||
|
Loading…
Reference in New Issue
Block a user