Merge branch 'kleipeda-experimental' of /home/siegert/atbfs01entwicklung/Elektronik/PTU/git_bare_repos/libmobilisis-calc into kleipeda-experimental

This commit is contained in:
Siegfried Siegert 2024-08-02 11:55:12 +02:00
commit f946cd13e4
Signed by: SiegfriedSiegert
GPG Key ID: 68371E015E8F0B03
3 changed files with 49 additions and 23 deletions

View File

@ -508,10 +508,12 @@ int CALCULATE_LIBRARY_API compute_next_timestep(parking_tariff_t *tariff, int cu
// without given YearPeriod, SpecialDays and SpecialDaysWorktime // without given YearPeriod, SpecialDays and SpecialDaysWorktime
if ((paymentMethodId == PaymentMethod::Steps) || if ((paymentMethodId == PaymentMethod::Steps) ||
// progressive tariff: e.g. Neuhauser, Kirchdorf (743) // progressive tariff: e.g. Neuhauser, Kirchdorf (743)
(paymentMethodId == PaymentMethod::Progressive)) (paymentMethodId == PaymentMethod::Progressive) ||
// (paymentMethodId == PaymentMethod::Degressive)) degressive tariff: e.g. Fuchs Technik (500) // degressive tariff: e.g. Fuchs Technik (500)
(paymentMethodId == PaymentMethod::Degressive))
{ {
QList<int> &stepList = Calculator::GetInstance().GetTimeSteps(tariff, paymentOptionIndex); QList<int> &stepList = Calculator::GetInstance().GetTimeSteps(tariff, paymentOptionIndex);
int const size = stepList.size(); int const size = stepList.size();
if (size == 0) { if (size == 0) {
qCritical() << "compute_next_timestep() *ERROR empty step-list*"; qCritical() << "compute_next_timestep() *ERROR empty step-list*";
@ -769,17 +771,19 @@ CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket(
QList<int> tlist = Calculator::GetInstance().GetTimeSteps(tariff); QList<int> tlist = Calculator::GetInstance().GetTimeSteps(tariff);
Q_UNUSED(tlist); Q_UNUSED(tlist);
// compute cost (price)
cost = Calculator::GetInstance().GetCostFromDuration(tariff, start_parking_time, netto_parking_time, paymentOptionIndex); cost = Calculator::GetInstance().GetCostFromDuration(tariff, start_parking_time, netto_parking_time, paymentOptionIndex);
int weekDay = start_parking_time.date().dayOfWeek(); int weekDay = start_parking_time.date().dayOfWeek();
int pop_carry_over_option_id = tariff->getPaymentOptions(paymentOptionIndex).pop_carry_over_option_id; int pop_carry_over_option_id = tariff->getPaymentOptions(paymentOptionIndex).pop_carry_over_option_id;
qCritical() << __func__ << __LINE__ << "configured carry-over-id" << pop_carry_over_option_id;
std::optional<ATBPeriodYear> yperiod = Utilities::GetYearPeriodActive(tariff, start_parking_time); std::optional<ATBPeriodYear> yperiod = Utilities::GetYearPeriodActive(tariff, start_parking_time);
if (yperiod.has_value()) { if (yperiod.has_value()) {
ATBPeriodYear const &period = yperiod.value(); ATBPeriodYear const &period = yperiod.value();
pop_carry_over_option_id = period.pye_id; pop_carry_over_option_id = period.pye_id;
qCritical() << __func__ << __LINE__ << "re-computed carry-over-id" << pop_carry_over_option_id;
} }
qCritical() << __func__ << __LINE__ << "carryOver-id" << pop_carry_over_option_id;
QTime const carryOverStart = tariff->TariffCarryOverOptions.find(pop_carry_over_option_id)->second.carryover[weekDay].static_start; QTime const carryOverStart = tariff->TariffCarryOverOptions.find(pop_carry_over_option_id)->second.carryover[weekDay].static_start;
int const carryOverDuration = tariff->TariffCarryOverOptions.find(pop_carry_over_option_id)->second.carryover[weekDay].duration; int const carryOverDuration = tariff->TariffCarryOverOptions.find(pop_carry_over_option_id)->second.carryover[weekDay].duration;
@ -793,6 +797,9 @@ CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket(
std::optional<ATBPrepaid> prepaidOption = tariff->getPrepaidType(prepaid_option_id); std::optional<ATBPrepaid> prepaidOption = tariff->getPrepaidType(prepaid_option_id);
if (prepaidOption.has_value()) { if (prepaidOption.has_value()) {
ATBPrepaid const &p = prepaidOption.value(); ATBPrepaid const &p = prepaidOption.value();
if (p.never) {
qCritical() << __func__ << __LINE__ << "prepaid: no";
} else {
if (start_parking_time.time() < p.static_end) { // static_end: e.g. 08:00:00 if (start_parking_time.time() < p.static_end) { // static_end: e.g. 08:00:00
effectiveStartTime.setTime(p.static_end); effectiveStartTime.setTime(p.static_end);
} else } else
@ -800,6 +807,7 @@ CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket(
effectiveStartTime.setTime(p.static_start); effectiveStartTime.setTime(p.static_start);
} }
} }
}
// handle carry over // handle carry over
int minutesUntilCarryOver = effectiveStartTime.time().secsTo(carryOverStart) / 60; int minutesUntilCarryOver = effectiveStartTime.time().secsTo(carryOverStart) / 60;
@ -841,6 +849,12 @@ CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket(
return calcState.set(CalcState::State::INVALID_START_DATE); return calcState.set(CalcState::State::INVALID_START_DATE);
} }
if (end_parking_time.time().hour() == 0 && end_parking_time.time().minute() == 0) {
end_parking_time = end_parking_time.addDays(-1);
end_parking_time.setTime(QTime(23, 59, 0));
}
qCritical() << __func__ << __LINE__ << "end_parking_time" << end_parking_time.toString(Qt::ISODate);
return calcState.set(CalcState::State::SUCCESS); return calcState.set(CalcState::State::SUCCESS);
} }

View File

@ -1018,7 +1018,8 @@ uint32_t Calculator::GetCostFromDuration(Configuration * cfg,
if (paymentMethodId == PaymentMethod::Steps || if (paymentMethodId == PaymentMethod::Steps ||
paymentMethodId == PaymentMethod::Degressive) { paymentMethodId == PaymentMethod::Degressive) {
int const timeStepInMinutes = start.secsTo(end) / 60; int const timeStepInMinutes = start.secsTo(end) / 60;
QList<int> tlist = Calculator::GetInstance().GetTimeSteps(cfg, paymentOptionIndex, start);
qCritical() << DBG_HEADER << "timeStepList" << timeStepInMinutes << tlist;
qCritical() << DBG_HEADER << "timeStepInMinutes" << timeStepInMinutes << start.toString(Qt::ISODate); qCritical() << DBG_HEADER << "timeStepInMinutes" << timeStepInMinutes << start.toString(Qt::ISODate);
return GetPriceForTimeStep(cfg, timeStepInMinutes, paymentOptionIndex); return GetPriceForTimeStep(cfg, timeStepInMinutes, paymentOptionIndex);
@ -2809,11 +2810,13 @@ uint32_t Calculator::GetPriceForTimeStep(Configuration *cfg, int timeStep, int p
// paymentOptionIndex = 1; // paymentOptionIndex = 1;
int const pop_id = cfg->getPaymentOptions(paymentOptionIndex).pop_id; int const pop_id = cfg->getPaymentOptions(paymentOptionIndex).pop_id;
int const pop_accumulate_durations = cfg->getPaymentOptions(paymentOptionIndex).pop_accumulate_durations;
int const pop_accumulate_prices = cfg->getPaymentOptions(paymentOptionIndex).pop_accumulate_prices; int const pop_accumulate_prices = cfg->getPaymentOptions(paymentOptionIndex).pop_accumulate_prices;
uint32_t price = 0; uint32_t price = 0;
int pun_duration = 0;
//qCritical() << "(" << __func__ << ":" << __LINE__ << ") paymentOptionIndex" << paymentOptionIndex; qCritical() << "(" << __func__ << ":" << __LINE__ << ") paymentOptionIndex" << paymentOptionIndex;
//qCritical() << "(" << __func__ << ":" << __LINE__ << ") timeStep" << timeStep; //qCritical() << "(" << __func__ << ":" << __LINE__ << ") timeStep" << timeStep;
//qCritical() << "(" << __func__ << ":" << __LINE__ << ") pop_id" << pop_id; //qCritical() << "(" << __func__ << ":" << __LINE__ << ") pop_id" << pop_id;
@ -2827,19 +2830,25 @@ uint32_t Calculator::GetPriceForTimeStep(Configuration *cfg, int timeStep, int p
//qCritical() << "(" << __func__ << ":" << __LINE__ << ") pun_id" << pun_id; //qCritical() << "(" << __func__ << ":" << __LINE__ << ") pun_id" << pun_id;
//qCritical() << "(" << __func__ << ":" << __LINE__ << ") pun_unit_id" << payment_unit_id; //qCritical() << "(" << __func__ << ":" << __LINE__ << ") pun_unit_id" << payment_unit_id;
int const pun_duration = cfg->Duration.find(payment_unit_id)->second.pun_duration; if (pop_accumulate_durations) {
//int const pun_duration = cfg->Duration.find(2)->second.pun_duration; pun_duration += cfg->Duration.find(payment_unit_id)->second.pun_duration;
} else {
pun_duration = cfg->Duration.find(payment_unit_id)->second.pun_duration;
}
if (pop_accumulate_prices) { if (pop_accumulate_prices) {
price += itr->second.pra_price; price += itr->second.pra_price;
} else { } else {
price = (uint32_t)(itr->second.pra_price); price = (uint32_t)(itr->second.pra_price);
} }
//qCritical() << "(" << __func__ << ":" << __LINE__ << ") price" << price; if (DBG_LEVEL >= DBG_DEBUG) {
//qCritical() << "(" << __func__ << ":" << __LINE__ << ") pun_id" << pun_id; qCritical() << "(" << __func__ << ":" << __LINE__ << ") price" << price;
//qCritical() << "(" << __func__ << ":" << __LINE__ << ") pun_unit_id" << payment_unit_id; qCritical() << "(" << __func__ << ":" << __LINE__ << ") pun_id" << pun_id;
//qCritical() << "(" << __func__ << ":" << __LINE__ << ") pun_duration" << pun_duration; qCritical() << "(" << __func__ << ":" << __LINE__ << ") pun_unit_id" << payment_unit_id;
//qCritical() << "(" << __func__ << ":" << __LINE__ << ") timeStep" << timeStep; qCritical() << "(" << __func__ << ":" << __LINE__ << ") pun_duration" << pun_duration;
qCritical() << "(" << __func__ << ":" << __LINE__ << ") timeStep" << timeStep;
}
if (timeStep == pun_duration) { if (timeStep == pun_duration) {
qCritical() << "(" << __func__ << ":" << __LINE__ << ") return price" << price; qCritical() << "(" << __func__ << ":" << __LINE__ << ") return price" << price;

View File

@ -47,11 +47,11 @@ extern "C" char* strptime(const char* s,
#define NEUHAUSER_CHRISTOPH_REISEN (0) #define NEUHAUSER_CHRISTOPH_REISEN (0)
#define NEUHAUSER_PERNEGG_AN_DER_MUR (0) #define NEUHAUSER_PERNEGG_AN_DER_MUR (0)
#define NEUHAUSER_STOCKERAU (0) #define NEUHAUSER_STOCKERAU (0)
#define KLEIPEDA_LITAUEN (1) #define KLEIPEDA_LITAUEN (0)
#define SEXTEN (0) #define SEXTEN (0)
#define SCHNALS_LEITER_KIRCHL (0) #define SCHNALS_LEITER_KIRCHL (0)
#define SCHNALS_STAUMAUER (SCHNALS_LEITER_KIRCHL) #define SCHNALS_STAUMAUER (SCHNALS_LEITER_KIRCHL)
#define VALSER_ALM (0) #define VALSER_ALM (1)
#if NEUHAUSER_KIRCHDORF==1 #if NEUHAUSER_KIRCHDORF==1
static bool test_neuhauser_kirchdorf(int step, double cost) { static bool test_neuhauser_kirchdorf(int step, double cost) {
@ -919,22 +919,24 @@ int main() {
s.setTime(QTime(12, 0, 0)); s.setTime(QTime(12, 0, 0));
int minimal_parking_price = get_minimal_parkingprice(&cfg, int minimal_parking_price = get_minimal_parkingprice(&cfg,
PermitType(PERMIT_TYPE::SHORT_TERM_PARKING), PermitType(PERMIT_TYPE::SHORT_TERM_PARKING_PKW),
paymentOptionIndex, s); paymentOptionIndex, s);
#if 0
qCritical() << "minimal parking price" << minimal_parking_price; qCritical() << "minimal parking price" << minimal_parking_price;
for (int i = 0; i < 8; ++i) { for (int i = 0; i < 8; ++i) {
calcState = compute_duration_for_parking_ticket(&cfg, s, calcState = compute_duration_for_parking_ticket(&cfg, s,
(double)minimal_parking_price + i*800, (double)minimal_parking_price + i*800,
end, PermitType(PERMIT_TYPE::SHORT_TERM_PARKING)); end, PermitType(PERMIT_TYPE::SHORT_TERM_PARKING_PKW));
qCritical() << "RUN" << i << end.toString(Qt::ISODate) << calcState.toString(); qCritical() << "RUN" << i << end.toString(Qt::ISODate) << calcState.toString();
} }
#else
s.setTime(QTime(15, 0, 0)); s.setTime(QTime(15, 0, 0));
minimal_parking_price = get_minimal_parkingprice(&cfg, minimal_parking_price = get_minimal_parkingprice(&cfg,
PermitType(PERMIT_TYPE::SHORT_TERM_PARKING), PermitType(PERMIT_TYPE::SHORT_TERM_PARKING_PKW),
paymentOptionIndex, s); paymentOptionIndex, s);
qCritical() << "minimal parking price" << minimal_parking_price; qCritical() << "minimal parking price" << minimal_parking_price;
@ -942,9 +944,10 @@ int main() {
for (int i = 0; i < 8; ++i) { for (int i = 0; i < 8; ++i) {
calcState = compute_duration_for_parking_ticket(&cfg, s, calcState = compute_duration_for_parking_ticket(&cfg, s,
(double)minimal_parking_price + i*800, (double)minimal_parking_price + i*800,
end, PermitType(PERMIT_TYPE::SHORT_TERM_PARKING)); end, PermitType(PERMIT_TYPE::SHORT_TERM_PARKING_PKW));
qCritical() << "RUN" << i << end.toString(Qt::ISODate) << calcState.toString(); qCritical() << "RUN" << i << end.toString(Qt::ISODate) << calcState.toString();
} }
#endif
} }
} }
#endif #endif