Compare commits

..

No commits in common. "b0c4ad0e2e3572cdf6a30915027eb3b3dd302f63" and "aba38d26143555d1659d3dd9866e7ffa72f1742a" have entirely different histories.

10 changed files with 250 additions and 343 deletions

View File

@ -196,25 +196,11 @@ int CALCULATE_LIBRARY_API get_zone_nr(int zone = -1);
int CALCULATE_LIBRARY_API compute_next_timestep(parking_tariff_t *tariff, int currentTimeMinutes, int UpDown); int CALCULATE_LIBRARY_API compute_next_timestep(parking_tariff_t *tariff, int currentTimeMinutes, int UpDown);
QList<int> CALCULATE_LIBRARY_API get_time_steps(Configuration *cfg); QList<int> CALCULATE_LIBRARY_API get_time_steps(Configuration *cfg);
int CALCULATE_LIBRARY_API get_minimal_parkingtime(Configuration *cfg, PERMIT_TYPE permitType = PERMIT_TYPE::SHORT_TERM_PARKING);
int CALCULATE_LIBRARY_API get_minimal_parkingtime(Configuration *cfg, int CALCULATE_LIBRARY_API get_maximal_parkingtime(Configuration *cfg, PERMIT_TYPE permitType = PERMIT_TYPE::SHORT_TERM_PARKING);
PERMIT_TYPE permitType = PERMIT_TYPE::SHORT_TERM_PARKING, int CALCULATE_LIBRARY_API get_minimal_parkingprice(Configuration *cfg, PERMIT_TYPE permitType = PERMIT_TYPE::SHORT_TERM_PARKING);
int paymentOptionIndex=0); int CALCULATE_LIBRARY_API get_maximal_parkingprice(Configuration *cfg, PERMIT_TYPE permitType = PERMIT_TYPE::SHORT_TERM_PARKING);
int CALCULATE_LIBRARY_API compute_product_price(Configuration const *cfg, PERMIT_TYPE permitType = PERMIT_TYPE::SHORT_TERM_PARKING);
int CALCULATE_LIBRARY_API get_maximal_parkingtime(Configuration *cfg,
PERMIT_TYPE permitType = PERMIT_TYPE::SHORT_TERM_PARKING,
int paymentOptionIndex=0);
int CALCULATE_LIBRARY_API get_minimal_parkingprice(Configuration *cfg,
PERMIT_TYPE permitType = PERMIT_TYPE::SHORT_TERM_PARKING,
int paymentOptionIndex=0);
int CALCULATE_LIBRARY_API get_maximal_parkingprice(Configuration *cfg,
PERMIT_TYPE permitType = PERMIT_TYPE::SHORT_TERM_PARKING,
int paymentOptionIndex=0);
int CALCULATE_LIBRARY_API compute_product_price(Configuration const *cfg,
PERMIT_TYPE permitType = PERMIT_TYPE::SHORT_TERM_PARKING);
CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket( // deprecated CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket( // deprecated
parking_tariff_t *tariff, parking_tariff_t *tariff,

View File

@ -14,7 +14,7 @@
using namespace std; using namespace std;
class Calculator { class Calculator {
mutable QVector<QList<int>> m_timeSteps; mutable QList<int> m_timeSteps;
mutable QList<int> m_priceSteps; mutable QList<int> m_priceSteps;
protected: protected:
@ -29,17 +29,8 @@ public:
return c; return c;
} }
void ResetTimeSteps(int paymentOptionIndex) { void ResetTimeSteps() { m_timeSteps.clear(); }
if (m_timeSteps.size() > 0) { QList<int> timeSteps() const { return m_timeSteps; }
m_timeSteps[paymentOptionIndex].clear();
}
}
QList<int> timeSteps(int paymentOptionIndex=0) const {
if (m_timeSteps.size() > 0) {
return m_timeSteps[paymentOptionIndex];
}
return QList<int>();
}
void ResetPriceSteps() { m_priceSteps.clear(); } void ResetPriceSteps() { m_priceSteps.clear(); }
QList<int> priceSteps() const { return m_priceSteps; } QList<int> priceSteps() const { return m_priceSteps; }
@ -75,8 +66,8 @@ public:
// helper function to find time steps for a tariff with PaymentMethod::Steps // helper function to find time steps for a tariff with PaymentMethod::Steps
// (e.g. Schoenau/Koenigsee) // (e.g. Schoenau/Koenigsee)
// //
QList<int> GetTimeSteps(Configuration *cfg, int paymentOptionIndex=0) const; QList<int> GetTimeSteps(Configuration *cfg) const;
QList<int> GetSteps(Configuration *cfg, int paymentOptionIndex=0) const { return GetTimeSteps(cfg, paymentOptionIndex); } QList<int> GetSteps(Configuration *cfg) const { return GetTimeSteps(cfg); }
QList<int> GetPriceSteps(Configuration *cfg) const; QList<int> GetPriceSteps(Configuration *cfg) const;

View File

@ -63,12 +63,10 @@ public:
/// <returns>Returns operation status bool (OK | FAIL) </returns> /// <returns>Returns operation status bool (OK | FAIL) </returns>
bool ParseJson(Configuration* cfg, const char* json); bool ParseJson(Configuration* cfg, const char* json);
ATBPaymentOption &getPaymentOptions(int paymentOptionsIndex=0); ATBPaymentOption &getPaymentOptions();
ATBPaymentOption const &getPaymentOptions(int paymentOptionsIndex=0) const; ATBPaymentOption const &getPaymentOptions() const;
QVector<ATBPaymentOption> &getAllPaymentOptions(); QVector<ATBPaymentOption> &getAllPaymentOptions();
QVector<ATBPaymentOption> const &getAllPaymentOptions() const; QVector<ATBPaymentOption> const &getAllPaymentOptions() const;
int getCurrentPaymentOptionIndex(QDateTime const &dt) const;
bool isHoliday(QDateTime const &dt) const;
std::optional<QVector<ATBPaymentRate>> getPaymentRateForAllKeys() const; std::optional<QVector<ATBPaymentRate>> getPaymentRateForAllKeys() const;
std::optional<QVector<ATBPaymentRate>> getPaymentRateForKey(int key) const; std::optional<QVector<ATBPaymentRate>> getPaymentRateForKey(int key) const;
std::optional<QVector<ATBDailyTicket>> getDailyTicketsForAllKeys() const; std::optional<QVector<ATBDailyTicket>> getDailyTicketsForAllKeys() const;

View File

@ -1,9 +1,5 @@
#ifndef PAYMENT_OPT_H_INCLUDED #pragma once
#define PAYMENT_OPT_H_INCLUDED
#include <string> #include <string>
#include <cinttypes>
class ATBPaymentOption class ATBPaymentOption
{ {
@ -41,8 +37,6 @@ public:
int pop_carry_over; int pop_carry_over;
int pop_carry_over_time_range_id; int pop_carry_over_time_range_id;
int pop_daily_card_price; int pop_daily_card_price;
uint64_t pop_business_hours; int pop_business_hours;
int pop_time_step_config; int pop_time_step_config;
}; };
#endif // PAYMENT_OPT_H_INCLUDED

View File

@ -4,58 +4,19 @@
/// <summary> /// <summary>
/// Business hours (byte represents payment option id) /// Business hours (byte represents payment option id)
/// </summary> /// </summary>
/// enum BusinessHours
#define _MON_ (1ULL << 8)
#define _TUE_ (1ULL << 9)
#define _WED_ (1ULL << 10)
#define _THU_ (1ULL << 11)
#define _FRI_ (1ULL << 12)
#define _SAT_ (1ULL << 13)
#define _SUN_ (1ULL << 14)
#define _WEEK_DAYS_ ((_MON_|_TUE_|_WED_|_THU_|_FRI_))
#define _WORKING_DAYS_ ((_MON_|_TUE_|_WED_|_THU_|_FRI_|_SAT_))
#define _ALL_DAYS_ ((_MON_|_TUE_|_WED_|_THU_|_FRI_|_SAT_|_SUN_))
#define _OFFICIAL_HOLIDAY_ (1ULL << 15)
#define _ONLY_WEEKEND ((_SAT_|_SUN_))
#define _ONLY_OPEN_FOR_BUSINESS_DAYS (1ULL << 16) /* verkaufsoffen */
#define _NOT_DEFINED (~0ULL)
enum BusinessHours : std::uint64_t
{ {
NoRestriction_24_7 = 0, NoRestriction_24_7 = 0,
OnlyWorkingDays = 1, // [Monday-Friday] OnlyWorkingDays = 1, // [Monday-Friday]
OnlyWeekDays = 2, // [Monday-Saturday] OnlyWeekDays = 2, // [Monday-Saturday]
OnlyWeekEnd = 4, // [Saturday+Sunday] OnlyWeekEnd = 4, // [Saturday+Sunday]
OnlyOfficialHolidays = 8, OnlyOfficialHolidays = 8,
OnlySundaysAndHolidays = 12, // [Sun+Holiday]
OnlySpecialDays = 16, OnlySpecialDays = 16,
OnlySchoolHolidays = 32, OnlySchoolHolidays = 32,
SpecialAndSchoolHolidays = 48, SpecialAndSchoolHolidays = 48,
OnlyOpenForBusinessDays = 64, // verkaufsoffen OnlyOpenForBusinessDays = 64, // verkaufsoffen
AllDaysWithRestrictedHours = 128, // every day, restricted to some time range AllDaysWithRestrictedHours = 128, // every day, restricted to some time range
NoBusinessHoursDefined = 255, NoBusinessHoursDefined = 255
// new 12.04.2024
NO_RESTRICTION_24_7 = 0,
MON = _MON_,
TUE = _TUE_,
WED = _WED_,
THU = _THU_,
FRI = _FRI_,
SAT = _SAT_,
SUN = _SUN_,
WEEK_DAYS = _WEEK_DAYS_,
WORKING_DAYS = _WORKING_DAYS_,
ALL_DAYS = _ALL_DAYS_,
OFFICIAL_HOLIDAY = _OFFICIAL_HOLIDAY_,
ONLY_WEEKEND = _ONLY_WEEKEND,
ONLY_OPEN_FOR_BUSINESS_DAYS = _ONLY_OPEN_FOR_BUSINESS_DAYS,
NOT_DEFINED = _NOT_DEFINED
};
struct BusinessHours_struct {
BusinessHours bh;
}; };
#endif // TARIFF_BUSINESS_HOURS_H_INCLUDED #endif // TARIFF_BUSINESS_HOURS_H_INCLUDED

View File

@ -14,14 +14,12 @@ QList<int> CALCULATE_LIBRARY_API get_time_steps(Configuration *cfg) {
return Calculator::GetInstance().GetTimeSteps(cfg); return Calculator::GetInstance().GetTimeSteps(cfg);
} }
int CALCULATE_LIBRARY_API get_minimal_parkingtime(Configuration *cfg, int CALCULATE_LIBRARY_API get_minimal_parkingtime(Configuration *cfg, PERMIT_TYPE permitType) {
PERMIT_TYPE permitType,
int paymentOptionIndex) {
int minTime = 0; int minTime = 0;
switch(permitType) { switch(permitType) {
case PERMIT_TYPE::SHORT_TERM_PARKING: { // e.g. szeged (customer_281) case PERMIT_TYPE::SHORT_TERM_PARKING: { // e.g. szeged (customer_281)
minTime = cfg->getPaymentOptions(paymentOptionIndex).pop_min_time; minTime = cfg->getPaymentOptions().pop_min_time;
} break; } break;
case PERMIT_TYPE::DAY_TICKET_ADULT: { case PERMIT_TYPE::DAY_TICKET_ADULT: {
} break; } break;
@ -32,22 +30,20 @@ int CALCULATE_LIBRARY_API get_minimal_parkingtime(Configuration *cfg,
default: default:
// for each new sell-procedure, recomute the timesteps. implicitly, set // for each new sell-procedure, recomute the timesteps. implicitly, set
// the minimal parking time. // the minimal parking time.
Calculator::GetInstance().ResetTimeSteps(paymentOptionIndex); Calculator::GetInstance().ResetTimeSteps();
Calculator::GetInstance().GetTimeSteps(cfg, paymentOptionIndex); Calculator::GetInstance().GetTimeSteps(cfg);
minTime = qRound(cfg->getPaymentOptions(paymentOptionIndex).pop_min_time); minTime = qRound(cfg->getPaymentOptions().pop_min_time);
} }
return minTime; return minTime;
} }
int CALCULATE_LIBRARY_API get_maximal_parkingtime(Configuration *cfg, int CALCULATE_LIBRARY_API get_maximal_parkingtime(Configuration *cfg, PERMIT_TYPE permitType) {
PERMIT_TYPE permitType,
int paymentOptionIndex) {
int maxTime = 0; int maxTime = 0;
switch(permitType) { switch(permitType) {
case PERMIT_TYPE::SHORT_TERM_PARKING: { // e.g. szeged (customer_281) case PERMIT_TYPE::SHORT_TERM_PARKING: { // e.g. szeged (customer_281)
maxTime = cfg->getPaymentOptions(paymentOptionIndex).pop_max_time; maxTime = cfg->getPaymentOptions().pop_max_time;
} break; } break;
case PERMIT_TYPE::DAY_TICKET_ADULT: { case PERMIT_TYPE::DAY_TICKET_ADULT: {
} break; } break;
@ -61,14 +57,12 @@ int CALCULATE_LIBRARY_API get_maximal_parkingtime(Configuration *cfg,
return maxTime; return maxTime;
} }
int CALCULATE_LIBRARY_API get_minimal_parkingprice(Configuration *cfg, int CALCULATE_LIBRARY_API get_minimal_parkingprice(Configuration *cfg, PERMIT_TYPE permitType) {
PERMIT_TYPE permitType,
int paymentOptionIndex) {
int minPrice = -1; int minPrice = -1;
switch(permitType) { switch(permitType) {
case PERMIT_TYPE::SHORT_TERM_PARKING: { // e.g. szeged (customer_281) case PERMIT_TYPE::SHORT_TERM_PARKING: { // e.g. szeged (customer_281)
minPrice = cfg->getPaymentOptions(paymentOptionIndex).pop_min_price; minPrice = cfg->getPaymentOptions().pop_min_price;
} break; } break;
case PERMIT_TYPE::DAY_TICKET_ADULT: { case PERMIT_TYPE::DAY_TICKET_ADULT: {
} break; } break;
@ -125,9 +119,7 @@ int CALCULATE_LIBRARY_API compute_product_price(Configuration const *cfg, PERMIT
return 0; return 0;
} }
int CALCULATE_LIBRARY_API get_maximal_parkingprice(Configuration *cfg, int CALCULATE_LIBRARY_API get_maximal_parkingprice(Configuration *cfg, PERMIT_TYPE permitType) {
PERMIT_TYPE permitType,
int paymentOptionIndex) {
int maxPrice = -1; int maxPrice = -1;
static const PaymentMethod paymentMethodId = Utilities::getPaymentMethodId(cfg); static const PaymentMethod paymentMethodId = Utilities::getPaymentMethodId(cfg);
@ -136,8 +128,8 @@ int CALCULATE_LIBRARY_API get_maximal_parkingprice(Configuration *cfg,
if (paymentMethodId == PaymentMethod::Progressive || paymentMethodId == PaymentMethod::Steps) { if (paymentMethodId == PaymentMethod::Progressive || paymentMethodId == PaymentMethod::Steps) {
maxPrice = Utilities::getMaximalParkingPrice(cfg, paymentMethodId); maxPrice = Utilities::getMaximalParkingPrice(cfg, paymentMethodId);
} else { // PaymentMethod::Linear -> e.g. szeged } else { // PaymentMethod::Linear -> e.g. szeged
int const key = cfg->getPaymentOptions(paymentOptionIndex).pop_id; int const key = cfg->getPaymentOptions().pop_id;
int const maxTime = cfg->getPaymentOptions(paymentOptionIndex).pop_max_time; // maxTime is given in minutes int const maxTime = cfg->getPaymentOptions().pop_max_time; // maxTime is given in minutes
std::optional<QVector<ATBPaymentRate>> const &pv = cfg->getPaymentRateForKey(key); std::optional<QVector<ATBPaymentRate>> const &pv = cfg->getPaymentRateForKey(key);
if (pv) { if (pv) {
QVector<ATBPaymentRate> const &paymentRate = pv.value(); QVector<ATBPaymentRate> const &paymentRate = pv.value();

View File

@ -1569,26 +1569,24 @@ QList<int> Calculator::GetPriceSteps(Configuration * /*cfg*/) const {
return QList<int>(); return QList<int>();
} }
QList<int> Calculator::GetTimeSteps(Configuration *cfg, int paymentOptionIndex) const { QList<int> Calculator::GetTimeSteps(Configuration *cfg) const {
qCritical() << "(" << __func__ << ":" << __LINE__ << ")" << "paymentOptionIndex:" << paymentOptionIndex; if (m_timeSteps.size() > 0) {
if (m_timeSteps.size() > paymentOptionIndex) {
//qCritical() << __PRETTY_FUNCTION__ << "timeSteps:" << m_timeSteps; //qCritical() << __PRETTY_FUNCTION__ << "timeSteps:" << m_timeSteps;
return m_timeSteps[paymentOptionIndex]; return m_timeSteps;
} }
QDateTime start = QDateTime::currentDateTime(); QDateTime start = QDateTime::currentDateTime();
start.setTime(QTime(start.time().hour(), start.time().minute(), 0)); start.setTime(QTime(start.time().hour(), start.time().minute(), 0));
int const pop_id = cfg->getPaymentOptions(paymentOptionIndex).pop_id; int const pop_id = cfg->getPaymentOptions().pop_id;
int const pop_carry_over = cfg->getPaymentOptions(paymentOptionIndex).pop_carry_over; int const pop_carry_over = cfg->getPaymentOptions().pop_carry_over;
int const pop_time_step_config = cfg->getPaymentOptions(paymentOptionIndex).pop_time_step_config; int const pop_time_step_config = cfg->getPaymentOptions().pop_time_step_config;
static PaymentMethod const paymentMethodId = Utilities::getPaymentMethodId(cfg); static PaymentMethod const paymentMethodId = Utilities::getPaymentMethodId(cfg);
qCritical() << "(" << __func__ << ":" << __LINE__ << ") start parking time:" << start.toString(Qt::ISODate); qCritical() << __func__ << ":" << __LINE__ << " start parking time:" << start.toString(Qt::ISODate);
qCritical() << "(" << __func__ << ":" << __LINE__ << ") payment option id:" << pop_id; qCritical() << __func__ << ":" << __LINE__ << " payment option id:" << pop_id;
qCritical() << "(" << __func__ << ":" << __LINE__ << ") payment option carry over:" << pop_carry_over; qCritical() << __func__ << ":" << __LINE__ << "payment option carry over:" << pop_carry_over;
if (pop_time_step_config == (int)ATBTimeStepConfig::TimeStepConfig::DYNAMIC) { if (pop_time_step_config == (int)ATBTimeStepConfig::TimeStepConfig::DYNAMIC) {
//qCritical() << __PRETTY_FUNCTION__ << "payment option time step config:" << "TimeStepConfig::DYNAMIC"; //qCritical() << __PRETTY_FUNCTION__ << "payment option time step config:" << "TimeStepConfig::DYNAMIC";
@ -1597,13 +1595,13 @@ QList<int> Calculator::GetTimeSteps(Configuration *cfg, int paymentOptionIndex)
std::size_t const s = cfg->TimeRange.size(); std::size_t const s = cfg->TimeRange.size();
for (std::size_t id = 1; id <= s; ++id) { for (std::size_t id = 1; id <= s; ++id) {
int const step = Utilities::getTimeRangeStep(cfg, id, paymentMethodId); int const step = Utilities::getTimeRangeStep(cfg, id, paymentMethodId);
m_timeSteps[paymentOptionIndex].append(step); m_timeSteps.append(step);
} }
} else { } else {
uint16_t timeStepCompensation = 0; uint16_t timeStepCompensation = 0;
if (pop_carry_over) { if (pop_carry_over) {
int const pop_carry_over_time_range_id = cfg->getPaymentOptions(paymentOptionIndex).pop_carry_over_time_range_id; int const pop_carry_over_time_range_id = cfg->getPaymentOptions().pop_carry_over_time_range_id;
QTime const carryOverTimeRangeFrom = cfg->TimeRange.find(pop_carry_over_time_range_id)->second.time_range_from; QTime const carryOverTimeRangeFrom = cfg->TimeRange.find(pop_carry_over_time_range_id)->second.time_range_from;
QTime const carryOverTimeRangeTo = cfg->TimeRange.find(pop_carry_over_time_range_id)->second.time_range_to; QTime const carryOverTimeRangeTo = cfg->TimeRange.find(pop_carry_over_time_range_id)->second.time_range_to;
@ -1627,19 +1625,19 @@ QList<int> Calculator::GetTimeSteps(Configuration *cfg, int paymentOptionIndex)
.arg(timeStep).arg(duration.pun_duration_max); .arg(timeStep).arg(duration.pun_duration_max);
break; break;
} }
qCritical() << "(" << __func__ << ":" << __LINE__ << ") configured minimal parking time:" << cfg->getPaymentOptions(paymentOptionIndex).pop_min_time; qCritical() << __PRETTY_FUNCTION__ << "configured minimal parking time:" << cfg->getPaymentOptions().pop_min_time;
// set dynamic minimal parking time // set dynamic minimal parking time
cfg->getPaymentOptions().pop_min_time = timeStep; cfg->getPaymentOptions().pop_min_time = timeStep;
qCritical() << "(" << __func__ << ":" << __LINE__ << ") computed minimal parking time:" << cfg->getPaymentOptions(paymentOptionIndex).pop_min_time; qCritical() << __PRETTY_FUNCTION__ << " computed minimal parking time:" << cfg->getPaymentOptions().pop_min_time;
duration.pun_duration = timeStep; duration.pun_duration = timeStep;
timeStepCompensation = duration.pun_duration_max - duration.pun_duration; timeStepCompensation = duration.pun_duration_max - duration.pun_duration;
m_timeSteps[paymentOptionIndex] << duration.pun_duration; m_timeSteps << duration.pun_duration;
} else { } else {
duration.pun_duration = duration.pun_duration_max - timeStepCompensation; duration.pun_duration = duration.pun_duration_max - timeStepCompensation;
m_timeSteps[paymentOptionIndex] << duration.pun_duration;; m_timeSteps << duration.pun_duration;;
} }
cfg->Duration.erase(search); cfg->Duration.erase(search);
@ -1660,26 +1658,19 @@ QList<int> Calculator::GetTimeSteps(Configuration *cfg, int paymentOptionIndex)
} }
} }
} else { } else {
qCritical() << "(" << __func__ << ":" << __LINE__ << ") payment option time step config:" << "TimeStepConfig::STATIC"; qCritical() << __PRETTY_FUNCTION__ << "payment option time step config:" << "TimeStepConfig::STATIC";
for (auto[itr, rangeEnd] = cfg->PaymentRate.equal_range(pop_id); itr != rangeEnd; ++itr) for (auto[itr, rangeEnd] = cfg->PaymentRate.equal_range(pop_id); itr != rangeEnd; ++itr)
{ {
int const durationId = itr->second.pra_payment_unit_id; int const durationId = itr->second.pra_payment_unit_id;
int const durationUnit = cfg->Duration.find(durationId)->second.pun_duration; int const durationUnit = cfg->Duration.find(durationId)->second.pun_duration;
int size = m_timeSteps.size(); m_timeSteps << durationUnit;
while (size <= paymentOptionIndex) {
m_timeSteps.push_back(QList<int>());
size = m_timeSteps.size();
}
m_timeSteps[paymentOptionIndex] << durationUnit;
} }
} }
qCritical() << "(" << __func__ << ":" << __LINE__ << ")" << "NEW timeSteps:" << m_timeSteps; qCritical() << __PRETTY_FUNCTION__ << "NEW timeSteps:" << m_timeSteps;
return m_timeSteps[paymentOptionIndex]; return m_timeSteps;
} }
uint32_t Calculator::GetPriceForTimeStep(Configuration *cfg, int timeStep) const { uint32_t Calculator::GetPriceForTimeStep(Configuration *cfg, int timeStep) const {

View File

@ -3,7 +3,6 @@
#include "time_range_header.h" #include "time_range_header.h"
#include "tariff_timestep_config.h" #include "tariff_timestep_config.h"
#include "tariff_permit_type.h" #include "tariff_permit_type.h"
#include "tariff_business_hours.h"
#include <QString> #include <QString>
#include <QDebug> #include <QDebug>
@ -543,76 +542,15 @@ bool Configuration::ParseJson(Configuration* cfg, const char* json)
} }
} }
int Configuration::getCurrentPaymentOptionIndex(QDateTime const &dt) const {
int const numOptions = getAllPaymentOptions().size();
for (int opt=0; opt < numOptions; ++opt) { ATBPaymentOption const &Configuration::getPaymentOptions() const {
uint64_t const pop_business_hours = getPaymentOptions(opt).pop_business_hours;
uint64_t p = 0;
switch (dt.date().dayOfWeek()) {
case (int)Qt::Monday: {
p = BusinessHours::MON;
if ((pop_business_hours & p) == p) {
return opt;
}
} break;
case (int)Qt::Tuesday: {
p = BusinessHours::TUE;
if ((pop_business_hours & p) == p) {
return opt;
}
} break;
case (int)Qt::Wednesday: {
p = BusinessHours::WED;
if ((pop_business_hours & p) == p) {
return opt;
}
} break;
case (int)Qt::Thursday: {
p = BusinessHours::THU;
if ((pop_business_hours & p) == p) {
return opt;
}
} break;
case (int)Qt::Friday: {
p = BusinessHours::FRI;
if ((pop_business_hours & p) == p) {
return opt;
}
} break;
case (int)Qt::Saturday: {
p = BusinessHours::SAT;
if ((pop_business_hours & p) == p) {
return opt;
}
} break;
case (int)Qt::Sunday: {
p = BusinessHours::SUN;
if (isHoliday(dt)) {
p |= BusinessHours::OFFICIAL_HOLIDAY;
}
if ((pop_business_hours & p) == p) {
return opt;
}
} break;
}
}
return -1;
}
bool Configuration::isHoliday(QDateTime const &dt) const {
return false;
}
ATBPaymentOption const &Configuration::getPaymentOptions(int paymentOptionsIndex) const {
Q_ASSERT(!this->currentPaymentOptions.isEmpty()); Q_ASSERT(!this->currentPaymentOptions.isEmpty());
return this->currentPaymentOptions.at(paymentOptionsIndex); return this->currentPaymentOptions.at(0);
} }
ATBPaymentOption &Configuration::getPaymentOptions(int paymentOptionsIndex) { ATBPaymentOption &Configuration::getPaymentOptions() {
Q_ASSERT(!this->currentPaymentOptions.isEmpty()); Q_ASSERT(!this->currentPaymentOptions.isEmpty());
return this->currentPaymentOptions[paymentOptionsIndex]; return this->currentPaymentOptions[0];
} }
QVector<ATBPaymentOption> const &Configuration::getAllPaymentOptions() const { QVector<ATBPaymentOption> const &Configuration::getAllPaymentOptions() const {

View File

@ -260,7 +260,7 @@ bool Utilities::CheckSpecialDay(Configuration* cfg, const char* currentDateTimeS
//cout << "CheckSpecialDay() => Month is in range between start and end" << endl; //cout << "CheckSpecialDay() => Month is in range between start and end" << endl;
if ((current_tm.tm_mday >= start_tm.tm_mday) && (current_tm.tm_mday <= end_tm.tm_mday)) if ((current_tm.tm_mday >= start_tm.tm_mday) && (current_tm.tm_mday <= end_tm.tm_mday))
{ {
//LOG_DEBUG("CheckSpecialDay() => SPECIAL DAY"); LOG_DEBUG("CheckSpecialDay() => SPECIAL DAY");
*specialDayId = spec_days_itr->second.ped_id; *specialDayId = spec_days_itr->second.ped_id;
*specialDayPrice = cfg->SpecialDaysWorktime.find(*specialDayId)->second.pedwt_price; *specialDayPrice = cfg->SpecialDaysWorktime.find(*specialDayId)->second.pedwt_price;
return true; return true;
@ -275,7 +275,7 @@ bool Utilities::CheckSpecialDay(Configuration* cfg, const char* currentDateTimeS
//cout << "CheckSpecialDay() => Month is in range between start and end" << endl; //cout << "CheckSpecialDay() => Month is in range between start and end" << endl;
if ((current_tm.tm_mday >= start_tm.tm_mday) && (current_tm.tm_mday <= end_tm.tm_mday)) if ((current_tm.tm_mday >= start_tm.tm_mday) && (current_tm.tm_mday <= end_tm.tm_mday))
{ {
//LOG_DEBUG("CheckSpecialDay() => SPECIAL DAY"); LOG_DEBUG("CheckSpecialDay() => SPECIAL DAY");
*specialDayId = spec_days_itr->second.ped_id; *specialDayId = spec_days_itr->second.ped_id;
*specialDayPrice = cfg->SpecialDaysWorktime.find(*specialDayId)->second.pedwt_price; *specialDayPrice = cfg->SpecialDaysWorktime.find(*specialDayId)->second.pedwt_price;
return true; return true;
@ -317,7 +317,7 @@ bool Utilities::CheckSpecialDay(Configuration const *cfg,
continue; continue;
} }
} }
//qDebug() << "CheckSpecialDay() => SPECIAL DAY"; qDebug() << "CheckSpecialDay() => SPECIAL DAY";
*specialDayId = spec_days_itr->second.ped_id; *specialDayId = spec_days_itr->second.ped_id;
*specialDayPrice = cfg->SpecialDaysWorktime.find(*specialDayId)->second.pedwt_price; *specialDayPrice = cfg->SpecialDaysWorktime.find(*specialDayId)->second.pedwt_price;
return true; return true;

View File

@ -43,6 +43,122 @@ extern "C" char* strptime(const char* s,
#define NEUHAUSER_KIRCHDORF (0) #define NEUHAUSER_KIRCHDORF (0)
#define BAD_NEUENAHR_AHRWEILER (1) #define BAD_NEUENAHR_AHRWEILER (1)
#if NEUHAUSER_KIRCHDORF==1
static bool test_neuhauser_kirchdorf(int step, double cost) {
switch (step) {
case 30:
if (cost != 30) {
qCritical() << "ERROR COMPUTING COST"
<< "HAVE" << cost
<< "SHOULD" << 30;
return false;
}
break;
case 35:
if (cost != 40) {
qCritical() << "ERROR COMPUTING COST"
<< "HAVE" << cost
<< "SHOULD" << 40;
return false;
}
break;
case 40:
if (cost != 50) {
qCritical() << "ERROR COMPUTING COST"
<< "HAVE" << cost
<< "SHOULD" << 50;
return false;
}
break;
case 45:
if (cost != 60) {
qCritical() << "ERROR COMPUTING COST"
<< "HAVE" << cost
<< "SHOULD" << 60;
return false;
}
break;
case 50:
if (cost != 70) {
qCritical() << "ERROR COMPUTING COST"
<< "HAVE" << cost
<< "SHOULD" << 70;
return false;
}
break;
case 55:
if (cost != 80) {
qCritical() << "ERROR COMPUTING COST"
<< "HAVE" << cost
<< "SHOULD" << 80;
return false;
}
break;
case 60:
if (cost != 90) {
qCritical() << "ERROR COMPUTING COST"
<< "HAVE" << cost
<< "SHOULD" << 90;
return false;
}
break;
case 65:
if (cost != 100) {
qCritical() << "ERROR COMPUTING COST"
<< "HAVE" << cost
<< "SHOULD" << 100;
return false;
}
break;
case 70:
if (cost != 110) {
qCritical() << "ERROR COMPUTING COST"
<< "HAVE" << cost
<< "SHOULD" << 110;
return false;
}
break;
case 75:
if (cost != 120) {
qCritical() << "ERROR COMPUTING COST"
<< "HAVE" << cost
<< "SHOULD" << 120;
return false;
}
break;
case 80:
if (cost != 130) {
qCritical() << "ERROR COMPUTING COST"
<< "HAVE" << cost
<< "SHOULD" << 130;
return false;
}
break;
case 85:
if (cost != 140) {
qCritical() << "ERROR COMPUTING COST"
<< "HAVE" << cost
<< "SHOULD" << 140;
return false;
}
break;
case 90:
if (cost != 150) {
qCritical() << "ERROR COMPUTING COST"
<< "HAVE" << cost
<< "SHOULD" << 150;
return false;
}
break;
default:
break;
}
return true;
}
#endif
int main() { int main() {
#if BAD_NEUENAHR_AHRWEILER==1 #if BAD_NEUENAHR_AHRWEILER==1
std::ifstream input; std::ifstream input;
@ -51,10 +167,8 @@ int main() {
int pop_min_price; int pop_min_price;
int pop_max_price; int pop_max_price;
int pop_daily_card_price; int pop_daily_card_price;
int pop_carry_over;
int pop_carry_over_time_range_id;
for (int zone=2; zone < 3; ++zone) { for (int zone=1; zone < 2; ++zone) {
//for (int t=6; t < 7; t+=20) { //for (int t=6; t < 7; t+=20) {
switch (zone) { switch (zone) {
case 1: { case 1: {
@ -100,7 +214,6 @@ int main() {
if (isParsed) { if (isParsed) {
// test library functions // test library functions
if (zone == 1) {
pop_min_time = get_minimal_parkingtime(&cfg); pop_min_time = get_minimal_parkingtime(&cfg);
pop_max_time = get_maximal_parkingtime(&cfg); pop_max_time = get_maximal_parkingtime(&cfg);
pop_min_price = get_minimal_parkingprice(&cfg); pop_min_price = get_minimal_parkingprice(&cfg);
@ -188,72 +301,13 @@ int main() {
//qCritical() << "duration" << duration.c_str(); //qCritical() << "duration" << duration.c_str();
} }
} }
} // zone == 1
if (zone == 2) {
int const numOptions = cfg.getAllPaymentOptions().size();
#if 0
for (int payOpt=0; payOpt < numOptions; ++payOpt) {
pop_min_time = get_minimal_parkingtime(&cfg, PERMIT_TYPE::SHORT_TERM_PARKING, payOpt);
pop_max_time = get_maximal_parkingtime(&cfg, PERMIT_TYPE::SHORT_TERM_PARKING, payOpt);
pop_min_price = get_minimal_parkingprice(&cfg, PERMIT_TYPE::SHORT_TERM_PARKING, payOpt);
pop_max_price = get_maximal_parkingprice(&cfg, PERMIT_TYPE::SHORT_TERM_PARKING, payOpt);
pop_daily_card_price = cfg.getPaymentOptions(payOpt).pop_daily_card_price;
pop_carry_over = cfg.getPaymentOptions(payOpt).pop_carry_over;
pop_carry_over_time_range_id = cfg.getPaymentOptions(payOpt).pop_carry_over_time_range_id;
qCritical() << QString(" pop_min_time[%1]: %2").arg(payOpt).arg(pop_min_time);
qCritical() << QString(" pop_max_time[%1]: %2").arg(payOpt).arg(pop_max_time);
qCritical() << QString(" pop_min_price[%1]: %2").arg(payOpt).arg(pop_min_price);
qCritical() << QString(" pop_max_price[%1]: %2").arg(payOpt).arg(pop_max_price);
qCritical() << QString(" pop_daily_card_price[%1]: %2").arg(payOpt).arg(pop_daily_card_price);
qCritical() << QString(" pop_carry_over[%1]: %2").arg(payOpt).arg(pop_carry_over);
qCritical() << QString("pop_carry_over_time_range_id[%1]: %2").arg(payOpt).arg(pop_carry_over_time_range_id);
if (pop_carry_over_time_range_id != -1) {
QTime const carryOverTimeRangeFrom = cfg.TimeRange.find(pop_carry_over_time_range_id)->second.time_range_from;
QTime const carryOverTimeRangeTo = cfg.TimeRange.find(pop_carry_over_time_range_id)->second.time_range_to;
qCritical() << QString(" timeRangeFrom[%1]: %2").arg(payOpt).arg(carryOverTimeRangeFrom.toString(Qt::ISODate));
qCritical() << QString(" timeRangeTo[%1]: %2").arg(payOpt).arg(carryOverTimeRangeTo.toString(Qt::ISODate));
}
}
#endif
QDateTime start(QDate(2024, 4, 14), QTime());
QDateTime end;
struct price_t price;
//start = QDateTime::currentDateTime();
int paymentOptionIndex = cfg.getCurrentPaymentOptionIndex(start);
if (paymentOptionIndex != -1) {
qCritical() << "paymentOptionIndex" << paymentOptionIndex;
QList<int> const timeSteps = Calculator::GetInstance().GetTimeSteps(&cfg, paymentOptionIndex);
qCritical() << "TimeSteps" << timeSteps;
// QDateTime start = s.addSecs(offset * 60);
QList<int>::const_iterator step;
for (step = timeSteps.cbegin(); step != timeSteps.cend(); ++step) {
double cost = 0;
//if (compute_price_for_parking_ticket(&cfg, start, *step, end, &price)) {
// cost = price.netto;
//}
}
}
}
} }
} }
#endif #endif
#if SCHOENAU_KOENIGSEE==1 #if SCHOENAU_KOENIGSEE==1
//QString f("/opt/ptu5/opt/customer_332/etc/psa_tariff/tariff01.json"); QString f("/opt/ptu5/opt/customer_332/etc/psa_tariff/tariff01.json");
QString f("/opt/ptu5/opt/customer_332/etc/psa_tariff/tariff02.json"); //QString f("/opt/ptu5/opt/customer_332/etc/psa_tariff/tariff02.json");
std::ifstream input(f.toUtf8().constData()); std::ifstream input(f.toUtf8().constData());
@ -275,22 +329,24 @@ int main() {
QDateTime start = QDateTime::currentDateTime(); QDateTime start = QDateTime::currentDateTime();
// zone 1 // zone 1
//int timeSteps[] = {60, 180, 1440, 2880, 4320, 5670, 7200, 8640, 10080, 11520, 12960, 14400}; //int timeSteps[9] = {60, 180, 1440, 2880, 4320, 5670, 7200, 8640, 10080};
// zone 2
//int timeSteps[3] = {60, 180, 1440};
static QList<int> const timeSteps = Calculator::GetInstance().GetTimeSteps(&cfg); static QList<int> const timeSteps = Calculator::GetInstance().GetTimeSteps(&cfg);
qCritical() << "TimeSteps" << timeSteps; qCritical() << "TimeSteps" << timeSteps;
for (int i = 0 ; i < timeSteps.size(); ++i) { // for (int i = 0 ; i < timeSteps.size(); ++i) {
QDateTime end = start.addSecs(timeSteps.at(i)*60); // QDateTime end = start.addSecs(timeSteps.at(i)*60);
//
double price = Calculator::GetInstance().GetCostFromDuration( // double price = Calculator::GetInstance().GetCostFromDuration(
&cfg, // &cfg,
start, // start,
timeSteps.at(i)); // timeSteps.at(i));
qDebug() << "GetCostFromDuration() time: " << timeSteps.at(i) // qDebug() << "GetCostFromDuration() time: " << timeSteps.at(i) << "price=" << price;
<< "(" << timeSteps.at(i)/60 << "h)" //}
<< "price=" << price;
}
} }
#endif #endif