If out-of-service, use start of out-of-service action as output-date.

This commit is contained in:
Gerhard Hoffmann 2024-10-01 09:23:15 +02:00
parent 03dd6c44da
commit 3109e82ef8

View File

@ -154,14 +154,20 @@ std::optional<ATBTariffPrepaid> getPrepaid(Configuration const *cfg, QDateTime c
std::optional<ATBTariffCarryOver> getCarryOver(Configuration const *cfg, QDateTime const &dt) { std::optional<ATBTariffCarryOver> getCarryOver(Configuration const *cfg, QDateTime const &dt) {
std::optional<ATBTariffCarryOver> value = std::nullopt; std::optional<ATBTariffCarryOver> value = std::nullopt;
int weekDay = dt.date().dayOfWeek(); int weekDay = dt.date().dayOfWeek();
// qCritical() << __func__ << ":" << __LINE__ << dt.toString(Qt::ISODate) << weekDay;
ATBTime inputTime(dt.time()); ATBTime inputTime(dt.time());
auto const &carryOverRange = cfg->TariffCarryOvers.equal_range(weekDay); auto const &carryOverRange = cfg->TariffCarryOvers.equal_range(weekDay);
for (auto i = carryOverRange.first; i != carryOverRange.second; ++i) { for (auto i = carryOverRange.first; i != carryOverRange.second; ++i) {
ATBTariffCarryOver const &carryOver = i->second; ATBTariffCarryOver const &carryOver = i->second;
TimeRange const &carryOverTimeRange = carryOver.m_range; TimeRange const &carryOverTimeRange = carryOver.m_range;
if (inputTime >= carryOverTimeRange.m_start && inputTime < carryOverTimeRange.m_end) { if (inputTime >= carryOverTimeRange.m_start && inputTime < carryOverTimeRange.m_end) {
value = value.value_or(i->second); // qCritical() << __func__ << ":" << __LINE__ << carryOverTimeRange.m_start.toString(Qt::ISODate);
// qCritical() << __func__ << ":" << __LINE__ << carryOverTimeRange.m_end.toString(Qt::ISODate);
value = value.value_or(carryOver);
break; break;
} }
} }
@ -325,14 +331,11 @@ Calculator::ComputeDurationFromCost(Configuration *cfg,
free_parking_time_in_minutes = 0; free_parking_time_in_minutes = 0;
int const nettoParktimeForCost = priceNettoParktime[int(cost)]; int const nettoParktimeForCost = priceNettoParktime[int(cost)];
qCritical() << __func__ << ":" << __LINE__ << "nettoParktimeForCost" << nettoParktimeForCost; qCritical() << __func__ << ":" << __LINE__ << QString("cost=%1 nettoParkTimeForCost=%2").
arg(cost).arg(nettoParktimeForCost);
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 < 1000 && netto_parking_time_in_minutes < nettoParktimeForCost) {
// qCritical() << __func__ << ":" << __LINE__ << "cnt [" << cnt; // qCritical() << __func__ << ":" << __LINE__ << "cnt [" << cnt;
brutto_parking_time_in_minutes = free_parking_time_in_minutes + netto_parking_time_in_minutes; brutto_parking_time_in_minutes = free_parking_time_in_minutes + netto_parking_time_in_minutes;
@ -347,6 +350,8 @@ Calculator::ComputeDurationFromCost(Configuration *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)) {
dt.setTime(QTime(oos.value().m_range.m_start.hour(),
oos.value().m_range.m_start.minute(), 0));
if (overPaid) { if (overPaid) {
QList <int> keys = nettoParktimePrice.keys(); QList <int> keys = nettoParktimePrice.keys();
for (int k = 0; k < keys.size(); ++k) { for (int k = 0; k < keys.size(); ++k) {
@ -370,45 +375,40 @@ Calculator::ComputeDurationFromCost(Configuration *cfg,
} }
return std::make_pair(CalcState(CalcState::State::OVERPAID), dt); return std::make_pair(CalcState(CalcState::State::OVERPAID), dt);
} }
if (startDateNotOutOfService) { qCritical() << __func__ << ":" << __LINE__ << "set time-limit reached";
if (truncate) { qCritical() << __func__ << ":" << __LINE__ << "netto-parking-time" << netto_parking_time_in_minutes;
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]]; Calculator::GetInstance().setTimeLimitReached(true);
qCritical() << __func__ << ":" << __LINE__ << keys[k] << maxPriceForTimeLimit << cost; QList <int> keys = nettoParktimePrice.keys();
// Calculator::GetInstance().setCostAtTimeLimit(nettoParktimePrice[keys[k]]); for (int k = 0; k < keys.size(); ++k) {
if (cost > maxPriceForTimeLimit) { if (keys[k] < netto_parking_time_in_minutes) {
cfg->getPaymentOptions(paymentOptionIndex).pop_max_price = maxPriceForTimeLimit; continue;
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);
} }
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); 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 {
startDateNotOutOfService = true;
} }
if (computationStarted == false) { if (computationStarted == false) {
@ -478,7 +478,7 @@ Calculator::ComputeDurationFromCost(Configuration *cfg,
// qCritical() << __func__ << ":" << __LINE__ << "cnt" << cnt << "]"; // qCritical() << __func__ << ":" << __LINE__ << "cnt" << cnt << "]";
} }
if (cnt >= 10) { if (cnt >= 1000) {
qCritical() << __func__ << ":" << __LINE__ << "BREAK"; qCritical() << __func__ << ":" << __LINE__ << "BREAK";
} }