Fix with min time in GetDurationFromCost

This commit is contained in:
Moran Rod 2023-05-14 17:19:24 +02:00
parent 1142efaec2
commit 6b3c1cbf0c
2 changed files with 73 additions and 70 deletions

View File

@ -43,6 +43,7 @@ std::string Calculator::GetDurationFromCost(Configuration* cfg,
double min_price = 0;
min_price = cfg->PaymentOption.find(payment_option)->second.pop_min_price;
if(price < min_price)
{
return "PARKING NOT ALLOWED";
@ -109,6 +110,8 @@ std::string Calculator::GetDurationFromCost(Configuration* cfg,
}
if (price_per_unit < 0) price_per_unit = 1.0f;
if((price/price_per_unit) < minMin) return "PARKING NOT ALLOWED";
LOG_DEBUG("Calculated price per minute: ", price_per_unit);
if (price_per_unit < 0)

View File

@ -34,9 +34,9 @@ int main() {
if (init_tariff(&tariff, "C:\\Users\\MROD\\Documents\\QtCreator\\build-MOBILISIS-Calculator-Desktop_Qt_5_12_12_MSVC2017_32bit-Debug\\main\\etc\\psa_tariff\\zone1.json")) {
struct price_t price;
memset(&price, 0x00, sizeof(price));
QDateTime start = QDateTime::fromString("2023-05-12T15:00:34",Qt::ISODate); //QDateTime::currentDateTime();
QDateTime start = QDateTime::fromString("2023-05-12T15:00:38",Qt::ISODate); //QDateTime::currentDateTime();
time_t start_parking_time = start.toSecsSinceEpoch() / 60;
time_t end_parking_time = start_parking_time + 610;
time_t end_parking_time = start_parking_time + 15;
if (compute_price_for_parking_ticket(tariff,
start_parking_time,
@ -46,75 +46,75 @@ int main() {
}
QString duration;
if(compute_duration_for_parking_ticket(tariff,start_parking_time,188,duration))
if(compute_duration_for_parking_ticket(tariff,start_parking_time,37.5,duration))
{
qDebug() << "GetDurationFromCost() => duration=" << duration;
}
// // tests
// struct tm now;
// memset(&now, 0, sizeof(now));
// // tests
// struct tm now;
// memset(&now, 0, sizeof(now));
// // 3.Jan 2023 -> Tuesday
// strptime("2023-01-03T14:00:00", "%Y-%m-%dT%H:%M:%S", &now);
// for (int i = 0; i < 600; ++i) {
// start_parking_time = mktime(&now);
// end_parking_time = start_parking_time + 240; // duration == 240
// // 3.Jan 2023 -> Tuesday
// strptime("2023-01-03T14:00:00", "%Y-%m-%dT%H:%M:%S", &now);
// for (int i = 0; i < 600; ++i) {
// start_parking_time = mktime(&now);
// end_parking_time = start_parking_time + 240; // duration == 240
// if (compute_price_for_parking_ticket(tariff,
// start_parking_time,
// end_parking_time,
// &price)) {
// int const zone = get_zone_nr(1);
// switch (zone) {
// case 1:
// assert(price.netto == 879); // expected value: 880
// break;
// case 2:
// /* fall through */
// case 3:
// assert(price.netto == 1920);
// break;
// }
// }
// time_t t = start_parking_time + 60;
// now = *localtime(&t);
// }
// //
// // test May 1st 2023
// //
// memset(&now, 0, sizeof(now));
// strptime("2023-04-30T06:00:00", "%Y-%m-%dT%H:%M:%S", &now);
// now.tm_hour -= 1; // for ctime
// // for (int i=0; i<6*24; ++i) {
// for (int i=0; i<1; ++i) {
// int const duration = 120;
// time_t t = mktime(&now);
// start_parking_time = t / 60;
// end_parking_time = start_parking_time + duration;
// if (compute_price_for_parking_ticket(tariff,
// start_parking_time,
// end_parking_time,
// &price)) {
// int const zone = get_zone_nr(1);
// switch (zone) {
// case 1:
// assert(price.netto == 879); // expected value: 880
// break;
// case 2:
// /* fall through */
// case 3:
// assert(price.netto == 1920);
// break;
// }
// }
// time_t t = start_parking_time + 60;
// now = *localtime(&t);
// }
// //
// // test May 1st 2023
// //
// memset(&now, 0, sizeof(now));
// strptime("2023-04-30T06:00:00", "%Y-%m-%dT%H:%M:%S", &now);
// now.tm_hour -= 1; // for ctime
// // for (int i=0; i<6*24; ++i) {
// for (int i=0; i<1; ++i) {
// int const duration = 120;
// time_t t = mktime(&now);
// start_parking_time = t / 60;
// end_parking_time = start_parking_time + duration;
// if (compute_price_for_parking_ticket(tariff,
// start_parking_time,
// end_parking_time,
// &price)) {
// int const zone = get_zone_nr();
// switch (zone) {
// case 1:
// qDebug() << i << zone << ctime(&t) << price.netto << " FT";
// assert(price.netto == 440);
// break;
// case 2:
// /* fall through */
// case 3:
// qDebug() << i << zone << ctime(&t) << price.netto << " FT";
// assert(price.netto == 960);
// break;
// }
// }
// if (compute_price_for_parking_ticket(tariff,
// start_parking_time,
// end_parking_time,
// &price)) {
// int const zone = get_zone_nr();
// switch (zone) {
// case 1:
// qDebug() << i << zone << ctime(&t) << price.netto << " FT";
// assert(price.netto == 440);
// break;
// case 2:
// /* fall through */
// case 3:
// qDebug() << i << zone << ctime(&t) << price.netto << " FT";
// assert(price.netto == 960);
// break;
// }
// }
// t = (start_parking_time + 60)*60;
// now = *localtime(&t);
// }
// t = (start_parking_time + 60)*60;
// now = *localtime(&t);
// }
free_tariff(tariff);
}
@ -151,7 +151,7 @@ int main() {
struct tm now; // = Utilities::DateTimeToStructTm("2023-03-01T16:00:00");
memset(&now, 0, sizeof(now));
char buffer[64];
//#if 0
//#if 0
// 3.Jan 2023 -> Tuesday
strptime("2023-01-03T14:00:00", "%Y-%m-%dT%H:%M:%S", &now);
for (int i = 0; i < 600; ++i) {
@ -226,8 +226,8 @@ int main() {
int const duration = 120;
double cost = calculator.GetCostFromDuration(&cfg,
PaymentOption::Option1, buffer, duration,
false, true);
PaymentOption::Option1, buffer, duration,
false, true);
switch (zone) {
case 1:
@ -265,8 +265,8 @@ int main() {
int const duration = 120;
double cost = calculator.GetCostFromDuration(&cfg,
PaymentOption::Option1, buffer, duration,
false, true);
PaymentOption::Option1, buffer, duration,
false, true);
switch (zone) {
case 1:
@ -299,8 +299,8 @@ int main() {
double const compCost = (duration < 15) ? 0 : duration * ((zone == 1) ? 3.6666 : 8.0);
double cost = calculator.GetCostFromDuration(&cfg,
PaymentOption::Option1, buffer, duration,
false, true);
PaymentOption::Option1, buffer, duration,
false, true);
if (fabs(cost - compCost) > 1.0) { // zone 1 has rounding errors
cout << "ERROR ===> [" << i << "] " << asctime(&now)
<< " - Total cost is: " << cost << " FT (computed="