Compare commits

..

No commits in common. "f47695de8b953f2a8bbe9589043a7712c418e3b3" and "25b3143d887a7884cfd266b7d4a2f118d45553ae" have entirely different histories.

12 changed files with 90 additions and 928 deletions

View File

@ -36,7 +36,6 @@
using namespace std;
using namespace rapidjson;
class Calculator;
class Configuration
{
@ -60,7 +59,7 @@ public:
multimap<int, ATBPaymentRate> PaymentRate;
SpecialDaysWorktimeType SpecialDaysWorktime;
SpecialDaysType SpecialDays;
multimap<Qt::DayOfWeek, ATBWeekDay> WeekDays;
multimap<int, ATBWeekDays> WeekDays;
multimap<int, ATBPeriodYear> YearPeriod;
multimap<int, ATBWeekDaysWorktime> WeekDaysWorktime;
ATBPaymentOptionType PaymentOption;
@ -127,15 +126,3 @@ private:
QVector<ATBPaymentOption> currentPaymentOptions;
};
bool previousDayHoliday(Configuration const &cfg, QDateTime const &t);
bool isHoliday(Configuration const &cfg, QDateTime const &t);
int getPaymentOptionIndex(Configuration const &cfg);
ATBWeekDay parseWeekDay(Configuration &cfg,
rapidjson::GenericMemberIterator<false,
rapidjson::UTF8<char>,
rapidjson::MemoryPoolAllocator<rapidjson::CrtAllocator>> k,
QString const &innerObjName,
Qt::DayOfWeek weekDay,
QString const &weekDayName);

View File

@ -41,9 +41,7 @@ public:
pop_use_only_upto_datetime = ""; // deprecated
pop_use_only_for_duration = 0; // deprecated
pop_plus_steps = 1; // +: jump <x=1> steps forward
pop_plus_steps_saved = 1;
pop_minus_steps = 1; // -: jump <x=1> steps backward
pop_allow_overpay = false;
}
int pop_id;
@ -74,9 +72,7 @@ public:
bool pop_accumulate_prices;
bool pop_accumulate_durations;
int pop_plus_steps;
int pop_plus_steps_saved;
int pop_minus_steps;
bool pop_allow_overpay;
struct ATBMaxDateTime {
int direction;

View File

@ -1,61 +0,0 @@
#ifndef ATB_TARIFF_CARRYOVER_SETTINGS_H_INCLUDED
#define ATB_TARIFF_CARRYOVER_SETTINGS_H_INCLUDED
#include <QDebug>
#include <QDateTime>
#include <functional>
struct ATBTariffCarryOverSettings {
// parking time limit not violated: return false, otherwise: return true.
using ParkingTimeLimitChecker = std::function<bool(ATBTariffCarryOverSettings const&,
QDateTime const &endTime, int paymentOptionIndex)>;
int m_duration;
QTime m_start;
QTime m_end;
ParkingTimeLimitChecker m_parkingTimeLimitChecker;
QTime m_parking_time_limit;
QTime m_about_to_exceed_parking_time_limit;
explicit ATBTariffCarryOverSettings()
: m_duration(0)
, m_start(QTime())
, m_end(QTime())
, m_parkingTimeLimitChecker([](ATBTariffCarryOverSettings const&, QDateTime const &, int) { return false; })
, m_parking_time_limit(QTime())
, m_about_to_exceed_parking_time_limit(QTime()) {}
explicit ATBTariffCarryOverSettings(int duration, QTime const &start,
QTime const &end,
QTime const &parking_time_limit,
QTime const &about_to_exceed_parking_time_limit,
ParkingTimeLimitChecker parkingTimeLimitChecker)
: m_duration(duration)
, m_start(start)
, m_end(end)
, m_parkingTimeLimitChecker(std::move(parkingTimeLimitChecker))
, m_parking_time_limit(parking_time_limit)
, m_about_to_exceed_parking_time_limit(about_to_exceed_parking_time_limit) {
}
bool parkingTimeLimitExceeded(QDateTime const &endTime, int paymentOptionIndex) const {
return m_parkingTimeLimitChecker(*this, endTime, paymentOptionIndex);
}
friend QDebug operator<<(QDebug debug, ATBTariffCarryOverSettings const &co) {
QDebugStateSaver saver(debug);
debug.nospace()
<< " duration: " << co.m_duration << "\n"
<< " start: " << co.m_start.toString(Qt::ISODate) << "\n"
<< " end: " << co.m_end.toString(Qt::ISODate) << "\n"
<< " parking_time_limit: " << co.m_parking_time_limit.toString(Qt::ISODate) << endl;
return debug;
}
};
#endif // ATB_TARIFF_CARRYOVER_SETTINGS_H_INCLUDED

View File

@ -14,8 +14,6 @@
void setDebugLevel(int level);
int getDebugLevel();
#if 0
static void print() {
std::cerr << "\n";
if (getDebugLevel() == DBG_LEVEL_FATAL) {
@ -77,6 +75,4 @@ static void LOG_FATAL(const Arg1& arg1, const Args&&... args) {
}
}
#endif
#endif // TARIFF_LOG_INCLUDED_H

View File

@ -1,40 +0,0 @@
#ifndef ATB_TARIFF_SETTINGS_H_INCLUDED
#define ATB_TARIFF_SETTINGS_H_INCLUDED
#include <QDebug>
struct ATBTariffSettings {
int m_max_price;
int m_min_price;
int m_max_time;
int m_min_time;
explicit ATBTariffSettings()
: m_max_price(0)
, m_min_price(0)
, m_max_time(0)
, m_min_time(0) {
}
explicit ATBTariffSettings(int max_price, int min_price, int max_time, int min_time)
: m_max_price(max_price)
, m_min_price(min_price)
, m_max_time(max_time)
, m_min_time(min_time) {
}
friend QDebug operator<<(QDebug debug, ATBTariffSettings const &ts) {
QDebugStateSaver saver(debug);
debug.nospace()
<< " max_price: " << ts.m_max_price << "\n"
<< " min_price: " << ts.m_min_price << "\n"
<< " max_time: " << ts.m_max_time << "\n"
<< " min_time: " << ts.m_min_time << endl;
return debug;
}
};
#endif // ATB_TARIFF_SETTINGS_H_INCLUDED

View File

@ -1,57 +1,10 @@
#include "tariff_settings.h"
#include "tariff_carryover_settings.h"
#pragma once
#include <string>
#include <QString>
#include <Qt>
#include <QDate>
struct ATBWeekDay {
enum WeekDayType {USUAL_WEEKDAY=0, HOLIDAY=1};
Qt::DayOfWeek m_id;
QString m_name;
QDate m_date;
WeekDayType m_type;
ATBTariffSettings m_tariffSettings;
ATBTariffCarryOverSettings m_tariffCarryOverSettings;
explicit ATBWeekDay()
: m_id(Qt::Monday)
, m_name("")
, m_date(QDate())
, m_type(USUAL_WEEKDAY)
, m_tariffSettings()
, m_tariffCarryOverSettings() {}
explicit ATBWeekDay(Qt::DayOfWeek id, QString const &name, WeekDayType type,
QDate const &date,
ATBTariffSettings const &tariffSettings,
ATBTariffCarryOverSettings const &tariffCarryOverSettings)
: m_id(id)
, m_name(name)
, m_date(date)
, m_type(type)
, m_tariffSettings(tariffSettings)
, m_tariffCarryOverSettings(tariffCarryOverSettings) {}
ATBTariffCarryOverSettings &getTariffCarryOverSettings() { return m_tariffCarryOverSettings; }
ATBTariffCarryOverSettings const &getTariffCarryOverSettings() const { return m_tariffCarryOverSettings; }
ATBTariffSettings &getTariffSettings() { return m_tariffSettings; }
ATBTariffSettings const &getTariffSettings() const { return m_tariffSettings; }
friend QDebug operator<<(QDebug debug, ATBWeekDay const &wd) {
QDebugStateSaver saver(debug);
debug.nospace()
<< " id: " << (int)wd.m_id << "\n"
<< " name: " << wd.m_name << "\n"
<< " type: " << (int)wd.m_type << "\n\n"
<< " tariff settings: " << "\n"
<< wd.m_tariffSettings << "\n"
<< "tariff carryover settings: " << "\n"
<< wd.m_tariffCarryOverSettings << endl;
return debug;
}
};
class ATBWeekDays
{
public:
int pdiw_id;
std::string pdiw_label;
int pdiw_index;
};

View File

@ -36,10 +36,7 @@ int CALCULATE_LIBRARY_API get_minimal_parkingtime(Configuration const *cfg,
int paymentOptionIndex) {
int minTime = 0;
paymentOptionIndex = getPaymentOptionIndex(*cfg);
if (paymentOptionIndex == -1) {
paymentOptionIndex = cfg->getPaymentOptionIndex(permitType);
}
paymentOptionIndex = cfg->getPaymentOptionIndex(permitType);
qCritical() << __func__ << __LINE__ << "paymentOptionIndex" << paymentOptionIndex;
qCritical() << __func__ << __LINE__ << "permit" << PermitType(permitType).toString();
@ -72,10 +69,7 @@ int CALCULATE_LIBRARY_API get_maximal_parkingtime(Configuration const *cfg,
PERMIT_TYPE permitType,
int paymentOptionIndex) {
paymentOptionIndex = getPaymentOptionIndex(*cfg);
if (paymentOptionIndex == -1) {
paymentOptionIndex = cfg->getPaymentOptionIndex(permitType);
}
paymentOptionIndex = cfg->getPaymentOptionIndex(permitType);
int maxTime = 0;
switch(permitType) {
@ -100,10 +94,7 @@ int CALCULATE_LIBRARY_API get_minimal_parkingprice(Configuration *cfg,
int paymentOptionIndex,
QDateTime const &start) {
int minPrice = -1;
if ((paymentOptionIndex = getPaymentOptionIndex(*cfg)) == -1) {
paymentOptionIndex = cfg->getPaymentOptionIndex(permitType);
}
paymentOptionIndex = cfg->getPaymentOptionIndex(permitType);
int payment_method_id = cfg->getPaymentOptions(paymentOptionIndex).pop_payment_method_id;
@ -330,9 +321,7 @@ int CALCULATE_LIBRARY_API get_maximal_parkingprice(Configuration *cfg,
int maxPrice = -1;
static const PaymentMethod paymentMethodId = Utilities::getPaymentMethodId(cfg);
if ((paymentOptionIndex = getPaymentOptionIndex(*cfg)) == -1) {
paymentOptionIndex = cfg->getPaymentOptionIndex(permitType);
}
paymentOptionIndex = cfg->getPaymentOptionIndex(permitType);
switch(permitType) {
case PERMIT_TYPE::SHORT_TERM_PARKING: { // e.g. szeged (customer_281)
@ -485,11 +474,7 @@ int CALCULATE_LIBRARY_API compute_next_timestep(parking_tariff_t *tariff, int cu
// return currentTimeMinutes;
//}
int paymentOptionIndex = getPaymentOptionIndex(*tariff);
if (paymentOptionIndex == -1) {
paymentOptionIndex = tariff->getPaymentOptionIndex(permitType);
}
int const paymentOptionIndex = tariff->getPaymentOptionIndex(permitType);
int const &pop_plus_steps = tariff->getPaymentOptions(paymentOptionIndex).pop_plus_steps;
int const &pop_minus_steps = tariff->getPaymentOptions(paymentOptionIndex).pop_minus_steps;
@ -554,7 +539,7 @@ int CALCULATE_LIBRARY_API compute_next_timestep(parking_tariff_t *tariff, int cu
}
}
// max. tolerance set to 3 minutes
// unsigned const tolerance = std::min(minimalDistance, (unsigned)(3));
unsigned const tolerance = std::min(minimalDistance, (unsigned)(3));
if (j != -1) {
stepList[j] = currentTimeMinutes;
}
@ -669,10 +654,7 @@ CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket(
CalcState calcState;
int paymentOptionIndex = getPaymentOptionIndex(*tariff);
if (paymentOptionIndex == -1) {
paymentOptionIndex = tariff->getPaymentOptionIndex(permitType.get());
}
int const paymentOptionIndex = tariff->getPaymentOptionIndex(permitType.get());
double minMin = tariff->PaymentOption.find(tariff->getPaymentOptions(paymentOptionIndex).pop_payment_method_id)->second.pop_min_time;
double maxMin = tariff->PaymentOption.find(tariff->getPaymentOptions(paymentOptionIndex).pop_payment_method_id)->second.pop_max_time;
@ -739,10 +721,7 @@ CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket(
QDateTime start_parking_time(start_parking_time_);
int paymentOptionIndex = getPaymentOptionIndex(*tariff);
if (paymentOptionIndex == -1) {
paymentOptionIndex = tariff->getPaymentOptionIndex(permitType);
}
int paymentOptionIndex = tariff->getPaymentOptionIndex(permitType);
double minMin = tariff->getPaymentOptions(paymentOptionIndex).pop_min_time;
double maxMin = tariff->getPaymentOptions(paymentOptionIndex).pop_max_time;
@ -842,24 +821,6 @@ CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket(
end_parking_time = effectiveStartTime.addSecs(netto_parking_time*60);
}
end_parking_time.setTime(QTime(end_parking_time.time().hour(),
end_parking_time.time().minute(), 0));
qCritical() << __func__ << ":" << __LINE__ << "end-parking-time:" << end_parking_time.toString(Qt::ISODate);
weekDay = end_parking_time.date().dayOfWeek();
for (auto[itr, rangeEnd] = tariff->WeekDays.equal_range((Qt::DayOfWeek)weekDay); itr != rangeEnd; ++itr) {
ATBWeekDay const &wd = itr->second;
bool const parkTimeLimitViolated = wd.getTariffCarryOverSettings().parkingTimeLimitExceeded(end_parking_time, paymentOptionIndex);
if (parkTimeLimitViolated) {
calcState.setDesc(QString("line=%1 endTime=%2: park-time-limit violated").arg(__LINE__)
.arg(end_parking_time.time().toString(Qt::ISODate)));
return calcState.set(CalcState::State::ABOVE_MAX_PARKING_TIME);
}
}
} else {
cost = Calculator::GetInstance().GetCostFromDuration(
tariff,
@ -912,11 +873,7 @@ CalcState CALCULATE_LIBRARY_API compute_duration_for_parking_ticket(
QString cs = start.toString(Qt::ISODate);
bool prepaid = true;
int paymentOptionIndex = getPaymentOptionIndex(*tariff);
if (paymentOptionIndex == -1) {
paymentOptionIndex = tariff->getPaymentOptionIndex(permitType);
}
int paymentOptionIndex = tariff->getPaymentOptionIndex(permitType);
int prepaid_option_id = tariff->getPaymentOptions(paymentOptionIndex).pop_prepaid_option_id;
if (prepaid_option_id == 2) { // see tariff03.json for 502: 2 means no prepaid-option
prepaid = false;
@ -956,16 +913,8 @@ CalcState CALCULATE_LIBRARY_API compute_duration_for_parking_ticket(
CalcState calcState;
bool prepaid = true;
int paymentOptionIndex = getPaymentOptionIndex(*tariff);
if (paymentOptionIndex == -1) {
paymentOptionIndex = tariff->getPaymentOptionIndex(permitType);
}
qCritical() << __func__ << ":" << __LINE__ << " payment option index: " << paymentOptionIndex;
int paymentOptionIndex = tariff->getPaymentOptionIndex(permitType);
int prepaid_option_id = tariff->getPaymentOptions(paymentOptionIndex).pop_prepaid_option_id;
if (prepaid_option_id == 2) {
prepaid = false;
}
@ -980,28 +929,6 @@ CalcState CALCULATE_LIBRARY_API compute_duration_for_parking_ticket(
}
if (start_parking_time.isValid()) {
int const pop_time_step_config = tariff->getPaymentOptions(paymentOptionIndex).pop_time_step_config;
if (pop_time_step_config == (int)ATBTimeStepConfig::TimeStepConfig::STATIC) {
// handle prepaid option
QDateTime effectiveStartTime(start_parking_time);
int const prepaid_option_id = tariff->getPaymentOptions(paymentOptionIndex).pop_prepaid_option_id;
std::optional<ATBPrepaid> prepaidOption = tariff->getPrepaidType(prepaid_option_id);
if (prepaidOption.has_value()) {
ATBPrepaid const &p = prepaidOption.value();
if (p.never) {
qCritical() << __func__ << __LINE__ << "prepaid: no";
} else {
if (start_parking_time.time() < p.static_end) { // static_end: e.g. 08:00:00
effectiveStartTime.setTime(p.static_end);
} else
if (start_parking_time.time() > p.static_start) { // static_start: e.g. 22:00:00
effectiveStartTime.setTime(p.static_start);
}
}
}
}
QString cs = start_parking_time.toString(Qt::ISODate);
QString endTime = Calculator::GetInstance().GetDurationFromCost(
tariff,
@ -1069,91 +996,20 @@ CalcState CALCULATE_LIBRARY_API compute_duration_for_parking_ticket(
} else {
ticketEndTime = QDateTime::fromString(endTime,Qt::ISODate);
qCritical() << __func__ << ":" << __LINE__ << "ticketEndTime:" << ticketEndTime.toString(Qt::ISODate);
qCritical() << __func__ << ":" << __LINE__ << "step-config:" << pop_time_step_config;
if (!ticketEndTime.isValid()) {
calcState.setDesc(QString("ticketEndTime=%1").arg(endTime));
return calcState.set(CalcState::State::WRONG_ISO_TIME_FORMAT);
}
if (pop_time_step_config == (int)ATBTimeStepConfig::TimeStepConfig::STATIC) {
// handle carry over for ticket-end-time
qCritical() << __func__ << ":" << __LINE__ << "ticketEndTime:" << ticketEndTime.toString(Qt::ISODate);
int weekDay = start_parking_time.date().dayOfWeek();
int pop_carry_over_option_id = tariff->getPaymentOptions(paymentOptionIndex).pop_carry_over_option_id;
qCritical() << __func__ << ":" << __LINE__ << "configured carry-over-id" << pop_carry_over_option_id;
std::optional<ATBPeriodYear> yperiod = Utilities::GetYearPeriodActive(tariff, start_parking_time);
if (yperiod.has_value()) {
ATBPeriodYear const &period = yperiod.value();
pop_carry_over_option_id = period.pye_id;
qCritical() << __func__ << ":" << __LINE__ << "re-computed carry-over-id" << pop_carry_over_option_id;
}
QTime carryOverStart;
QTime carryOverEnd;
int carryOverDuration = -1;
// using TariffCarryOverType = std::multimap<int, ATBCarryOver>;
std::multimap<int, ATBCarryOver>::const_iterator it;
if ((it = tariff->TariffCarryOverOptions.find(pop_carry_over_option_id)) !=
tariff->TariffCarryOverOptions.cend()) {
carryOverStart = it->second.carryover[weekDay].static_start;
carryOverEnd = it->second.carryover[weekDay].static_end;
carryOverDuration = it->second.carryover[weekDay].duration;
}
if (carryOverStart.isValid() && carryOverEnd.isValid()) {
qCritical() << __func__ << ":" << __LINE__ << "carryOverStart" << carryOverStart.toString(Qt::ISODate);
qCritical() << __func__ << ":" << __LINE__ << "carryOverEnd" << carryOverEnd.toString(Qt::ISODate);
qCritical() << __func__ << ":" << __LINE__ << "carryOverDuration" << carryOverDuration;
}
if (carryOverStart.isValid() && carryOverEnd.isValid() && carryOverDuration != -1) {
// qCritical() << __func__ << __LINE__ << "ticketEndTime.time():" << ticketEndTime.time().toString(Qt::ISODate);
if (ticketEndTime.time() > carryOverStart) {
// qCritical() << __func__ << __LINE__ << "ticketEndTime.time():" << ticketEndTime.time().toString(Qt::ISODate);
ticketEndTime = ticketEndTime.addSecs(carryOverDuration * 60);
} else {
// qCritical() << __func__ << __LINE__ << "ticketEndTime.time():" << ticketEndTime.time().toString(Qt::ISODate);
if (ticketEndTime.time() < carryOverEnd) {
// qCritical() << __func__ << __LINE__ << "ticketEndTime.time():" << ticketEndTime.time().toString(Qt::ISODate);
ticketEndTime = ticketEndTime.addSecs(carryOverDuration * 60);
}
}
} else {
qCritical() << __func__ << ":" << __LINE__ << "WARNING: wrong carry-over-settings";
}
}
ticketEndTime.setTime(QTime(ticketEndTime.time().hour(),
ticketEndTime.time().minute(), 0));
qCritical() << __func__ << ":" << __LINE__ << "ticketEndTime:" << ticketEndTime.toString(Qt::ISODate);
for (auto[itr, rangeEnd] = tariff->WeekDays.equal_range((Qt::DayOfWeek)(ticketEndTime.date().dayOfWeek()));
itr != rangeEnd;
++itr) {
ATBWeekDay const &wd = itr->second;
bool const parkTimeLimitViolated = wd.getTariffCarryOverSettings().parkingTimeLimitExceeded(ticketEndTime, paymentOptionIndex);
if (parkTimeLimitViolated) {
calcState.setDesc(QString("line=%1 endTime=%2: park-time-limit violated").arg(__LINE__)
.arg(ticketEndTime.time().toString(Qt::ISODate)));
return calcState.set(CalcState::State::ABOVE_MAX_PARKING_TIME);
}
}
if (ticketEndTime.time().hour() == 0 && ticketEndTime.time().minute() == 0) {
ticketEndTime = ticketEndTime.addDays(-1);
ticketEndTime.setTime(QTime(23, 59, 0));
}
// DEBUG
qCritical() << __func__ << ":" << __LINE__ << " endTime:" << endTime;
qCritical() << __func__ << ":" << __LINE__ << "ticketEndTime:" << ticketEndTime.toString(Qt::ISODate);
qCritical() << "compute_duration_for_parking_ticket(): ";
qCritical() << " endTime: " << endTime;
qCritical() << " ticketEndTime: " << ticketEndTime;
}
} else {
return calcState.set(CalcState::State::INVALID_START_DATE);
@ -1165,7 +1021,7 @@ CalcState CALCULATE_LIBRARY_API compute_duration_for_parking_ticket(
CalcState CALCULATE_LIBRARY_API compute_duration_for_daily_ticket(parking_tariff_t *tariff,
QDateTime const &start_parking_time,
QDateTime &ticketEndTime,
PermitType /* PermitType */)
PermitType PermitType)
{
CalcState calcState;
if (start_parking_time.isValid()) {

View File

@ -122,7 +122,7 @@ std::string Calculator::GetDurationFromCost(Configuration* cfg,
uint8_t payment_option,
char const *startDatetimePassed, // given in local time
double cost,
PermitType /*permitType*/,
PermitType permitType,
bool nextDay,
bool prepaid)
{
@ -133,13 +133,7 @@ std::string Calculator::GetDurationFromCost(Configuration* cfg,
QDateTime inputDate = QDateTime::fromString(startDatetimePassed, Qt::ISODate);
inputDate.setTime(QTime(inputDate.time().hour(), inputDate.time().minute(), 0));
static const PaymentMethod paymentMethodId = Utilities::getPaymentMethodId(cfg);
int paymentOptionIndex = getPaymentOptionIndex(*cfg);
if (paymentOptionIndex == -1) {
paymentOptionIndex = cfg->getPaymentOptionIndex(QDateTime::fromString(startDatetimePassed, Qt::ISODate));
}
qCritical() << DBG_HEADER << " option index:" << paymentOptionIndex;
int const paymentOptionIndex = cfg->getPaymentOptionIndex(permitType.get());
if (DBG_LEVEL >= DBG_DEBUG) {
qCritical() << DBG_HEADER << " start:" << inputDate.toString(Qt::ISODate);
@ -268,15 +262,11 @@ std::string Calculator::GetDurationFromCost(Configuration* cfg,
int const pop_id = cfg->getPaymentOptions(paymentOptionIndex).pop_id;
int const pop_max_price = cfg->getPaymentOptions(paymentOptionIndex).pop_max_price;
int const pop_min_price = cfg->getPaymentOptions(paymentOptionIndex).pop_min_price;
int const pop_allow_overpay = cfg->getPaymentOptions(paymentOptionIndex).pop_allow_overpay;
if (cost > pop_max_price) {
qCritical() << DBG_HEADER << "MAX-PARKING-PRICE" << pop_max_price << ", COST" << cost;
if (pop_allow_overpay == false) {
return CalcState::OVERPAID.toStdString();
}
cost = pop_max_price;
// return CalcState::OVERPAID.toStdString();
qCritical() << DBG_HEADER << "MAX-PARKING-PRICE" << pop_max_price << ", COST" << cost;
//return CalcState::OVERPAID.toStdString();
}
if (cost < pop_min_price) {
@ -405,7 +395,7 @@ std::string Calculator::GetDurationFromCost(Configuration* cfg,
int new_price = 0;
int durationInSecs = 0;
uint32_t duration_previous = 0;
// bool found = false;
bool found = false;
for (auto[itr, rangeEnd] = cfg->PaymentRate.equal_range(pop_id); itr != rangeEnd; ++itr) {
int const pra_price = itr->second.pra_price;
@ -434,7 +424,7 @@ std::string Calculator::GetDurationFromCost(Configuration* cfg,
duration_previous = durationUnit;
//qCritical() << "(" << __func__ << ":" << __LINE__ << ") ZZZZZZ duration_previous" << duration_previous;
} else {
//found = true;
found = true;
//qCritical() << "(" << __func__ << ":" << __LINE__ << ") WWWWWW duration_previous" << duration_previous;
QString s = inputDate.toString(Qt::ISODate);
QDateTime d(QDateTime::fromString(s, Qt::ISODate));
@ -1426,10 +1416,7 @@ double Calculator::GetCostFromDuration(Configuration* cfg,
Q_UNUSED(payment_option);
Q_UNUSED(nextDay);
int paymentOptionIndex = getPaymentOptionIndex(*cfg);
if (paymentOptionIndex == -1) {
paymentOptionIndex = cfg->getPaymentOptionIndex(permitType.get());
}
int const paymentOptionIndex = cfg->getPaymentOptionIndex(permitType.get());
static const PaymentMethod paymentMethodId = Utilities::getPaymentMethodId(cfg);
if (paymentMethodId == PaymentMethod::Steps) {
if (tariffIs24_7(cfg)) {
@ -2581,7 +2568,7 @@ QList<int> &Calculator::GetTimeSteps(Configuration *cfg, int paymentOptionIndex,
// qCritical() << "(" << __func__ << ":" << __LINE__ << ") runtime in minutes (1):" << runtimeInMinutes;
// int const pop_truncate_last_interpolation_step = cfg->getPaymentOptions(paymentOptionIndex).pop_truncate_last_interpolation_step;
int const pop_truncate_last_interpolation_step = cfg->getPaymentOptions(paymentOptionIndex).pop_truncate_last_interpolation_step;
// TODO: auslagern
for (auto[itr, rangeEnd] = cfg->PaymentRate.equal_range(pop_id); itr != rangeEnd; ++itr) {
@ -2606,7 +2593,7 @@ QList<int> &Calculator::GetTimeSteps(Configuration *cfg, int paymentOptionIndex,
auto search = cfg->Duration.find(durationId);
if (search != cfg->Duration.end()) {
ATBDuration duration = search->second;
// ATBDuration &previous = search->second;
ATBDuration &previous = search->second;
if (duration.pun_interpolation_id == -1) {
@ -2636,7 +2623,7 @@ QList<int> &Calculator::GetTimeSteps(Configuration *cfg, int paymentOptionIndex,
// qCritical() << "(" << __func__ << ":" << __LINE__ << ") interpolation dynamic end:" << interpolationEnd.toString(Qt::ISODate);
// qCritical() << "(" << __func__ << ":" << __LINE__ << ") interpolation dynamic end time:" << end_time;
// int pop_min_time = cfg->getPaymentOptions(paymentOptionIndex).pop_min_time;
int pop_min_time = cfg->getPaymentOptions(paymentOptionIndex).pop_min_time;
runtimeInMinutes += duration.pun_duration;
nextTimeStep = start.addSecs(runtimeInMinutes * 60);
@ -2713,7 +2700,7 @@ QList<int> &Calculator::GetTimeSteps(Configuration *cfg, int paymentOptionIndex,
//qCritical() << "(" << __func__ << ":" << __LINE__ << ") runtime in minutes:" << runtimeInMinutes;
QDateTime s = start.addSecs(runtimeInMinutes * 60);
// int const minutes = s.time().secsTo(carryOverStart) / 60;
int const minutes = s.time().secsTo(carryOverStart) / 60;
#if 0
if (minutes > 0) {

View File

@ -8,8 +8,6 @@
#include "tariff_global_defines.h"
#include "tariff_carryover.h"
#include "tariff_global_defines.h"
#include "tariff_settings.h"
#include "tariff_carryover_settings.h"
#include <QString>
#include <QDebug>
@ -23,13 +21,7 @@ MemberType Configuration::IdentifyJsonMember(const char* member_name)
if (strcmp(member_name, "PaymentRate") == 0) return MemberType::PaymentRateType;
if (strcmp(member_name, "PaymentOption") == 0) return MemberType::PaymentOptionType;
if (strcmp(member_name, "Duration") == 0) return MemberType::DurationType;
if (strcmp(member_name, "Monday") == 0) return MemberType::WeekDaysType;
if (strcmp(member_name, "Tuesday") == 0) return MemberType::WeekDaysType;
if (strcmp(member_name, "Wednesday") == 0) return MemberType::WeekDaysType;
if (strcmp(member_name, "Thursday") == 0) return MemberType::WeekDaysType;
if (strcmp(member_name, "Friday") == 0) return MemberType::WeekDaysType;
if (strcmp(member_name, "Saturday") == 0) return MemberType::WeekDaysType;
if (strcmp(member_name, "Sunday") == 0) return MemberType::WeekDaysType;
//if (strcmp(member_name, "WeekDays") == 0) return MemberType::WeekDaysType;
if (strcmp(member_name, "WeekDaysWorktime") == 0) return MemberType::WeekDaysWorkTimeType;
if (strcmp(member_name, "SpecialDaysWorktime") == 0) return MemberType::SpecialDaysWorktimeType;
if (strcmp(member_name, "SpecialDays") == 0) return MemberType::SpecialDaysType;
@ -46,286 +38,6 @@ MemberType Configuration::IdentifyJsonMember(const char* member_name)
else return MemberType::UnknownType;
}
ATBWeekDay parseWeekDay(Configuration &cfg,
rapidjson::GenericMemberIterator<false,
rapidjson::UTF8<char>,
rapidjson::MemoryPoolAllocator<rapidjson::CrtAllocator>> k,
QString const &innerObjName,
Qt::DayOfWeek weekDay,
QString const &weekDayName) {
int max_price = 0;
int min_price = 0;
int min_time = 0;
int max_time = 0;
int duration = 0;
ATBWeekDay WeekDay;
QTime start, end, parking_time_limit, about_to_exceed_limit;
ATBTariffCarryOverSettings::ParkingTimeLimitChecker parkTimeLimitChecker;
if (innerObjName == QString("week_day_default")) {
if (k->value.IsObject()) {
auto obj = k->value.GetObject();
for (auto m = obj.MemberBegin(); m != obj.MemberEnd(); ++m) {
QString const &name = m->name.GetString();
if (name == "week_day_type") {
//
} else
if (name == "tariff_settings") {
if (m->value.IsObject()) {
auto obj = m->value.GetObject();
for (auto n = obj.MemberBegin(); n != obj.MemberEnd(); ++n) {
QString const &name = QString::fromStdString(n->name.GetString());
if (name == "min_time") {
if (n->value.IsInt()) { min_time = n->value.GetInt(); }
} else if (name == "max_time") {
if (n->value.IsInt()) { max_time = n->value.GetInt(); }
} else if (name == "min_price") {
if (n->value.IsInt()) { min_price = n->value.GetInt(); }
} else if (name == "max_price") {
if (n->value.IsInt()) { max_price = n->value.GetInt(); }
}
}
}
} else
if (name == "carry_over_settings") {
if (m->value.IsObject()) {
auto obj = m->value.GetObject();
for (auto n = obj.MemberBegin(); n != obj.MemberEnd(); ++n) {
QString const &name = QString::fromStdString(n->name.GetString());
if (name == "duration") {
if (n->value.IsInt()) {
duration = n->value.GetInt();
}
} else
if (name == "start") {
if (n->value.IsString()) {
start = QTime::fromString(QString::fromStdString(n->value.GetString()), Qt::ISODate);
}
} else
if (name == "end") {
if (n->value.IsString()) {
end = QTime::fromString(QString::fromStdString(n->value.GetString()), Qt::ISODate);
}
} else
if (name == "parking_time_limit") {
if (n->value.IsObject()) {
auto o = n->value.GetObject();
for (auto l = o.MemberBegin(); l != o.MemberEnd(); ++l) {
if (l->name.IsString()) {
QString const &member = QString::fromStdString(l->name.GetString());
if (member == "default") {
if (l->value.IsArray()) {
auto limits = l->value.GetArray();
if (limits.Size() >= 2) {
about_to_exceed_limit = QTime::fromString(QString::fromStdString(limits[0].GetString()), Qt::ISODate);
parking_time_limit = QTime::fromString(QString::fromStdString(limits[1].GetString()), Qt::ISODate);
}
parkTimeLimitChecker = [&cfg, weekDay, weekDayName](ATBTariffCarryOverSettings const& cs,
QDateTime const &endTime,
int paymentOptionIndex) {
if (endTime.date().dayOfWeek() == (int)weekDay) {
if (endTime.time() > cs.m_parking_time_limit) {
qCritical() << __func__ << ":" << __LINE__
<< QString("ERROR time limit for end-time violated: [%1, %2 end-time=%3], but time-limit=%4")
.arg(weekDayName)
.arg(endTime.date().toString(Qt::ISODate))
.arg(endTime.time().toString(Qt::ISODate))
.arg(cs.m_parking_time_limit.toString(Qt::ISODate));
return true;
}
if (endTime.time() >= cs.m_about_to_exceed_parking_time_limit) {
cfg.getPaymentOptions(paymentOptionIndex).pop_plus_steps = 1;
} else {
cfg.getPaymentOptions(paymentOptionIndex).pop_plus_steps =
cfg.getPaymentOptions(paymentOptionIndex).pop_plus_steps_saved;
}
}
return false;
};
}
} else
if (member == "prev_day_holiday?") {
if (l->value.IsArray()) {
auto limits = l->value.GetArray();
if (limits.Size() >= 2) {
about_to_exceed_limit = QTime::fromString(QString::fromStdString(limits[0].GetString()), Qt::ISODate);
parking_time_limit = QTime::fromString(QString::fromStdString(limits[1].GetString()), Qt::ISODate);
}
parkTimeLimitChecker = [&cfg, weekDayName](ATBTariffCarryOverSettings const& cs,
QDateTime const &endTime,
int paymentOptionIndex) {
if (previousDayHoliday(cfg, endTime)) {
if (endTime.time() > cs.m_parking_time_limit) {
qCritical() << __func__ << ":" << __LINE__
<< QString("ERROR time limit for end-time violated: [%1, %2, end-time=%3], but time-limit=%4")
.arg(weekDayName)
.arg(endTime.date().toString(Qt::ISODate))
.arg(endTime.time().toString(Qt::ISODate))
.arg(cs.m_parking_time_limit.toString(Qt::ISODate));
return true;
}
if (endTime.time() >= cs.m_about_to_exceed_parking_time_limit) {
cfg.getPaymentOptions(paymentOptionIndex).pop_plus_steps = 1;
} else {
cfg.getPaymentOptions(paymentOptionIndex).pop_plus_steps =
cfg.getPaymentOptions(paymentOptionIndex).pop_plus_steps_saved;
}
}
return false;
};
}
}
}
}
}
}
}
}
}
}
ATBTariffSettings ts(max_price, min_price, max_time, min_time);
ATBTariffCarryOverSettings cs(duration, start, end, parking_time_limit, about_to_exceed_limit,
parkTimeLimitChecker);
WeekDay = ATBWeekDay(weekDay, weekDayName, ATBWeekDay::USUAL_WEEKDAY, QDate(), ts, cs);
} // if (k->value.IsObject()) {
} else {
QDate date(QDate::fromString(innerObjName, Qt::ISODate));
if (date.isValid()) {
if (k->value.IsObject()) {
auto obj = k->value.GetObject();
for (auto m = obj.MemberBegin(); m != obj.MemberEnd(); ++m) {
QString const &name = m->name.GetString();
if (name == "week_day_type") {
// TODO
} else
if (name == "tariff_settings") {
if (m->value.IsObject()) {
auto obj = m->value.GetObject();
for (auto n = obj.MemberBegin(); n != obj.MemberEnd(); ++n) {
QString const &name = QString::fromStdString(n->name.GetString());
if (name == "min_time") {
if (n->value.IsInt()) { min_time = n->value.GetInt(); }
} else if (name == "max_time") {
if (n->value.IsInt()) { max_time = n->value.GetInt(); }
} else if (name == "min_price") {
if (n->value.IsInt()) { min_price = n->value.GetInt(); }
} else if (name == "max_price") {
if (n->value.IsInt()) { max_price = n->value.GetInt(); }
}
}
}
} else
if (name == "carry_over_settings") {
if (m->value.IsObject()) {
auto obj = m->value.GetObject();
for (auto n = obj.MemberBegin(); n != obj.MemberEnd(); ++n) {
QString const &name = QString::fromStdString(n->name.GetString());
if (name == "duration") {
if (n->value.IsInt()) {
duration = n->value.GetInt();
}
} else
if (name == "start") {
if (n->value.IsString()) {
start = QTime::fromString(QString::fromStdString(n->value.GetString()), Qt::ISODate);
}
} else
if (name == "end") {
if (n->value.IsString()) {
end = QTime::fromString(QString::fromStdString(n->value.GetString()), Qt::ISODate);
}
} else
if (name == "parking_time_limit") {
if (n->value.IsObject()) {
auto o = n->value.GetObject();
for (auto l = o.MemberBegin(); l != o.MemberEnd(); ++l) {
if (l->name.IsString()) {
QString const &member = QString::fromStdString(l->name.GetString());
if (member == "default") {
if (l->value.IsArray()) {
auto limits = l->value.GetArray();
if (limits.Size() >= 2) {
about_to_exceed_limit = QTime::fromString(QString::fromStdString(limits[0].GetString()), Qt::ISODate);
parking_time_limit = QTime::fromString(QString::fromStdString(limits[1].GetString()), Qt::ISODate);
}
}
parkTimeLimitChecker = [&cfg, weekDay](ATBTariffCarryOverSettings const& cs,
QDateTime const &endTime,
int paymentOptionIndex) {
if (endTime.date().dayOfWeek() == (int)weekDay) {
if (endTime.time() > cs.m_parking_time_limit) {
qCritical() << __func__ << ":" << __LINE__
<< QString("ERROR time limit for end-time violated: end-time=%1, but time-limit=%2")
.arg(endTime.time().toString(Qt::ISODate))
.arg(cs.m_parking_time_limit.toString(Qt::ISODate));
return true;
}
if (endTime.time() >= cs.m_about_to_exceed_parking_time_limit) {
cfg.getPaymentOptions(paymentOptionIndex).pop_plus_steps = 1;
} else {
cfg.getPaymentOptions(paymentOptionIndex).pop_plus_steps =
cfg.getPaymentOptions(paymentOptionIndex).pop_plus_steps_saved;
}
}
return false;
};
} else
if (member == "prev_day_holiday?") {
if (l->value.IsArray()) {
auto limits = l->value.GetArray();
if (limits.Size() >= 2) {
about_to_exceed_limit = QTime::fromString(QString::fromStdString(limits[0].GetString()), Qt::ISODate);
parking_time_limit = QTime::fromString(QString::fromStdString(limits[1].GetString()), Qt::ISODate);
}
}
parkTimeLimitChecker = [&cfg](ATBTariffCarryOverSettings const& cs,
QDateTime const &endTime,
int paymentOptionIndex) {
if (previousDayHoliday(cfg, endTime)) {
if (endTime.time() > cs.m_parking_time_limit) {
qCritical() << __func__ << ":" << __LINE__
<< QString("ERROR time limit for end-time violated: end-time=%1, but time-limit=%2")
.arg(endTime.time().toString(Qt::ISODate))
.arg(cs.m_parking_time_limit.toString(Qt::ISODate));
return true;
}
if (endTime.time() >= cs.m_about_to_exceed_parking_time_limit) {
cfg.getPaymentOptions(paymentOptionIndex).pop_plus_steps = 1;
} else {
cfg.getPaymentOptions(paymentOptionIndex).pop_plus_steps =
cfg.getPaymentOptions(paymentOptionIndex).pop_plus_steps_saved;
}
}
return false;
};
}
}
}
}
}
}
}
}
}
ATBTariffSettings ts(max_price, min_price, max_time, min_time);
ATBTariffCarryOverSettings cs(duration, start, end, parking_time_limit,
about_to_exceed_limit, parkTimeLimitChecker);
WeekDay = ATBWeekDay(weekDay, weekDayName, ATBWeekDay::HOLIDAY, date, ts, cs);
} else {// if (k->value.IsObject()) {
qCritical() << __func__ << ":" << __LINE__ << "ERROR: no object";
}
} else {
qCritical() << __func__ << __LINE__
<< "ERROR: invalid date for" << weekDayName << "," << innerObjName;
}
}
return WeekDay;
}
/// <inheritdoc/>
bool Configuration::ParseJson(Configuration* cfg, const char* json)
{
@ -384,7 +96,7 @@ bool Configuration::ParseJson(Configuration* cfg, const char* json)
ATBPaymentRate PaymentRate;
ATBSpecialDaysWorktime SpecialDaysWorktime;
ATBSpecialDays SpecialDays;
//ATBWeekDay WeekDay;
ATBWeekDays WeekDays;
ATBWeekDaysWorktime WeekDaysWorktime;
ATBPeriodYear YearPeriod;
ATBDailyTicket DailyTicket;
@ -400,29 +112,29 @@ bool Configuration::ParseJson(Configuration* cfg, const char* json)
MemberType mb_type = MemberType::UnknownType;
this->currentPaymentOptions.clear();
// Get all JSON object members
// This code should run only once (to load JSON variables into memory)
for (auto i = document.MemberBegin(); i != document.MemberEnd(); i++)
{
// Get name of all general members of JSON, don't print name if NULL
const char* mb_name = i->name.GetString();
if (mb_name == NULL) continue;
// Get all JSON object members
// This code should run only once (to load JSON variables into memory)
for (auto i = document.MemberBegin(); i != document.MemberEnd(); i++)
{
// Get name of all general members of JSON, don't print name if NULL
const char* mb_name = i->name.GetString();
if (mb_name == NULL) continue;
if (document[mb_name].IsString()) {
QString const _mb_name(mb_name);
if (_mb_name.startsWith("Project", Qt::CaseInsensitive)) {
cfg->project.project = document[mb_name].GetString();
continue;
}
if (_mb_name.startsWith("Version", Qt::CaseInsensitive)) {
cfg->project.version = document[mb_name].GetString();
continue;
}
if (_mb_name.startsWith("Info", Qt::CaseInsensitive)) {
cfg->project.info = document[mb_name].GetString();
continue;
}
if (document[mb_name].IsString()) {
QString const _mb_name(mb_name);
if (_mb_name.startsWith("Project", Qt::CaseInsensitive)) {
cfg->project.project = document[mb_name].GetString();
continue;
}
if (_mb_name.startsWith("Version", Qt::CaseInsensitive)) {
cfg->project.version = document[mb_name].GetString();
continue;
}
if (_mb_name.startsWith("Info", Qt::CaseInsensitive)) {
cfg->project.info = document[mb_name].GetString();
continue;
}
}
// ... everything else should be an array
if (!document[mb_name].IsArray()) {
@ -459,36 +171,6 @@ bool Configuration::ParseJson(Configuration* cfg, const char* json)
{
case MemberType::UnknownType:
break;
case MemberType::WeekDaysType: {
ATBWeekDay WeekDay;
if (QString(mb_name) == "Monday") {
WeekDay = parseWeekDay(*cfg, k, inner_obj_name, Qt::Monday, mb_name);
} else
if (QString(mb_name) == "Tuesday") {
WeekDay = parseWeekDay(*cfg, k, inner_obj_name, Qt::Tuesday, mb_name);
} else
if (QString(mb_name) == "Wednesday") {
WeekDay = parseWeekDay(*cfg, k, inner_obj_name, Qt::Wednesday, mb_name);
} else
if (QString(mb_name) == "Thursday") {
WeekDay = parseWeekDay(*cfg, k, inner_obj_name, Qt::Thursday, mb_name);
} else
if (QString(mb_name) == "Friday") {
WeekDay = parseWeekDay(*cfg, k, inner_obj_name, Qt::Friday, mb_name);
} else
if (QString(mb_name) == "Saturday") {
WeekDay = parseWeekDay(*cfg, k, inner_obj_name, Qt::Saturday, mb_name);
} else
if (QString(mb_name) == "Sunday") {
WeekDay = parseWeekDay(*cfg, k, inner_obj_name, Qt::Sunday, mb_name);
} else {
qCritical() << "ERROR: unknown week day" << mb_name;
}
cfg->WeekDays.insert(pair<Qt::DayOfWeek, ATBWeekDay>(WeekDay.m_id, WeekDay));
// qCritical() << WeekDay;
} break;
case MemberType::CarryOverType: {
if (QString(inner_obj_name) == QString("carry_over_id")) {
if (k->value.IsInt()) {
@ -919,16 +601,11 @@ bool Configuration::ParseJson(Configuration* cfg, const char* json)
} else if (strcmp(inner_obj_name, "pop_plus_steps") == 0) {
if (k->value.IsInt()) {
this->currentPaymentOptions.last().pop_plus_steps = k->value.GetInt();
this->currentPaymentOptions.last().pop_plus_steps_saved = k->value.GetInt();
}
} else if (strcmp(inner_obj_name, "pop_minus_steps") == 0) {
if (k->value.IsInt()) {
this->currentPaymentOptions.last().pop_minus_steps = k->value.GetInt();
}
} else if (strcmp(inner_obj_name, "pop_allow_overpay") == 0) {
if (k->value.IsBool()) {
this->currentPaymentOptions.last().pop_allow_overpay = k->value.GetBool();
}
} else if (strcmp(inner_obj_name, "pop_payment_method_id") == 0) {
this->currentPaymentOptions.last().pop_payment_method_id = k->value.GetInt();
} else if (strcmp(inner_obj_name, "pop_day_end_time") == 0) {
@ -1093,11 +770,6 @@ bool Configuration::ParseJson(Configuration* cfg, const char* json)
switch (mb_type) {
case MemberType::UnknownType:
break;
case MemberType::WeekDaysType:
// qCritical() << "INSERT" << (int)WeekDay.m_id << WeekDay.m_date.toString(Qt::ISODate);
// cfg->WeekDays.insert(pair<Qt::DayOfWeek, ATBWeekDay>(WeekDay.m_id, WeekDay));
// qCritical() << WeekDay;
break;
case MemberType::PaymentMethodType:
cfg->PaymentMethod.insert(pair<int, ATBPaymentMethod>(PaymentMethod.pme_id, PaymentMethod));
break;
@ -1508,6 +1180,7 @@ int Configuration::getPaymentOptionIndex(PERMIT_TYPE permitType) const {
std::optional<QVector<ATBPaymentOption>> paymentOptions = getPaymentOptionsForAllKeys();
if (paymentOptions) {
QVector<ATBPaymentOption> const vec = paymentOptions.value();
PermitType const p(permitType);
@ -1521,69 +1194,6 @@ int Configuration::getPaymentOptionIndex(PERMIT_TYPE permitType) const {
return 0;
}
int getPaymentOptionIndex(Configuration const &cfg) {
int const numOptions = cfg.getAllPaymentOptions().size();
for (int opt=0; opt < numOptions; ++opt) {
uint64_t const pop_business_hours = cfg.getPaymentOptions(opt).pop_business_hours;
if (pop_business_hours == 0) { // 0 == 24/7
return opt;
}
QDateTime const dt = QDateTime::currentDateTime();
int const dayOfWeek = dt.date().dayOfWeek();
switch (dayOfWeek) {
case (int)Qt::Monday: {
if (pop_business_hours & BusinessHours::MON) {
return opt;
}
} break;
case (int)Qt::Tuesday: {
if (pop_business_hours & BusinessHours::TUE) {
return opt;
}
} break;
case (int)Qt::Wednesday: {
if (pop_business_hours & BusinessHours::WED) {
return opt;
}
} break;
case (int)Qt::Thursday: {
if (pop_business_hours & BusinessHours::THU) {
return opt;
}
} break;
case (int)Qt::Friday: {
if (pop_business_hours & BusinessHours::FRI) {
return opt;
}
} break;
case (int)Qt::Saturday: {
if (pop_business_hours & BusinessHours::SAT) {
return opt;
}
} break;
case (int)Qt::Sunday: {
if (pop_business_hours & BusinessHours::SUN) {
return opt;
}
} break;
}
if (isHoliday(cfg, dt)) {
if (pop_business_hours & BusinessHours::OFFICIAL_HOLIDAY) {
return opt;
}
}
}
return -1;
}
std::optional<QVector<ATBTariffProduct>>
Configuration::getTariffProductForProductId(PermitType permitType) const {
QString permitTypeName(permitType);
@ -1838,42 +1448,3 @@ Configuration::getWeekDayWorkTime(QTime const &time, Qt::DayOfWeek dayOfWeek) {
return value;
}
bool isHoliday(Configuration const &cfg, QDateTime const &t) {
int const weekDay = t.date().dayOfWeek();
for (auto[iter, rEnd] = cfg.WeekDays.equal_range(static_cast<Qt::DayOfWeek>(weekDay));
iter != rEnd;
++iter) {
if (iter->second.m_type == ATBWeekDay::WeekDayType::HOLIDAY) {
QDate const &d = iter->second.m_date;
if (!d.isNull() && d.isValid()) {
if (t.date() == d) {
return true;
}
}
}
}
return false;
}
bool previousDayHoliday(Configuration const &cfg, QDateTime const &t) {
int const weekDay = t.date().dayOfWeek();
int const previousWeekDay = (weekDay == static_cast<int>(Qt::Monday)) ?
static_cast<int>(Qt::Sunday) : (weekDay - 1);
for (auto[iter, rEnd] = cfg.WeekDays.equal_range(static_cast<Qt::DayOfWeek>(previousWeekDay));
iter != rEnd;
++iter) {
if (iter->second.m_type == ATBWeekDay::WeekDayType::HOLIDAY) {
QDate const &d = iter->second.m_date;
if (!d.isNull() && d.isValid()) {
if (t.addDays(-1).date() == d) {
return true;
}
}
}
}
return false;
}

View File

@ -207,13 +207,7 @@ bool Utilities::IsYearPeriodActive(Configuration const *cfg, QDateTime const &dt
dt.date().day());
QDate const s(2004, year.second.pye_start_month, year.second.pye_start_day);
QDate const e(2004, year.second.pye_end_month, year.second.pye_end_day);
//qCritical() << __func__ << __LINE__ << " d" << d.toString(Qt::ISODate);
//qCritical() << __func__ << __LINE__ << "start" << s.toString(Qt::ISODate);
//qCritical() << __func__ << __LINE__ << " end" << e.toString(Qt::ISODate);
if (s <= e) {
return (d >= s && d <= e);
}
return (d >= s || d <= e);
return (d >= s && d <= e);
})) {
qCritical() << "NO VALID YEAR PERIOD";
return false;

View File

@ -43,7 +43,7 @@ extern "C" char* strptime(const char* s,
#define NEUHAUSER_LINSINGER_MASCHINENBAU (0)
#define NEUHAUSER_NORDISCHES_AUSBILDUNGSZENTRUM (0)
#define NEUHAUSER_BILEXA_GALTUER (0)
#define BAD_NEUENAHR_AHRWEILER (1)
#define BAD_NEUENAHR_AHRWEILER (0)
#define NEUHAUSER_CHRISTOPH_REISEN (0)
#define NEUHAUSER_PERNEGG_AN_DER_MUR (0)
#define NEUHAUSER_STOCKERAU (0)
@ -51,7 +51,7 @@ extern "C" char* strptime(const char* s,
#define SEXTEN (0)
#define SCHNALS_LEITER_KIRCHL (0)
#define SCHNALS_STAUMAUER (SCHNALS_LEITER_KIRCHL)
#define VALSER_ALM (0)
#define VALSER_ALM (1)
#if NEUHAUSER_KIRCHDORF==1
static bool test_neuhauser_kirchdorf(int step, double cost) {
@ -339,20 +339,20 @@ int main() {
cout << endl;
if (isParsed) {
//pop_min_time = get_minimal_parkingtime(&cfg);
//pop_max_time = get_maximal_parkingtime(&cfg);
//pop_min_price = get_minimal_parkingprice(&cfg);
//pop_max_price = get_maximal_parkingprice(&cfg);
//pop_daily_card_price = cfg.getPaymentOptions().pop_daily_card_price;
pop_min_time = get_minimal_parkingtime(&cfg);
pop_max_time = get_maximal_parkingtime(&cfg);
pop_min_price = get_minimal_parkingprice(&cfg);
pop_max_price = get_maximal_parkingprice(&cfg);
pop_daily_card_price = cfg.getPaymentOptions().pop_daily_card_price;
//qCritical() << " pop_min_time: " << pop_min_time;
//qCritical() << " pop_max_time: " << pop_max_time;
//qCritical() << " pop_min_price: " << pop_min_price;
//qCritical() << " pop_max_price: " << pop_max_price;
qCritical() << " pop_min_time: " << pop_min_time;
qCritical() << " pop_max_time: " << pop_max_time;
qCritical() << " pop_min_price: " << pop_min_price;
qCritical() << " pop_max_price: " << pop_max_price;
//QList<int> timeSteps = Calculator::GetInstance().GetTimeSteps(&cfg);
//qCritical() << "TimeSteps" << timeSteps;
QList<int> timeSteps = Calculator::GetInstance().GetTimeSteps(&cfg);
qCritical() << "TimeSteps" << timeSteps;
// return 0;
@ -363,7 +363,8 @@ int main() {
// for (int day = Qt::Monday; day <= Qt::Sunday; ++day) {
for (int day = Qt::Monday; day <= Qt::Monday; ++day) {
QDateTime s(QDate(2024, 8, 19 + day), QTime()); // 20: (whit) monday,..., 26: sunday
QDateTime s(QDate(2024, 7, 29 + day), QTime()); // 20: (whit) monday,..., 26: sunday
QDateTime end;
switch (day) {
case (int)Qt::Monday:
@ -389,30 +390,6 @@ int main() {
break;
}
QDateTime start(s);
start.setTime(QTime(21, 30, 0));
QDateTime end;
int netto_parking_time = 14 * 60;
struct price_t costs;
PermitType pt(PERMIT_TYPE::SHORT_TERM_PARKING);
double cost = 150;
//cs = compute_price_for_parking_ticket(&cfg, start, netto_parking_time,
// end, &costs, pt);
//qCritical() << "start" << start.toString(Qt::ISODate) << "< cost" << costs.netto
// << "> end" << end.toString(Qt::ISODate);
cs = compute_duration_for_parking_ticket(&cfg, start, cost, end, PermitType(PERMIT_TYPE::SHORT_TERM_PARKING));
qCritical() << "start" << start.toString(Qt::ISODate) << "< cost" << cost
<< "> end" << end.toString(Qt::ISODate);
//}
exit(0);
/*
CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket(
@ -1380,7 +1357,7 @@ int main() {
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) {
switch (zone) {
case 1: {
@ -1389,7 +1366,6 @@ int main() {
//pop_max_time = 6*60;
} break;
case 2: {
qCritical() << " ZONE 2: KURZZEIT 1";
// kuzzeit-1-tarif
input.open("/opt/ptu5/opt/customer_249/etc/psa_tariff/tariff02.json");
//pop_max_time = 5*60;
@ -1432,11 +1408,6 @@ int main() {
cout << endl;
if (isParsed) {
qCritical() << "Parsed";
exit(0);
// test library functions
if (zone == 1) {
@ -1463,10 +1434,10 @@ int main() {
static QList<int> const timeSteps = Calculator::GetInstance().GetTimeSteps(&cfg);
qCritical() << "TimeSteps" << timeSteps;
//if (stepsConfigured != timeSteps) {
// qCritical() << "TIME-STEPS SHOULD BE" << stepsConfigured;
// return -1;
//}
if (stepsConfigured != timeSteps) {
qCritical() << "TIME-STEPS SHOULD BE" << stepsConfigured;
return -1;
}
QDateTime start = QDateTime::currentDateTime();
@ -1474,8 +1445,7 @@ int main() {
double price1 = 0;
double price2 = 0;
//for (int m=0; m < 1440; ++m) {
for (int m=480; m < 481; ++m) {
for (int m=0; m < 1440; ++m) {
start.setTime(QTime(0, 0, 0));
start = start.addSecs(m*60);
@ -1492,7 +1462,7 @@ int main() {
//}
CalcState cs;
#if 1
for (int i = 0, j=timeSteps.size() ; i < timeSteps.size(); --j, ++i) {
QDateTime end = start.addSecs(timeSteps.at(i)*60);
@ -1527,21 +1497,6 @@ int main() {
// cost[i], false, true);
//qCritical() << "duration" << duration.c_str();
}
#else
double cost = 80;
qCritical() << "START" << start.toString(Qt::ISODate) << "cost" << cost;
QDateTime end;
cs = compute_duration_for_parking_ticket(&cfg, start, cost, end,
PermitType(PERMIT_TYPE::SHORT_TERM_PARKING));
qCritical() << __LINE__ << cs.toString()
<< "START" << start.toString(Qt::ISODate)
<< "<duration" << start.secsTo(end) / 60
<< "cost" << cost
<< "> end" << end.toString(Qt::ISODate);
//}
#endif
}
} // zone == 1
if (zone == 2) {
@ -1579,18 +1534,18 @@ int main() {
bool fail;
QDateTime start;
for (int i=1; i < 2; ++i) {
for (int i=0; i < 4; ++i) {
switch (i) {
case 0:
start = QDateTime(QDate(2024, 5, 1), QTime(16, 0, 0)); // holiday
fail = false;
break;
case 1:
start = QDateTime(QDate(2024, 10, 3), QTime(17, 0, 0)); // sunday
start = QDateTime(QDate(2024, 4, 21), QTime(16, 0, 0)); // sunday
fail = false;
break;
case 2:
start = QDateTime(QDate(2024, 4, 22), QTime(17, 30, 0)); // monday
start = QDateTime(QDate(2024, 4, 22), QTime(8, 0, 0)); // monday
fail = false;
break;
case 3:
@ -1614,52 +1569,18 @@ int main() {
QList<int>::const_iterator step;
for (step = timeSteps.cbegin(); step != timeSteps.cend(); ++step) {
//qCritical() << __LINE__
// << "START" << start.toString(Qt::ISODate)
// << "<duration" << *step;
// if (*step != 180)
// continue;
double cost = 0;
CalcState cs;
QDateTime s(start);
qCritical() << __LINE__
<< "START" << start.toString(Qt::ISODate)
<< "<duration" << *step;
#if 0
if ((cs = compute_price_for_parking_ticket(&cfg, s, *step, end, &price,
PermitType(PERMIT_TYPE::SHORT_TERM_PARKING)))) {
if ((cs = compute_price_for_parking_ticket(&cfg, start, *step, end, &price, PermitType(PERMIT_TYPE::SHORT_TERM_PARKING)))) {
cost = price.netto;
qCritical() << __LINE__
<< "START" << start.toString(Qt::ISODate)
<< "<duration" << *step
<< "cost" << cost
<< "> end" << end.toString(Qt::ISODate);
qCritical() << "step" << *step << ": cost" << cost;
} else {
if (fail == false) {
qCritical() << "<<<ERROR>>> cs =" << QString(cs);
}
}
#else
cost = 210;
qCritical() << "START" << start.toString(Qt::ISODate) << "cost" << cost;
cs = compute_duration_for_parking_ticket(&cfg, start, cost, end,
PermitType(PERMIT_TYPE::SHORT_TERM_PARKING));
qCritical() << __LINE__ << cs.toString()
<< "START" << start.toString(Qt::ISODate)
<< "<duration" << start.secsTo(end) / 60
<< "cost" << cost
<< "> end" << end.toString(Qt::ISODate);
break;
//}
#endif
}
} else {
qCritical() << "ERROR paymentOptionIndex =" << paymentOptionIndex;

View File

@ -30,7 +30,9 @@ SOURCES += main.cpp
# HEADERS +=
OTHER_FILES += \
/opt/ptu5/opt/customer_249/etc/psa_tariff/tariff02.json
/opt/ptu5/opt/customer_502/etc/psa_tariff/tariff01.json \
/opt/ptu5/opt/customer_502/etc/psa_tariff/tariff02.json \
/opt/ptu5/opt/customer_502/etc/psa_tariff/tariff03.json