Compare commits
8 Commits
d4363e71cd
...
03dd6c44da
Author | SHA1 | Date | |
---|---|---|---|
03dd6c44da | |||
212c792b77 | |||
ab3cdb32ae | |||
4f23ab3d68 | |||
acbc27cfb2 | |||
bcbe95d483 | |||
e3bbca86d5 | |||
5868d3b510 |
@ -27,9 +27,16 @@ class Calculator {
|
|||||||
QDateTime const &start,
|
QDateTime const &start,
|
||||||
int netto_parking_time,
|
int netto_parking_time,
|
||||||
int paymentOptionIndex);
|
int paymentOptionIndex);
|
||||||
|
struct State {
|
||||||
|
bool m_timeLimitReached;
|
||||||
|
uint32_t m_costAtTimeLimit;
|
||||||
|
} m_state;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
explicit Calculator() = default;
|
explicit Calculator() {
|
||||||
|
m_state.m_timeLimitReached = false;
|
||||||
|
m_state.m_costAtTimeLimit = ~0;
|
||||||
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Calculator(Calculator const &other) = delete;
|
Calculator(Calculator const &other) = delete;
|
||||||
@ -40,6 +47,12 @@ public:
|
|||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool timeLimitReached() const { return m_state.m_timeLimitReached; }
|
||||||
|
void setTimeLimitReached(bool timeLimitReached) { m_state.m_timeLimitReached = timeLimitReached; }
|
||||||
|
bool costAtTimeLimit() const { return m_state.m_costAtTimeLimit; }
|
||||||
|
void setCostAtTimeLimit(uint32_t cost) { if (m_state.m_costAtTimeLimit > cost) m_state.m_costAtTimeLimit = cost; }
|
||||||
|
void resetCostAtTimeLimit() { m_state.m_costAtTimeLimit = ~0; }
|
||||||
|
|
||||||
void ResetTimeSteps(int paymentOptionIndex) {
|
void ResetTimeSteps(int paymentOptionIndex) {
|
||||||
if (m_timeSteps.size() > 0 && paymentOptionIndex < m_timeSteps.size()) {
|
if (m_timeSteps.size() > 0 && paymentOptionIndex < m_timeSteps.size()) {
|
||||||
m_timeSteps[paymentOptionIndex].clear();
|
m_timeSteps[paymentOptionIndex].clear();
|
||||||
@ -87,8 +100,8 @@ public:
|
|||||||
double GetCostFromDuration(Configuration* cfg, uint8_t vehicle_type, QDateTime &start_datetime, QDateTime & end_datetime, int durationMin,
|
double GetCostFromDuration(Configuration* cfg, uint8_t vehicle_type, QDateTime &start_datetime, QDateTime & end_datetime, int durationMin,
|
||||||
PermitType permitType, bool nextDay = false, bool prepaid = false);
|
PermitType permitType, bool nextDay = false, bool prepaid = false);
|
||||||
|
|
||||||
std::pair<CalcState, QDateTime> ComputeDurationFromCost(Configuration const* cfg, QDateTime const &startDatetimePassed, int cost);
|
std::pair<CalcState, QDateTime> ComputeDurationFromCost(Configuration *cfg, QDateTime const &startDatetimePassed, int cost);
|
||||||
std::pair<CalcState, std::optional<int>> ComputeCostFromDuration(Configuration const* cfg, QDateTime const &startDatetime, QDateTime &endDatetime, int nettoParkingTime);
|
std::pair<CalcState, std::optional<int>> ComputeCostFromDuration(Configuration *cfg, QDateTime const &startDatetime, QDateTime &endDatetime, int nettoParkingTime);
|
||||||
|
|
||||||
// Daily ticket
|
// Daily ticket
|
||||||
QDateTime GetDailyTicketDuration(Configuration* cfg, const QDateTime start_datetime, uint8_t payment_option, bool carry_over);
|
QDateTime GetDailyTicketDuration(Configuration* cfg, const QDateTime start_datetime, uint8_t payment_option, bool carry_over);
|
||||||
|
@ -484,6 +484,15 @@ int CALCULATE_LIBRARY_API compute_next_timestep(parking_tariff_t *tariff, int cu
|
|||||||
qCritical() << __LINE__ << "compute_next_timestep() currentTimeMinutes: " << currentTimeMinutes;
|
qCritical() << __LINE__ << "compute_next_timestep() currentTimeMinutes: " << currentTimeMinutes;
|
||||||
qCritical() << __LINE__ << "compute_next_timestep() up/down (1=up, 0=down): " << UpDown;
|
qCritical() << __LINE__ << "compute_next_timestep() up/down (1=up, 0=down): " << UpDown;
|
||||||
|
|
||||||
|
if (UpDown == 1) {
|
||||||
|
if (Calculator::GetInstance().timeLimitReached()) {
|
||||||
|
qCritical() << __LINE__ << "compute_next_timestep() time limit reached";
|
||||||
|
Calculator::GetInstance().setTimeLimitReached(false);
|
||||||
|
Calculator::GetInstance().resetCostAtTimeLimit();
|
||||||
|
return currentTimeMinutes;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// FIXME
|
// FIXME
|
||||||
//std::optional<ATBPaymentOption> paymentOption = tariff->getPaymentOptionForKey(permitType.get());
|
//std::optional<ATBPaymentOption> paymentOption = tariff->getPaymentOptionForKey(permitType.get());
|
||||||
//if (!paymentOption.has_value()) {
|
//if (!paymentOption.has_value()) {
|
||||||
@ -691,6 +700,8 @@ CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket(
|
|||||||
paymentOptionIndex = tariff->getPaymentOptionIndex(permitType.get());
|
paymentOptionIndex = tariff->getPaymentOptionIndex(permitType.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
qCritical() << __func__ << ":" << __LINE__ << "pop_max_price" << tariff->getPaymentOptions(paymentOptionIndex).pop_max_price;
|
||||||
|
|
||||||
tariff->getPaymentOptions(paymentOptionIndex).pop_max_price
|
tariff->getPaymentOptions(paymentOptionIndex).pop_max_price
|
||||||
= tariff->getPaymentOptions(paymentOptionIndex).pop_max_price_save;
|
= tariff->getPaymentOptions(paymentOptionIndex).pop_max_price_save;
|
||||||
|
|
||||||
@ -973,7 +984,9 @@ CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket(
|
|||||||
Calculator::GetInstance().ComputeCostFromDuration(tariff, start_parking_time, end_parking_time, netto_parking_time);
|
Calculator::GetInstance().ComputeCostFromDuration(tariff, start_parking_time, end_parking_time, netto_parking_time);
|
||||||
CalcState const cs = p.first;
|
CalcState const cs = p.first;
|
||||||
|
|
||||||
if ((cs.getStatus() == CalcState::State::SUCCESS || cs.getStatus() == CalcState::State::SUCCESS_MAXPRICE)) {
|
if ((cs.getStatus() == CalcState::State::SUCCESS ||
|
||||||
|
cs.getStatus() == CalcState::State::SUCCESS_MAXPRICE ||
|
||||||
|
cs.getStatus() == CalcState::State::OVERPAID)) {
|
||||||
if (p.second.has_value()) {
|
if (p.second.has_value()) {
|
||||||
cost = p.second.value();
|
cost = p.second.value();
|
||||||
}
|
}
|
||||||
@ -1023,6 +1036,10 @@ CalcState CALCULATE_LIBRARY_API compute_duration_for_parking_ticket(
|
|||||||
double price,
|
double price,
|
||||||
QString &duration,
|
QString &duration,
|
||||||
PermitType permitType) {
|
PermitType permitType) {
|
||||||
|
|
||||||
|
tariff->getPaymentOptions(0).pop_max_price
|
||||||
|
= tariff->getPaymentOptions(0).pop_max_price_save;
|
||||||
|
|
||||||
CalcState calcState;
|
CalcState calcState;
|
||||||
QDate const d(1970, 1, 1);
|
QDate const d(1970, 1, 1);
|
||||||
QTime const t(0, 0, 0);
|
QTime const t(0, 0, 0);
|
||||||
@ -1078,6 +1095,9 @@ CalcState CALCULATE_LIBRARY_API compute_duration_for_parking_ticket(
|
|||||||
QDateTime &ticketEndTime,
|
QDateTime &ticketEndTime,
|
||||||
PermitType permitType)
|
PermitType permitType)
|
||||||
{
|
{
|
||||||
|
tariff->getPaymentOptions(0).pop_max_price
|
||||||
|
= tariff->getPaymentOptions(0).pop_max_price_save;
|
||||||
|
|
||||||
CalcState calcState;
|
CalcState calcState;
|
||||||
|
|
||||||
bool prepaid = true;
|
bool prepaid = true;
|
||||||
@ -1405,6 +1425,9 @@ CalcState CALCULATE_LIBRARY_API compute_duration_for_daily_ticket(parking_tariff
|
|||||||
QDateTime &ticketEndTime,
|
QDateTime &ticketEndTime,
|
||||||
PermitType /* PermitType */)
|
PermitType /* PermitType */)
|
||||||
{
|
{
|
||||||
|
tariff->getPaymentOptions(0).pop_max_price
|
||||||
|
= tariff->getPaymentOptions(0).pop_max_price_save;
|
||||||
|
|
||||||
CalcState calcState;
|
CalcState calcState;
|
||||||
if (start_parking_time.isValid()) {
|
if (start_parking_time.isValid()) {
|
||||||
|
|
||||||
@ -1436,8 +1459,11 @@ CalcState CALCULATE_LIBRARY_API compute_price_for_daily_ticket(
|
|||||||
QDateTime &endDatetime,
|
QDateTime &endDatetime,
|
||||||
PERMIT_TYPE permitType,
|
PERMIT_TYPE permitType,
|
||||||
struct price_t *price) {// return value
|
struct price_t *price) {// return value
|
||||||
CalcState calcState;
|
|
||||||
|
|
||||||
|
tariff->getPaymentOptions(0).pop_max_price
|
||||||
|
= tariff->getPaymentOptions(0).pop_max_price_save;
|
||||||
|
|
||||||
|
CalcState calcState;
|
||||||
|
|
||||||
if (startDatetime.isValid()) {
|
if (startDatetime.isValid()) {
|
||||||
if (std::optional<struct price_t> p =
|
if (std::optional<struct price_t> p =
|
||||||
|
@ -235,7 +235,7 @@ std::optional<ATBTariffOutOfService> getOutOfService(Configuration const *cfg, Q
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::pair<CalcState, QDateTime>
|
std::pair<CalcState, QDateTime>
|
||||||
Calculator::ComputeDurationFromCost(Configuration const *cfg,
|
Calculator::ComputeDurationFromCost(Configuration *cfg,
|
||||||
QDateTime const &startDatetimePassed, // given in local time
|
QDateTime const &startDatetimePassed, // given in local time
|
||||||
int cost) {
|
int cost) {
|
||||||
|
|
||||||
@ -328,6 +328,8 @@ Calculator::ComputeDurationFromCost(Configuration const *cfg,
|
|||||||
qCritical() << __func__ << ":" << __LINE__ << "nettoParktimeForCost" << nettoParktimeForCost;
|
qCritical() << __func__ << ":" << __LINE__ << "nettoParktimeForCost" << nettoParktimeForCost;
|
||||||
|
|
||||||
bool startDateNotOutOfService = false;
|
bool startDateNotOutOfService = false;
|
||||||
|
bool truncate = true; // TODO
|
||||||
|
// Calculator::GetInstance().setTimeLimitReached(false);
|
||||||
|
|
||||||
int cnt = 0;
|
int cnt = 0;
|
||||||
while (++cnt < 10 && netto_parking_time_in_minutes < nettoParktimeForCost) {
|
while (++cnt < 10 && netto_parking_time_in_minutes < nettoParktimeForCost) {
|
||||||
@ -345,10 +347,64 @@ Calculator::ComputeDurationFromCost(Configuration const *cfg,
|
|||||||
.arg(free_parking_time_in_minutes);
|
.arg(free_parking_time_in_minutes);
|
||||||
|
|
||||||
if (std::optional<ATBTariffOutOfService> oos = getOutOfService(cfg, dt)) {
|
if (std::optional<ATBTariffOutOfService> oos = getOutOfService(cfg, dt)) {
|
||||||
if (overPaid || startDateNotOutOfService) {
|
if (overPaid) {
|
||||||
return std::make_pair(CalcState(CalcState::State::OVERPAID,
|
QList <int> keys = nettoParktimePrice.keys();
|
||||||
CalcState::OVERPAID), dt);
|
for (int k = 0; k < keys.size(); ++k) {
|
||||||
|
if (keys[k] < netto_parking_time_in_minutes) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
int const maxPriceForTimeLimit = nettoParktimePrice[keys[k]];
|
||||||
|
if (cost > maxPriceForTimeLimit) {
|
||||||
|
cfg->getPaymentOptions(paymentOptionIndex).pop_max_price = maxPriceForTimeLimit;
|
||||||
|
|
||||||
|
CalcState cs(CalcState::State::OVERPAID);
|
||||||
|
return std::make_pair(cs, dt);
|
||||||
|
}
|
||||||
|
if (cost == maxPriceForTimeLimit) {
|
||||||
|
cfg->getPaymentOptions(paymentOptionIndex).pop_max_price = maxPriceForTimeLimit;
|
||||||
|
|
||||||
|
CalcState cs(CalcState::State::SUCCESS_MAXPRICE);
|
||||||
|
return std::make_pair(cs, dt);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return std::make_pair(CalcState(CalcState::State::OVERPAID), dt);
|
||||||
}
|
}
|
||||||
|
if (startDateNotOutOfService) {
|
||||||
|
if (truncate) {
|
||||||
|
qCritical() << __func__ << ":" << __LINE__ << "set time-limit reached";
|
||||||
|
qCritical() << __func__ << ":" << __LINE__ << "netto-parking-time" << netto_parking_time_in_minutes;
|
||||||
|
Calculator::GetInstance().setTimeLimitReached(true);
|
||||||
|
QList <int> keys = nettoParktimePrice.keys();
|
||||||
|
for (int k = 0; k < keys.size(); ++k) {
|
||||||
|
if (keys[k] < netto_parking_time_in_minutes) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
int const maxPriceForTimeLimit = nettoParktimePrice[keys[k]];
|
||||||
|
qCritical() << __func__ << ":" << __LINE__ << keys[k] << maxPriceForTimeLimit << cost;
|
||||||
|
// Calculator::GetInstance().setCostAtTimeLimit(nettoParktimePrice[keys[k]]);
|
||||||
|
if (cost > maxPriceForTimeLimit) {
|
||||||
|
cfg->getPaymentOptions(paymentOptionIndex).pop_max_price = maxPriceForTimeLimit;
|
||||||
|
|
||||||
|
CalcState cs(CalcState::State::OVERPAID);
|
||||||
|
return std::make_pair(cs, dt);
|
||||||
|
}
|
||||||
|
if (cost == maxPriceForTimeLimit) {
|
||||||
|
cfg->getPaymentOptions(paymentOptionIndex).pop_max_price = maxPriceForTimeLimit;
|
||||||
|
|
||||||
|
CalcState cs(CalcState::State::SUCCESS_MAXPRICE);
|
||||||
|
return std::make_pair(cs, dt);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
qCritical() << __func__ << ":" << __LINE__ << "DT" << dt.toString(Qt::ISODate);
|
||||||
|
return std::make_pair(CalcState(CalcState::State::SUCCESS), dt);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
qCritical() << __func__ << ":" << __LINE__ << "outside allowed parking time" << dt.toString(Qt::ISODate);
|
||||||
|
|
||||||
return std::make_pair(CalcState(CalcState::State::OUTSIDE_ALLOWED_PARKING_TIME,
|
return std::make_pair(CalcState(CalcState::State::OUTSIDE_ALLOWED_PARKING_TIME,
|
||||||
CalcState::OUTSIDE_ALLOWED_PARKING_TIME), dt);
|
CalcState::OUTSIDE_ALLOWED_PARKING_TIME), dt);
|
||||||
} else {
|
} else {
|
||||||
@ -463,7 +519,7 @@ Calculator::ComputeDurationFromCost(Configuration const *cfg,
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::pair<CalcState, std::optional<int>>
|
std::pair<CalcState, std::optional<int>>
|
||||||
Calculator::ComputeCostFromDuration(Configuration const* cfg, QDateTime const &startDatetime,
|
Calculator::ComputeCostFromDuration(Configuration *cfg, QDateTime const &startDatetime,
|
||||||
QDateTime &endDatetime, int nettoParkingTime) {
|
QDateTime &endDatetime, int nettoParkingTime) {
|
||||||
|
|
||||||
// TODO
|
// TODO
|
||||||
@ -517,16 +573,17 @@ Calculator::ComputeCostFromDuration(Configuration const* cfg, QDateTime const &s
|
|||||||
qCritical() << __func__ << ":" << __LINE__ << "result"
|
qCritical() << __func__ << ":" << __LINE__ << "result"
|
||||||
<< r.first.toString() << r.second.toString(Qt::ISODate);
|
<< r.first.toString() << r.second.toString(Qt::ISODate);
|
||||||
|
|
||||||
|
|
||||||
returnState = r.first;
|
returnState = r.first;
|
||||||
|
endDatetime = r.second;
|
||||||
|
|
||||||
|
|
||||||
if (returnState.getStatus() == CalcState::State::SUCCESS ||
|
if (returnState.getStatus() == CalcState::State::SUCCESS ||
|
||||||
returnState.getStatus() == CalcState::State::SUCCESS_MAXPRICE) {
|
returnState.getStatus() == CalcState::State::SUCCESS_MAXPRICE ||
|
||||||
|
returnState.getStatus() == CalcState::State::OVERPAID) {
|
||||||
endDatetime = r.second;
|
|
||||||
|
|
||||||
qCritical() << __func__ << ":" << __LINE__ << "--- endDateTime" << endDatetime.toString(Qt::ISODate);
|
qCritical() << __func__ << ":" << __LINE__ << "--- endDateTime" << endDatetime.toString(Qt::ISODate);
|
||||||
qCritical() << __func__ << ":" << __LINE__ << "------ r.second" << r.second.toString(Qt::ISODate);
|
qCritical() << __func__ << ":" << __LINE__ << "------ r.second" << r.second.toString(Qt::ISODate);
|
||||||
|
qCritical() << __func__ << ":" << __LINE__ << "status" << returnState.toString() << (int)returnState.getStatus();
|
||||||
|
|
||||||
if (!endDatetime.isNull() && endDatetime.isValid()) {
|
if (!endDatetime.isNull() && endDatetime.isValid()) {
|
||||||
cost = c;
|
cost = c;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user