Compare commits

..

26 Commits

Author SHA1 Message Date
f47695de8b Add pop_plus_steps_saved 2024-09-02 17:16:47 +02:00
cce3db301b Minor: comment out some code to prevent compiler warnings (about some unused
variables).
2024-09-02 17:15:33 +02:00
5cab0de9fb Use free function getPaymentOptionIndex() to compute index of valid
payment-option-section in tariff-file based on configured businessHours.
2024-09-02 17:14:20 +02:00
f92906f680 Minor: debug output. 2024-09-02 17:13:11 +02:00
8cdeef26fc Check if computed ticket-end-time violates a carry-over-limit defined in
tariff-file.
2024-09-02 17:11:48 +02:00
52ebbf7bc9 Use free function getPaymentOptionIndex() in serveral places to compute valid
index of a payment-option-section within tariff file. If this is not possible,
then try the already available functionality.
2024-09-02 17:09:26 +02:00
349e9d8b06 Add free functions isHoliday() to check if the current day is a holiday
and previousDayHoliday() to check if previous day (relative to endtime) is a
holiday.
2024-09-02 17:05:32 +02:00
68a1c24861 Add free function getPaymentOptionIndex():
Compute payment option index base on current start-date-time and
	businesshour-setiing in tariff-file.
	Returns -1 to indicate error.
2024-09-02 17:03:37 +02:00
c946c106d1 Configuration::ParseJson():
Save the pop_plus_steps setting: sometimes it is necessary to adapt the
	pop_plus_steps-variable in order to hit a time-limit-boundary exactly.
	Otherwise the next computed time-step might overshoot the time-limit,
	and when moving backwards (via Minus-Button) there is a better
	resolution: going backwards, the user could hit the exact time-limit,
	which he could not when going up.
2024-09-02 16:58:34 +02:00
f24f1fe646 Configuration::ParseJson():
Call parseWeekDay() to reading the week-day-settings.
2024-09-02 16:57:11 +02:00
c6b8a37263 ParseJson():
Minor: some reformatting of source code.
2024-09-02 16:55:48 +02:00
58d8f16681 ParseWeekDay():
Parsing "Monday" - "Sunday" section i a tariff-file.

	Each day has a memebr named "week_day_default".

	It contains the valid default tariff settings for a usual day (i.e. no
	holiday etc.)
	It also contains the carry-over-settings for the usual day.

	In case there is some holiday on this day (for instance on "Monday"),
	the the date of the holiday replaces the name "week_day_default".
	Otherwise the structure is the same as for a usual day.
2024-09-02 16:49:21 +02:00
431664d8b9 IdentifyJsonMember():
Add "Monday" - "Sunday" as level-1 sections in a tariff-file.
2024-09-02 16:47:46 +02:00
53cf9a7341 Add description for tariff-settings.w 2024-09-02 16:46:00 +02:00
3a18ee2d7c Add description for carry-over-settings 2024-09-02 16:45:35 +02:00
929a8a4a27 Reuse of "class ATBWeekDays":
Description of a weekday: Mon-Sun. For holidays contains a type-flag
	to indicate such a day.

	Each weekday has some tariff-settings and some carry-over-settings.
2024-09-02 16:41:26 +02:00
2b9657787d add tests for bad-neuenahr 2024-09-02 16:40:38 +02:00
eca285cc25 remove obsolete print-function 2024-09-02 16:40:07 +02:00
bda8914f1a Add free functions:
previousDayHoliday():
	Check if previous day was a holiday. Check is done relative to
	computed endtime.

isHoliday():
	Check if startDateTime is on a holiday.

getPaymentOptionIndex():
	Compute the index of the payment-options-section inside a tariff-file.
	This is done as workaround (and backward compatibility).

parseWeekDay():
	Parse new structure of tariff-file.
2024-09-02 16:35:25 +02:00
a3983ed427 check for time-step-config == STATIC 2024-08-21 17:46:35 +02:00
f8805e9e78 compute_duration_for_parking_ticket():
Fix: handle carry-over for coin-insertion.
2024-08-21 15:40:55 +02:00
7a6360f392 compute_duration_for_parking_ticket():
Fix: handle prepaid-setting for coin-insertion.
2024-08-21 15:39:44 +02:00
08a249f393 return OVERPAID in case overpay is not allowed 2024-08-21 15:39:05 +02:00
7c173ae292 parse for pop_allow_overpay 2024-08-21 15:38:06 +02:00
80637260f3 Utilities::IsYearPeriodActive():
Fix: take into account if start-date <= end-date or not.
	     Otherwise check is wrong, and no valid year period is returned.
2024-08-21 15:35:03 +02:00
9b524d63e5 Add 'pop_allow_overpay' setting: set vai tariff-file if operpay is allowed. 2024-08-21 15:33:02 +02:00
12 changed files with 928 additions and 90 deletions

View File

@ -36,6 +36,7 @@
using namespace std;
using namespace rapidjson;
class Calculator;
class Configuration
{
@ -59,7 +60,7 @@ public:
multimap<int, ATBPaymentRate> PaymentRate;
SpecialDaysWorktimeType SpecialDaysWorktime;
SpecialDaysType SpecialDays;
multimap<int, ATBWeekDays> WeekDays;
multimap<Qt::DayOfWeek, ATBWeekDay> WeekDays;
multimap<int, ATBPeriodYear> YearPeriod;
multimap<int, ATBWeekDaysWorktime> WeekDaysWorktime;
ATBPaymentOptionType PaymentOption;
@ -126,3 +127,15 @@ 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,7 +41,9 @@ 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;
@ -72,7 +74,9 @@ 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

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

View File

@ -0,0 +1,40 @@
#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,10 +1,57 @@
#pragma once
#include <string>
#include "tariff_settings.h"
#include "tariff_carryover_settings.h"
class ATBWeekDays
{
public:
int pdiw_id;
std::string pdiw_label;
int pdiw_index;
#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;
}
};

View File

@ -36,7 +36,10 @@ int CALCULATE_LIBRARY_API get_minimal_parkingtime(Configuration const *cfg,
int paymentOptionIndex) {
int minTime = 0;
paymentOptionIndex = cfg->getPaymentOptionIndex(permitType);
paymentOptionIndex = getPaymentOptionIndex(*cfg);
if (paymentOptionIndex == -1) {
paymentOptionIndex = cfg->getPaymentOptionIndex(permitType);
}
qCritical() << __func__ << __LINE__ << "paymentOptionIndex" << paymentOptionIndex;
qCritical() << __func__ << __LINE__ << "permit" << PermitType(permitType).toString();
@ -69,7 +72,10 @@ int CALCULATE_LIBRARY_API get_maximal_parkingtime(Configuration const *cfg,
PERMIT_TYPE permitType,
int paymentOptionIndex) {
paymentOptionIndex = cfg->getPaymentOptionIndex(permitType);
paymentOptionIndex = getPaymentOptionIndex(*cfg);
if (paymentOptionIndex == -1) {
paymentOptionIndex = cfg->getPaymentOptionIndex(permitType);
}
int maxTime = 0;
switch(permitType) {
@ -94,7 +100,10 @@ int CALCULATE_LIBRARY_API get_minimal_parkingprice(Configuration *cfg,
int paymentOptionIndex,
QDateTime const &start) {
int minPrice = -1;
paymentOptionIndex = cfg->getPaymentOptionIndex(permitType);
if ((paymentOptionIndex = getPaymentOptionIndex(*cfg)) == -1) {
paymentOptionIndex = cfg->getPaymentOptionIndex(permitType);
}
int payment_method_id = cfg->getPaymentOptions(paymentOptionIndex).pop_payment_method_id;
@ -321,7 +330,9 @@ int CALCULATE_LIBRARY_API get_maximal_parkingprice(Configuration *cfg,
int maxPrice = -1;
static const PaymentMethod paymentMethodId = Utilities::getPaymentMethodId(cfg);
paymentOptionIndex = cfg->getPaymentOptionIndex(permitType);
if ((paymentOptionIndex = getPaymentOptionIndex(*cfg)) == -1) {
paymentOptionIndex = cfg->getPaymentOptionIndex(permitType);
}
switch(permitType) {
case PERMIT_TYPE::SHORT_TERM_PARKING: { // e.g. szeged (customer_281)
@ -474,7 +485,11 @@ int CALCULATE_LIBRARY_API compute_next_timestep(parking_tariff_t *tariff, int cu
// return currentTimeMinutes;
//}
int const paymentOptionIndex = tariff->getPaymentOptionIndex(permitType);
int paymentOptionIndex = getPaymentOptionIndex(*tariff);
if (paymentOptionIndex == -1) {
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;
@ -539,7 +554,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;
}
@ -654,7 +669,10 @@ CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket(
CalcState calcState;
int const paymentOptionIndex = tariff->getPaymentOptionIndex(permitType.get());
int paymentOptionIndex = getPaymentOptionIndex(*tariff);
if (paymentOptionIndex == -1) {
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;
@ -721,7 +739,10 @@ CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket(
QDateTime start_parking_time(start_parking_time_);
int paymentOptionIndex = tariff->getPaymentOptionIndex(permitType);
int paymentOptionIndex = getPaymentOptionIndex(*tariff);
if (paymentOptionIndex == -1) {
paymentOptionIndex = tariff->getPaymentOptionIndex(permitType);
}
double minMin = tariff->getPaymentOptions(paymentOptionIndex).pop_min_time;
double maxMin = tariff->getPaymentOptions(paymentOptionIndex).pop_max_time;
@ -821,6 +842,24 @@ 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,
@ -873,7 +912,11 @@ CalcState CALCULATE_LIBRARY_API compute_duration_for_parking_ticket(
QString cs = start.toString(Qt::ISODate);
bool prepaid = true;
int paymentOptionIndex = tariff->getPaymentOptionIndex(permitType);
int paymentOptionIndex = getPaymentOptionIndex(*tariff);
if (paymentOptionIndex == -1) {
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;
@ -913,8 +956,16 @@ CalcState CALCULATE_LIBRARY_API compute_duration_for_parking_ticket(
CalcState calcState;
bool prepaid = true;
int paymentOptionIndex = tariff->getPaymentOptionIndex(permitType);
int paymentOptionIndex = getPaymentOptionIndex(*tariff);
if (paymentOptionIndex == -1) {
paymentOptionIndex = tariff->getPaymentOptionIndex(permitType);
}
qCritical() << __func__ << ":" << __LINE__ << " payment option index: " << paymentOptionIndex;
int prepaid_option_id = tariff->getPaymentOptions(paymentOptionIndex).pop_prepaid_option_id;
if (prepaid_option_id == 2) {
prepaid = false;
}
@ -929,6 +980,28 @@ 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,
@ -996,20 +1069,91 @@ 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() << "compute_duration_for_parking_ticket(): ";
qCritical() << " endTime: " << endTime;
qCritical() << " ticketEndTime: " << ticketEndTime;
qCritical() << __func__ << ":" << __LINE__ << " endTime:" << endTime;
qCritical() << __func__ << ":" << __LINE__ << "ticketEndTime:" << ticketEndTime.toString(Qt::ISODate);
}
} else {
return calcState.set(CalcState::State::INVALID_START_DATE);
@ -1021,7 +1165,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,7 +133,13 @@ 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 const paymentOptionIndex = cfg->getPaymentOptionIndex(permitType.get());
int paymentOptionIndex = getPaymentOptionIndex(*cfg);
if (paymentOptionIndex == -1) {
paymentOptionIndex = cfg->getPaymentOptionIndex(QDateTime::fromString(startDatetimePassed, Qt::ISODate));
}
qCritical() << DBG_HEADER << " option index:" << paymentOptionIndex;
if (DBG_LEVEL >= DBG_DEBUG) {
qCritical() << DBG_HEADER << " start:" << inputDate.toString(Qt::ISODate);
@ -262,11 +268,15 @@ 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) {
cost = pop_max_price;
qCritical() << DBG_HEADER << "MAX-PARKING-PRICE" << pop_max_price << ", COST" << cost;
//return CalcState::OVERPAID.toStdString();
if (pop_allow_overpay == false) {
return CalcState::OVERPAID.toStdString();
}
cost = pop_max_price;
// return CalcState::OVERPAID.toStdString();
}
if (cost < pop_min_price) {
@ -395,7 +405,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;
@ -424,7 +434,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));
@ -1416,7 +1426,10 @@ double Calculator::GetCostFromDuration(Configuration* cfg,
Q_UNUSED(payment_option);
Q_UNUSED(nextDay);
int const paymentOptionIndex = cfg->getPaymentOptionIndex(permitType.get());
int paymentOptionIndex = getPaymentOptionIndex(*cfg);
if (paymentOptionIndex == -1) {
paymentOptionIndex = cfg->getPaymentOptionIndex(permitType.get());
}
static const PaymentMethod paymentMethodId = Utilities::getPaymentMethodId(cfg);
if (paymentMethodId == PaymentMethod::Steps) {
if (tariffIs24_7(cfg)) {
@ -2568,7 +2581,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) {
@ -2593,7 +2606,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) {
@ -2623,7 +2636,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);
@ -2700,7 +2713,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,6 +8,8 @@
#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>
@ -21,7 +23,13 @@ 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, "WeekDays") == 0) return MemberType::WeekDaysType;
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, "WeekDaysWorktime") == 0) return MemberType::WeekDaysWorkTimeType;
if (strcmp(member_name, "SpecialDaysWorktime") == 0) return MemberType::SpecialDaysWorktimeType;
if (strcmp(member_name, "SpecialDays") == 0) return MemberType::SpecialDaysType;
@ -38,6 +46,286 @@ 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)
{
@ -96,7 +384,7 @@ bool Configuration::ParseJson(Configuration* cfg, const char* json)
ATBPaymentRate PaymentRate;
ATBSpecialDaysWorktime SpecialDaysWorktime;
ATBSpecialDays SpecialDays;
ATBWeekDays WeekDays;
//ATBWeekDay WeekDay;
ATBWeekDaysWorktime WeekDaysWorktime;
ATBPeriodYear YearPeriod;
ATBDailyTicket DailyTicket;
@ -112,29 +400,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 (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 (_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()) {
@ -171,6 +459,36 @@ 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()) {
@ -601,11 +919,16 @@ 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) {
@ -770,6 +1093,11 @@ 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;
@ -1180,7 +1508,6 @@ 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);
@ -1194,6 +1521,69 @@ 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);
@ -1448,3 +1838,42 @@ 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,7 +207,13 @@ 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);
return (d >= s && d <= e);
//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);
})) {
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 (0)
#define BAD_NEUENAHR_AHRWEILER (1)
#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 (1)
#define VALSER_ALM (0)
#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,8 +363,7 @@ int main() {
// for (int day = Qt::Monday; day <= Qt::Sunday; ++day) {
for (int day = Qt::Monday; day <= Qt::Monday; ++day) {
QDateTime s(QDate(2024, 7, 29 + day), QTime()); // 20: (whit) monday,..., 26: sunday
QDateTime end;
QDateTime s(QDate(2024, 8, 19 + day), QTime()); // 20: (whit) monday,..., 26: sunday
switch (day) {
case (int)Qt::Monday:
@ -390,6 +389,30 @@ 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(
@ -1357,7 +1380,7 @@ int main() {
int pop_carry_over;
int pop_carry_over_time_range_id;
for (int zone=1; zone < 2; ++zone) {
for (int zone=2; zone < 3; ++zone) {
//for (int t=6; t < 7; t+=20) {
switch (zone) {
case 1: {
@ -1366,6 +1389,7 @@ 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;
@ -1408,6 +1432,11 @@ int main() {
cout << endl;
if (isParsed) {
qCritical() << "Parsed";
exit(0);
// test library functions
if (zone == 1) {
@ -1434,10 +1463,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();
@ -1445,7 +1474,8 @@ int main() {
double price1 = 0;
double price2 = 0;
for (int m=0; m < 1440; ++m) {
//for (int m=0; m < 1440; ++m) {
for (int m=480; m < 481; ++m) {
start.setTime(QTime(0, 0, 0));
start = start.addSecs(m*60);
@ -1462,7 +1492,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);
@ -1497,6 +1527,21 @@ 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) {
@ -1534,18 +1579,18 @@ int main() {
bool fail;
QDateTime start;
for (int i=0; i < 4; ++i) {
for (int i=1; i < 2; ++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
start = QDateTime(QDate(2024, 10, 3), QTime(17, 0, 0)); // sunday
fail = false;
break;
case 2:
start = QDateTime(QDate(2024, 4, 22), QTime(8, 0, 0)); // monday
start = QDateTime(QDate(2024, 4, 22), QTime(17, 30, 0)); // monday
fail = false;
break;
case 3:
@ -1569,18 +1614,52 @@ 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;
if ((cs = compute_price_for_parking_ticket(&cfg, start, *step, end, &price, PermitType(PERMIT_TYPE::SHORT_TERM_PARKING)))) {
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)))) {
cost = price.netto;
qCritical() << "step" << *step << ": cost" << cost;
qCritical() << __LINE__
<< "START" << start.toString(Qt::ISODate)
<< "<duration" << *step
<< "cost" << cost
<< "> end" << end.toString(Qt::ISODate);
} 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,9 +30,7 @@ SOURCES += main.cpp
# HEADERS +=
OTHER_FILES += \
/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
/opt/ptu5/opt/customer_249/etc/psa_tariff/tariff02.json