Compare commits

...

3 Commits

Author SHA1 Message Date
abbbd06f93 GetCostFromDuration(): re-implement cpmputation for paymentMethod==progressive
(e.g. neuhauser/kirchdorf (743))
2024-02-27 12:25:13 +01:00
ac6e45a913 test cases for neuhauser-kirchdorf 2024-02-27 12:23:52 +01:00
b741d2e312 test 2024-02-26 16:57:37 +01:00
2 changed files with 426 additions and 180 deletions

View File

@ -522,6 +522,10 @@ double Calculator::GetCostFromDuration(Configuration* cfg,
int weekdayIdLast = -1; int weekdayIdLast = -1;
int durationMinutesBrutto = 0; int durationMinutesBrutto = 0;
//#define _DEBUG_ 1
#define _DEBUG_ 0
QDateTime current = start; QDateTime current = start;
int days = 7; int days = 7;
@ -571,120 +575,309 @@ double Calculator::GetCostFromDuration(Configuration* cfg,
uint price = 0; uint price = 0;
if (carryOverNotSet) { if (carryOverNotSet) {
int range = 0;
int minsToCarryOver = 0; // from one work-time to the other on the same day int minsToCarryOver = 0; // from one work-time to the other on the same day
int minsUsed = 0; int minsUsed = 0;
QDateTime lastCurrent = QDateTime(); QDateTime lastCurrent = QDateTime();
QVector<ATBWeekDaysWorktime> weekDayWorkTimeRanges;
using WTIterator = std::multimap<int, ATBWeekDaysWorktime>::const_iterator;
std::pair<WTIterator, WTIterator> p = cfg->WeekDaysWorktime.equal_range(weekdayId);
for (WTIterator itr = p.first; itr != p.second; ++itr) {
weekDayWorkTimeRanges.append(itr->second); // working with vector is easier
}
int weekDayWorkTimeIndex = 0;
bool moveToNextTimeRange = false;
// time ranges for Neuhauser-Kirchdorf (743): 30, 5, 5, ... 5
auto timeRangeIt = cfg->TimeRange.cbegin(); auto timeRangeIt = cfg->TimeRange.cbegin();
for (; timeRangeIt != cfg->TimeRange.cend(); ++timeRangeIt) { while (timeRangeIt != cfg->TimeRange.cend()) { // ; ++timeRangeIt) {
using WTIterator = std::multimap<int, ATBWeekDaysWorktime>::const_iterator;
std::pair<WTIterator, WTIterator> p = cfg->WeekDaysWorktime.equal_range(weekdayId);
for (WTIterator itr = p.first; itr != p.second; ++itr) { if (weekDayWorkTimeIndex >= weekDayWorkTimeRanges.size()) {
++range;
QTime const &from = Utilities::WeekDaysWorkTimeFrom(itr); #if _DEBUG_==1
QTime const &to = Utilities::WeekDaysWorkTimeUntil(itr); qCritical() << "(" << __func__ << ":" << __LINE__ << ")"
<< "weekDayWorkTimeIndex" << weekDayWorkTimeIndex
<< "weekDayWorkTimeRanges.size()" << weekDayWorkTimeRanges.size();
#endif
end_datetime = current;
return price;
}
Q_ASSERT_X(from < to, __func__, "MISCONFIGURED WORK-TIMES"); QTime const &from = QTime::fromString(weekDayWorkTimeRanges[weekDayWorkTimeIndex].pwd_time_from.c_str(), Qt::ISODate);
QTime const &to = QTime::fromString(weekDayWorkTimeRanges[weekDayWorkTimeIndex].pwd_time_to.c_str(), Qt::ISODate);
if (current.time() >= to) { #if _DEBUG_==1
continue; // try to use next available work-time qCritical() << "(" << __func__ << ":" << __LINE__ << ")"
} else << "current" << current.toString(Qt::ISODate)
if (current.time() <= from) { << "from" << from.toString(Qt::ISODate)
if (prepaid) { << "to" << to.toString(Qt::ISODate);
lastCurrent = current; #endif
current.setTime(from); // move current forward (range==1),
// as prepaid is set
uint const minutesMoved = lastCurrent.secsTo(current) / 60;
durationMinutesBrutto += minutesMoved;
if (range == 1) { Q_ASSERT_X(from < to, __func__, "MISCONFIGURED WORK-TIMES");
start_datetime = current;
}
}
}
while (timeRangeIt != cfg->TimeRange.cend()) { if (current.time() >= to) {
ATBTimeRange timeRange = timeRangeIt->second; ++weekDayWorkTimeIndex;
timeRange.computeQTimes(current.time()); #if _DEBUG_==1
qCritical() << "(" << __func__ << ":" << __LINE__ << ")"
<< "try to use next available work-time with"
<< "weekDayWorkTimeIndex" << weekDayWorkTimeIndex
<< "price" << price;
#endif
// time range is not affected
continue;
} else
if (current.time() <= from) {
if (prepaid) {
lastCurrent = current;
current.setTime(from); // move current forward (range==1),
// as prepaid is set
uint const minutesMoved = lastCurrent.secsTo(current) / 60;
durationMinutesBrutto += minutesMoved;
int duration = timeRange.time_range_to_in_minutes_from_start - #if _DEBUG_==1
timeRange.time_range_from_in_minutes_from_start; qCritical() << "(" << __func__ << ":" << __LINE__ << ")"
<< "lastCurrent" << lastCurrent.toString(Qt::ISODate)
<< "current" << current.toString(Qt::ISODate)
<< "minutesMoved" << minutesMoved
<< "durationMinutesBrutto" << durationMinutesBrutto;
#endif
if (minsUsed > 0) { if (weekDayWorkTimeIndex == 0) {
duration -= minsUsed; start_datetime = current;
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;
} else {
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);
break;
}
}
}
if (durationMinutes <= 0) {
end_datetime = current;
return price;
}
++timeRangeIt;
} else {
lastCurrent = current;
current.setTime(to);
minsUsed = lastCurrent.secsTo(current) / 60;
// mod duration: possibly discard some minutes in
// the next time-range
if (durationMinutes >= minsUsed) {
minsToCarryOver = durationMinutes - minsUsed;
}
durationMinutes -= minsUsed;
durationMinutesNetto += minsUsed;
durationMinutesBrutto += minsUsed;
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;
break;
}
}
}
break;
} }
} }
} }
ATBTimeRange timeRange = timeRangeIt->second;
timeRange.computeQTimes(current.time());
int duration = timeRange.time_range_to_in_minutes_from_start -
timeRange.time_range_from_in_minutes_from_start;
#if _DEBUG_==1
qCritical() << "(" << __func__ << ":" << __LINE__ << ")"
<< "current" << current.toString(Qt::ISODate)
<< "duration" << duration
<< "minsUsed" << minsUsed
<< "minsToCarryOver" << minsToCarryOver
<< "weekDayWorkTimeIndex" << weekDayWorkTimeIndex
<< "price" << price;
#endif
if (minsToCarryOver > 0) { // the price for this time range
// has been is paid already
Q_ASSERT_X(weekDayWorkTimeIndex > 0, __func__, "WRONG-WORK-TIME");
current = current.addSecs(minsToCarryOver*60);
durationMinutes -= minsToCarryOver;
durationMinutesNetto += minsToCarryOver;
durationMinutesBrutto += minsToCarryOver;
minsToCarryOver = 0;
#if _DEBUG_==1
qCritical() << "(" << __func__ << ":" << __LINE__ << ")"
<< "current" << current.toString(Qt::ISODate)
<< "duration" << duration
<< "durationMinutes" << durationMinutes
<< "durationMinutesNetto" << durationMinutesNetto
<< "durationMinutesBrutto" << durationMinutesBrutto;
#endif
if (durationMinutes <= 0) {
end_datetime = current;
#if _DEBUG_==1
qCritical() << "(" << __func__ << ":" << __LINE__ << ")"
<< "end_datetime" << end_datetime.toString(Qt::ISODate)
<< "price" << price;
#endif
return price;
}
}
if (current.addSecs(duration * 60).time() <= to) {
#if _DEBUG_==1
qCritical() << "(" << __func__ << ":" << __LINE__ << ")"
<< "current" << current.toString(Qt::ISODate)
<< "current.addSecs(" << duration * 60 << ")" << current.addSecs(duration*60).time().toString(Qt::ISODate)
<< "duration" << duration
<< "to" << to.toString(Qt::ISODate)
<< "minsUsed" << minsUsed
<< "minsToCarryOver" << minsToCarryOver
<< "weekDayWorkTimeIndex" << weekDayWorkTimeIndex
<< "durationMinutes" << durationMinutes;
#endif
moveToNextTimeRange = false;
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);
// price has been updated; use next time range
moveToNextTimeRange = true;
break;
}
}
#if _DEBUG_==1
qCritical() << "(" << __func__ << ":" << __LINE__ << ")"
<< "current" << current.toString(Qt::ISODate)
<< "duration" << duration
<< "to" << to.toString(Qt::ISODate)
<< "price" << price
<< "minsToCarryOver" << minsToCarryOver
<< "weekDayWorkTimeIndex" << weekDayWorkTimeIndex
<< "durationMinutes" << durationMinutes
<< "durationMinutesNetto" << durationMinutesNetto
<< "durationMinutesBrutto" << durationMinutesBrutto;
#endif
if (durationMinutes <= 0) {
end_datetime = current;
#if _DEBUG_==1
qCritical() << "(" << __func__ << ":" << __LINE__ << ")"
<< "end_datetime" << end_datetime.toString(Qt::ISODate)
<< "price" << price;
#endif
return price;
}
if (moveToNextTimeRange) {
if (++timeRangeIt != cfg->TimeRange.cend()) {
continue;
}
}
// havin a new time range means that we always have a new
// work-time-range
// ++timeRangeIt;
} else { // current.addSecs(duration * 60).time() > to
#if _DEBUG_==1
qCritical() << "(" << __func__ << ":" << __LINE__ << ")"
<< "current" << current.toString(Qt::ISODate)
<< "current.addSecs(" << duration * 60 << ")" << current.addSecs(duration*60).time().toString(Qt::ISODate)
<< "duration" << duration
<< ", to:" << to.toString(Qt::ISODate);
#endif
lastCurrent = current;
current.setTime(to);
minsUsed = lastCurrent.secsTo(current) / 60;
#if _DEBUG_==1
qCritical() << "(" << __func__ << ":" << __LINE__ << ")"
<< "lastCurrent" << lastCurrent.toString(Qt::ISODate)
<< "current" << current.toString(Qt::ISODate)
<< "duration" << duration
<< "to" << to.toString(Qt::ISODate)
<< "minsUsed" << minsUsed
<< "minsToCarryOver" << minsToCarryOver
<< "weekDayWorkTimeIndex" << weekDayWorkTimeIndex
<< "durationMinutes" << durationMinutes;
#endif
// mod duration: possibly discard some minutes in
// the next time-range
if (duration >= minsUsed) {
minsToCarryOver = duration - minsUsed;
}
durationMinutes -= minsUsed;
durationMinutesNetto += minsUsed;
durationMinutesBrutto += minsUsed;
#if _DEBUG_==1
qCritical() << "(" << __func__ << ":" << __LINE__ << ")"
<< "lastCurrent" << lastCurrent.toString(Qt::ISODate)
<< "current" << current.toString(Qt::ISODate)
<< "duration" << duration
<< "to" << to.toString(Qt::ISODate)
<< "minsUsed" << minsUsed
<< "minsToCarryOver" << minsToCarryOver
<< "weekDayWorkTimeIndex" << weekDayWorkTimeIndex
<< "durationMinutes" << durationMinutes
<< "price" << price;
#endif
moveToNextTimeRange = false;
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;
// price has been updated; use next time range
moveToNextTimeRange = true;
break;
}
}
}
#if _DEBUG_==1
qCritical() << "(" << __func__ << ":" << __LINE__ << ")"
<< "current" << current.toString(Qt::ISODate)
<< "duration" << duration
<< "minsUsed" << minsUsed
<< "durationMinutes" << durationMinutes
<< "moveToNextTimeRange" << moveToNextTimeRange
<< "price" << price;
#endif
if (moveToNextTimeRange) {
if (++timeRangeIt != cfg->TimeRange.cend()) {
continue;
}
// no valid time range left
end_datetime = current;
#if _DEBUG_==1
qCritical() << "(" << __func__ << ":" << __LINE__ << ")"
<< "end_datetime" << end_datetime.toString(Qt::ISODate)
<< "price" << price;
#endif
return price;
}
}
end_datetime = start.addSecs(durationMinutesBrutto * 60); end_datetime = start.addSecs(durationMinutesBrutto * 60);
#if _DEBUG_==1
qCritical() << "(" << __func__ << ":" << __LINE__ << ")"
<< "start" << start.toString(Qt::ISODate)
<< "end_datetime" << end_datetime.toString(Qt::ISODate)
<< "final price" << std::max(price, minParkingPrice);
#endif
return std::max(price, minParkingPrice); return std::max(price, minParkingPrice);
} } // while (timeRangeIt != cfg->TimeRange.cend()) {
} }
#if _DEBUG_==1
qCritical() << "(" << __func__ << ":" << __LINE__ << ")"
<< "INVALID END TIME";
#endif
end_datetime = QDateTime(); end_datetime = QDateTime();
return 0; return 0;
} }

View File

@ -40,7 +40,7 @@ extern "C" char* strptime(const char* s,
#define NEUHAUSER_LINSINGER_MASCHINENBAU (0) #define NEUHAUSER_LINSINGER_MASCHINENBAU (0)
#define NEUHAUSER_NORDISCHES_AUSBILDUNGSZENTRUM (0) #define NEUHAUSER_NORDISCHES_AUSBILDUNGSZENTRUM (0)
#define NEUHAUSER_BILEXA_GALTUER (0) #define NEUHAUSER_BILEXA_GALTUER (0)
#define NEUHAUSER_KIRCHDORF (0) #define NEUHAUSER_KIRCHDORF (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) {
@ -205,12 +205,12 @@ int main() {
#endif #endif
#if NEUHAUSER_KIRCHDORF==1 #if NEUHAUSER_KIRCHDORF==1
if (QDir("/opt/app/tools/atbupdate/customer_743").exists()) { //if (QDir("/opt/app/tools/atbupdate/customer_743").exists()) {
if(QFileInfo::exists("/etc/psa_tariff/tariff01.json")) { // if(QFileInfo::exists("/etc/psa_tariff/tariff01.json")) {
// if (true) { if (true) {
// if(true) { if(true) {
const char *f = "/etc/psa_tariff/tariff01.json"; // const char *f = "/etc/psa_tariff/tariff01.json";
// const char *f = "/opt/ptu5/opt/customer_743/etc/psa_tariff/tariff01.json"; const char *f = "/opt/ptu5/opt/customer_743/etc/psa_tariff/tariff01.json";
std::ifstream input(f); std::ifstream input(f);
std::stringstream sstr; std::stringstream sstr;
@ -270,78 +270,150 @@ int main() {
for (step = steps.cbegin(); step != steps.cend(); ++step) { for (step = steps.cbegin(); step != steps.cend(); ++step) {
qCritical() << QString("*** NEXT STEP: %1 ***").arg(*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 = 7*60; offset < (18*60)-90; ++offset) {
//for (int offset = (18*60)-90; offset < 18*60; ++offset) {
//for (int offset = 1046; offset < 1047; ++offset) {
QDateTime start = s.addSecs(offset * 60); QDateTime start = s.addSecs(offset * 60);
QDateTime const firstStart = start; QDateTime const firstStart = start;
//if (*step != 35) continue;
if (compute_price_for_parking_ticket(&cfg, start, *step, end, &price)) { if (compute_price_for_parking_ticket(&cfg, start, *step, end, &price)) {
double cost = price.netto; double cost = price.netto;
//qCritical() << "****" << offset << *step << "****"; qCritical() << "****" << offset << *step << "****";
//qCritical() << " firstStart :" << firstStart.toString(Qt::ISODate); qCritical() << " firstStart :" << firstStart.toString(Qt::ISODate);
//qCritical() << " start :" << start.toString(Qt::ISODate); qCritical() << " start :" << start.toString(Qt::ISODate);
//qCritical() << " end :" << end.toString(Qt::ISODate); qCritical() << " end :" << end.toString(Qt::ISODate);
qCritical() << " cost :" << cost;
if (offset < 8*60) { // [7:00 - 8:00[ if (offset < 8*60) { // [7:00 - 8:00[
if (!test_neuhauser_kirchdorf(*step, cost)) { double new_cost = cost;
if (offset > (18*60)-(*step)) {
new_cost += ((*step-30)/5)*10;
qCritical() << __LINE__ << "new_cost" << new_cost << "(cost" << cost << ")";
}
if (!test_neuhauser_kirchdorf(*step, new_cost)) {
qCritical() << "ERROR AT OFFSET" << offset; qCritical() << "ERROR AT OFFSET" << offset;
return -1; //return -1;
} }
} else } else
if (offset < 9*60) { // [8:00 - 9:00[ if (offset < 9*60) { // [8:00 - 9:00[
if (!test_neuhauser_kirchdorf(*step, cost)) { double new_cost = cost;
if (offset > (18*60)-(*step)) {
new_cost += ((*step-30)/5)*10;
qCritical() << __LINE__ << "new_cost" << new_cost << "(cost" << cost << ")";
}
if (!test_neuhauser_kirchdorf(*step, new_cost)) {
qCritical() << "ERROR AT OFFSET" << offset; qCritical() << "ERROR AT OFFSET" << offset;
return -1; //return -1;
} }
} else } else
if (offset < 10*60) { if (offset < 10*60) {
if (!test_neuhauser_kirchdorf(*step, cost)) { double new_cost = cost;
if (offset > (18*60)-(*step)) {
new_cost += ((*step-30)/5)*10;
qCritical() << __LINE__ << "new_cost" << new_cost << "(cost" << cost << ")";
}
if (!test_neuhauser_kirchdorf(*step, new_cost)) {
qCritical() << "ERROR AT OFFSET" << offset; qCritical() << "ERROR AT OFFSET" << offset;
return -1; //return -1;
} }
} else } else
if (offset < 11*60) { if (offset < 11*60) {
if (!test_neuhauser_kirchdorf(*step, cost)) { double new_cost = cost;
if (offset > (18*60)-(*step)) {
new_cost += ((*step-30)/5)*10;
qCritical() << __LINE__ << "new_cost" << new_cost << "(cost" << cost << ")";
}
if (!test_neuhauser_kirchdorf(*step, new_cost)) {
qCritical() << "ERROR AT OFFSET" << offset; qCritical() << "ERROR AT OFFSET" << offset;
return -1; //return -1;
} }
} else } else
if (offset < 12*60) { if (offset < 12*60) {
if (!test_neuhauser_kirchdorf(*step, cost)) { double new_cost = cost;
if (offset > (18*60)-(*step)) {
new_cost += ((*step-30)/5)*10;
qCritical() << __LINE__ << "new_cost" << new_cost << "(cost" << cost << ")";
}
if (!test_neuhauser_kirchdorf(*step, new_cost)) {
qCritical() << "ERROR AT OFFSET" << offset; qCritical() << "ERROR AT OFFSET" << offset;
return -1; //return -1;
} }
} else } else
if (offset < 13*60) { if (offset < 13*60) {
if (!test_neuhauser_kirchdorf(*step, cost)) { double new_cost = cost;
if (offset > (18*60)-(*step)) {
new_cost += ((*step-30)/5)*10;
qCritical() << __LINE__ << "new_cost" << new_cost << "(cost" << cost << ")";
}
if (!test_neuhauser_kirchdorf(*step, new_cost)) {
qCritical() << "ERROR AT OFFSET" << offset; qCritical() << "ERROR AT OFFSET" << offset;
return -1; //return -1;
} }
} else } else
if (offset < 14*60) { if (offset < 14*60) {
if (!test_neuhauser_kirchdorf(*step, cost)) { double new_cost = cost;
if (offset > (18*60)-(*step)) {
new_cost += ((*step-30)/5)*10;
qCritical() << __LINE__ << "new_cost" << new_cost << "(cost" << cost << ")";
}
if (!test_neuhauser_kirchdorf(*step, new_cost)) {
qCritical() << "ERROR AT OFFSET" << offset; qCritical() << "ERROR AT OFFSET" << offset;
return -1; //return -1;
} }
} else } else
if (offset < 15*60) { if (offset < 15*60) {
if (!test_neuhauser_kirchdorf(*step, cost)) { double new_cost = cost;
if (offset > (18*60)-(*step)) {
new_cost += ((*step-30)/5)*10;
qCritical() << __LINE__ << "new_cost" << new_cost << "(cost" << cost << ")";
}
if (!test_neuhauser_kirchdorf(*step, new_cost)) {
qCritical() << "ERROR AT OFFSET" << offset; qCritical() << "ERROR AT OFFSET" << offset;
return -1; //return -1;
} }
} else } else
if (offset < 16*60) { if (offset < 16*60) {
if (!test_neuhauser_kirchdorf(*step, cost)) { double new_cost = cost;
if (offset > (18*60)-(*step)) {
new_cost += ((*step-30)/5)*10;
qCritical() << __LINE__ << "new_cost" << new_cost << "(cost" << cost << ")";
}
if (!test_neuhauser_kirchdorf(*step, new_cost)) {
qCritical() << "ERROR AT OFFSET" << offset; qCritical() << "ERROR AT OFFSET" << offset;
return -1; //return -1;
} }
} else } else
if (offset < 17*60) { if (offset < 17*60) {
if (!test_neuhauser_kirchdorf(*step, cost)) { double new_cost = cost;
if (offset > (18*60)-(*step)) {
double const f = ((*step-30)/5)*10;
new_cost += f;
new_cost = std::min(new_cost, f+30);
qCritical() << __LINE__ << "new_cost" << new_cost << "(cost" << cost << ")";
}
if (!test_neuhauser_kirchdorf(*step, new_cost)) {
qCritical() << "ERROR AT OFFSET" << offset; qCritical() << "ERROR AT OFFSET" << offset;
return -1; //return -1;
}
} else
if (offset < 18*60) {
double new_cost = cost;
if (offset > (18*60)-(*step)) {
double const f = ((*step-30)/5)*10;
new_cost += f;
new_cost = std::min(new_cost, f+30);
qCritical() << __LINE__ << "new_cost" << new_cost << "(cost" << cost << ")";
}
if (!test_neuhauser_kirchdorf(*step, new_cost)) {
qCritical() << "ERROR AT OFFSET" << offset;
// return -1;
} }
} else { } else {
qCritical() << "WARN OFFSET TOO HIGH" << offset; qCritical() << "ERROR OFFSET TOO HIGH" << offset;
return -1;
} }
} else { } else {
@ -648,7 +720,9 @@ int main() {
} }
return 0; return 0;
#elif SZEGED==1 #endif
#if SZEGED==1
std::ifstream input; std::ifstream input;
int pop_min_time; int pop_min_time;
int pop_max_time; int pop_max_time;
@ -660,27 +734,27 @@ int main() {
//for (int t=6; t < 7; t+=20) { //for (int t=6; t < 7; t+=20) {
switch (zone) { switch (zone) {
case 1: { 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; //pop_max_time = 6*60;
} break; } break;
case 2: { 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; //pop_max_time = 5*60;
} break; } break;
case 3: { 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; //pop_max_time = 6*60;
} break; } break;
case 4: { 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; //pop_max_time = 4*60;
} break; } break;
case 5: { 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; //pop_max_time = 6*60;
} break; } break;
case 6: { 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; //pop_max_time = 4*60;
} break; } break;
default: default:
@ -735,7 +809,6 @@ int main() {
QDateTime s(QDate(2023, 11, 30), QTime()); QDateTime s(QDate(2023, 11, 30), QTime());
QDateTime end; QDateTime end;
int cnt = 1; int cnt = 1;
#if 1
if (zone == 1) { if (zone == 1) {
m.insert(5, pop_min_price); m.insert(5, pop_min_price);
m.insert(10, pop_min_price); // 42 m.insert(10, pop_min_price); // 42
@ -1245,13 +1318,13 @@ int main() {
//qCritical() << start.toString(Qt::ISODate) << end.toString(Qt::ISODate) //qCritical() << start.toString(Qt::ISODate) << end.toString(Qt::ISODate)
// << duration << cost; // << duration << cost;
//if (cost != m[duration]) { if (cost != m[duration]) {
// qCritical() << "ERROR computing_price_for_parking_ticket" qCritical() << "ERROR computing_price_for_parking_ticket"
// << "duration" << duration << "duration" << duration
// << "HAVE cost" << cost << "HAVE cost" << cost
// << "SHOULD HAVE cost" << m[duration]; << "SHOULD HAVE cost" << m[duration];
// return -1; return -1;
//} }
} else { } else {
qCritical() << "ERROR computing_price_for_parking_ticket AT" qCritical() << "ERROR computing_price_for_parking_ticket AT"
<< cnt << "duration" << duration << cnt << "duration" << duration
@ -1262,54 +1335,34 @@ int main() {
end = QDateTime(); end = QDateTime();
price.netto = 0; price.netto = 0;
if (zone >= 1 && zone <= 6) { if (compute_price_for_daily_ticket(&cfg, start, end, PERMIT_TYPE::DAY_TICKET, &price)) {
if (compute_price_for_daily_ticket(&cfg, start, end, PERMIT_TYPE::DAY_TICKET, &price)) { if (price.netto != pop_daily_card_price) {
if (price.netto != pop_daily_card_price) { qCritical() << "ERROR computing_price_for_daily_ticket"
qCritical() << "ERROR computing_price_for_daily_ticket" << "duration" << duration
<< "duration" << duration << "HAVE cost" << price.netto
<< "HAVE cost" << price.netto << "SHOULD HAVE cost" << pop_daily_card_price;
<< "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; 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; ++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 +1563,6 @@ int main() {
} }
} }
} }
#endif #endif
return 0;
} }