Compare commits

..

No commits in common. "d07fdd8540c436602cc566fb52c37dc206cfea99" and "b70094abb507bba4ae01ba50cc7053784e783451" have entirely different histories.

13 changed files with 827 additions and 1356 deletions

View File

@ -17,16 +17,6 @@ class Calculator {
mutable QVector<QList<int>> m_timeSteps;
mutable QList<int> m_priceSteps;
CalcState isParkingAllowedForWeekDay(Configuration const *cfg,
QDateTime const &start,
int netto_parking_time,
int paymentOptionIndex);
CalcState isParkingAllowedForSpecialDay(Configuration const *cfg,
QDateTime const &start,
int netto_parking_time,
int paymentOptionIndex);
protected:
explicit Calculator() = default;
@ -54,13 +44,7 @@ public:
void ResetPriceSteps() { m_priceSteps.clear(); }
QList<int> priceSteps() const { return m_priceSteps; }
CalcState isParkingAllowed(Configuration const *cfg,
QDateTime const &start);
CalcState isParkingAllowed(Configuration const *cfg,
QDateTime const &start,
int netto_parking_time,
int paymentOptionIndex);
CalcState isParkingAllowed(Configuration const *cfg, QDateTime const &start);
/// <summary>
/// Gets duration in seconds from cost
@ -112,8 +96,8 @@ public:
// testing public:
// Introduced for PaymentMethod::Steps (e.g. Schoenau)
// For tariff of following structure: only steps, no special days, nonstop.
uint32_t GetCostFromDuration(Configuration *cfg, QDateTime const &start, quint64 durationMinutes, int paymentOptionIndex=0) const;
uint32_t GetCostFromDuration(Configuration *cfg, QDateTime const &start, QDateTime const &end, int paymentOptionIndex=0) const;
uint32_t GetCostFromDuration(Configuration *cfg, QDateTime const &start, quint64 durationMinutes) const;
uint32_t GetCostFromDuration(Configuration *cfg, QDateTime const &start, QDateTime const &end) const;
private:
Ticket private_GetCostFromDuration(Configuration const* cfg,
@ -129,7 +113,7 @@ private:
int durationMinutes);
//
uint32_t GetPriceForTimeStep(Configuration *cfg, int timeStep, int paymentOptionIndex=0) const;
uint32_t GetPriceForTimeStep(Configuration *cfg, int timeStep) const;
uint32_t GetPriceForStep(Configuration *cfg, int step) const {
return GetPriceForTimeStep(cfg, step);
}

View File

@ -36,9 +36,6 @@ class Calculator;
class Configuration
{
public:
using SpecialDaysType = std::multimap<int, ATBSpecialDays>;
using SpecialDaysWorktimeType = std::multimap<int, ATBSpecialDaysWorktime>;
ATBProject project;
ATBCurrency Currency;
ATBDuration duration;
@ -46,8 +43,8 @@ public:
multimap<int, ATBDuration> Duration;
multimap<int, ATBPaymentMethod> PaymentMethod;
multimap<int, ATBPaymentRate> PaymentRate;
SpecialDaysWorktimeType SpecialDaysWorktime;
SpecialDaysType SpecialDays;
multimap<int, ATBSpecialDaysWorktime> SpecialDaysWorktime;
multimap<int, ATBSpecialDays> SpecialDays;
multimap<int, ATBWeekDays> WeekDays;
multimap<int, ATBPeriodYear> YearPeriod;
multimap<int, ATBWeekDaysWorktime> WeekDaysWorktime;
@ -70,14 +67,8 @@ public:
ATBPaymentOption const &getPaymentOptions(int paymentOptionsIndex=0) const;
QVector<ATBPaymentOption> &getAllPaymentOptions();
QVector<ATBPaymentOption> const &getAllPaymentOptions() const;
int getPaymentOptionIndex(QDateTime const &dt) const;
int getPaymentOptionIndexIfSpecialDay(QDateTime const &dt) const;
bool isSpecialDay(QDateTime const &dt) const;
int specialDayId(QDateTime const &dt) const;
ATBSpecialDays specialDay(QDateTime const &dt) const;
bool isDayIncluded(uint64_t businessHours, QDateTime const &dt) const;
bool isDayIncludedAsSpecialDay(uint64_t businessHours, QDateTime const &dt) const;
bool isDayIncludedAsSpecialDay(uint64_t businessHours, int specialDayId) const;
int getCurrentPaymentOptionIndex(QDateTime const &dt) const;
bool isHoliday(QDateTime const &dt) const;
std::optional<QVector<ATBPaymentRate>> getPaymentRateForAllKeys() const;
std::optional<QVector<ATBPaymentRate>> getPaymentRateForKey(int key) const;
std::optional<QVector<ATBDailyTicket>> getDailyTicketsForAllKeys() const;

View File

@ -23,8 +23,6 @@ public:
pop_max_price = 0;
pop_carry_over = -1;
pop_carry_over_time_range_id = -1;
pop_carry_over_start_time_range = -1;
pop_carry_over_end_time_range = -1;
pop_daily_card_price = -1;
pop_business_hours = -1;
pop_time_step_config = -1;
@ -42,8 +40,6 @@ public:
double pop_max_price;
int pop_carry_over;
int pop_carry_over_time_range_id;
int pop_carry_over_start_time_range;
int pop_carry_over_end_time_range;
int pop_daily_card_price;
uint64_t pop_business_hours;
int pop_time_step_config;

View File

@ -4,12 +4,10 @@
class ATBSpecialDays
{
public:
explicit ATBSpecialDays() = default;
int ped_id;
std::string ped_label;
std::string ped_date_start;
std::string ped_date_end;
int ped_period_special_day_id;
int ped_payment_option_id;
int ped_period_special_day_id;
int ped_year;
};
};

View File

@ -6,23 +6,20 @@
/// </summary>
///
#include <Qt>
#define _NO_RESTRICTION_24_7_ (uint64_t)(0ULL)
#define _MON_ (uint64_t)(1ULL << 8)
#define _TUE_ (uint64_t)(1ULL << 9)
#define _WED_ (uint64_t)(1ULL << 10)
#define _THU_ (uint64_t)(1ULL << 11)
#define _FRI_ (uint64_t)(1ULL << 12)
#define _SAT_ (uint64_t)(1ULL << 13)
#define _SUN_ (uint64_t)(1ULL << 14)
#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_ (uint64_t)(1ULL << 15)
#define _ONLY_WEEKEND_ ((_SAT_|_SUN_))
#define _ONLY_OPEN_FOR_BUSINESS_DAYS_ (uint64_t)(1ULL << 16) /* verkaufsoffen */
#define _NOT_DEFINED_ (uint64_t)(~0ULL)
#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
{
@ -40,7 +37,7 @@ enum BusinessHours : std::uint64_t
NoBusinessHoursDefined = 255,
// new 12.04.2024
NO_RESTRICTION_24_7 = _NO_RESTRICTION_24_7_,
NO_RESTRICTION_24_7 = 0,
MON = _MON_,
TUE = _TUE_,
WED = _WED_,
@ -52,26 +49,11 @@ enum BusinessHours : std::uint64_t
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_
ONLY_WEEKEND = _ONLY_WEEKEND,
ONLY_OPEN_FOR_BUSINESS_DAYS = _ONLY_OPEN_FOR_BUSINESS_DAYS,
NOT_DEFINED = _NOT_DEFINED
};
#if 0
static bool business(uint64_t businessHours, QDateTime &const dt) {
switch (dayOfWeek) {
case Qt::Monday:
(businessHours & _MON_) == _MON_;
case Qt::Tuesday:
case Qt::Wednesday:
case Qt::Thursday:
case Qt::Saturday:
case Qt::Sunday:
}
}
#endif
struct BusinessHours_struct {
BusinessHours bh;
};

View File

@ -1,6 +0,0 @@
#ifndef TARIFF_GLOBAL_DEFINES_H_INCLUDED
#define TARIFF_GLOBAL_DEFINES_H_INCLUDED
#define DBG_HEADER "(" << __func__ << ":" << __LINE__ << ")"
#endif // TARIFF_GLOBAL_DEFINES_H_INCLUDED

View File

@ -15,9 +15,6 @@
using namespace std;
namespace Utilities {
bool isDayIncluded(uint64_t businessHours, QDateTime const &dt);
/// <summary>
/// Get day of week from current date (Zeller's Algorithm), starting day is Sunday
/// </summary>
@ -79,9 +76,7 @@ namespace Utilities {
double CalculatePricePerUnit(double pra_price, double durationUnit = -1);
QTime SpecialDaysWorkTimeFrom(Configuration const *cfg, int specialDayId);
QTime SpecialDaysWorkTimeFrom(Configuration::SpecialDaysWorktimeType::const_iterator it);
QTime SpecialDaysWorkTimeUntil(Configuration const *cfg, int specialDayId);
QTime SpecialDaysWorkTimeUntil(Configuration::SpecialDaysWorktimeType::const_iterator it);
QTime WeekDaysWorkTimeFrom(std::multimap<int, ATBWeekDaysWorktime>::const_iterator itr);
QTime WeekDaysWorkTimeUntil(std::multimap<int, ATBWeekDaysWorktime>::const_iterator itr);
int WeekDayId(std::multimap<int, ATBWeekDaysWorktime>::const_iterator itr);
@ -99,5 +94,4 @@ namespace Utilities {
BusinessHours getBusinessHours(Configuration const *cfg, PaymentMethod methodId);
uint32_t computeWeekDaysPrice(Configuration const *cfg, PaymentMethod id);
double computeWeekDaysDurationUnit(Configuration const *cfg, PaymentMethod id);
QStringList dumpBusinessHours(uint64_t businessHours);
}

View File

@ -79,8 +79,7 @@ HEADERS += \
include/mobilisis/tariff_timebase.h \
include/mobilisis/tariff_timestep_config.h \
include/mobilisis/tariff_product.h \
include/mobilisis/tariff_permit_type.h \
include/mobilisis/tariff_global_defines.h
include/mobilisis/tariff_permit_type.h
OTHER_FILES += src/main.cpp \
../tariffs/tariff_korneuburg.json \

View File

@ -445,11 +445,8 @@ CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket(
bool prepaid)
{
CalcState calcState;
int paymentOptionIndex = tariff->getPaymentOptionIndex(start_parking_time);
double minMin = tariff->getPaymentOptions(paymentOptionIndex).pop_min_time;
double maxMin = tariff->getPaymentOptions(paymentOptionIndex).pop_max_time;
double minMin = tariff->getPaymentOptions().pop_min_time;
double maxMin = tariff->getPaymentOptions().pop_max_time;
// DEBUG
qCritical() << "compute_price_for_parking_ticket() " << endl
@ -480,13 +477,11 @@ CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket(
double cost = -1;
if (start_parking_time.isValid()) {
if (tariff->getPaymentOptions().pop_payment_method_id == PaymentMethod::Steps) {
// hier muesste man unterscheiden: uebertrag oder nicht?
calcState = Calculator::GetInstance().isParkingAllowed(tariff, start_parking_time,
netto_parking_time, paymentOptionIndex);
calcState = Calculator::GetInstance().isParkingAllowed(tariff, start_parking_time);
if (calcState.getStatus() == CalcState::State::OUTSIDE_ALLOWED_PARKING_TIME) {
return calcState;
}
cost = Calculator::GetInstance().GetCostFromDuration(tariff, start_parking_time, netto_parking_time, paymentOptionIndex);
cost = Calculator::GetInstance().GetCostFromDuration(tariff, start_parking_time, netto_parking_time);
} else {
cost = Calculator::GetInstance().GetCostFromDuration(
tariff,
@ -496,7 +491,7 @@ CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket(
netto_parking_time, // minutes, netto
false, prepaid);
}
double minCost = tariff->getPaymentOptions(paymentOptionIndex).pop_min_price;
double minCost = tariff->getPaymentOptions().pop_min_price;
if (cost < minCost) {
calcState.setDesc(QString("minCost=%1, cost=%2").arg(minCost, cost));
return calcState.set(CalcState::State::BELOW_MIN_PARKING_PRICE);

View File

@ -4,7 +4,6 @@
#include "tariff_log.h"
#include "tariff_time_range.h"
#include "ticket.h"
#include "tariff_global_defines.h"
#include <sstream>
#include <algorithm>
@ -591,283 +590,30 @@ std::string Calculator::GetDurationFromCost(Configuration* cfg,
uint32_t Calculator::GetCostFromDuration(Configuration *cfg,
QDateTime const &start,
quint64 timeStepInMinutes,
int paymentOptionIndex) const {
quint64 timeStepInMinutes) const {
// for instance, a tariff as used in Schoenau, Koenigssee: only steps, no
// special days, nonstop.
static const PaymentMethod paymentMethodId = Utilities::getPaymentMethodId(cfg);
if (paymentMethodId == PaymentMethod::Steps) {
QDateTime const end = start.addSecs(timeStepInMinutes*60);
return GetCostFromDuration(cfg, start, end, paymentOptionIndex);
return GetCostFromDuration(cfg, start, end);
}
return 0;
}
uint32_t Calculator::GetCostFromDuration(Configuration * cfg,
QDateTime const &start,
QDateTime const &end,
int paymentOptionIndex) const {
QDateTime const &end) const {
static const PaymentMethod paymentMethodId = Utilities::getPaymentMethodId(cfg);
if (paymentMethodId == PaymentMethod::Steps) {
int const timeStepInMinutes = start.secsTo(end) / 60;
return GetPriceForTimeStep(cfg, timeStepInMinutes, paymentOptionIndex);
return GetPriceForTimeStep(cfg, timeStepInMinutes);
}
return 0;
}
CalcState Calculator::isParkingAllowedForWeekDay(Configuration const *cfg,
QDateTime const &start,
int netto_parking_time,
int paymentOptionIndex) {
qCritical() << DBG_HEADER << "start" << start.toString(Qt::ISODate)
<< "paymentOptionIndex" << paymentOptionIndex;
QString errorStr = "UNKNOWN ERROR";
PaymentMethod const paymentMethodId = Utilities::getPaymentMethodId(cfg);
if (paymentMethodId == PaymentMethod::Steps) {
uint64_t const businessHours = cfg->getPaymentOptions(paymentOptionIndex).pop_business_hours;
if (cfg->isDayIncluded(businessHours, start)) {
if (businessHours == BusinessHours::NO_RESTRICTION_24_7) {
return CalcState(CalcState::State::SUCCESS, "PARKING_ALLOWED",
QTime(0, 0, 0), QTime(23, 59, 59));
}
int const weekdayId = start.date().dayOfWeek();
if (cfg->WeekDaysWorktime.count(weekdayId) > 0) {
using WTIterator = std::multimap<int, ATBWeekDaysWorktime>::const_iterator;
std::pair<WTIterator, WTIterator> p = cfg->WeekDaysWorktime.equal_range(weekdayId);
for (WTIterator itr = p.first; itr != p.second; ++itr) {
QTime const &from = Utilities::WeekDaysWorkTimeFrom(itr);
QTime const &until = Utilities::WeekDaysWorkTimeUntil(itr);
qCritical() << DBG_HEADER
<< "CHECK IF PARKING IS ALLOWED IN TIME-RANGE ("
<< from.toString(Qt::ISODate) << "->" << until.toString(Qt::ISODate) << ") ...";
QTime const &startTime = start.time();
if (startTime >= from && startTime <= until) {
QTime const endTime = start.addSecs(netto_parking_time*60).time();
if (endTime <= until) {
return CalcState(CalcState::State::SUCCESS, "PARKING_ALLOWED", from, until);
} else {
errorStr = QString("%1 startTime not in range (%2 not in [%3, %4))")
.arg(__LINE__)
.arg(startTime.toString(Qt::ISODate))
.arg(from.toString(Qt::ISODate))
.arg(endTime.toString(Qt::ISODate));
}
} else {
errorStr = QString("%1 startTime not in range (%2 not in [%3, %4))")
.arg(__LINE__)
.arg(startTime.toString(Qt::ISODate))
.arg(from.toString(Qt::ISODate))
.arg(until.toString(Qt::ISODate));
}
int const pop_carry_over = cfg->getPaymentOptions(paymentOptionIndex).pop_carry_over;
if (pop_carry_over == 1) {
qCritical() << DBG_HEADER
<< "NO. CHECK IF PARKING IS ALLOWED WITH CARRY-OVER ...";
int const pop_carry_over_start_time_range = cfg->getPaymentOptions(paymentOptionIndex).pop_carry_over_start_time_range;
int const pop_carry_over_end_time_range = cfg->getPaymentOptions(paymentOptionIndex).pop_carry_over_end_time_range;
if (cfg->TimeRange.count(pop_carry_over_start_time_range) == 1 &&
cfg->TimeRange.count(pop_carry_over_end_time_range) == 1) {
ATBTimeRange s = cfg->TimeRange.find(pop_carry_over_start_time_range)->second;
ATBTimeRange e = cfg->TimeRange.find(pop_carry_over_end_time_range)->second;
if (startTime >= s.getTimeFrom() && startTime <= s.getTimeUntil()) {
QDateTime sd = start;
sd.setTime(s.getTimeUntil());
QDateTime ed = start.addDays(1);
ed.setTime(e.getTimeFrom());
int const jumpSecs = sd.secsTo(ed);
QDateTime const end = start.addSecs(netto_parking_time*60 + jumpSecs);
if (end.time() <= e.getTimeUntil()) {
qCritical() << DBG_HEADER
<< "PARKING IS ALLOWED WITH CARRY-OVER ("
<< start.toString(Qt::ISODate) << "->" << ed.toString(Qt::ISODate) << ")";
return CalcState(CalcState::State::SUCCESS, "PARKING_ALLOWED",
startTime, end.time());
} else {
errorStr = QString("endTime %1 exceeds [%2, %3))")
.arg(end.toString(Qt::ISODate))
.arg(sd.toString(Qt::ISODate))
.arg(ed.toString(Qt::ISODate));
}
} else {
errorStr = QString("startTime %1 exceeds [%2, %3))")
.arg(startTime.toString(Qt::ISODate))
.arg(s.getTimeFrom().toString(Qt::ISODate))
.arg(s.getTimeUntil().toString(Qt::ISODate));
}
} else {
errorStr = "no carry-over limits configured";
}
} else {
errorStr = "no carry-over configured";
}
}
} else {
errorStr = QString("no weekday configured for day-id %1").arg(weekdayId);
}
} else {
errorStr = QString("start %1 not contained in business hours %2")
.arg(start.toString(Qt::ISODate))
.arg(businessHours);
}
}
return CalcState(CalcState::State::OUTSIDE_ALLOWED_PARKING_TIME, errorStr,
QTime(), QTime());
}
CalcState Calculator::isParkingAllowedForSpecialDay(Configuration const *cfg,
QDateTime const &start,
int netto_parking_time,
int paymentOptionIndex) {
QString errorStr = "UNKNOWN ERROR";
qCritical() << DBG_HEADER << "start" << start.toString(Qt::ISODate)
<< "paymentOptionIndex" << paymentOptionIndex;
PaymentMethod const paymentMethodId = Utilities::getPaymentMethodId(cfg);
if (paymentMethodId == PaymentMethod::Steps) {
//uint64_t const businessHours = cfg->getPaymentOptions(paymentOptionIndex).pop_business_hours;
int const specialDayId = cfg->specialDayId(start);
if ((specialDayId > 0) && (cfg->SpecialDaysWorktime.count(specialDayId) > 0)) {
using SDIterator = Configuration::SpecialDaysWorktimeType::const_iterator;
std::pair<SDIterator, SDIterator> p = cfg->SpecialDaysWorktime.equal_range(specialDayId);
for (SDIterator it = p.first; it != p.second; ++it) {
QTime const &from = Utilities::SpecialDaysWorkTimeFrom(it);
QTime const &until = Utilities::SpecialDaysWorkTimeUntil(it);
qCritical() << DBG_HEADER
<< "CHECK IF PARKING IS ALLOWED IN TIME-RANGE ("
<< from.toString(Qt::ISODate) << "->" << until.toString(Qt::ISODate) << ") ...";
QTime const &startTime = start.time();
if (startTime >= from && startTime <= until) {
QTime const endTime = start.addSecs(netto_parking_time*60).time();
if (endTime <= until) {
return CalcState(CalcState::State::SUCCESS, "PARKING_ALLOWED", from, until);
} else {
errorStr = QString("%1 startTime not in range (%2 not in [%3, %4))")
.arg(__LINE__)
.arg(startTime.toString(Qt::ISODate))
.arg(from.toString(Qt::ISODate))
.arg(endTime.toString(Qt::ISODate));
}
} else {
errorStr = QString("%1 startTime not in range (%2 not in [%3, %4))")
.arg(__LINE__)
.arg(startTime.toString(Qt::ISODate))
.arg(from.toString(Qt::ISODate))
.arg(until.toString(Qt::ISODate));
}
int const pop_carry_over = cfg->getPaymentOptions(paymentOptionIndex).pop_carry_over;
if (pop_carry_over == 1) {
qCritical() << DBG_HEADER << "NO. CHECK IF PARKING IS ALLOWED WITH CARRY-OVER ...";
int const pop_carry_over_start_time_range = cfg->getPaymentOptions(paymentOptionIndex).pop_carry_over_start_time_range;
int const pop_carry_over_end_time_range = cfg->getPaymentOptions(paymentOptionIndex).pop_carry_over_end_time_range;
if (cfg->TimeRange.count(pop_carry_over_start_time_range) == 1 &&
cfg->TimeRange.count(pop_carry_over_end_time_range) == 1) {
ATBTimeRange s = cfg->TimeRange.find(pop_carry_over_start_time_range)->second;
ATBTimeRange e = cfg->TimeRange.find(pop_carry_over_end_time_range)->second;
if (startTime >= s.getTimeFrom() && startTime <= s.getTimeUntil()) {
QDateTime sd = start;
sd.setTime(s.getTimeUntil());
QDateTime ed = start.addDays(1);
ed.setTime(e.getTimeFrom());
int const jumpSecs = sd.secsTo(ed);
QDateTime const end = start.addSecs(netto_parking_time*60 + jumpSecs);
if (end.time() <= e.getTimeUntil()) {
ed.setTime(e.getTimeUntil()); // for printing
qCritical() << DBG_HEADER
<< "PARKING IS ALLOWED WITH CARRY-OVER ("
<< start.toString(Qt::ISODate) << "->" << ed.toString(Qt::ISODate) << ")";
return CalcState(CalcState::State::SUCCESS, "PARKING_ALLOWED",
startTime, end.time());
} else {
ed.setTime(e.getTimeUntil()); // for printing
errorStr = QString("endTime %1 exceeds [%2, %3))")
.arg(end.toString(Qt::ISODate))
.arg(sd.toString(Qt::ISODate))
.arg(ed.toString(Qt::ISODate));
}
} else {
errorStr = QString("startTime %1 exceeds [%2, %3))")
.arg(startTime.toString(Qt::ISODate))
.arg(s.getTimeFrom().toString(Qt::ISODate))
.arg(s.getTimeUntil().toString(Qt::ISODate));
}
} else {
errorStr = "no carry-over limits configured";
}
} else {
errorStr = "no carry-over configured";
}
}
}
}
return CalcState(CalcState::State::OUTSIDE_ALLOWED_PARKING_TIME, errorStr,
QTime(), QTime());
}
CalcState Calculator::isParkingAllowed(Configuration const *cfg,
QDateTime const &start,
int netto_parking_time,
int paymentOptionIndex) {
qCritical() << DBG_HEADER << "CHECK IF PARKING IS ALLOWED AT"
<< start.toString(Qt::ISODate) << "...";
CalcState cs;
if ((cs = isParkingAllowedForWeekDay(cfg, start, netto_parking_time, paymentOptionIndex))) {
return cs;
}
qCritical() << DBG_HEADER << QString(cs);
if ((cs = isParkingAllowedForSpecialDay(cfg, start, netto_parking_time, paymentOptionIndex))) {
return cs;
}
qCritical() << DBG_HEADER << QString(cs);
return CalcState(CalcState::State::OUTSIDE_ALLOWED_PARKING_TIME, "UNKNOWN ERROR",
QTime(), QTime());
}
CalcState Calculator::isParkingAllowed(Configuration const *cfg,
QDateTime const &start) {
CalcState Calculator::isParkingAllowed(Configuration const *cfg, QDateTime const &start) {
static const PaymentMethod paymentMethodId = Utilities::getPaymentMethodId(cfg);
if (paymentMethodId == PaymentMethod::Steps) {
@ -1940,9 +1686,9 @@ QList<int> Calculator::GetTimeSteps(Configuration *cfg, int paymentOptionIndex)
return m_timeSteps[paymentOptionIndex];
}
uint32_t Calculator::GetPriceForTimeStep(Configuration *cfg, int timeStep, int paymentOptionIndex) const {
uint32_t Calculator::GetPriceForTimeStep(Configuration *cfg, int timeStep) const {
int const pop_id = cfg->getPaymentOptions(paymentOptionIndex).pop_id;
int const pop_id = cfg->getPaymentOptions().pop_id;
for (auto[itr, rangeEnd] = cfg->PaymentRate.equal_range(pop_id); itr != rangeEnd; ++itr)
{

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,5 @@
#include "utilities.h"
#include "tariff_log.h"
#include "tariff_business_hours.h"
#include <QDebug>
#include <algorithm>
@ -334,14 +333,6 @@ QTime Utilities::SpecialDaysWorkTimeFrom(Configuration const *cfg, int specialDa
return QTime::fromString(cfg->SpecialDaysWorktime.find(specialDayId)->second.pedwt_time_from.c_str(), Qt::ISODate);
}
QTime Utilities::SpecialDaysWorkTimeFrom(Configuration::SpecialDaysWorktimeType::const_iterator it) {
return QTime::fromString(it->second.pedwt_time_from.c_str(), Qt::ISODate);
}
QTime Utilities::SpecialDaysWorkTimeUntil(Configuration::SpecialDaysWorktimeType::const_iterator it) {
return QTime::fromString(it->second.pedwt_time_to.c_str(), Qt::ISODate);
}
QTime Utilities::SpecialDaysWorkTimeUntil(Configuration const *cfg, int specialDayId) {
return QTime::fromString(cfg->SpecialDaysWorktime.find(specialDayId)->second.pedwt_time_to.c_str(), Qt::ISODate);
}
@ -429,10 +420,10 @@ uint32_t Utilities::getFirstDurationStep(Configuration const *cfg, PaymentMethod
}
BusinessHours Utilities::getBusinessHours(Configuration const *cfg, PaymentMethod methodId) {
uint64_t businessHours = cfg->PaymentOption.find(methodId)->second.pop_business_hours;
int businessHours = cfg->PaymentOption.find(methodId)->second.pop_business_hours;
switch (businessHours) {
//case NoRestriction_24_7: return BusinessHours::NoRestriction_24_7;
case NoRestriction_24_7: return BusinessHours::NoRestriction_24_7;
case OnlyWorkingDays: return BusinessHours::OnlyWorkingDays;
case OnlyWeekDays: return BusinessHours::OnlyWeekDays;
case OnlyWeekEnd: return BusinessHours::OnlyWeekEnd;
@ -442,21 +433,6 @@ BusinessHours Utilities::getBusinessHours(Configuration const *cfg, PaymentMetho
case SpecialAndSchoolHolidays: return BusinessHours::SpecialAndSchoolHolidays;
case OnlyOpenForBusinessDays: return BusinessHours::OnlyOpenForBusinessDays;
case AllDaysWithRestrictedHours: return BusinessHours::AllDaysWithRestrictedHours;
case _NO_RESTRICTION_24_7_: return BusinessHours::NO_RESTRICTION_24_7;
case _MON_: return BusinessHours::MON;
case _TUE_: return BusinessHours::TUE;
case _WED_: return BusinessHours::WED;
case _THU_: return BusinessHours::THU;
case _FRI_: return BusinessHours::FRI;
case _SAT_: return BusinessHours::SAT;
case _SUN_: return BusinessHours::SUN;
case _WEEK_DAYS_: return BusinessHours::WEEK_DAYS;
case _WORKING_DAYS_: return BusinessHours::WORKING_DAYS;
case _ALL_DAYS_: return BusinessHours::ALL_DAYS;
case _OFFICIAL_HOLIDAY_: return BusinessHours::OFFICIAL_HOLIDAY;
case _ONLY_WEEKEND_: return BusinessHours::ONLY_WEEKEND;
case _ONLY_OPEN_FOR_BUSINESS_DAYS_: return BusinessHours::ONLY_OPEN_FOR_BUSINESS_DAYS;
case _NOT_DEFINED_: return BusinessHours::NOT_DEFINED;
}
return BusinessHours::NoBusinessHoursDefined;
}
@ -471,82 +447,3 @@ double Utilities::computeWeekDaysDurationUnit(Configuration const *cfg, PaymentM
int durationId = cfg->PaymentRate.find(pop_id)->second.pra_payment_unit_id;
return (double)(cfg->Duration.find(durationId)->second.pun_duration);
}
bool Utilities::isDayIncluded(uint64_t businessHours, QDateTime const &dt) {
int dayOfWeek = dt.date().dayOfWeek();
switch (dayOfWeek) {
case Qt::Monday:
return ((businessHours & BusinessHours::MON) == BusinessHours::MON);
case Qt::Tuesday:
return ((businessHours & BusinessHours::TUE) == BusinessHours::TUE);
case Qt::Wednesday:
return ((businessHours & BusinessHours::WED) == BusinessHours::WED);
case Qt::Thursday:
return ((businessHours & BusinessHours::THU) == BusinessHours::THU);
case Qt::Friday:
return ((businessHours & BusinessHours::FRI) == BusinessHours::FRI);
case Qt::Saturday:
return ((businessHours & BusinessHours::SAT) == BusinessHours::SAT);
case Qt::Sunday:
return ((businessHours & BusinessHours::SUN) == BusinessHours::SUN);
default:;
}
return false;
}
QStringList Utilities::dumpBusinessHours(uint64_t businessHours) {
QStringList s;
if ((businessHours & BusinessHours::MON) == BusinessHours::MON) {
if ((businessHours & BusinessHours::OFFICIAL_HOLIDAY) == BusinessHours::OFFICIAL_HOLIDAY) {
s << "MON (Holiday)";
} else {
s << "MON";
}
}
if ((businessHours & BusinessHours::TUE) == BusinessHours::TUE) {
if ((businessHours & BusinessHours::OFFICIAL_HOLIDAY) == BusinessHours::OFFICIAL_HOLIDAY) {
s << "TUE (Holiday)";
} else {
s << "TUE";
}
}
if ((businessHours & BusinessHours::WED) == BusinessHours::WED) {
if ((businessHours & BusinessHours::OFFICIAL_HOLIDAY) == BusinessHours::OFFICIAL_HOLIDAY) {
s << "WED (Holiday)";
} else {
s << "WED";
}
}
if ((businessHours & BusinessHours::THU) == BusinessHours::THU) {
if ((businessHours & BusinessHours::OFFICIAL_HOLIDAY) == BusinessHours::OFFICIAL_HOLIDAY) {
s << "THU (Holiday)";
} else {
s << "THU";
}
}
if ((businessHours & BusinessHours::FRI) == BusinessHours::FRI) {
if ((businessHours & BusinessHours::OFFICIAL_HOLIDAY) == BusinessHours::OFFICIAL_HOLIDAY) {
s << "FRI (Holiday)";
} else {
s << "FRI";
}
}
if ((businessHours & BusinessHours::SAT) == BusinessHours::SAT) {
if ((businessHours & BusinessHours::OFFICIAL_HOLIDAY) == BusinessHours::OFFICIAL_HOLIDAY) {
s << "SAT (Holiday)";
} else {
s << "SAT";
}
}
if ((businessHours & BusinessHours::SUN) == BusinessHours::SUN) {
if ((businessHours & BusinessHours::OFFICIAL_HOLIDAY) == BusinessHours::OFFICIAL_HOLIDAY) {
s << "SUN (Holiday)";
} else {
s << "SUN";
}
}
return s;
}

View File

@ -41,9 +41,9 @@ extern "C" char* strptime(const char* s,
#define NEUHAUSER_NORDISCHES_AUSBILDUNGSZENTRUM (0)
#define NEUHAUSER_BILEXA_GALTUER (0)
#define NEUHAUSER_KIRCHDORF (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_PERNEGG_AN_DER_MUR (1)
int main() {
#if NEUHAUSER_PERNEGG_AN_DER_MUR==1
@ -408,59 +408,29 @@ int main() {
}
#endif
bool fail;
QDateTime start;
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, 4, 21), QTime(16, 0, 0)); // sunday
fail = false;
break;
case 2:
start = QDateTime(QDate(2024, 4, 22), QTime(8, 0, 0)); // monday
fail = false;
break;
case 3:
start = QDateTime(QDate(2024, 4, 22), QTime(17, 30, 0)); // monday
fail = true;
break;
default:;
}
QDateTime start(QDate(2024, 4, 14), QTime());
QDateTime end;
struct price_t price;
QDateTime end;
struct price_t price;
//start = QDateTime::currentDateTime();
//start = QDateTime::currentDateTime();
QList<int> timeSteps;
int paymentOptionIndex = cfg.getCurrentPaymentOptionIndex(start);
if (paymentOptionIndex != -1) {
qCritical() << "paymentOptionIndex" << paymentOptionIndex;
QList<int> const timeSteps = Calculator::GetInstance().GetTimeSteps(&cfg, paymentOptionIndex);
qCritical() << "TimeSteps" << timeSteps;
int paymentOptionIndex = cfg.getPaymentOptionIndex(start);
if (paymentOptionIndex != -1) {
qCritical() << "paymentOptionIndex" << paymentOptionIndex;
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) {
QList<int>::const_iterator step;
for (step = timeSteps.cbegin(); step != timeSteps.cend(); ++step) {
double cost = 0;
CalcState cs;
double cost = 0;
if ((cs = compute_price_for_parking_ticket(&cfg, start, *step, end, &price))) {
cost = price.netto;
qCritical() << "step" << *step << ": cost" << cost;
} else {
if (fail == false) {
qCritical() << "<<<ERROR>>> cs =" << QString(cs);
}
}
}
} else {
qCritical() << "ERROR paymentOptionIndex =" << paymentOptionIndex;
//if (compute_price_for_parking_ticket(&cfg, start, *step, end, &price)) {
// cost = price.netto;
//}
}
}
}