diff --git a/library/src/calculator_functions.cpp b/library/src/calculator_functions.cpp index 9170b27..75958f4 100644 --- a/library/src/calculator_functions.cpp +++ b/library/src/calculator_functions.cpp @@ -614,19 +614,48 @@ double Calculator::GetCostFromDuration(Configuration* cfg, int duration = timeRange.time_range_to_in_minutes_from_start - timeRange.time_range_from_in_minutes_from_start; - if (minsUsed > 0) { - duration -= minsUsed; - minsUsed = 0; - } + qCritical() << __func__ << ":" << __LINE__ + << "current" << current.toString(Qt::ISODate) + << "duration" << duration + << "minsUsed" << minsUsed + << "minsToCarryOver" << minsToCarryOver; + + + //if (minsUsed > 0) { + // duration -= minsUsed; + // minsUsed = 0; + //} if (current.addSecs(duration * 60).time() <= to) { if (minsToCarryOver > 0) { // the price for this time range // has been is paid already - durationMinutes -= duration; - durationMinutesNetto += duration; - durationMinutesBrutto += duration; - current = current.addSecs(duration*60); - minsToCarryOver = 0; + if (minsUsed == 0) { + for(const auto &x: cfg->PaymentRate) { + ATBPaymentRate const rate = x.second; + if (rate.pra_payment_unit_id == timeRange.time_range_payment_type_id) { + price += (uint)rate.pra_price; + + durationMinutes -= duration; + durationMinutesNetto += duration; + durationMinutesBrutto += duration; + + current = current.addSecs(duration * 60); + + if (durationMinutes <= 0) { + end_datetime = current; + return price; + } + + break; + } + } + } else { + durationMinutes -= duration; + durationMinutesNetto += duration; + durationMinutesBrutto += duration; + current = current.addSecs(duration*60); + minsToCarryOver = 0; + } } else { for(const auto &x: cfg->PaymentRate) { ATBPaymentRate const rate = x.second; diff --git a/main/main.cpp b/main/main.cpp index 19b684b..9f59694 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -40,7 +40,7 @@ extern "C" char* strptime(const char* s, #define NEUHAUSER_LINSINGER_MASCHINENBAU (0) #define NEUHAUSER_NORDISCHES_AUSBILDUNGSZENTRUM (0) #define NEUHAUSER_BILEXA_GALTUER (0) -#define NEUHAUSER_KIRCHDORF (0) +#define NEUHAUSER_KIRCHDORF (1) #if NEUHAUSER_KIRCHDORF==1 static bool test_neuhauser_kirchdorf(int step, double cost) { @@ -205,12 +205,12 @@ int main() { #endif #if NEUHAUSER_KIRCHDORF==1 - if (QDir("/opt/app/tools/atbupdate/customer_743").exists()) { - if(QFileInfo::exists("/etc/psa_tariff/tariff01.json")) { - // if (true) { - // if(true) { - const char *f = "/etc/psa_tariff/tariff01.json"; - // const char *f = "/opt/ptu5/opt/customer_743/etc/psa_tariff/tariff01.json"; + //if (QDir("/opt/app/tools/atbupdate/customer_743").exists()) { + // if(QFileInfo::exists("/etc/psa_tariff/tariff01.json")) { + if (true) { + if(true) { + // const char *f = "/etc/psa_tariff/tariff01.json"; + const char *f = "/opt/ptu5/opt/customer_743/etc/psa_tariff/tariff01.json"; std::ifstream input(f); std::stringstream sstr; @@ -269,17 +269,19 @@ int main() { QList::const_iterator step; for (step = steps.cbegin(); step != steps.cend(); ++step) { qCritical() << QString("*** NEXT STEP: %1 ***").arg(*step); - for (int offset = 7*60; offset < 18*60; ++offset) { + //for (int offset = 7*60; offset < 18*60; ++offset) { + for (int offset = 690; offset < 691; ++offset) { QDateTime start = s.addSecs(offset * 60); QDateTime const firstStart = start; if (compute_price_for_parking_ticket(&cfg, start, *step, end, &price)) { double cost = price.netto; - //qCritical() << "****" << offset << *step << "****"; - //qCritical() << " firstStart :" << firstStart.toString(Qt::ISODate); - //qCritical() << " start :" << start.toString(Qt::ISODate); - //qCritical() << " end :" << end.toString(Qt::ISODate); + qCritical() << "****" << offset << *step << "****"; + qCritical() << " firstStart :" << firstStart.toString(Qt::ISODate); + qCritical() << " start :" << start.toString(Qt::ISODate); + qCritical() << " end :" << end.toString(Qt::ISODate); + qCritical() << " cost :" << cost; if (offset < 8*60) { // [7:00 - 8:00[ if (!test_neuhauser_kirchdorf(*step, cost)) { @@ -648,7 +650,9 @@ int main() { } return 0; -#elif SZEGED==1 +#endif + +#if SZEGED==1 std::ifstream input; int pop_min_time; int pop_max_time; @@ -660,27 +664,27 @@ int main() { //for (int t=6; t < 7; t+=20) { switch (zone) { case 1: { - input.open("/home/linux/customer_281/etc/psa_tariff/tariff01.json"); + input.open("/opt/ptu5/opt/customer_281/etc/psa_tariff/tariff01.json"); //pop_max_time = 6*60; } break; case 2: { - input.open("/home/linux/customer_281/etc/psa_tariff/tariff02.json"); + input.open("/opt/ptu5/opt/customer_281/etc/psa_tariff/tariff02.json"); //pop_max_time = 5*60; } break; case 3: { - input.open("/home/linux/customer_281/etc/psa_tariff/tariff03.json"); + input.open("/opt/ptu5/opt/customer_281/etc/psa_tariff/tariff03.json"); //pop_max_time = 6*60; } break; case 4: { - input.open("/home/linux/customer_281/etc/psa_tariff/tariff04.json"); + input.open("/opt/ptu5/opt/customer_281/etc/psa_tariff/tariff04.json"); //pop_max_time = 4*60; } break; case 5: { - input.open("/home/linux/customer_281/etc/psa_tariff/tariff05.json"); + input.open("/opt/ptu5/opt/customer_281/etc/psa_tariff/tariff05.json"); //pop_max_time = 6*60; } break; case 6: { - input.open("/home/linux/customer_281/etc/psa_tariff/tariff06.json"); + input.open("/opt/ptu5/opt/customer_281/etc/psa_tariff/tariff06.json"); //pop_max_time = 4*60; } break; default: @@ -735,7 +739,6 @@ int main() { QDateTime s(QDate(2023, 11, 30), QTime()); QDateTime end; int cnt = 1; -#if 1 if (zone == 1) { m.insert(5, pop_min_price); m.insert(10, pop_min_price); // 42 @@ -1245,13 +1248,13 @@ int main() { //qCritical() << start.toString(Qt::ISODate) << end.toString(Qt::ISODate) // << duration << cost; - //if (cost != m[duration]) { - // qCritical() << "ERROR computing_price_for_parking_ticket" - // << "duration" << duration - // << "HAVE cost" << cost - // << "SHOULD HAVE cost" << m[duration]; - // return -1; - //} + if (cost != m[duration]) { + qCritical() << "ERROR computing_price_for_parking_ticket" + << "duration" << duration + << "HAVE cost" << cost + << "SHOULD HAVE cost" << m[duration]; + return -1; + } } else { qCritical() << "ERROR computing_price_for_parking_ticket AT" << cnt << "duration" << duration @@ -1262,54 +1265,34 @@ int main() { end = QDateTime(); price.netto = 0; - if (zone >= 1 && zone <= 6) { - if (compute_price_for_daily_ticket(&cfg, start, end, PERMIT_TYPE::DAY_TICKET, &price)) { - if (price.netto != pop_daily_card_price) { - qCritical() << "ERROR computing_price_for_daily_ticket" - << "duration" << duration - << "HAVE cost" << price.netto - << "SHOULD HAVE cost" << pop_daily_card_price; - return -1; - } - } else { - qCritical() << "ERROR computing_price_for_daily_ticket AT" - << "start" << start.toString(Qt::ISODate); + if (compute_price_for_daily_ticket(&cfg, start, end, PERMIT_TYPE::DAY_TICKET, &price)) { + if (price.netto != pop_daily_card_price) { + qCritical() << "ERROR computing_price_for_daily_ticket" + << "duration" << duration + << "HAVE cost" << price.netto + << "SHOULD HAVE cost" << pop_daily_card_price; return -1; } + } else { + qCritical() << "ERROR computing_price_for_daily_ticket AT" + << "start" << start.toString(Qt::ISODate); + return -1; } +// start = s.addSecs(offset * 60); +// end = QDateTime(); + //if (compute_duration_for_daily_ticket(&cfg, start, end)) { +// +// } else { +// qCritical() << "ERROR computing_duration_for_daily_ticket AT" +// << "start" << start.toString(Qt::ISODate); +// return -1; +// } + ++cnt; } } - -#else - QDateTime start = s.addSecs(480 * 60); // 8:00:00 - double cost = 2000; - std::string duration = Calculator::GetInstance().GetDurationFromCost(&cfg, - 3, - start.toString(Qt::ISODate).toStdString().c_str(), - cost, false, true); - qCritical() << cnt << "start" << start.toString(Qt::ISODate) - << "cost" << cost - << "until" << duration.c_str() << start.secsTo(QDateTime::fromString(duration.c_str(), Qt::ISODate)) / 60; -#endif } -#if 0 - { - QDateTime start(QDate(2023, 12, 1), QTime(18, 0)); - QDateTime end; - double cost = Calculator::GetInstance().GetCostFromDuration(&cfg, 3, start, end, 60); - // Q_ASSERT(cost == 150); - qCritical() << "end" << end.toString(Qt::ISODate) << "cost" << cost; - } - { - QDateTime start(QDate(2023, 10, 31), QTime(18, 0)); - QDateTime end; - double cost = Calculator::GetInstance().GetCostFromDuration(&cfg, 3, start, end, 60); - //Q_ASSERT(cost == 150); - qCritical() << "end" << end.toString(Qt::ISODate) << "cost" << cost; - } -#endif } } @@ -1510,6 +1493,6 @@ int main() { } } } + #endif - return 0; }