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-07-31 08:06:45 +02:00
commit 0d0d34cb87
Signed by: SiegfriedSiegert
GPG Key ID: 68371E015E8F0B03
4 changed files with 302 additions and 181 deletions

View File

@ -94,6 +94,40 @@ int CALCULATE_LIBRARY_API get_minimal_parkingprice(Configuration *cfg,
int minPrice = -1; int minPrice = -1;
paymentOptionIndex = cfg->getPaymentOptionIndex(permitType); paymentOptionIndex = cfg->getPaymentOptionIndex(permitType);
int payment_method_id = cfg->getPaymentOptions(paymentOptionIndex).pop_payment_method_id;
if (payment_method_id == PaymentMethod::Degressive) {
// Degressive: new for Fuchs Technik (500), ValserAlm (Fane):
// the minimal price has to be calculated, in cannot be hard coded into
// the tariff file.
// The working times have a reference into the payment rates. Two special
// entries (with the numbers 1000/1001) point to the respective prices.
switch(permitType) {
default: {
// find the correct work time range
int weekDay = start.date().dayOfWeek();
std::optional<QVector<ATBWeekDaysWorktime>> const &wd = cfg->getAllWeekDayWorkTimes();
if (wd.has_value()) {
QVector<ATBWeekDaysWorktime> const &vec = wd.value();
for (int i = 0; i < vec.size(); ++i) {
ATBWeekDaysWorktime const &wt = vec[i];
if (wt.pwd_period_day_in_week_id == weekDay) {
if (start.time() >= QTime::fromString(QString::fromStdString(wt.pwd_time_from), Qt::ISODate)
&& start.time() <= QTime::fromString(QString::fromStdString(wt.pwd_time_to), Qt::ISODate)) {
// found worktime range
int pop_id = wt.pwd_pop_id; // 1000 or 1001
for (auto[itr, rangeEnd] = cfg->PaymentRate.equal_range(pop_id); itr != rangeEnd; ++itr) {
i = vec.size(); // to leave outer loop
minPrice = itr->second.pra_price; // this is now the minimal price
break;
}
}
}
}
}
}
}
} else {
switch(permitType) { switch(permitType) {
case PERMIT_TYPE::SHORT_TERM_PARKING: { // e.g. szeged (customer_281) case PERMIT_TYPE::SHORT_TERM_PARKING: { // e.g. szeged (customer_281)
minPrice = cfg->getPaymentOptions(paymentOptionIndex).pop_min_price; minPrice = cfg->getPaymentOptions(paymentOptionIndex).pop_min_price;
@ -110,6 +144,7 @@ int CALCULATE_LIBRARY_API get_minimal_parkingprice(Configuration *cfg,
default: default:
minPrice = cfg->getPaymentOptions(paymentOptionIndex).pop_min_price; minPrice = cfg->getPaymentOptions(paymentOptionIndex).pop_min_price;
} }
}
return minPrice; return minPrice;
} }
@ -767,15 +802,25 @@ CalcState CALCULATE_LIBRARY_API compute_duration_for_parking_ticket(
if (start.isValid()) { if (start.isValid()) {
QString cs = start.toString(Qt::ISODate); QString cs = start.toString(Qt::ISODate);
bool prepaid = true;
int paymentOptionIndex = tariff->getPaymentOptionIndex(permitType);
int prepaid_option_id = tariff->getPaymentOptions(paymentOptionIndex).pop_prepaid_option_id;
if (prepaid_option_id == 2) { // see tariff03.json for 502: 2 means no prepaid-option
prepaid = false;
}
bool const nextDay = false;
// DEBUG // DEBUG
qCritical() << "compute_duration_for_parking_ticket(): "; qCritical() << "compute_duration_for_parking_ticket(1): ";
qCritical() << " payment option index: " << paymentOptionIndex;
qCritical() << " prepaid: " << prepaid;
qCritical() << " start (cs): " << cs; qCritical() << " start (cs): " << cs;
qCritical() << " price: " << price; qCritical() << " price: " << price;
duration = Calculator::GetInstance().GetDurationFromCost(tariff, duration = Calculator::GetInstance().GetDurationFromCost(tariff,
tariff->getPaymentOptions().pop_payment_method_id, tariff->getPaymentOptions(paymentOptionIndex).pop_payment_method_id,
cs.toLocal8Bit().constData(), cs.toLocal8Bit().constData(),
price, false, true).c_str(); price, permitType, nextDay, prepaid).c_str();
QDateTime d = QDateTime::fromString(duration, Qt::ISODate); QDateTime d = QDateTime::fromString(duration, Qt::ISODate);
if (!d.isValid()) { if (!d.isValid()) {
calcState.setDesc(QString("ticketEndTime=%1").arg(duration)); calcState.setDesc(QString("ticketEndTime=%1").arg(duration));
@ -796,16 +841,28 @@ CalcState CALCULATE_LIBRARY_API compute_duration_for_parking_ticket(
PermitType permitType) PermitType permitType)
{ {
CalcState calcState; CalcState calcState;
bool prepaid = true;
int paymentOptionIndex = tariff->getPaymentOptionIndex(permitType);
int prepaid_option_id = tariff->getPaymentOptions(paymentOptionIndex).pop_prepaid_option_id;
if (prepaid_option_id == 2) {
prepaid = false;
}
bool const nextDay = false;
// DEBUG
qCritical() << "compute_duration_for_parking_ticket(2): ";
qCritical() << " payment option index: " << paymentOptionIndex;
qCritical() << " prepaid: " << prepaid;
qCritical() << " price: " << price;
if (start_parking_time.isValid()) { if (start_parking_time.isValid()) {
QString cs = start_parking_time.toString(Qt::ISODate); QString cs = start_parking_time.toString(Qt::ISODate);
QString endTime = Calculator::GetInstance().GetDurationFromCost( QString endTime = Calculator::GetInstance().GetDurationFromCost(
tariff, tariff,
tariff->getPaymentOptions().pop_payment_method_id, tariff->getPaymentOptions().pop_payment_method_id,
cs.toLocal8Bit().constData(), cs.toLocal8Bit().constData(),
price, price, permitType, nextDay, prepaid).c_str();
permitType,
false,
true).c_str();
if (endTime == CalcState::SUCCESS) { if (endTime == CalcState::SUCCESS) {
calcState.setDesc(QString("SUCCESS")); calcState.setDesc(QString("SUCCESS"));

View File

@ -133,12 +133,91 @@ std::string Calculator::GetDurationFromCost(Configuration* cfg,
QDateTime inputDate = QDateTime::fromString(startDatetimePassed, Qt::ISODate); QDateTime inputDate = QDateTime::fromString(startDatetimePassed, Qt::ISODate);
inputDate.setTime(QTime(inputDate.time().hour(), inputDate.time().minute(), 0)); inputDate.setTime(QTime(inputDate.time().hour(), inputDate.time().minute(), 0));
static const PaymentMethod paymentMethodId = Utilities::getPaymentMethodId(cfg); static const PaymentMethod paymentMethodId = Utilities::getPaymentMethodId(cfg);
int const paymentOptionIndex = cfg->getPaymentOptionIndex(permitType.get());
qCritical() << DBG_HEADER << " start" << inputDate.toString(Qt::ISODate); qCritical() << DBG_HEADER << " start:" << inputDate.toString(Qt::ISODate);
qCritical() << DBG_HEADER << "paymentMethodId" << static_cast<int>(paymentMethodId); qCritical() << DBG_HEADER << " option index:" << paymentOptionIndex;
qCritical() << DBG_HEADER << "paymentMethodId:" << static_cast<int>(paymentMethodId);
qCritical() << DBG_HEADER << " prepaid:" << prepaid;
qCritical() << DBG_HEADER << " cost (price):" << cost;
Calculator::GetInstance().GetTimeSteps(cfg, 0, inputDate); QList<int> tsteps = Calculator::GetInstance().GetTimeSteps(cfg, paymentOptionIndex, inputDate);
qCritical() << DBG_HEADER << " time steps:" << tsteps;
if (paymentMethodId == PaymentMethod::Degressive) {
if (prepaid == false) {
int const pop_id = cfg->getPaymentOptions(paymentOptionIndex).pop_id;
int const pop_accumulate_prices = cfg->getPaymentOptions(paymentOptionIndex).pop_accumulate_prices;
int const pop_accumulate_durations = cfg->getPaymentOptions(paymentOptionIndex).pop_accumulate_durations;
// qCritical() << DBG_HEADER << " pop id:" << pop_id;
int price = 0;
int new_price = 0;
int durationInMinutes = 0;
uint32_t duration_previous = 0;
// bool found = false;
for (auto[itr, rangeEnd] = cfg->PaymentRate.equal_range(pop_id); itr != rangeEnd; ++itr) {
int const pra_price = itr->second.pra_price;
int const durationId = itr->second.pra_payment_unit_id;
if (pop_accumulate_prices) {
price += pra_price;
} else {
price = pra_price;
}
//qCritical() << DBG_HEADER << " PRICE" << price << "COST" << cost;
//qCritical() << DBG_HEADER << " duration id" << durationId;
auto search = cfg->Duration.find(durationId);
if (search != cfg->Duration.end()) {
// found now the duration in minutes
// check if we are still inside the working-time-range
ATBDuration duration = search->second;
if (pop_accumulate_prices) {
uint32_t const durationUnit = cfg->Duration.find(durationId)->second.pun_duration;
new_price += pra_price;
// qCritical() << "(" << __func__ << ":" << __LINE__ << ") old price" << price << ", new_price:" << new_price;
if (new_price <= cost) {
duration_previous = durationUnit;
if (pop_accumulate_durations) {
durationInMinutes += durationUnit;
}
//qCritical() << "(" << __func__ << ":" << __LINE__ << ") duration_previous" << duration_previous;
//qCritical() << "(" << __func__ << ":" << __LINE__ << ") duration in minutes" << durationInMinutes;
//qCritical() << "(" << __func__ << ":" << __LINE__ << ") old price" << price << ", new_price:" << new_price;
} else {
//found = true;
//qCritical() << "(" << __func__ << ":" << __LINE__ << ") duration_previous" << duration_previous;
//qCritical() << "(" << __func__ << ":" << __LINE__ << ") duration in minutes" << durationInMinutes;
QString s = inputDate.toString(Qt::ISODate);
QDateTime d(QDateTime::fromString(s, Qt::ISODate));
d = d.addSecs(duration_previous * 60);
//qCritical() << DBG_HEADER << "XXXX" << d;
return d.toString(Qt::ISODate).toStdString();
}
}
if ((double)price == cost) {
//qCritical() << DBG_HEADER << "price" << price << "cost" << cost;
//qCritical() << DBG_HEADER << "duration in minutes" << durationInMinutes;
QString s = inputDate.toString(Qt::ISODate);
QDateTime d(QDateTime::fromString(s, Qt::ISODate));
d = d.addSecs(durationInMinutes * 60);
//qCritical() << DBG_HEADER << "YYYY" << d;
return d.toString(Qt::ISODate).toStdString();
}
}
}
} else {
qCritical() << DBG_HEADER << " TODO";
}
} else
if (paymentMethodId == PaymentMethod::Steps) { if (paymentMethodId == PaymentMethod::Steps) {
if (tariffIs24_7(cfg)) { if (tariffIs24_7(cfg)) {
// use tariff with structure as for instance Schoenau, Koenigsee: // use tariff with structure as for instance Schoenau, Koenigsee:
@ -155,8 +234,6 @@ std::string Calculator::GetDurationFromCost(Configuration* cfg,
} }
} }
int paymentOptionIndex = cfg->getPaymentOptionIndex(permitType.get());
int const pop_id = cfg->getPaymentOptions(paymentOptionIndex).pop_id; int const pop_id = cfg->getPaymentOptions(paymentOptionIndex).pop_id;
int const pop_max_price = cfg->getPaymentOptions(paymentOptionIndex).pop_max_price; int const pop_max_price = cfg->getPaymentOptions(paymentOptionIndex).pop_max_price;
int const pop_min_price = cfg->getPaymentOptions(paymentOptionIndex).pop_min_price; int const pop_min_price = cfg->getPaymentOptions(paymentOptionIndex).pop_min_price;
@ -174,10 +251,7 @@ std::string Calculator::GetDurationFromCost(Configuration* cfg,
// int const pop_pre_paid = 1; // int const pop_pre_paid = 1;
//qCritical() << __func__ << __LINE__;
if (prepaid) { if (prepaid) {
//qCritical() << __func__ << __LINE__;
// no limits on pre-pay-option, i.e. pre-pay-ranges are exactly // no limits on pre-pay-option, i.e. pre-pay-ranges are exactly
// the complements of operational-ranges // the complements of operational-ranges
@ -235,6 +309,8 @@ std::string Calculator::GetDurationFromCost(Configuration* cfg,
} }
} }
} }
} else {
qCritical() << "(" << __func__ << ":" << __LINE__ << "no prepaid";
} }
#if DEBUG_GET_DURATION_FROM_COST==1 #if DEBUG_GET_DURATION_FROM_COST==1
@ -2215,12 +2291,12 @@ QList<int> &Calculator::GetTimeSteps(Configuration *cfg, int paymentOptionIndex,
QDateTime start = s; QDateTime start = s;
start.setTime(QTime(s.time().hour(), s.time().minute(), 0)); start.setTime(QTime(s.time().hour(), s.time().minute(), 0));
int const pop_id = cfg->getPaymentOptions(paymentOptionIndex).pop_id;
if (DBG_LEVEL >= DBG_DEBUG) { if (DBG_LEVEL >= DBG_DEBUG) {
qCritical() << "(" << __func__ << ":" << __LINE__ << ") pop_id:" << pop_id; qCritical() << "(" << __func__ << ":" << __LINE__ << ") start:" << start.toString(Qt::ISODate);
} }
int const pop_id = cfg->getPaymentOptions(paymentOptionIndex).pop_id;
int const pop_carry_over = cfg->getPaymentOptions(paymentOptionIndex).pop_carry_over; int const pop_carry_over = cfg->getPaymentOptions(paymentOptionIndex).pop_carry_over;
int const pop_time_step_config = cfg->getPaymentOptions(paymentOptionIndex).pop_time_step_config; int const pop_time_step_config = cfg->getPaymentOptions(paymentOptionIndex).pop_time_step_config;
int const pop_prepaid_option_id = cfg->getPaymentOptions(paymentOptionIndex).pop_prepaid_option_id; int const pop_prepaid_option_id = cfg->getPaymentOptions(paymentOptionIndex).pop_prepaid_option_id;
@ -2230,7 +2306,8 @@ QList<int> &Calculator::GetTimeSteps(Configuration *cfg, int paymentOptionIndex,
if (DBG_LEVEL >= DBG_DEBUG) { if (DBG_LEVEL >= DBG_DEBUG) {
qCritical() << "(" << __func__ << ":" << __LINE__ << ") start parking time:" << start.toString(Qt::ISODate); qCritical() << "(" << __func__ << ":" << __LINE__ << ") start parking time:" << start.toString(Qt::ISODate);
qCritical() << "(" << __func__ << ":" << __LINE__ << ") payment option id:" << pop_id; qCritical() << "(" << __func__ << ":" << __LINE__ << ") payment option id:" << pop_id;
qCritical() << "(" << __func__ << ":" << __LINE__ << ") time step configuration:" << pop_time_step_config; qCritical() << "(" << __func__ << ":" << __LINE__ << ") payment method id:" << static_cast<int>(paymentMethodId);
qCritical() << "(" << __func__ << ":" << __LINE__ << ") time step config:" << pop_time_step_config;
qCritical() << "(" << __func__ << ":" << __LINE__ << ") prepaid option id:" << pop_prepaid_option_id; qCritical() << "(" << __func__ << ":" << __LINE__ << ") prepaid option id:" << pop_prepaid_option_id;
} }
@ -2249,8 +2326,8 @@ QList<int> &Calculator::GetTimeSteps(Configuration *cfg, int paymentOptionIndex,
// for instance: until 13.59: price 8, from 14:00: price 5, then for the next day: 8 // for instance: until 13.59: price 8, from 14:00: price 5, then for the next day: 8
// for the following days: 8 euros // for the following days: 8 euros
qCritical() << "(" << __func__ << ":" << __LINE__ << ") degressive:"; //qCritical() << "(" << __func__ << ":" << __LINE__ << ") degressive:";
qCritical() << "(" << __func__ << ":" << __LINE__ << ") paymentOptionIndex:" << paymentOptionIndex; //qCritical() << "(" << __func__ << ":" << __LINE__ << ") paymentOptionIndex:" << paymentOptionIndex;
m_timeSteps[paymentOptionIndex].clear(); m_timeSteps[paymentOptionIndex].clear();
// lookup pop_next_id in worktimes; // lookup pop_next_id in worktimes;
@ -2258,7 +2335,7 @@ QList<int> &Calculator::GetTimeSteps(Configuration *cfg, int paymentOptionIndex,
if (w.has_value()) { if (w.has_value()) {
QVector<ATBWeekDaysWorktime> const &vec = w.value(); QVector<ATBWeekDaysWorktime> const &vec = w.value();
if (pop_carry_over == false) { //if (pop_carry_over == false) {
for (int i = 1; i <= vec.size(); ++i) { for (int i = 1; i <= vec.size(); ++i) {
QTime const &from = QTime::fromString(QString::fromStdString(vec[i-1].pwd_time_from), Qt::ISODate); QTime const &from = QTime::fromString(QString::fromStdString(vec[i-1].pwd_time_from), Qt::ISODate);
QString const &toStr = QString::fromStdString(vec[i-1].pwd_time_to); QString const &toStr = QString::fromStdString(vec[i-1].pwd_time_to);
@ -2266,20 +2343,24 @@ QList<int> &Calculator::GetTimeSteps(Configuration *cfg, int paymentOptionIndex,
int weekDayId = vec[i-1].pwd_period_day_in_week_id; int weekDayId = vec[i-1].pwd_period_day_in_week_id;
if (start.date().dayOfWeek() == weekDayId) { if (start.date().dayOfWeek() == weekDayId) {
if (DBG_LEVEL >= DBG_DEBUG) {
qCritical() << "(" << __func__ << ":" << __LINE__ << ")" << weekDayId; qCritical() << "(" << __func__ << ":" << __LINE__ << ")" << weekDayId;
qCritical() << "(" << __func__ << ":" << __LINE__ << ") from" << from.toString(Qt::ISODate); qCritical() << "(" << __func__ << ":" << __LINE__ << ") from" << from.toString(Qt::ISODate);
qCritical() << "(" << __func__ << ":" << __LINE__ << ") to" << to.toString(Qt::ISODate); qCritical() << "(" << __func__ << ":" << __LINE__ << ") to" << to.toString(Qt::ISODate);
qCritical() << "(" << __func__ << ":" << __LINE__ << ") start" << start.toString(Qt::ISODate); qCritical() << "(" << __func__ << ":" << __LINE__ << ") start" << start.toString(Qt::ISODate);
}
if (start.time() >= from && start.time() < to) { if (start.time() >= from && start.time() < to) {
int runtimeInMinutes = (start.time().secsTo(to) / 60); int runtimeInMinutes = (start.time().secsTo(to) / 60);
if (to.hour() == 23 && to.minute() == 59) { if (to.hour() == 23 && to.minute() == 59) {
runtimeInMinutes += 1; runtimeInMinutes += 1;
} }
if (DBG_LEVEL >= DBG_DEBUG) {
qCritical() << "(" << __func__ << ":" << __LINE__ << ") runTimeInMinutes" << runtimeInMinutes; qCritical() << "(" << __func__ << ":" << __LINE__ << ") runTimeInMinutes" << runtimeInMinutes;
qCritical() << "(" << __func__ << ":" << __LINE__ << ") index" << paymentOptionIndex; qCritical() << "(" << __func__ << ":" << __LINE__ << ") index" << paymentOptionIndex;
}
m_timeSteps[paymentOptionIndex] << runtimeInMinutes; // m_timeSteps[paymentOptionIndex] << runtimeInMinutes;
cfg->getPaymentOptions(paymentOptionIndex).pop_min_time = runtimeInMinutes; cfg->getPaymentOptions(paymentOptionIndex).pop_min_time = runtimeInMinutes;
@ -2287,7 +2368,9 @@ QList<int> &Calculator::GetTimeSteps(Configuration *cfg, int paymentOptionIndex,
// int pwd_id = vec[i-1].pwd_id; // int pwd_id = vec[i-1].pwd_id;
// int pwd_next_id = vec[i-1].pwd_next_id; // int pwd_next_id = vec[i-1].pwd_next_id;
if (DBG_LEVEL >= DBG_DEBUG) {
qCritical() << "(" << __func__ << ":" << __LINE__ << ") pop_id" << pop_id; qCritical() << "(" << __func__ << ":" << __LINE__ << ") pop_id" << pop_id;
}
int price = -1; int price = -1;
int durationId = -1; int durationId = -1;
@ -2307,13 +2390,17 @@ QList<int> &Calculator::GetTimeSteps(Configuration *cfg, int paymentOptionIndex,
} }
if (price >= 0 && durationId >= 0) { if (price >= 0 && durationId >= 0) {
if (DBG_LEVEL >= DBG_DEBUG) {
qCritical() << "(" << __func__ << ":" << __LINE__ << ") durationId" << durationId; qCritical() << "(" << __func__ << ":" << __LINE__ << ") durationId" << durationId;
qCritical() << "(" << __func__ << ":" << __LINE__ << ") price" << price; qCritical() << "(" << __func__ << ":" << __LINE__ << ") price" << price;
}
pop_id = cfg->getPaymentOptions(paymentOptionIndex).pop_id; pop_id = cfg->getPaymentOptions(paymentOptionIndex).pop_id;
for (auto[itr, rangeEnd] = cfg->PaymentRate.equal_range(pop_id); itr != rangeEnd; ++itr) { for (auto[itr, rangeEnd] = cfg->PaymentRate.equal_range(pop_id); itr != rangeEnd; ++itr) {
if (durationId == itr->second.pra_payment_unit_id) { if (durationId == itr->second.pra_payment_unit_id) {
itr->second.pra_price = price; itr->second.pra_price = price;
cfg->getPaymentOptions(paymentOptionIndex).pop_min_price = price;
qCritical() << "(" << __func__ << ":" << __LINE__ << ") park min price" << price;
break; break;
} }
} }
@ -2324,15 +2411,16 @@ QList<int> &Calculator::GetTimeSteps(Configuration *cfg, int paymentOptionIndex,
} // if (start.date().dayOfWeek() == weekDayId) { } // if (start.date().dayOfWeek() == weekDayId) {
} // for (int i = 1; i <= vec.size(); ++i) { } // for (int i = 1; i <= vec.size(); ++i) {
// show content: m_timeSteps[paymentOptionIndex].clear();
int runtimeInMinutes = 0;
for (Configuration::TariffDurationType::const_iterator it = cfg->Duration.cbegin(); for (Configuration::TariffDurationType::const_iterator it = cfg->Duration.cbegin();
it != cfg->Duration.cend(); it != cfg->Duration.cend();
++it) { ++it) {
qCritical() << "(" << __func__ << ":" << __LINE__ << ")" runtimeInMinutes += it->second.pun_duration;
<< (*it).first << " => " << (*it).second; m_timeSteps[paymentOptionIndex] << runtimeInMinutes;
} }
} // if (pop_carry_over == false) { //} // if (pop_carry_over == false) {
} // if (w.has_value()) { } // if (w.has_value()) {
} else { } else {
uint16_t timeStepCompensation = 0; uint16_t timeStepCompensation = 0;

View File

@ -801,7 +801,7 @@ int main() {
int pop_max_price; int pop_max_price;
int pop_daily_card_price; int pop_daily_card_price;
int zone = 1; int zone = 3;
if (zone == 1) { if (zone == 1) {
input.open("/opt/ptu5/opt/customer_502/etc/psa_tariff/tariff01.json"); input.open("/opt/ptu5/opt/customer_502/etc/psa_tariff/tariff01.json");
@ -824,7 +824,7 @@ int main() {
if (isParsed) { if (isParsed) {
if (zone == 1) { if (zone == 1 || zone == 3) {
/* /*
pop_min_time = get_minimal_parkingtime(&cfg, PERMIT_TYPE::SHORT_TERM_PARKING_PKW); pop_min_time = get_minimal_parkingtime(&cfg, PERMIT_TYPE::SHORT_TERM_PARKING_PKW);
pop_max_time = get_maximal_parkingtime(&cfg, PERMIT_TYPE::SHORT_TERM_PARKING_PKW); pop_max_time = get_maximal_parkingtime(&cfg, PERMIT_TYPE::SHORT_TERM_PARKING_PKW);
@ -848,7 +848,8 @@ int main() {
qCritical() << " pop_min_price_bus: " << pop_min_price; qCritical() << " pop_min_price_bus: " << pop_min_price;
qCritical() << " pop_max_price_bus: " << pop_max_price; qCritical() << " pop_max_price_bus: " << pop_max_price;
*/ */
} else { }
if (zone == 2) {
pop_min_time = get_minimal_parkingtime(&cfg); pop_min_time = get_minimal_parkingtime(&cfg);
pop_max_time = get_maximal_parkingtime(&cfg); pop_max_time = get_maximal_parkingtime(&cfg);
pop_min_price = get_minimal_parkingprice(&cfg); pop_min_price = get_minimal_parkingprice(&cfg);
@ -897,7 +898,7 @@ int main() {
//qCritical() << calcState.toString(); //qCritical() << calcState.toString();
calcState = compute_duration_for_parking_ticket(&cfg, s, calcState = compute_duration_for_parking_ticket(&cfg, s,
(double)6000, end, PermitType(PERMIT_TYPE::SHORT_TERM_PARKING_BUS)); (double)9000, end, PermitType(PERMIT_TYPE::SHORT_TERM_PARKING_BUS));
qCritical() << end.toString(Qt::ISODate); qCritical() << end.toString(Qt::ISODate);
qCritical() << calcState.toString(); qCritical() << calcState.toString();
} }
@ -957,89 +958,62 @@ int main() {
#endif #endif
} }
if (zone == 3) { if (zone == 3) {
int price; //QDateTime xx(QDateTime::fromString("2024-07-31T00:00:00", Qt::ISODate));
QDateTime productStart; //xx = xx.addSecs(-60); // --> "2024-07-30T23:59:00"
QDateTime productEnd; //qCritical() << xx.toString(Qt::ISODate);
QDateTime start = QDateTime::currentDateTime();
#if 0 //QDateTime s(QDateTime::currentDateTime());
start.setTime(QTime(0, 0, 0)); //s.setTime(QTime(12, 0, 0));
price = compute_product_price(&cfg, PERMIT_TYPE::DAY_TICKET, start); //QList<int> timeSteps = Calculator::GetInstance().GetTimeSteps(&cfg, 0, s);
qCritical() << QString("line=%1 price (%2) :") //qCritical() << timeSteps;
.arg(__LINE__) int Down = 0;
.arg(start.time().toString(Qt::ISODate)) << price; int Up = 1;
price = get_minimal_parkingprice(&cfg, PERMIT_TYPE::DAY_TICKET, 0, start); QDateTime const start = QDateTime::currentDateTime();
qCritical() << QString("line=%1 get_minimal_parkingprice:").arg(__LINE__) << price; int paymentOptionIndex = cfg.getPaymentOptionIndex(PERMIT_TYPE::SHORT_TERM_PARKING_PKW);
start.setTime(QTime(14, 0, 0)); if (paymentOptionIndex != 0) {
productStart = productEnd = QDateTime(); qCritical() << "ERROR paymentOptionIndex" << paymentOptionIndex
price = compute_product_price(&cfg, PERMIT_TYPE::DAY_TICKET, start, &productStart, &productEnd); << "< 0 for start" << start.toString(Qt::ISODate);
qCritical() << QString("line=%1 price (%2-%3) :") exit(-1);
.arg(__LINE__) }
.arg(productStart.time().toString(Qt::ISODate))
.arg(productEnd.time().toString(Qt::ISODate)) //QSet<uint32_t> const prices1{800, 1600, 2400, 3200, 4000, 4800, 5600};
<< price; //QSet<uint32_t> const prices2{500, 1600, 2400, 3200, 4000, 4800, 5600};
price = get_minimal_parkingprice(&cfg, PERMIT_TYPE::DAY_TICKET, 0, start); QDateTime end;
qCritical() << QString("line=%1 get_minimal_parkingprice:").arg(__LINE__) CalcState calcState;
<< price;
QDateTime s(QDateTime::currentDateTime());
price = compute_product_price(&cfg, PERMIT_TYPE::DAY_TICKET, start); s.setTime(QTime(12, 0, 0));
qCritical() << QString("line=%1 price:").arg(__LINE__) << price;
int minimal_parking_price = get_minimal_parkingprice(&cfg,
start.setTime(QTime(15, 0, 0)); PermitType(PERMIT_TYPE::SHORT_TERM_PARKING_PKW),
productStart = productEnd = QDateTime(); paymentOptionIndex, s);
price = compute_product_price(&cfg, PERMIT_TYPE::DAY_TICKET, start, &productStart, &productEnd);
qCritical() << QString("line=%1 price (%2-%3) :") qCritical() << "minimal parking price" << minimal_parking_price;
.arg(__LINE__)
.arg(productStart.time().toString(Qt::ISODate)) for (int i = 0; i < 8; ++i) {
.arg(productEnd.time().toString(Qt::ISODate)) calcState = compute_duration_for_parking_ticket(&cfg, s,
<< price; (double)minimal_parking_price + i*800,
end, PermitType(PERMIT_TYPE::SHORT_TERM_PARKING_PKW));
price = get_minimal_parkingprice(&cfg, PERMIT_TYPE::DAY_TICKET, 0, start); qCritical() << "RUN" << i << end.toString(Qt::ISODate) << calcState.toString();
qCritical() << QString("line=%1 get_minimal_parkingprice:").arg(__LINE__) << price; }
start.setTime(QTime(16, 0, 0)); s.setTime(QTime(15, 0, 0));
productStart = productEnd = QDateTime();
price = compute_product_price(&cfg, PERMIT_TYPE::DAY_TICKET, start, &productStart, &productEnd); minimal_parking_price = get_minimal_parkingprice(&cfg,
qCritical() << QString("line=%1 price (%2-%3) :") PermitType(PERMIT_TYPE::SHORT_TERM_PARKING_PKW),
.arg(__LINE__) paymentOptionIndex, s);
.arg(productStart.time().toString(Qt::ISODate))
.arg(productEnd.time().toString(Qt::ISODate)) qCritical() << "minimal parking price" << minimal_parking_price;
<< price;
for (int i = 0; i < 8; ++i) {
price = get_minimal_parkingprice(&cfg, PERMIT_TYPE::DAY_TICKET, 0, start); calcState = compute_duration_for_parking_ticket(&cfg, s,
qCritical() << QString("line=%1 get_minimal_parkingprice:").arg(__LINE__) << price; (double)minimal_parking_price + i*800,
end, PermitType(PERMIT_TYPE::SHORT_TERM_PARKING_PKW));
start.setTime(QTime(17, 0, 0)); qCritical() << "RUN" << i << end.toString(Qt::ISODate) << calcState.toString();
productStart = productEnd = QDateTime();
price = compute_product_price(&cfg, PERMIT_TYPE::DAY_TICKET, start, &productStart, &productEnd);
qCritical() << QString("line=%1 price (%2-%3) :")
.arg(__LINE__)
.arg(productStart.time().toString(Qt::ISODate))
.arg(productEnd.time().toString(Qt::ISODate))
<< price;
//price = get_minimal_parkingprice(&cfg, PERMIT_TYPE::DAY_TICKET, 0, start);
//qCritical() << QString("line=%1 get_minimal_parkingprice:").arg(__LINE__) << price;
//price = get_minimal_parkingprice(&cfg, PERMIT_TYPE::DAY_TICKET);
//qCritical() << QString("line=%1 get_minimal_parkingprice:").arg(__LINE__) << price;
#else
for (int h = 0; h < 24; ++h) {
start.setTime(QTime(h, 0, 0));
productStart = productEnd = QDateTime();
price = compute_product_price(&cfg, PERMIT_TYPE::DAY_TICKET, start, &productStart, &productEnd);
qCritical() << QString("line=%1 %2 price (%3-%4) :")
.arg(__LINE__)
.arg(start.time().toString(Qt::ISODate))
.arg(productStart.time().toString(Qt::ISODate))
.arg(productEnd.time().toString(Qt::ISODate))
<< price;
} }
#endif
} }
} }
#endif #endif

View File

@ -30,7 +30,9 @@ SOURCES += main.cpp
# HEADERS += # HEADERS +=
OTHER_FILES += \ OTHER_FILES += \
/home/linux/customer_505/etc/psa_tariff/tariff01.json /opt/ptu5/opt/customer_502/etc/psa_tariff/tariff01.json \
/opt/ptu5/opt/customer_502/etc/psa_tariff/tariff02.json \
/opt/ptu5/opt/customer_502/etc/psa_tariff/tariff03.json