Implement get_minimal_parkingtime() and get_time_steps().

This commit is contained in:
Gerhard Hoffmann 2024-01-22 15:41:20 +01:00
parent 0ce630dfa3
commit b43fa274bd
3 changed files with 73 additions and 66 deletions

View File

@ -44,7 +44,7 @@ public:
// helper function to find time steps for a tariff with PaymentMethod::Steps
// (e.g. Schoenau/Koenigsee)
//
QList<int> GetTimeSteps(Configuration *cfg, quint64 startInMinutes = QDateTime::currentSecsSinceEpoch() / 60) const;
QList<int> GetTimeSteps(Configuration *cfg) const;
QList<int> GetSteps(Configuration *cfg) const { return GetTimeSteps(cfg); }
// additional helper functions

View File

@ -12,8 +12,15 @@
static Calculator calculator;
QList<int> CALCULATE_LIBRARY_API get_time_steps(Configuration *cfg, qint64 startInMinutes) {
return calculator.GetTimeSteps(cfg, startInMinutes);
QList<int> CALCULATE_LIBRARY_API get_time_steps(Configuration *cfg) {
return calculator.GetTimeSteps(cfg);
}
int CALCULATE_LIBRARY_API get_minimum_parkingtime(Configuration *cfg) {
// get_time_steps() possibly re-computes pop_min_time: see
// calculator.GetTimeSteps()
get_time_steps(cfg);
return qRound(cfg->getPaymentOptions().pop_min_time);
}
int CALCULATE_LIBRARY_API get_zone_nr(int zone)

View File

@ -695,21 +695,22 @@ Ticket Calculator::private_GetDurationFromCost(Configuration *cfg,
cost, Ticket::s[VALID]);
}
QList<int> Calculator::GetTimeSteps(Configuration *cfg, quint64 startInMinutes) const {
static QList<int> timeSteps;
QList<int> Calculator::GetTimeSteps(Configuration *cfg) const {
QList<int> timeSteps;
QDateTime start = QDateTime::currentDateTime();
start.setTime(QTime(start.time().hour(), start.time().minute(), 0));
if (timeSteps.size() == 0) {
int const pop_id = cfg->getPaymentOptions().pop_id;
int const pop_carry_over = cfg->getPaymentOptions().pop_carry_over;
int const pop_time_step_config = cfg->getPaymentOptions().pop_time_step_config;
qCritical() << " start parking time:" << start.toString(Qt::ISODate);
qCritical() << " payment option id:" << pop_id;
qCritical() << " payment option carry over:" << pop_carry_over;
qCritical() << "payment option time step config:" << pop_time_step_config;
if (pop_time_step_config == (int)ATBTimeStepConfig::TimeStepConfig::DYNAMIC) {
QDateTime start;
start.setSecsSinceEpoch(startInMinutes * 60);
uint16_t timeStepCompensation = 0;
if (pop_carry_over) {
@ -776,7 +777,6 @@ QList<int> Calculator::GetTimeSteps(Configuration *cfg, quint64 startInMinutes)
timeSteps << durationUnit;
}
}
}
return timeSteps;
}