(1) Fix debug output.

(2) Use UpDown-Argument for calculation of next tiem step.
This commit is contained in:
Gerhard Hoffmann 2023-12-08 10:16:52 +01:00
parent 2d696941a5
commit 0f05a1a784

View File

@ -97,6 +97,7 @@ 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)
{
qCritical() << " compute_next_timestep() currentTimeMinutes: " << currentTimeMinutes;
Configuration const *cfg = tariff;
// compute payment method id (e.g. Linear=3, Steps=4)
@ -157,21 +158,23 @@ int CALCULATE_LIBRARY_API compute_next_timestep(parking_tariff_t *tariff, int cu
// value is an offset from the start time and cannot be used as a
// QDateTime.
qCritical() << "compute_next_timestep() currentTimeMinutes:" << currentTimeMinutes;
qCritical() << "compute_next_timestep() up/down (1=up, 0=down):" << UpDown;
// 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;
qCritical() << " compute_next_timestep() maxParkingTime:" << maxParkingTime;
qCritical() << " compute_next_timestep() minParkingTime:" << minParkingTime;
// 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;
firstDurationStep = ((UpDown == 1) ? firstDurationStep : -firstDurationStep);
qCritical() << " compute_next_timestep() firstDurationStep:" << firstDurationStep;
int nextTimeStep = currentTimeMinutes + firstDurationStep;
if (currentTimeMinutes >= minParkingTime && nextTimeStep <= maxParkingTime) {
qCritical() << " compute_next_timestep() nextTimeStep:" << nextTimeStep;
return nextTimeStep;