Compare commits

...

8 Commits

Author SHA1 Message Date
03dd6c44da Always reset pop_max_price to configured value. 2024-09-30 16:58:23 +02:00
212c792b77 compute_price_for_parking_ticket():
Include opverpaid option in price-computation.
2024-09-30 16:57:18 +02:00
ab3cdb32ae compute_next_timestep():
Restrict time-step-list when time-limit has been reached: +/-_button
	does not move upward anymore.
2024-09-30 16:55:25 +02:00
4f23ab3d68 ComputeCostFromDuration():
Add price when overpaid occurred.
2024-09-30 16:53:25 +02:00
acbc27cfb2 ComputeDurationFromCost():
If overapid or trunctae has been set, then truncated max. parking time
	to time-limit configured in tariff-file.
2024-09-30 16:51:51 +02:00
bcbe95d483 Add hard-coded trauncate flag. 2024-09-30 16:51:02 +02:00
e3bbca86d5 Minor: changed parameter type to non-const. 2024-09-30 16:50:21 +02:00
5868d3b510 Introduce computational state 2024-09-30 16:46:36 +02:00
3 changed files with 110 additions and 14 deletions

View File

@ -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);

View File

@ -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 =

View File

@ -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;