prepared test case for neuhauser-kirchdorf

This commit is contained in:
Gerhard Hoffmann 2024-02-22 08:02:55 +01:00
parent 7933c826e6
commit 30768c6931

View File

@ -27,6 +27,7 @@ extern "C" char* strptime(const char* s,
#include <QDebug> #include <QDebug>
#include <QDateTime> #include <QDateTime>
#include <QDir> #include <QDir>
#include <QFileInfo>
#include <fstream> #include <fstream>
#include <sstream> #include <sstream>
@ -41,6 +42,121 @@ extern "C" char* strptime(const char* s,
#define NEUHAUSER_BILEXA_GALTUER (0) #define NEUHAUSER_BILEXA_GALTUER (0)
#define NEUHAUSER_KIRCHDORF (1) #define NEUHAUSER_KIRCHDORF (1)
#if NEUHAUSER_KIRCHDORF==1
static bool test_neuhauser_kirchdorf(int step, double cost) {
switch (step) {
case 30:
if (cost != 30) {
qCritical() << "ERROR COMPUTING COST"
<< "HAVE" << cost
<< "SHOULD" << 30;
return false;
}
break;
case 35:
if (cost != 40) {
qCritical() << "ERROR COMPUTING COST"
<< "HAVE" << cost
<< "SHOULD" << 40;
return false;
}
break;
case 40:
if (cost != 50) {
qCritical() << "ERROR COMPUTING COST"
<< "HAVE" << cost
<< "SHOULD" << 50;
return false;
}
break;
case 45:
if (cost != 60) {
qCritical() << "ERROR COMPUTING COST"
<< "HAVE" << cost
<< "SHOULD" << 60;
return false;
}
break;
case 50:
if (cost != 70) {
qCritical() << "ERROR COMPUTING COST"
<< "HAVE" << cost
<< "SHOULD" << 70;
return false;
}
break;
case 55:
if (cost != 80) {
qCritical() << "ERROR COMPUTING COST"
<< "HAVE" << cost
<< "SHOULD" << 80;
return false;
}
break;
case 60:
if (cost != 90) {
qCritical() << "ERROR COMPUTING COST"
<< "HAVE" << cost
<< "SHOULD" << 90;
return false;
}
break;
case 65:
if (cost != 100) {
qCritical() << "ERROR COMPUTING COST"
<< "HAVE" << cost
<< "SHOULD" << 100;
return false;
}
break;
case 70:
if (cost != 110) {
qCritical() << "ERROR COMPUTING COST"
<< "HAVE" << cost
<< "SHOULD" << 110;
return false;
}
break;
case 75:
if (cost != 120) {
qCritical() << "ERROR COMPUTING COST"
<< "HAVE" << cost
<< "SHOULD" << 120;
return false;
}
break;
case 80:
if (cost != 130) {
qCritical() << "ERROR COMPUTING COST"
<< "HAVE" << cost
<< "SHOULD" << 130;
return false;
}
break;
case 85:
if (cost != 140) {
qCritical() << "ERROR COMPUTING COST"
<< "HAVE" << cost
<< "SHOULD" << 140;
return false;
}
break;
case 90:
if (cost != 150) {
qCritical() << "ERROR COMPUTING COST"
<< "HAVE" << cost
<< "SHOULD" << 150;
return false;
}
break;
default:
break;
}
return true;
}
#endif
int main() { int main() {
#if SCHOENAU_KOENIGSEE==1 #if SCHOENAU_KOENIGSEE==1
@ -89,6 +205,160 @@ int main() {
#endif #endif
#if NEUHAUSER_KIRCHDORF==1 #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";
std::ifstream input(f);
std::stringstream sstr;
while(input >> sstr.rdbuf());
std::string json(sstr.str());
Configuration cfg;
bool isParsed = cfg.ParseJson(&cfg, json.c_str());
if (!isParsed) {
qCritical() << "ERROR: CANNOT PARSE" << f;
return -1;
}
qCritical() << "Successfully parsed" << f;
int const minParkingTime = get_minimal_parkingtime(&cfg);
int const maxParkingTime = get_maximal_parkingtime(&cfg);
int const minParkingPrice = get_minimal_parkingprice(&cfg);
if (minParkingTime != 30) {
qCritical() << "ERROR: WRONG MIN_PARKING_TIME" << minParkingTime;
return -1;
}
qCritical() << "min_parking_time " << minParkingTime;
if (maxParkingTime != 90) {
qCritical() << "ERROR: WRONG MAX_PARKING_TIME" << maxParkingTime;
return -1;
}
qCritical() << "max_parking_time " << maxParkingTime;
if (minParkingPrice != 30) {
qCritical() << "ERROR: WRONG MIN_PARKING_PRICE" << minParkingPrice;
return -1;
}
qCritical() << "min_parking_price" << minParkingPrice;
QList<int> const stepsConfigured
= QList(std::initializer_list<int>{
30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90});
QList<int> const steps = Calculator::GetInstance().GetTimeSteps(&cfg);
if (stepsConfigured != steps) {
qCritical() << "ERROR: WRONG TIME-STEP-LIST" << steps;
qCritical() << "SHOULD BE" << stepsConfigured;
return -1;
}
qCritical() << "time steps" << steps;
QDateTime s(QDate(2024, 2, 21), QTime());
QDateTime end;
struct price_t price;
QList<int>::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) {
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);
if (offset < 8*60) { // [7:00 - 8:00[
if (!test_neuhauser_kirchdorf(*step, cost)) {
qCritical() << "ERROR AT OFFSET" << offset;
return -1;
}
} else
if (offset < 9*60) { // [8:00 - 9:00[
if (!test_neuhauser_kirchdorf(*step, cost)) {
qCritical() << "ERROR AT OFFSET" << offset;
return -1;
}
} else
if (offset < 10*60) {
if (!test_neuhauser_kirchdorf(*step, cost)) {
qCritical() << "ERROR AT OFFSET" << offset;
return -1;
}
} else
if (offset < 11*60) {
if (!test_neuhauser_kirchdorf(*step, cost)) {
qCritical() << "ERROR AT OFFSET" << offset;
return -1;
}
} else
if (offset < 12*60) {
if (!test_neuhauser_kirchdorf(*step, cost)) {
qCritical() << "ERROR AT OFFSET" << offset;
return -1;
}
} else
if (offset < 13*60) {
if (!test_neuhauser_kirchdorf(*step, cost)) {
qCritical() << "ERROR AT OFFSET" << offset;
return -1;
}
} else
if (offset < 14*60) {
if (!test_neuhauser_kirchdorf(*step, cost)) {
qCritical() << "ERROR AT OFFSET" << offset;
return -1;
}
} else
if (offset < 15*60) {
if (!test_neuhauser_kirchdorf(*step, cost)) {
qCritical() << "ERROR AT OFFSET" << offset;
return -1;
}
} else
if (offset < 16*60) {
if (!test_neuhauser_kirchdorf(*step, cost)) {
qCritical() << "ERROR AT OFFSET" << offset;
return -1;
}
} else
if (offset < 17*60) {
if (!test_neuhauser_kirchdorf(*step, cost)) {
qCritical() << "ERROR AT OFFSET" << offset;
return -1;
}
} else {
qCritical() << "WARN OFFSET TOO HIGH" << offset;
}
} else {
qCritical() << "ERROR COMPUTING PRICE FOR"
<< "start" << start.toString(Qt::ISODate)
<< "step" << *step
<< "end" << end.toString(Qt::ISODate);
return -1;
}
}
}
}
return 0;
}
#if 0
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);
@ -110,18 +380,18 @@ int main() {
qCritical() << "max_parking_time " << maxParkingTime; qCritical() << "max_parking_time " << maxParkingTime;
qCritical() << "min_parking_price" << minParkingPrice; qCritical() << "min_parking_price" << minParkingPrice;
#if 1
bool nextDay = false; bool nextDay = false;
bool prePaid = true; bool prePaid = true;
// bool carryOver = false; // bool carryOver = false;
//QDateTime s = QDateTime::currentDateTime();
QDateTime s(QDate(2024, 2, 21), QTime()); QDateTime s(QDate(2024, 2, 21), QTime());
QDateTime end; QDateTime end;
for (int duration = 30; duration <= 90; duration += 5) { for (int duration = 30; duration <= 90; duration += 5) {
// for (int duration = 30; duration <= maxParkingTime; duration += 5) { // for (int duration = 30; duration <= maxParkingTime; duration += 5) {
qCritical() << ""; qCritical() << "";
//for (int offset = 420; offset <= 1080; ++offset) {
for (int offset = 420; offset <= 1080; ++offset) { for (int offset = 420; offset <= 1080; ++offset) {
//for (int offset = 0; offset <= 0; ++offset) {
//for (int offset = 420; offset <= 1080; ++offset) { //for (int offset = 420; offset <= 1080; ++offset) {
//if (offset > 720 && offset < 840) { //if (offset > 720 && offset < 840) {
// continue; // continue;
@ -130,7 +400,12 @@ int main() {
QDateTime const firstStart = start; QDateTime const firstStart = start;
// qCritical() << "start" << start.toString(Qt::ISODate); // qCritical() << "start" << start.toString(Qt::ISODate);
double cost = Calculator::GetInstance().GetCostFromDuration(&cfg, 1, start, end, duration, nextDay, prePaid); // double cost = Calculator::GetInstance().GetCostFromDuration(&cfg, 1, start, end, duration, nextDay, prePaid);
struct price_t price;
compute_price_for_parking_ticket(&cfg, start, duration, end, &price);
double cost = price.netto;
//#if COST_FROM_DURATION==0 //#if COST_FROM_DURATION==0
double cost_soll = 30 + ((duration-30)/5 * 10); double cost_soll = 30 + ((duration-30)/5 * 10);
@ -144,10 +419,10 @@ int main() {
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() << "duration (soll):" << duration; //qCritical() << "duration (soll):" << duration;
qCritical() << "duration (ist) :" << duration_ist; //qCritical() << "duration (ist) :" << duration_ist;
qCritical() << " cost (soll):" << cost_soll; //qCritical() << " cost (soll):" << cost_soll;
qCritical() << " cost (ist) :" << cost; //qCritical() << " cost (ist) :" << cost;
// if (cost_soll != cost) { // if (cost_soll != cost) {
//qCritical() << "ERROR" << __func__ << ":" << __LINE__ //qCritical() << "ERROR" << __func__ << ":" << __LINE__
@ -161,32 +436,31 @@ int main() {
// } // }
//#else //#else
start = s.addSecs(offset * 60); //start = s.addSecs(offset * 60);
std::string duration = Calculator::GetInstance().GetDurationFromCost(&cfg, 1, //std::string duration = Calculator::GetInstance().GetDurationFromCost(&cfg, 1,
start.toString(Qt::ISODate).toStdString().c_str(), // start.toString(Qt::ISODate).toStdString().c_str(),
cost, false, true); // cost, false, true);
if (end.toString(Qt::ISODate) != QString(duration.c_str())) { //if (end.toString(Qt::ISODate) != QString(duration.c_str())) {
//qCritical() << "ERROR" << end.toString(Qt::ISODate) //qCritical() << "ERROR" << end.toString(Qt::ISODate)
// << QString(duration.c_str()); // << QString(duration.c_str());
//break; //break;
} //}
qCritical() << "start" << start.toString(Qt::ISODate) //qCritical() << "start" << start.toString(Qt::ISODate)
<< "cost" << cost // << "cost" << cost
<< "until" << duration.c_str() // << "until" << duration.c_str()
<< "end" << end.toString(Qt::ISODate) // << "end" << end.toString(Qt::ISODate)
<< ":" << start.secsTo(QDateTime::fromString(duration.c_str(), Qt::ISODate)) / 60 // << ":" << start.secsTo(QDateTime::fromString(duration.c_str(), Qt::ISODate)) / 60
<< (end.toString(Qt::ISODate) == QString(duration.c_str())); // << (end.toString(Qt::ISODate) == QString(duration.c_str()));
//#endif // COST_FROM_DURATION //#endif // COST_FROM_DURATION
} }
} }
#endif // 0 #endif // 0
}
#endif #endif
#if NEUHAUSER_BILEXA_GALTUER==1 #if NEUHAUSER_BILEXA_GALTUER==1