Compare commits

...

4 Commits

Author SHA1 Message Date
648799629a GetTimeSteps():
Fix: check not only if "current" is above carryOverStart, but also
	     if "current" is below carryOverEnd.
2024-08-19 12:19:01 +02:00
84e2530767 Calculator::GetDurationFromCost():
Minor: debug output.
2024-08-19 12:18:05 +02:00
ceb78772dd Minor: debug output 2024-08-19 12:11:47 +02:00
675ba60733 tests for schnals/muehlbach 2024-08-19 12:10:43 +02:00
3 changed files with 42 additions and 31 deletions

View File

@ -923,12 +923,15 @@ CalcState CALCULATE_LIBRARY_API compute_duration_for_parking_ticket(
bool const nextDay = false;
// DEBUG
if (DBG_LEVEL >= DBG_DEBUG) {
qCritical() << "compute_duration_for_parking_ticket(2): ";
qCritical() << " payment option index: " << paymentOptionIndex;
qCritical() << " prepaid: " << prepaid;
qCritical() << " price: " << price;
}
// if (DBG_LEVEL >= DBG_DEBUG) {
qCritical() << "\ncompute_duration_for_parking_ticket(2):";
qCritical() << " start time:" << start_parking_time.toString(Qt::ISODate);
qCritical() << " payment option index:" << paymentOptionIndex;
qCritical() << " prepaid:" << prepaid;
qCritical() << " price:" << price;
qCritical() << " permit type:" << permitType.toString() << endl;
// }
if (start_parking_time.isValid()) {
QString cs = start_parking_time.toString(Qt::ISODate);
@ -1009,9 +1012,10 @@ CalcState CALCULATE_LIBRARY_API compute_duration_for_parking_ticket(
}
// DEBUG
qCritical() << "compute_duration_for_parking_ticket(): ";
qCritical() << " endTime: " << endTime;
qCritical() << " ticketEndTime: " << ticketEndTime;
qCritical() << "\ncompute_duration_for_parking_ticket():";
qCritical() << " start time:" << start_parking_time.toString(Qt::ISODate);
qCritical() << " endTime:" << endTime;
qCritical() << " ticketEndTime:" << ticketEndTime.toString(Qt::ISODate) << endl;
}
} else {
return calcState.set(CalcState::State::INVALID_START_DATE);

View File

@ -178,6 +178,9 @@ std::string Calculator::GetDurationFromCost(Configuration* cfg,
for (auto[itr, rangeEnd] = cfg->PaymentRate.equal_range(pop_id); itr != rangeEnd; ++itr) {
int const pra_price = itr->second.pra_price;
// qCritical() << DBG_HEADER << "pra_price" << pra_price;
int const durationId = itr->second.pra_payment_unit_id;
if (pop_accumulate_prices) {
price += pra_price;
@ -185,8 +188,8 @@ std::string Calculator::GetDurationFromCost(Configuration* cfg,
price = pra_price;
}
//qCritical() << DBG_HEADER << " PRICE" << price << "COST" << cost;
//qCritical() << DBG_HEADER << " duration id" << durationId;
// qCritical() << DBG_HEADER << " PRICE" << price << "COST" << cost;
// qCritical() << DBG_HEADER << " duration id" << durationId;
auto search = cfg->Duration.find(durationId);
if (search != cfg->Duration.end()) {
@ -2854,7 +2857,7 @@ QList<int> &Calculator::GetTimeSteps(Configuration *cfg, int paymentOptionIndex,
++it) {
it->second.pun_duration = it->second.pun_duration_saved;
// if (++cnt > 4) continue;
// if (++cnt > 2) continue;
if (DBG_LEVEL >= DBG_DEBUG) {
qCritical() << "(" << __func__ << ":" << __LINE__ << ") pun_id" << it->second.pun_id;
@ -2864,11 +2867,15 @@ QList<int> &Calculator::GetTimeSteps(Configuration *cfg, int paymentOptionIndex,
if (it->second.pun_netto) {
if (it->second.pun_round_to_next_24h_boundary == false) {
//int weekDay = start.date().dayOfWeek();
casePrepay = false;
if (m_timeSteps[paymentOptionIndex].isEmpty()) {
// handle possible prepay-condition, which applies only
// for the very first step
if (DBG_LEVEL >= DBG_DEBUG) {
qCritical() << "(" << __func__ << ":" << __LINE__ << ") prepay start" << prepayStart.toString(Qt::ISODate);
qCritical() << "(" << __func__ << ":" << __LINE__ << ") prepay end" << prepayEnd.toString(Qt::ISODate);
}
if (prepayStart <= start && start <= prepayEnd) {
it->second.pun_duration = prepayDurationInMinutes;
it->second.pun_duration += it->second.pun_duration_saved ;
@ -2884,22 +2891,15 @@ QList<int> &Calculator::GetTimeSteps(Configuration *cfg, int paymentOptionIndex,
if (!casePrepay) {
// handle possible carryover-condition
int durationInSecs = it->second.pun_duration_saved * 60;
if (DBG_LEVEL >= DBG_DEBUG) {
qCritical() << "(" << __func__ << ":" << __LINE__ << ")" << durationInSecs;
qCritical() << "(" << __func__ << ":" << __LINE__ << ") start" << start.toString(Qt::ISODate);
qCritical() << "(" << __func__ << ":" << __LINE__ << ") current" << current.toString(Qt::ISODate);
qCritical() << "(" << __func__ << ":" << __LINE__ << ") current next" << current.addSecs(durationInSecs).toString(Qt::ISODate);
}
int const durationInSecs = it->second.pun_duration_saved * 60;
it->second.pun_duration = it->second.pun_duration_saved;
if (current >= carryOverStart) {
if (current >= carryOverStart && current < carryOverEnd) {
it->second.pun_duration += current.secsTo(carryOverEnd) / 60;
} else {
// start < carryOverStart
QDateTime const &newCurrent = current.addSecs(durationInSecs);
if (newCurrent > carryOverStart) {
if (newCurrent > carryOverStart && newCurrent <= carryOverEnd) {
// cross carry over section
it->second.pun_next_step_correction = carryOverStart.secsTo(carryOverEnd) / 60;
it->second.pun_duration += it->second.pun_next_step_correction;
@ -2994,6 +2994,7 @@ QList<int> &Calculator::GetTimeSteps(Configuration *cfg, int paymentOptionIndex,
} else { // if (it->second.pun_netto) {
qCritical() << "(" << __func__ << ":" << __LINE__ << ") TODO";
qCritical() << "(" << __func__ << ":" << __LINE__ << ")\n" << it->second;
}
} else { // mutable == false
if (it->second.pun_brutto) { // no handling for prepay and carry-over
@ -3010,6 +3011,7 @@ QList<int> &Calculator::GetTimeSteps(Configuration *cfg, int paymentOptionIndex,
} else {
qCritical() << "(" << __func__ << ":" << __LINE__ << ") TODO";
qCritical() << "(" << __func__ << ":" << __LINE__ << ")\n" << it->second;
}
}
}
@ -3064,7 +3066,7 @@ uint32_t Calculator::GetPriceForTimeStep(Configuration *cfg, int timeStep, int p
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__ << ") pop_id" << pop_id;

View File

@ -741,9 +741,14 @@ int main() {
input.open("/opt/ptu5/opt/customer_502/etc/psa_tariff/tariff02.json");
}
if (zone == 3) {
input.open("/opt/ptu5/opt/customer_502/etc/psa_tariff/tariff03.json");
//input.open("/opt/ptu5/opt/customer_502/etc/psa_tariff/tariff03.json");
//input.open("/home/linux/customer_502/etc/psa_tariff/tariff01.json");
input.open("/home/linux/customer_502/etc/psa_tariff/tariff03.json");
// schnals
// input.open("/opt/ptu5/opt/customer_505/etc/psa_tariff/tariff01.json");
// muehlbach
input.open("/opt/ptu5/opt/customer_504/etc/psa_tariff/tariff01.json");
}
std::stringstream sstr;
@ -917,7 +922,7 @@ int main() {
QDateTime end;
QDateTime s(QDateTime::currentDateTime());
s.setTime(QTime(13, 30, 0));
s.setTime(QTime(10, 0, 0));
#if 0
@ -947,12 +952,12 @@ int main() {
#if 1
qCritical() << "start" << s.toString(Qt::ISODate);
//for (int i = 1; i < 11; ++i) {
for (int i = 1; i < 8; ++i) {
for (int i = 0; i < 21; ++i) {
calcState = compute_duration_for_parking_ticket(&cfg, s,
(double)i*200,
(double)i*10,
end, PermitType(PERMIT_TYPE::SHORT_TERM_PARKING_PKW));
qCritical() << "RUN" << i << ": start" << s.toString(Qt::ISODate)
<< ": price" << i*200 << "->" << end.toString(Qt::ISODate) << calcState.toString();
<< ": price" << i*10 << "->" << end.toString(Qt::ISODate) << calcState.toString();
}
#else
struct price_t price;