Compare commits
19 Commits
kleipeda-e
...
2.3.99-21
Author | SHA1 | Date | |
---|---|---|---|
1b716c48d2
|
|||
77e1414c13 | |||
d95275a72d | |||
577a17dc6a | |||
d8d32820a3 | |||
2ce0aeef1d | |||
0cba85eafb | |||
4030a4b165 | |||
8c7afdfcb1 | |||
932d4e8cb9 | |||
38abc65425 | |||
205896903b | |||
dbedfd094f | |||
57b9d16abc | |||
48afbc071c | |||
7a7b10260a | |||
1874b08210 | |||
88a0ebb688 | |||
a8ae9fc602 |
59
library/include/mobilisis/atb_time.h
Normal file
59
library/include/mobilisis/atb_time.h
Normal file
@@ -0,0 +1,59 @@
|
||||
#ifndef ATB_TIME_H_INCLUDED
|
||||
#define ATB_TIME_H_INCLUDED
|
||||
|
||||
#include <QDateTime>
|
||||
|
||||
class ATBTime {
|
||||
QDateTime const m_end;
|
||||
mutable QDateTime m_time;
|
||||
|
||||
public:
|
||||
explicit ATBTime();
|
||||
explicit ATBTime(int h, int m, int s = 0, int ms = 0);
|
||||
explicit ATBTime(QString const &time);
|
||||
|
||||
int hour() const { return m_time.time().hour(); }
|
||||
int minute() const { return m_time.time().minute(); }
|
||||
int second() const { return m_time.time().second(); }
|
||||
int msec() const { return m_time.time().msec(); }
|
||||
|
||||
int secsTo(QTime t) const { return m_time.time().secsTo(t); }
|
||||
int msecsTo(QTime t) const { return m_time.time().msecsTo(t); }
|
||||
|
||||
bool setHMS(int h, int m, int s, int ms = 0);
|
||||
|
||||
bool isNull() const { return m_time.time().isNull(); }
|
||||
bool isValid() const { return m_time.time().isValid(); }
|
||||
|
||||
|
||||
QTime addMSecs(int ms) const;
|
||||
QTime addMSecs(int ms);
|
||||
|
||||
QTime addSecs(int s) const;
|
||||
QTime addSecs(int s);
|
||||
|
||||
int msecsSinceStartOfDay() const;
|
||||
QString toString(Qt::DateFormat format = Qt::TextDate) const;
|
||||
|
||||
|
||||
static bool isValid(int h, int m, int s, int ms = 0);
|
||||
|
||||
static QTime currentTime() { return QDateTime::currentDateTime().time(); }
|
||||
|
||||
static constexpr QTime fromMSecsSinceStartOfDay(int msecs);
|
||||
|
||||
static QTime fromString(QString const &string, Qt::DateFormat format = Qt::TextDate);
|
||||
static QTime fromString(QString const &string, const QString &format);
|
||||
|
||||
friend bool operator!=(const ATBTime &lhs, const ATBTime &rhs) noexcept;
|
||||
friend bool operator<(const ATBTime &lhs, const ATBTime &rhs) noexcept;
|
||||
friend bool operator<=(const ATBTime &lhs, const ATBTime &rhs) noexcept;
|
||||
friend bool operator<(const ATBTime &lhs, const ATBTime &rhs) noexcept;
|
||||
friend bool operator>(const ATBTime &lhs, const ATBTime &rhs) noexcept;
|
||||
friend bool operator==(const ATBTime &lhs, const ATBTime &rhs) noexcept;
|
||||
friend QDataStream &operator<<(QDataStream &out, ATBTime time);
|
||||
friend QDataStream &operator>>(QDataStream &in, ATBTime &time);
|
||||
};
|
||||
|
||||
|
||||
#endif // ATB_TIME_H_INCLUDED
|
@@ -56,6 +56,7 @@ struct CALCULATE_LIBRARY_API CalcState {
|
||||
static QString const ABOVE_MAX_PARKING_PRICE;
|
||||
static QString const OVERPAID;
|
||||
static QString const OUTSIDE_ALLOWED_PARKING_TIME;
|
||||
static QString const SUCCESS_MAXPRICE;
|
||||
|
||||
enum class State : uint8_t {
|
||||
SUCCESS,
|
||||
@@ -71,7 +72,8 @@ struct CALCULATE_LIBRARY_API CalcState {
|
||||
BELOW_MIN_PARKING_PRICE,
|
||||
ABOVE_MAX_PARKING_PRICE,
|
||||
OVERPAID,
|
||||
OUTSIDE_ALLOWED_PARKING_TIME
|
||||
OUTSIDE_ALLOWED_PARKING_TIME,
|
||||
SUCCESS_MAXPRICE
|
||||
};
|
||||
|
||||
State m_status;
|
||||
@@ -106,6 +108,9 @@ struct CALCULATE_LIBRARY_API CalcState {
|
||||
case State::SUCCESS:
|
||||
s = CalcState::SUCCESS;
|
||||
break;
|
||||
case State::SUCCESS_MAXPRICE:
|
||||
s = CalcState::SUCCESS_MAXPRICE;
|
||||
break;
|
||||
case State::ERROR_PARSING_ZONE_NR:
|
||||
s = CalcState::ERROR_PARSING_ZONE_NR;
|
||||
break;
|
||||
@@ -158,6 +163,9 @@ struct CALCULATE_LIBRARY_API CalcState {
|
||||
case State::SUCCESS:
|
||||
s = CalcState::SUCCESS;
|
||||
break;
|
||||
case State::SUCCESS_MAXPRICE:
|
||||
s = CalcState::SUCCESS_MAXPRICE;
|
||||
break;
|
||||
case State::ERROR_PARSING_ZONE_NR:
|
||||
s = CalcState::ERROR_PARSING_ZONE_NR;
|
||||
break;
|
||||
@@ -207,6 +215,9 @@ struct CALCULATE_LIBRARY_API CalcState {
|
||||
if (desc == SUCCESS) {
|
||||
m_status = State::SUCCESS;
|
||||
} else
|
||||
if (desc == SUCCESS_MAXPRICE) {
|
||||
m_status = State::SUCCESS_MAXPRICE;
|
||||
}
|
||||
if (desc == ERROR_PARSING_ZONE_NR) {
|
||||
m_status = State::ERROR_PARSING_ZONE_NR;
|
||||
} else
|
||||
|
@@ -73,7 +73,7 @@ public:
|
||||
/// <returns>Returns duration in seconds (data type: double)</returns>
|
||||
std::pair<std::string, QDateTime>
|
||||
GetDurationFromCost(Configuration* cfg, uint8_t vehicle_type, char const* start_datetime, double price,
|
||||
PermitType permitType, bool nextDay = false, bool prepaid = false);
|
||||
PermitType permitType, bool nextDay = false, bool prepaid = false);
|
||||
|
||||
/// <summary>
|
||||
/// Gets cost from duration in seconds
|
||||
|
@@ -25,6 +25,7 @@ public:
|
||||
pop_max_time = 0;
|
||||
pop_min_price = 0;
|
||||
pop_max_price = 0;
|
||||
pop_max_price_save = 0;
|
||||
pop_carry_over = -1;
|
||||
pop_carry_over_option_id = -1;
|
||||
pop_prepaid_option_id = -1;
|
||||
@@ -61,6 +62,7 @@ public:
|
||||
double pop_max_time;
|
||||
double pop_min_price;
|
||||
double pop_max_price;
|
||||
double pop_max_price_save;
|
||||
int pop_carry_over;
|
||||
int pop_carry_over_option_id;
|
||||
bool pop_truncate_last_interpolation_step;
|
||||
|
@@ -4,6 +4,8 @@
|
||||
#include <QTime>
|
||||
#include <QString>
|
||||
|
||||
#include "atb_time.h"
|
||||
|
||||
struct ATBPrepaid {
|
||||
int id;
|
||||
bool anytime;
|
||||
|
@@ -35,7 +35,8 @@ SOURCES += \
|
||||
src/tariff_log.cpp \
|
||||
src/calculate_price.cpp \
|
||||
src/ticket.cpp \
|
||||
src/tariff_global_defines.cpp
|
||||
src/tariff_global_defines.cpp \
|
||||
src/atb_time.cpp
|
||||
|
||||
HEADERS += \
|
||||
include/mobilisis/calculator_functions.h \
|
||||
@@ -89,7 +90,8 @@ HEADERS += \
|
||||
include/mobilisis/tariff_interpolation.h \
|
||||
include/mobilisis/tariff_prepaid.h \
|
||||
include/mobilisis/tariff_carryover.h \
|
||||
include/mobilisis/tariff_global_defines.h
|
||||
include/mobilisis/tariff_global_defines.h \
|
||||
include/mobilisis/atb_time.h
|
||||
|
||||
OTHER_FILES += src/main.cpp \
|
||||
../tariffs/tariff_korneuburg.json \
|
||||
|
115
library/src/atb_time.cpp
Normal file
115
library/src/atb_time.cpp
Normal file
@@ -0,0 +1,115 @@
|
||||
#include "atb_time.h"
|
||||
|
||||
|
||||
ATBTime::ATBTime()
|
||||
: m_end(QDateTime::fromString("1970-01-02T00:00:00", Qt::ISODate))
|
||||
, m_time(QDateTime::fromString("1970-01-01T00:00:00", Qt::ISODate)) {
|
||||
}
|
||||
|
||||
ATBTime::ATBTime(int h, int m, int s, int ms)
|
||||
: m_end(QDateTime::fromString("1970-01-02T00:00:00", Qt::ISODate))
|
||||
, m_time(QDateTime::fromString("1970-01-01T00:00:00", Qt::ISODate)) {
|
||||
|
||||
QTime t(h, m, s, ms);
|
||||
m_time.setTime(t);
|
||||
}
|
||||
|
||||
ATBTime::ATBTime(QString const &t)
|
||||
: m_end(QDateTime::fromString("1970-01-02T00:00:00"))
|
||||
, m_time(QDateTime::fromString("1970-01-01T00:00:00")) {
|
||||
|
||||
if (t == "24:00:00") {
|
||||
m_time = m_end;
|
||||
} else {
|
||||
m_time.setTime(QTime::fromString(t, Qt::ISODate));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
QTime ATBTime::addMSecs(int ms) const {
|
||||
return m_time.time().addMSecs(ms);
|
||||
}
|
||||
|
||||
QTime ATBTime::addMSecs(int ms) {
|
||||
QTime t = m_time.time();
|
||||
t = t.addMSecs(ms);
|
||||
m_time.setTime(t);
|
||||
return t;
|
||||
}
|
||||
|
||||
QTime ATBTime::addSecs(int s) const {
|
||||
return m_time.time().addSecs(s);
|
||||
}
|
||||
|
||||
QTime ATBTime::addSecs(int s) {
|
||||
QTime t = m_time.time();
|
||||
t = t.addSecs(s);
|
||||
m_time.setTime(t);
|
||||
return t;
|
||||
}
|
||||
|
||||
constexpr QTime ATBTime::fromMSecsSinceStartOfDay(int msecs) {
|
||||
return QTime::fromMSecsSinceStartOfDay(msecs);
|
||||
}
|
||||
|
||||
QTime ATBTime::fromString(QString const &string, Qt::DateFormat format) {
|
||||
return QTime::fromString(string, format);
|
||||
}
|
||||
|
||||
QTime ATBTime::fromString(QString const &string, QString const &format) {
|
||||
return QTime::fromString(string, format);
|
||||
}
|
||||
|
||||
bool ATBTime::isValid(int h, int m, int s, int ms) {
|
||||
return QTime(h, m, s, ms).isValid();
|
||||
}
|
||||
|
||||
int ATBTime::msecsSinceStartOfDay() const {
|
||||
return m_time.time().msecsSinceStartOfDay();
|
||||
}
|
||||
|
||||
bool ATBTime::setHMS(int h, int m, int s, int ms) {
|
||||
if (isValid(h, m, s, ms)) {
|
||||
QTime t(h, m, s, ms);
|
||||
m_time.setTime(t);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
QString ATBTime::toString(Qt::DateFormat format) const {
|
||||
return m_time.time().toString(format);
|
||||
}
|
||||
|
||||
bool operator!=(const ATBTime &lhs, const ATBTime &rhs) noexcept {
|
||||
return lhs.m_time.time() != rhs.m_time.time();
|
||||
}
|
||||
|
||||
bool operator<=(const ATBTime &lhs, const ATBTime &rhs) noexcept {
|
||||
return lhs.m_time.time() <= rhs.m_time.time();
|
||||
|
||||
}
|
||||
|
||||
bool operator<(const ATBTime &lhs, const ATBTime &rhs) noexcept {
|
||||
return lhs.m_time.time() < rhs.m_time.time();
|
||||
}
|
||||
|
||||
bool operator>(const ATBTime &lhs, const ATBTime &rhs) noexcept {
|
||||
return lhs.m_time.time() > rhs.m_time.time();
|
||||
}
|
||||
|
||||
bool operator==(const ATBTime &lhs, const ATBTime &rhs) noexcept {
|
||||
return lhs.m_time.time() == rhs.m_time.time();
|
||||
}
|
||||
|
||||
QDataStream &operator<<(QDataStream &out, ATBTime time) {
|
||||
out << time.m_time.time();
|
||||
return out;
|
||||
}
|
||||
|
||||
QDataStream &operator>>(QDataStream &in, ATBTime &time) {
|
||||
QTime t;
|
||||
in >> t;
|
||||
time.m_time.setTime(t);
|
||||
return in;
|
||||
}
|
@@ -26,6 +26,7 @@ QString const CalcState::BELOW_MIN_PARKING_PRICE = "BELOW_MIN_PARKING_PRICE";
|
||||
QString const CalcState::ABOVE_MAX_PARKING_PRICE = "ABOVE_MAX_PARKING_PRICE";
|
||||
QString const CalcState::OVERPAID = "OVERPAID";
|
||||
QString const CalcState::OUTSIDE_ALLOWED_PARKING_TIME = "OUTSIDE_ALLOWED_PARKING_TIME";
|
||||
QString const CalcState::SUCCESS_MAXPRICE = "SUCCESS_MAXPRICE";
|
||||
|
||||
QList<int> CALCULATE_LIBRARY_API get_time_steps(Configuration *cfg) {
|
||||
return Calculator::GetInstance().GetTimeSteps(cfg);
|
||||
@@ -76,6 +77,7 @@ int CALCULATE_LIBRARY_API get_maximal_parkingtime(Configuration const *cfg,
|
||||
if (paymentOptionIndex == -1) {
|
||||
paymentOptionIndex = cfg->getPaymentOptionIndex(permitType);
|
||||
}
|
||||
|
||||
int maxTime = 0;
|
||||
|
||||
switch(permitType) {
|
||||
@@ -682,6 +684,9 @@ CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket(
|
||||
paymentOptionIndex = tariff->getPaymentOptionIndex(permitType.get());
|
||||
}
|
||||
|
||||
tariff->getPaymentOptions(paymentOptionIndex).pop_max_price
|
||||
= tariff->getPaymentOptions(paymentOptionIndex).pop_max_price_save;
|
||||
|
||||
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;
|
||||
|
||||
@@ -752,6 +757,9 @@ CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket(
|
||||
paymentOptionIndex = tariff->getPaymentOptionIndex(permitType);
|
||||
}
|
||||
|
||||
tariff->getPaymentOptions(paymentOptionIndex).pop_max_price
|
||||
= tariff->getPaymentOptions(paymentOptionIndex).pop_max_price_save;
|
||||
|
||||
double minMin = tariff->getPaymentOptions(paymentOptionIndex).pop_min_time;
|
||||
double maxMin = tariff->getPaymentOptions(paymentOptionIndex).pop_max_time;
|
||||
|
||||
@@ -818,6 +826,13 @@ CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket(
|
||||
qCritical() << __func__ << ":" << __LINE__ << " re-computed prepaid-id" << pop_prepaid_option_id;
|
||||
}
|
||||
|
||||
QTime carryOverStart = tariff->TariffCarryOverOptions.find(pop_carry_over_option_id)->second.carryover[weekDay].static_start;
|
||||
int carryOverDuration = tariff->TariffCarryOverOptions.find(pop_carry_over_option_id)->second.carryover[weekDay].duration;
|
||||
|
||||
qCritical() << __func__ << ":" << __LINE__ << " carryOverStart" << carryOverStart.toString(Qt::ISODate);
|
||||
qCritical() << __func__ << ":" << __LINE__ << "carryOverDuration" << carryOverDuration;
|
||||
|
||||
|
||||
QDateTime effectiveStartTime(start_parking_time);
|
||||
|
||||
// handle special days
|
||||
@@ -870,6 +885,9 @@ CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket(
|
||||
}
|
||||
}
|
||||
|
||||
effectiveStartTime.setTime(QTime(effectiveStartTime.time().hour(),
|
||||
effectiveStartTime.time().minute(), 0));
|
||||
|
||||
qCritical() << __func__ << ":" << __LINE__ << "effectiveStartTime:" << effectiveStartTime.toString(Qt::ISODate);
|
||||
|
||||
int const carryOver = tariff->getPaymentOptions(paymentOptionIndex).pop_carry_over;
|
||||
@@ -885,7 +903,7 @@ CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket(
|
||||
|
||||
// handle carry over
|
||||
int minutesUntilCarryOver = effectiveStartTime.time().secsTo(carryOverStart) / 60;
|
||||
if (netto_parking_time > minutesUntilCarryOver) {
|
||||
if ((minutesUntilCarryOver > 0) && (netto_parking_time > minutesUntilCarryOver)) {
|
||||
int const rest = netto_parking_time - minutesUntilCarryOver;
|
||||
QDateTime s(effectiveStartTime);
|
||||
s = s.addSecs(minutesUntilCarryOver * 60);
|
||||
@@ -935,6 +953,8 @@ CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket(
|
||||
//QTime const &tlimit = wd.getTariffCarryOverSettings().parkingTimeLimit();
|
||||
//end_parking_time.setTime(tlimit);
|
||||
|
||||
// max_price neu berechnen
|
||||
|
||||
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);
|
||||
@@ -1071,6 +1091,10 @@ CalcState CALCULATE_LIBRARY_API compute_duration_for_parking_ticket(
|
||||
if (pop_time_step_config == (int)ATBTimeStepConfig::TimeStepConfig::STATIC) {
|
||||
// handle prepaid option
|
||||
QDateTime effectiveStartTime(start_parking_time);
|
||||
|
||||
effectiveStartTime.setTime(QTime(effectiveStartTime.time().hour(),
|
||||
effectiveStartTime.time().minute(), 0));
|
||||
|
||||
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()) {
|
||||
@@ -1087,8 +1111,9 @@ CalcState CALCULATE_LIBRARY_API compute_duration_for_parking_ticket(
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
QString cs = start_parking_time.toString(Qt::ISODate);
|
||||
QDateTime start(start_parking_time);
|
||||
start.setTime(QTime(start.time().hour(), start.time().minute(), 0));
|
||||
QString cs = start.toString(Qt::ISODate);
|
||||
|
||||
std::pair<std::string, QDateTime> p_endTime
|
||||
= Calculator::GetInstance().GetDurationFromCost(
|
||||
@@ -1103,6 +1128,12 @@ CalcState CALCULATE_LIBRARY_API compute_duration_for_parking_ticket(
|
||||
if (endTime == CalcState::SUCCESS) {
|
||||
calcState.setDesc(QString("SUCCESS"));
|
||||
calcState.setStatus(endTime);
|
||||
qCritical() << __func__ << ":" << __LINE__ << "SUCCESS";
|
||||
} else
|
||||
if (endTime == CalcState::SUCCESS_MAXPRICE) {
|
||||
calcState.setDesc(QString("SUCCESS_MAXPRICE"));
|
||||
calcState.setStatus(endTime);
|
||||
qCritical() << __func__ << ":" << __LINE__ << "SUCCESS_MAXPRICE";
|
||||
} else
|
||||
if (endTime == CalcState::ERROR_PARSING_ZONE_NR) {
|
||||
calcState.setStatus(endTime);
|
||||
@@ -1160,8 +1191,14 @@ CalcState CALCULATE_LIBRARY_API compute_duration_for_parking_ticket(
|
||||
} else {
|
||||
ticketEndTime = QDateTime::fromString(endTime,Qt::ISODate);
|
||||
|
||||
ticketEndTime.setTime(QTime(ticketEndTime.time().hour(),
|
||||
ticketEndTime.time().minute(), 0));
|
||||
|
||||
int netto_parking_time = start_parking_time.secsTo(ticketEndTime) / 60;
|
||||
|
||||
qCritical() << __func__ << ":" << __LINE__ << "ticketEndTime:" << ticketEndTime.toString(Qt::ISODate);
|
||||
qCritical() << __func__ << ":" << __LINE__ << "step-config:" << pop_time_step_config;
|
||||
qCritical() << __func__ << ":" << __LINE__ << "netto-parking-time" << netto_parking_time;
|
||||
|
||||
if (!ticketEndTime.isValid()) {
|
||||
calcState.setDesc(QString("ticketEndTime=%1").arg(endTime));
|
||||
@@ -1203,10 +1240,25 @@ CalcState CALCULATE_LIBRARY_API compute_duration_for_parking_ticket(
|
||||
}
|
||||
|
||||
if (carryOverStart.isValid() && carryOverEnd.isValid() && carryOverDuration != -1) {
|
||||
|
||||
// note: in such a case (direct coins) carry-over has been handled
|
||||
// already in GetDurationFromCost()
|
||||
netto_parking_time -= carryOverDuration;
|
||||
qCritical() << __func__ << ":" << __LINE__ << "netto-parking-time" << netto_parking_time;
|
||||
|
||||
// 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
|
||||
if (ticketEndTime.time() == carryOverStart) {
|
||||
qCritical() << __func__ << __LINE__ << "ticketEndTime.time():" << ticketEndTime.time().toString(Qt::ISODate);
|
||||
qCritical() << __func__ << ":" << __LINE__ << " carryOverStart" << carryOverStart.toString(Qt::ISODate);
|
||||
ATBPaymentOption const &po = tariff->getPaymentOptions(paymentOptionIndex);
|
||||
if (po.pop_apply_carry_over_to_ticket_endtime) {
|
||||
ticketEndTime = ticketEndTime.addSecs(carryOverDuration * 60);
|
||||
qCritical() << __func__ << __LINE__ << "ticketEndTime.time():" << ticketEndTime.time().toString(Qt::ISODate);
|
||||
}
|
||||
} else {
|
||||
// qCritical() << __func__ << __LINE__ << "ticketEndTime.time():" << ticketEndTime.time().toString(Qt::ISODate);
|
||||
if (ticketEndTime.time() < carryOverEnd) {
|
||||
@@ -1219,23 +1271,85 @@ CalcState CALCULATE_LIBRARY_API compute_duration_for_parking_ticket(
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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(start_parking_time,
|
||||
ticketEndTime,
|
||||
paymentOptionIndex);
|
||||
bool parkTimeLimitViolated = wd.getTariffCarryOverSettings().parkingTimeLimitExceeded(start_parking_time,
|
||||
ticketEndTime,
|
||||
paymentOptionIndex);
|
||||
if (parkTimeLimitViolated) {
|
||||
//QTime const &tlimit = wd.getTariffCarryOverSettings().parkingTimeLimit();
|
||||
//ticketEndTime.setTime(tlimit);
|
||||
|
||||
QList<int> const &stepList = Calculator::GetInstance().GetTimeSteps(tariff, paymentOptionIndex);
|
||||
|
||||
QDateTime newTicketEndTime = ticketEndTime;
|
||||
|
||||
qCritical() << __func__ << ":" << __LINE__ << "PARK-TIME VIOLATED";
|
||||
|
||||
for (int i = stepList.size() - 1; i > 0; --i) {
|
||||
// qCritical() << __func__ << ":" << __LINE__ << "step[" << i << "]" << stepList.at(i);
|
||||
|
||||
if (netto_parking_time > 0 && stepList.at(i) <= netto_parking_time) {
|
||||
int const diff = stepList.at(i-1) - stepList.at(i);
|
||||
newTicketEndTime = newTicketEndTime.addSecs(diff * 60);
|
||||
|
||||
// qCritical() << __func__ << ":" << __LINE__ << "new-ticket-end-time" << newTicketEndTime.toString(Qt::ISODate);
|
||||
|
||||
parkTimeLimitViolated
|
||||
= wd.getTariffCarryOverSettings()
|
||||
.parkingTimeLimitExceeded(start_parking_time, newTicketEndTime, paymentOptionIndex);
|
||||
|
||||
if (!parkTimeLimitViolated) {
|
||||
|
||||
qCritical() << __func__ << ":" << __LINE__
|
||||
<< "PARK-TIME NOT VIOLATED FOR" << newTicketEndTime.toString(Qt::ISODate);
|
||||
|
||||
int duration = stepList.at(i-1);
|
||||
|
||||
// qCritical() << __func__ << ":" << __LINE__ << "duration" << duration;
|
||||
|
||||
std::multimap<int, ATBDuration>::const_iterator it;
|
||||
for (it = tariff->Duration.cbegin();
|
||||
it != tariff->Duration.cend();
|
||||
++it) {
|
||||
if (duration == it->second.pun_duration) {
|
||||
|
||||
// qCritical() << __func__ << ":" << __LINE__ << "duration" << duration;
|
||||
|
||||
ATBPaymentOption &po = tariff->getPaymentOptions(paymentOptionIndex);
|
||||
int const pop_id = po.pop_id;
|
||||
for (auto[itr, rangeEnd] = tariff->PaymentRate.equal_range(pop_id); itr != rangeEnd; ++itr) {
|
||||
int const durationId = itr->second.pra_payment_unit_id;
|
||||
|
||||
// qCritical() << __func__ << ":" << __LINE__ << "durationId" << durationId << it->second.pun_id;
|
||||
|
||||
// note: for this to work, Duration and PaymentRate must have
|
||||
// exactly the same structure
|
||||
if (durationId == it->second.pun_id) {
|
||||
int const pra_price = itr->second.pra_price;
|
||||
po.pop_max_price = pra_price;
|
||||
|
||||
qCritical() << __func__ << ":" << __LINE__ << "new max-price" << po.pop_max_price;
|
||||
|
||||
// note: ABOVE_MAX_PARKING_TIME would also be possible
|
||||
// but here max-parking-time is dynamic. And for
|
||||
// this dynamic value, opverpaid is actually correct
|
||||
|
||||
calcState.setDesc(CalcState::OVERPAID);
|
||||
calcState.setStatus(CalcState::OVERPAID);
|
||||
return calcState;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
@@ -1255,7 +1369,9 @@ CalcState CALCULATE_LIBRARY_API compute_duration_for_parking_ticket(
|
||||
return calcState.set(CalcState::State::INVALID_START_DATE);
|
||||
}
|
||||
|
||||
return calcState.set(CalcState::State::SUCCESS);
|
||||
//return calcState.set(CalcState::State::SUCCESS);
|
||||
qCritical() << __func__ << ":" << __LINE__ << " calcState" << calcState.toString();
|
||||
return calcState;
|
||||
}
|
||||
|
||||
CalcState CALCULATE_LIBRARY_API compute_duration_for_daily_ticket(parking_tariff_t *tariff,
|
||||
|
@@ -136,6 +136,7 @@ Calculator::GetDurationFromCost(Configuration* cfg,
|
||||
static const PaymentMethod paymentMethodId = Utilities::getPaymentMethodId(cfg);
|
||||
|
||||
bool overPaid = false;
|
||||
bool successMaxPrice = false; // max-price and cost match
|
||||
|
||||
int paymentOptionIndex = getPaymentOptionIndex(*cfg, inputDate);
|
||||
if (paymentOptionIndex == -1) {
|
||||
@@ -273,6 +274,11 @@ Calculator::GetDurationFromCost(Configuration* cfg,
|
||||
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 << "SUCCESS MAX-PARKING-PRICE" << pop_max_price << ", COST" << cost;
|
||||
successMaxPrice = true;
|
||||
}
|
||||
|
||||
if (cost > pop_max_price) {
|
||||
qCritical() << DBG_HEADER << "MAX-PARKING-PRICE" << pop_max_price << ", COST" << cost;
|
||||
if (pop_allow_overpay == false) {
|
||||
@@ -280,6 +286,7 @@ Calculator::GetDurationFromCost(Configuration* cfg,
|
||||
}
|
||||
cost = pop_max_price;
|
||||
overPaid = true;
|
||||
qCritical() << DBG_HEADER << "OVERPAID, MAX-PARKING-PRICE" << pop_max_price << ", COST" << cost;
|
||||
// return CalcState::OVERPAID.toStdString();
|
||||
}
|
||||
|
||||
@@ -447,6 +454,9 @@ Calculator::GetDurationFromCost(Configuration* cfg,
|
||||
if (overPaid) {
|
||||
return std::make_pair(CalcState::OVERPAID.toStdString(), d);
|
||||
}
|
||||
if (successMaxPrice) {
|
||||
return std::make_pair(CalcState::SUCCESS_MAXPRICE.toStdString(), d);
|
||||
}
|
||||
return std::make_pair(d.toString(Qt::ISODate).toStdString(), d);
|
||||
}
|
||||
} else {
|
||||
@@ -523,6 +533,16 @@ Calculator::GetDurationFromCost(Configuration* cfg,
|
||||
|
||||
//qCritical() << DBG_HEADER << "NEW INPUT" << inputDate.toString(Qt::ISODate);
|
||||
|
||||
int const pop_carry_over = cfg->getPaymentOptions(paymentOptionIndex).pop_carry_over;
|
||||
if (pop_carry_over) {
|
||||
int weekDay = inputDate.date().dayOfWeek();
|
||||
int const pop_carry_over_option_id = cfg->getPaymentOptions(paymentOptionIndex).pop_carry_over_option_id;
|
||||
if (pop_carry_over_option_id != -1) {
|
||||
int const carryOverDuration = cfg->TariffCarryOverOptions.find(pop_carry_over_option_id)->second.carryover[weekDay].duration;
|
||||
inputDate = inputDate.addSecs(carryOverDuration * 60);
|
||||
}
|
||||
}
|
||||
|
||||
inputDate = inputDate.addSecs(durationInSecs);
|
||||
#if DEBUG_GET_DURATION_FROM_COST==1
|
||||
qCritical() << DBG_HEADER << "TICKET-END" << inputDate.toString(Qt::ISODate);
|
||||
@@ -561,6 +581,9 @@ Calculator::GetDurationFromCost(Configuration* cfg,
|
||||
if (overPaid) {
|
||||
return std::make_pair(CalcState::OVERPAID.toStdString(), inputDate);
|
||||
}
|
||||
if (successMaxPrice) {
|
||||
return std::make_pair(CalcState::SUCCESS_MAXPRICE.toStdString(), inputDate);
|
||||
}
|
||||
return std::make_pair(s.toStdString(), inputDate);
|
||||
} // if ((double)price == cost) {
|
||||
else {
|
||||
@@ -648,6 +671,9 @@ Calculator::GetDurationFromCost(Configuration* cfg,
|
||||
if (overPaid) {
|
||||
return std::make_pair(CalcState::OVERPAID.toStdString(), end_datetime);
|
||||
}
|
||||
if (successMaxPrice) {
|
||||
return std::make_pair(CalcState::SUCCESS_MAXPRICE.toStdString(), end_datetime);
|
||||
}
|
||||
return std::make_pair(end_datetime.toString(Qt::ISODate).toStdString(), end_datetime);
|
||||
} else {
|
||||
QDateTime const dt = start;
|
||||
@@ -698,6 +724,9 @@ Calculator::GetDurationFromCost(Configuration* cfg,
|
||||
if (overPaid) {
|
||||
return std::make_pair(CalcState::OVERPAID.toStdString(), end_datetime);
|
||||
}
|
||||
if (successMaxPrice) {
|
||||
return std::make_pair(CalcState::SUCCESS_MAXPRICE.toStdString(), end_datetime);
|
||||
}
|
||||
return std::make_pair(end_datetime.toString(Qt::ISODate).toStdString(), end_datetime);
|
||||
}
|
||||
|
||||
@@ -796,6 +825,9 @@ Calculator::GetDurationFromCost(Configuration* cfg,
|
||||
if (overPaid) {
|
||||
return std::make_pair(CalcState::OVERPAID.toStdString(), end_datetime);
|
||||
}
|
||||
if (successMaxPrice) {
|
||||
return std::make_pair(CalcState::SUCCESS_MAXPRICE.toStdString(), end_datetime);
|
||||
}
|
||||
return std::make_pair(end_datetime.toString(Qt::ISODate).toStdString(), end_datetime);
|
||||
}
|
||||
}
|
||||
@@ -840,6 +872,9 @@ Calculator::GetDurationFromCost(Configuration* cfg,
|
||||
if (overPaid) {
|
||||
return std::make_pair(CalcState::OVERPAID.toStdString(), end_datetime);
|
||||
}
|
||||
if (successMaxPrice) {
|
||||
return std::make_pair(CalcState::SUCCESS_MAXPRICE.toStdString(), end_datetime);
|
||||
}
|
||||
return std::make_pair(end_datetime.toString(Qt::ISODate).toStdString(), end_datetime);
|
||||
}
|
||||
|
||||
@@ -874,6 +909,9 @@ Calculator::GetDurationFromCost(Configuration* cfg,
|
||||
if (overPaid) {
|
||||
return std::make_pair(CalcState::OVERPAID.toStdString(), end_datetime);
|
||||
}
|
||||
if (successMaxPrice) {
|
||||
return std::make_pair(CalcState::SUCCESS_MAXPRICE.toStdString(), end_datetime);
|
||||
}
|
||||
return std::make_pair(end_datetime.toString(Qt::ISODate).toStdString(), end_datetime);
|
||||
}
|
||||
|
||||
@@ -993,6 +1031,9 @@ Calculator::GetDurationFromCost(Configuration* cfg,
|
||||
if (overPaid) {
|
||||
return std::make_pair(CalcState::OVERPAID.toStdString(), end_datetime);
|
||||
}
|
||||
if (successMaxPrice) {
|
||||
return std::make_pair(CalcState::SUCCESS_MAXPRICE.toStdString(), end_datetime);
|
||||
}
|
||||
return std::make_pair(end_datetime.toString(Qt::ISODate).toStdString(), end_datetime);
|
||||
}
|
||||
}
|
||||
|
@@ -1000,6 +1000,7 @@ bool Configuration::ParseJson(Configuration* cfg, const char* json)
|
||||
this->currentPaymentOptions.last().pop_min_time = k->value.GetDouble();
|
||||
} else if (strcmp(inner_obj_name, "pop_max_price") == 0) {
|
||||
this->currentPaymentOptions.last().pop_max_price = k->value.GetDouble();
|
||||
this->currentPaymentOptions.last().pop_max_price_save = k->value.GetDouble();
|
||||
} else if (strcmp(inner_obj_name, "pop_max_time") == 0) {
|
||||
this->currentPaymentOptions.last().pop_max_time = k->value.GetDouble();
|
||||
} else if (strcmp(inner_obj_name, "pop_min_price") == 0) {
|
||||
|
@@ -34,7 +34,11 @@ OTHER_FILES += \
|
||||
/opt/ptu5/opt/customer_335/etc/psa_tariff/tariff02.json \
|
||||
/opt/ptu5/opt/customer_249/etc/psa_tariff/tariff01.json \
|
||||
/opt/ptu5/opt/customer_249/etc/psa_tariff/tariff02.json \
|
||||
/opt/ptu5/opt/customer_249/etc/psa_tariff/tariff03.json
|
||||
/opt/ptu5/opt/customer_249/etc/psa_tariff/tariff03.json \
|
||||
/opt/ptu5/opt/customer_249/etc/psa_tariff/tariff04.json \
|
||||
/opt/ptu5/opt/customer_249/etc/psa_tariff/tariff05.json \
|
||||
/opt/ptu5/opt/customer_249/etc/psa_tariff/tariff06.json \
|
||||
/opt/ptu5/opt/customer_249/etc/psa_tariff/tariff07.json
|
||||
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user