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,
|
||||
int netto_parking_time,
|
||||
int paymentOptionIndex);
|
||||
struct State {
|
||||
bool m_timeLimitReached;
|
||||
uint32_t m_costAtTimeLimit;
|
||||
} m_state;
|
||||
|
||||
protected:
|
||||
explicit Calculator() = default;
|
||||
explicit Calculator() {
|
||||
m_state.m_timeLimitReached = false;
|
||||
m_state.m_costAtTimeLimit = ~0;
|
||||
}
|
||||
|
||||
public:
|
||||
Calculator(Calculator const &other) = delete;
|
||||
@ -40,6 +47,12 @@ public:
|
||||
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) {
|
||||
if (m_timeSteps.size() > 0 && paymentOptionIndex < m_timeSteps.size()) {
|
||||
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,
|
||||
PermitType permitType, bool nextDay = false, bool prepaid = false);
|
||||
|
||||
std::pair<CalcState, QDateTime> ComputeDurationFromCost(Configuration const* 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, QDateTime> ComputeDurationFromCost(Configuration *cfg, QDateTime const &startDatetimePassed, int cost);
|
||||
std::pair<CalcState, std::optional<int>> ComputeCostFromDuration(Configuration *cfg, QDateTime const &startDatetime, QDateTime &endDatetime, int nettoParkingTime);
|
||||
|
||||
// Daily ticket
|
||||
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() 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
|
||||
//std::optional<ATBPaymentOption> paymentOption = tariff->getPaymentOptionForKey(permitType.get());
|
||||
//if (!paymentOption.has_value()) {
|
||||
@ -691,6 +700,8 @@ CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket(
|
||||
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_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);
|
||||
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()) {
|
||||
cost = p.second.value();
|
||||
}
|
||||
@ -1023,6 +1036,10 @@ CalcState CALCULATE_LIBRARY_API compute_duration_for_parking_ticket(
|
||||
double price,
|
||||
QString &duration,
|
||||
PermitType permitType) {
|
||||
|
||||
tariff->getPaymentOptions(0).pop_max_price
|
||||
= tariff->getPaymentOptions(0).pop_max_price_save;
|
||||
|
||||
CalcState calcState;
|
||||
QDate const d(1970, 1, 1);
|
||||
QTime const t(0, 0, 0);
|
||||
@ -1078,6 +1095,9 @@ CalcState CALCULATE_LIBRARY_API compute_duration_for_parking_ticket(
|
||||
QDateTime &ticketEndTime,
|
||||
PermitType permitType)
|
||||
{
|
||||
tariff->getPaymentOptions(0).pop_max_price
|
||||
= tariff->getPaymentOptions(0).pop_max_price_save;
|
||||
|
||||
CalcState calcState;
|
||||
|
||||
bool prepaid = true;
|
||||
@ -1405,6 +1425,9 @@ CalcState CALCULATE_LIBRARY_API compute_duration_for_daily_ticket(parking_tariff
|
||||
QDateTime &ticketEndTime,
|
||||
PermitType /* PermitType */)
|
||||
{
|
||||
tariff->getPaymentOptions(0).pop_max_price
|
||||
= tariff->getPaymentOptions(0).pop_max_price_save;
|
||||
|
||||
CalcState calcState;
|
||||
if (start_parking_time.isValid()) {
|
||||
|
||||
@ -1436,8 +1459,11 @@ CalcState CALCULATE_LIBRARY_API compute_price_for_daily_ticket(
|
||||
QDateTime &endDatetime,
|
||||
PERMIT_TYPE permitType,
|
||||
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 (std::optional<struct price_t> p =
|
||||
|
@ -235,7 +235,7 @@ std::optional<ATBTariffOutOfService> getOutOfService(Configuration const *cfg, Q
|
||||
}
|
||||
|
||||
std::pair<CalcState, QDateTime>
|
||||
Calculator::ComputeDurationFromCost(Configuration const *cfg,
|
||||
Calculator::ComputeDurationFromCost(Configuration *cfg,
|
||||
QDateTime const &startDatetimePassed, // given in local time
|
||||
int cost) {
|
||||
|
||||
@ -328,6 +328,8 @@ Calculator::ComputeDurationFromCost(Configuration const *cfg,
|
||||
qCritical() << __func__ << ":" << __LINE__ << "nettoParktimeForCost" << nettoParktimeForCost;
|
||||
|
||||
bool startDateNotOutOfService = false;
|
||||
bool truncate = true; // TODO
|
||||
// Calculator::GetInstance().setTimeLimitReached(false);
|
||||
|
||||
int cnt = 0;
|
||||
while (++cnt < 10 && netto_parking_time_in_minutes < nettoParktimeForCost) {
|
||||
@ -345,10 +347,64 @@ Calculator::ComputeDurationFromCost(Configuration const *cfg,
|
||||
.arg(free_parking_time_in_minutes);
|
||||
|
||||
if (std::optional<ATBTariffOutOfService> oos = getOutOfService(cfg, dt)) {
|
||||
if (overPaid || startDateNotOutOfService) {
|
||||
return std::make_pair(CalcState(CalcState::State::OVERPAID,
|
||||
CalcState::OVERPAID), dt);
|
||||
if (overPaid) {
|
||||
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]];
|
||||
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,
|
||||
CalcState::OUTSIDE_ALLOWED_PARKING_TIME), dt);
|
||||
} else {
|
||||
@ -463,7 +519,7 @@ Calculator::ComputeDurationFromCost(Configuration const *cfg,
|
||||
}
|
||||
|
||||
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) {
|
||||
|
||||
// TODO
|
||||
@ -517,16 +573,17 @@ Calculator::ComputeCostFromDuration(Configuration const* cfg, QDateTime const &s
|
||||
qCritical() << __func__ << ":" << __LINE__ << "result"
|
||||
<< r.first.toString() << r.second.toString(Qt::ISODate);
|
||||
|
||||
|
||||
returnState = r.first;
|
||||
endDatetime = r.second;
|
||||
|
||||
|
||||
if (returnState.getStatus() == CalcState::State::SUCCESS ||
|
||||
returnState.getStatus() == CalcState::State::SUCCESS_MAXPRICE) {
|
||||
|
||||
endDatetime = r.second;
|
||||
returnState.getStatus() == CalcState::State::SUCCESS_MAXPRICE ||
|
||||
returnState.getStatus() == CalcState::State::OVERPAID) {
|
||||
|
||||
qCritical() << __func__ << ":" << __LINE__ << "--- endDateTime" << endDatetime.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()) {
|
||||
cost = c;
|
||||
|
Loading…
x
Reference in New Issue
Block a user