Merge branch 'moransBranch'
This commit is contained in:
151
main/main.cpp
151
main/main.cpp
@@ -1,10 +1,9 @@
|
||||
#include <calculate_price.h>
|
||||
|
||||
|
||||
#ifdef WIN32
|
||||
#include <time.h>
|
||||
#include <iomanip>
|
||||
#include <sstream>
|
||||
#include <calculate_price.h>
|
||||
|
||||
|
||||
extern "C" char* strptime(const char* s,
|
||||
const char* f,
|
||||
@@ -33,6 +32,7 @@ extern "C" char* strptime(const char* s,
|
||||
#include <sstream>
|
||||
#include "calculator_functions.h"
|
||||
|
||||
|
||||
int main() {
|
||||
|
||||
std::ifstream input(QDir::homePath().append("/tariff01.json").toStdString());
|
||||
@@ -70,85 +70,90 @@ int main() {
|
||||
memset(&price, 0x00, sizeof(price));
|
||||
QDateTime start = QDateTime::fromString("2023-05-11T07:50:00",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 + 1230;
|
||||
|
||||
if (compute_price_for_parking_ticket(tariff,
|
||||
start_parking_time,
|
||||
end_parking_time,
|
||||
&price)) {
|
||||
&price))
|
||||
{
|
||||
qDebug() << "GetCostFromDuration() => price=" << price.netto;
|
||||
}
|
||||
|
||||
QString duration;
|
||||
if(compute_duration_for_parking_ticket(tariff,start_parking_time,1525,duration))
|
||||
if(compute_duration_for_parking_ticket(tariff,start_parking_time,3090,duration))
|
||||
{
|
||||
qDebug() << "GetDurationFromCost() => duration=" << duration;
|
||||
}
|
||||
|
||||
// // tests
|
||||
// struct tm now;
|
||||
// memset(&now, 0, sizeof(now));
|
||||
// Daily ticket
|
||||
compute_duration_for_daily_ticket(tariff,start.toString(Qt::ISODate),3);
|
||||
|
||||
// // 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
|
||||
//Configuration* cfg, QString start_datetime, uint8_t payment_option, bool carry_over
|
||||
// // tests
|
||||
// struct tm now;
|
||||
// memset(&now, 0, sizeof(now));
|
||||
|
||||
// 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;
|
||||
// // 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();
|
||||
// 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(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;
|
||||
|
||||
// t = (start_parking_time + 60)*60;
|
||||
// now = *localtime(&t);
|
||||
// }
|
||||
// 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);
|
||||
// }
|
||||
|
||||
free_tariff(tariff);
|
||||
}
|
||||
@@ -185,7 +190,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) {
|
||||
@@ -260,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 +304,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:
|
||||
@@ -333,8 +338,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="
|
||||
|
Reference in New Issue
Block a user