473 lines
31 KiB
C++
473 lines
31 KiB
C++
#ifdef WIN32
|
|
#include <time.h>
|
|
#include <iomanip>
|
|
#include <sstream>
|
|
#include <calculate_price.h>
|
|
|
|
|
|
extern "C" char* strptime(const char* s,
|
|
const char* f,
|
|
struct tm* tm) {
|
|
// Isn't the C++ standard lib nice? std::get_time is defined such that its
|
|
// format parameters are the exact same as strptime. Of course, we have to
|
|
// create a string stream first, and imbue it with the current C locale, and
|
|
// we also have to make sure we return the right things if it fails, or
|
|
// if it succeeds, but this is still far simpler an implementation than any
|
|
// of the versions in any of the C standard libraries.
|
|
std::istringstream input(s);
|
|
input.imbue(std::locale(setlocale(LC_ALL, nullptr)));
|
|
input >> std::get_time(tm, f);
|
|
if (input.fail()) {
|
|
return nullptr;
|
|
}
|
|
return (char*)(s + input.tellg());
|
|
}
|
|
#endif
|
|
|
|
#include <QDebug>
|
|
#include <QDateTime>
|
|
#include <QDir>
|
|
|
|
#include <fstream>
|
|
#include <sstream>
|
|
#include "calculator_functions.h"
|
|
#include <calculate_price.h>
|
|
|
|
#define SZEGED (0)
|
|
#define NEUHAUSER_KORNEUBURG (0)
|
|
#define NEUHAUSER_LINSINGER_MASCHINENBAU (0)
|
|
#define NEUHAUSER_NORDISCHES_AUSBILDUNGSZENTRUM (0)
|
|
#define NEUHAUSER_BILEXA_GALTUER (1)
|
|
|
|
|
|
int main() {
|
|
#if NEUHAUSER_BILEXA_GALTUER==1
|
|
std::ifstream input("/opt/ptu5/opt/customer_745/etc/psa_tariff/tariff01.json");
|
|
|
|
std::stringstream sstr;
|
|
while(input >> sstr.rdbuf());
|
|
std::string json(sstr.str());
|
|
|
|
Configuration cfg;
|
|
|
|
bool isParsed = cfg.ParseJson(&cfg, json.c_str());
|
|
cout << endl;
|
|
|
|
if (isParsed) {
|
|
int minParkingTime = get_minimal_parkingtime(&cfg);
|
|
QList<int> timeSteps = Calculator::GetInstance().GetTimeSteps(&cfg);
|
|
qCritical() << timeSteps;
|
|
int Down = 0;
|
|
int Up = 1;
|
|
//compute_next_timestep(&cfg, )
|
|
|
|
for (int i=0; i<timeSteps.size(); ++i) {
|
|
int nextTimeStep = compute_next_timestep(&cfg, timeSteps.at(i), Up);
|
|
qCritical() << "nextTimeStep" << nextTimeStep;
|
|
|
|
// uint32_t price = calculator.GetPriceForTimeStep(&cfg, timeSteps.at(i));
|
|
// uint32_t duration = calculator.GetDurationForPrice(&cfg, price);
|
|
// qCritical() << "nextTimeStep relative to start:"
|
|
// << duration << start.addSecs(duration * 60)
|
|
// << "(price so far:" << price << ")";
|
|
}
|
|
}
|
|
#endif
|
|
|
|
#if NEUHAUSER_NORDISCHES_AUSBILDUNGSZENTRUM==1
|
|
std::ifstream input("/tmp/tariff_naz.json");
|
|
|
|
std::stringstream sstr;
|
|
while(input >> sstr.rdbuf());
|
|
std::string json(sstr.str());
|
|
|
|
Configuration cfg;
|
|
|
|
bool isParsed = cfg.ParseJson(&cfg, json.c_str());
|
|
cout << endl;
|
|
|
|
if (isParsed) {
|
|
// Calculator calculator;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#if NEUHAUSER_LINSINGER_MASCHINENBAU==1
|
|
std::ifstream input("/tmp/tariff_linsinger_maschinenbau.json");
|
|
|
|
std::stringstream sstr;
|
|
while(input >> sstr.rdbuf());
|
|
std::string json(sstr.str());
|
|
|
|
Calculator calculator;
|
|
Configuration cfg;
|
|
|
|
bool isParsed = cfg.ParseJson(&cfg, json.c_str());
|
|
cout << endl;
|
|
|
|
if (isParsed) {
|
|
bool nextDay = false;
|
|
bool prePaid = false;
|
|
|
|
// zone 1 (lila)
|
|
QDateTime s(QDate(2023, 11, 30), QTime());
|
|
QDateTime end;
|
|
int marken[] = { 3*60, 5*60, 10*60};
|
|
for (int duration = 0; duration < 3; ++duration) {
|
|
for (int offset = 360; offset <= 1080; ++offset) {
|
|
QDateTime start = s.addSecs(offset * 60);
|
|
//qCritical() << "start" << start.toString(Qt::ISODate);
|
|
|
|
double cost = calculator.GetCostFromDuration(&cfg, 4, start, end, marken[duration], nextDay, prePaid);
|
|
//qCritical() << "";
|
|
//qCritical() << "start" << start.toString(Qt::ISODate)
|
|
// << "end" << end.toString(Qt::ISODate)
|
|
// << "duration" << marken[duration]
|
|
// << "cost" << cost;
|
|
|
|
std::string d = calculator.GetDurationFromCost(&cfg, 4, start.toString(Qt::ISODate).toStdString().c_str(), cost);
|
|
qCritical() << "start" << start.toString(Qt::ISODate)
|
|
<< "cost" << cost
|
|
<< "until" << d.c_str() << start.secsTo(QDateTime::fromString(d.c_str(), Qt::ISODate)) / 60;
|
|
}
|
|
}
|
|
}
|
|
#endif
|
|
|
|
#if NEUHAUSER_KORNEUBURG==1
|
|
std::ifstream input("/tmp/tariff_korneuburg.json");
|
|
int pop_max_time;
|
|
|
|
std::stringstream sstr;
|
|
while(input >> sstr.rdbuf());
|
|
std::string json(sstr.str());
|
|
|
|
Calculator calculator;
|
|
Configuration cfg;
|
|
|
|
bool isParsed = cfg.ParseJson(&cfg, json.c_str());
|
|
cout << endl;
|
|
|
|
if (isParsed) {
|
|
{
|
|
pop_max_time = 3*60;
|
|
bool nextDay = false;
|
|
bool prePaid = true;
|
|
// zone 1 (lila)
|
|
QDateTime s(QDate(2023, 11, 30), QTime());
|
|
QDateTime end;
|
|
for (int duration = 30; duration <= pop_max_time; duration += 5) {
|
|
for (int offset = 420; offset < 1140; ++offset) {
|
|
if (offset > 720 && offset < 840) {
|
|
continue;
|
|
}
|
|
QDateTime start = s.addSecs(offset * 60);
|
|
//qCritical() << "start" << start.toString(Qt::ISODate);
|
|
|
|
double cost = calculator.GetCostFromDuration(&cfg, 3, start, end, duration, nextDay, prePaid);
|
|
//Q_ASSERT(cost == duration*2.5);
|
|
//qCritical() << "";
|
|
//qCritical() << "start" << start.toString(Qt::ISODate)
|
|
// << "end" << end.toString(Qt::ISODate)
|
|
// << "duration" << duration
|
|
// << "cost" << cost;
|
|
|
|
std::string duration = calculator.GetDurationFromCost(&cfg, 3, start.toString(Qt::ISODate).toStdString().c_str(), cost);
|
|
//Q_ASSERT(cost == duration*2.5);
|
|
qCritical() << "start" << start.toString(Qt::ISODate)
|
|
<< "cost" << cost
|
|
<< "until" << duration.c_str() << start.secsTo(QDateTime::fromString(duration.c_str(), Qt::ISODate)) / 60;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return 0;
|
|
|
|
#elif SZEGED==1
|
|
std::ifstream input;
|
|
int pop_max_time;
|
|
|
|
for (int t=6; t < 7; t+=20) {
|
|
switch (t) {
|
|
case 1: {
|
|
input.open("/opt/ptu5/opt/customer_281/etc/psa_tariff/tariff01.json");
|
|
pop_max_time = 6*60;
|
|
} break;
|
|
case 2: {
|
|
input.open("/opt/ptu5/opt/customer_281/etc/psa_tariff/tariff02.json");
|
|
pop_max_time = 5*60;
|
|
} break;
|
|
case 3: {
|
|
input.open("/opt/ptu5/opt/customer_281/etc/psa_tariff/tariff03.json");
|
|
pop_max_time = 6*60;
|
|
} break;
|
|
case 4: {
|
|
input.open("/opt/ptu5/opt/customer_281/etc/psa_tariff/tariff04.json");
|
|
pop_max_time = 4*60;
|
|
} break;
|
|
case 5: {
|
|
input.open("/opt/ptu5/opt/customer_281/etc/psa_tariff/tariff05.json");
|
|
pop_max_time = 6*60;
|
|
} break;
|
|
case 6: {
|
|
input.open("/opt/ptu5/opt/customer_281/etc/psa_tariff/tariff06.json");
|
|
pop_max_time = 4*60;
|
|
} break;
|
|
default:
|
|
continue;
|
|
}
|
|
std::stringstream sstr;
|
|
while(input >> sstr.rdbuf());
|
|
std::string json(sstr.str());
|
|
|
|
Calculator calculator;
|
|
Configuration cfg;
|
|
|
|
bool isParsed = cfg.ParseJson(&cfg, json.c_str());
|
|
cout << endl;
|
|
|
|
if (isParsed) {
|
|
{
|
|
// zone 1 (lila)
|
|
QDateTime s(QDate(2023, 11, 30), QTime());
|
|
QDateTime end;
|
|
for (int duration = 15; duration <= pop_max_time; duration += 5) {
|
|
for (int offset = 480; offset < 1080; ++offset) {
|
|
QDateTime start = s.addSecs(offset * 60);
|
|
//qCritical() << "start" << start.toString(Qt::ISODate);
|
|
|
|
double cost = calculator.GetCostFromDuration(&cfg, 3, start, end, duration);
|
|
//Q_ASSERT(cost == duration*2.5);
|
|
//qCritical() << "";
|
|
//qCritical() << "start" << start.toString(Qt::ISODate)
|
|
// << "end" << end.toString(Qt::ISODate)
|
|
// << "duration" << duration
|
|
// << "cost" << cost;
|
|
|
|
std::string duration = calculator.GetDurationFromCost(&cfg, 3, start.toString(Qt::ISODate).toStdString().c_str(), cost);
|
|
//Q_ASSERT(cost == duration*2.5);
|
|
qCritical() << "start" << start.toString(Qt::ISODate)
|
|
<< "cost" << cost
|
|
<< "until" << duration.c_str() << start.secsTo(QDateTime::fromString(duration.c_str(), Qt::ISODate)) / 60;
|
|
}
|
|
}
|
|
}
|
|
{
|
|
QDateTime start(QDate(2023, 12, 1), QTime(18, 0));
|
|
QDateTime end;
|
|
double cost = calculator.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.GetCostFromDuration(&cfg, 3, start, end, 60);
|
|
//Q_ASSERT(cost == 150);
|
|
qCritical() << "end" << end.toString(Qt::ISODate) << "cost" << cost;
|
|
}
|
|
}
|
|
}
|
|
|
|
return 0;
|
|
|
|
#endif
|
|
|
|
#if 0
|
|
|
|
//std::string json = "{\"Currency\":[{\"pcu_id\":2,\"pcu_sign\":\"Ft\",\"pcu_major\":\"HUF\",\"pcu_minor\":\"\",\"pcu_active\":true}],\"PaymentMethod\":[{\"pme_id\":1,\"pme_label\":\"progressive\"},{\"pme_id\":2,\"pme_label\":\"degressive\"},{\"pme_id\":3,\"pme_label\":\"linear\"},{\"pme_id\":4,\"pme_label\":\"steps\"}],\"PaymentOption\":[{\"pop_id\":17,\"pop_label\":\"Zone 1\",\"pop_payment_method_id\":3,\"pop_day_end_time\":\"00:00:00\",\"pop_day_night_end_time\":\"00:00:00\",\"pop_price_night\":0,\"pop_min_time\":15,\"pop_max_time\":240,\"pop_min_price\":120,\"pop_carry_over\":1}],\"PaymentRate\":[{\"pra_payment_option_id\":17,\"pra_payment_unit_id\":3,\"pra_price\":480}],\"Duration\":[{\"pun_id\":1,\"pun_label\":\"1h\",\"pun_duration\":60},{\"pun_id\":2,\"pun_label\":\"1 min\",\"pun_duration\":1},{\"pun_id\":3,\"pun_label\":\"15 min\",\"pun_duration\":15},{\"pun_id\":4,\"pun_label\":\"1d\",\"pun_duration\":1440},{\"pun_id\":6,\"pun_label\":\"2h\",\"pun_duration\":120},{\"pun_id\":7,\"pun_label\":\"3h\",\"pun_duration\":180},{\"pun_id\":11,\"pun_label\":\"4h\",\"pun_duration\":240},{\"pun_id\":17,\"pun_label\":\"30 min\",\"pun_duration\":30},{\"pun_id\":18,\"pun_label\":\"1.5h\",\"pun_duration\":90},{\"pun_id\":20,\"pun_label\":\"10min\",\"pun_duration\":10}],\"WeekDaysWorktime\":[{\"pwd_id\":540,\"pwd_period_week_day_id\":32,\"pwd_period_day_in_week_id\":1,\"pwd_time_from\":\"08:00:00\",\"pwd_time_to\":\"18:00:00\"},{\"pwd_id\":541,\"pwd_period_week_day_id\":32,\"pwd_period_day_in_week_id\":2,\"pwd_time_from\":\"08:00:00\",\"pwd_time_to\":\"18:00:00\"},{\"pwd_id\":542,\"pwd_period_week_day_id\":32,\"pwd_period_day_in_week_id\":3,\"pwd_time_from\":\"08:00:00\",\"pwd_time_to\":\"18:00:00\"},{\"pwd_id\":543,\"pwd_period_week_day_id\":32,\"pwd_period_day_in_week_id\":4,\"pwd_time_from\":\"08:00:00\",\"pwd_time_to\":\"18:00:00\"},{\"pwd_id\":544,\"pwd_period_week_day_id\":32,\"pwd_period_day_in_week_id\":5,\"pwd_time_from\":\"08:00:00\",\"pwd_time_to\":\"18:00:00\"}],\"PeriodYear\":[{\"pye_id\":1,\"pye_label\":\"Summer\",\"pye_start_month\":6,\"pye_start_day\":1,\"pye_end_month\":9,\"pye_end_day\":30},{\"pye_id\":2,\"pye_label\":\"Winter\",\"pye_start_month\":10,\"pye_start_day\":1,\"pye_end_month\":5,\"pye_end_day\":31},{\"pye_id\":8,\"pye_label\":\"Whole year\",\"pye_start_month\":1,\"pye_start_day\":1,\"pye_end_month\":12,\"pye_end_day\":31}],\"SpecialDaysWorktime\":[{\"pedwt_id\":2156,\"pedwt_period_exc_day_id\":2024,\"pedwt_time_from\":\"00:00:00\",\"pedwt_time_to\":\"00:00:00\",\"pedwt_price\":0},{\"pedwt_id\":2158,\"pedwt_period_exc_day_id\":2025,\"pedwt_time_from\":\"00:00:00\",\"pedwt_time_to\":\"00:00:00\",\"pedwt_price\":0},{\"pedwt_id\":2160,\"pedwt_period_exc_day_id\":2026,\"pedwt_time_from\":\"00:00:00\",\"pedwt_time_to\":\"00:00:00\",\"pedwt_price\":0},{\"pedwt_id\":2162,\"pedwt_period_exc_day_id\":2027,\"pedwt_time_from\":\"00:00:00\",\"pedwt_time_to\":\"00:00:00\",\"pedwt_price\":0},{\"pedwt_id\":2164,\"pedwt_period_exc_day_id\":2028,\"pedwt_time_from\":\"00:00:00\",\"pedwt_time_to\":\"00:00:00\",\"pedwt_price\":0},{\"pedwt_id\":2170,\"pedwt_period_exc_day_id\":2030,\"pedwt_time_from\":\"00:00:00\",\"pedwt_time_to\":\"00:00:00\",\"pedwt_price\":0},{\"pedwt_id\":2172,\"pedwt_period_exc_day_id\":2032,\"pedwt_time_from\":\"00:00:00\",\"pedwt_time_to\":\"00:00:00\",\"pedwt_price\":0},{\"pedwt_id\":2174,\"pedwt_period_exc_day_id\":11,\"pedwt_time_from\":\"00:00:00\",\"pedwt_time_to\":\"00:00:00\",\"pedwt_price\":0},{\"pedwt_id\":2175,\"pedwt_period_exc_day_id\":13,\"pedwt_time_from\":\"00:00:00\",\"pedwt_time_to\":\"00:00:00\",\"pedwt_price\":0},{\"pedwt_id\":2178,\"pedwt_period_exc_day_id\":2022,\"pedwt_time_from\":\"00:00:00\",\"pedwt_time_to\":\"00:00:00\",\"pedwt_price\":0},{\"pedwt_id\":2179,\"pedwt_period_exc_day_id\":14,\"pedwt_time_from\":\"00:00:00\",\"pedwt_time_to\":\"00:00:00\",\"pedwt_price\":0},{\"pedwt_id\":2180,\"pedwt_period_exc_day_id\":2017,\"pedwt_time_from\":\"00:00:00\",\"pedwt_time_to\":\"00:00:00\",\"pedwt_price\":0},{\"pedwt_id\":2181,\"pedwt_period_exc_day_id\":2018,\"pedwt_time_from\":\"00:00:00\",\"pedwt_time_to\":\"00:00:00\",\"pedwt_price\":0},{\"pedwt_id\":2182,\"pedwt_period_exc_day_id\":2019,\"pedwt_time_from\":\"00:00:00\",\"pedwt_time_to\":\"00:00:00\",\"pedwt_price\":0},{\"pedwt_id\":2183,\"pedwt_period_exc_day_id\":2020,\"pedwt_time_from\":\"00:00:00\",\"pedwt_time_to\":\"00:00:00\",\"pedwt_price\":0},{\"pedwt_id\":2184,\"pedwt_period_exc_day_id\":2021,\"pedwt_time_from\":\"00:00:00\",\"pedwt_time_to\":\"00:00:00\",\"pedwt_price\":0},{\"pedwt_id\":2185,\"pedwt_period_exc_day_id\":2023,\"pedwt_time_from\":\"00:00:00\",\"pedwt_time_to\":\"00:00:00\",\"pedwt_price\":0},{\"pedwt_id\":2188,\"pedwt_period_exc_day_id\":2031,\"pedwt_time_from\":\"00:00:00\",\"pedwt_time_to\":\"00:00:00\",\"pedwt_price\":0},{\"pedwt_id\":2189,\"pedwt_period_exc_day_id\":2029,\"pedwt_time_from\":\"00:00:00\",\"pedwt_time_to\":\"00:00:00\",\"pedwt_price\":0},{\"pedwt_id\":2191,\"pedwt_period_exc_day_id\":2016,\"pedwt_time_from\":\"00:00:00\",\"pedwt_time_to\":\"00:00:00\",\"pedwt_price\":0},{\"pedwt_id\":2192,\"pedwt_period_exc_day_id\":2033,\"pedwt_time_from\":\"00:00:00\",\"pedwt_time_to\":\"00:00:00\",\"pedwt_price\":0},{\"pedwt_id\":2194,\"pedwt_period_exc_day_id\":2034,\"pedwt_time_from\":\"00:00:00\",\"pedwt_time_to\":\"00:00:00\",\"pedwt_price\":0},{\"pedwt_id\":2196,\"pedwt_period_exc_day_id\":2035,\"pedwt_time_from\":\"00:00:00\",\"pedwt_time_to\":\"00:00:00\",\"pedwt_price\":0},{\"pedwt_id\":2198,\"pedwt_period_exc_day_id\":2036,\"pedwt_time_from\":\"00:00:00\",\"pedwt_time_to\":\"00:00:00\",\"pedwt_price\":0},{\"pedwt_id\":2200,\"pedwt_period_exc_day_id\":2037,\"pedwt_time_from\":\"00:00:00\",\"pedwt_time_to\":\"00:00:00\",\"pedwt_price\":0},{\"pedwt_id\":2202,\"pedwt_period_exc_day_id\":2038,\"pedwt_time_from\":\"00:00:00\",\"pedwt_time_to\":\"00:00:00\",\"pedwt_price\":0},{\"pedwt_id\":2204,\"pedwt_period_exc_day_id\":2039,\"pedwt_time_from\":\"00:00:00\",\"pedwt_time_to\":\"00:00:00\",\"pedwt_price\":0},{\"pedwt_id\":2206,\"pedwt_period_exc_day_id\":2040,\"pedwt_time_from\":\"00:00:00\",\"pedwt_time_to\":\"00:00:00\",\"pedwt_price\":0},{\"pedwt_id\":2219,\"pedwt_period_exc_day_id\":2041,\"pedwt_time_from\":\"00:00:00\",\"pedwt_time_to\":\"00:00:00\",\"pedwt_price\":0},{\"pedwt_id\":2220,\"pedwt_period_exc_day_id\":2042,\"pedwt_time_from\":\"00:00:00\",\"pedwt_time_to\":\"00:00:00\",\"pedwt_price\":0},{\"pedwt_id\":2221,\"pedwt_period_exc_day_id\":2043,\"pedwt_time_from\":\"00:00:00\",\"pedwt_time_to\":\"00:00:00\",\"pedwt_price\":0},{\"pedwt_id\":2222,\"pedwt_period_exc_day_id\":2044,\"pedwt_time_from\":\"00:00:00\",\"pedwt_time_to\":\"00:00:00\",\"pedwt_price\":0},{\"pedwt_id\":2223,\"pedwt_period_exc_day_id\":2045,\"pedwt_time_from\":\"00:00:00\",\"pedwt_time_to\":\"01:00:00\",\"pedwt_price\":0},{\"pedwt_id\":2224,\"pedwt_period_exc_day_id\":2046,\"pedwt_time_from\":\"00:00:00\",\"pedwt_time_to\":\"00:00:00\",\"pedwt_price\":0}],\"SpecialDays\":[{\"ped_id\":11,\"ped_label\":\"Christmas 1st day\",\"ped_date_start\":\"2022-12-25\",\"ped_date_end\":\"2022-12-25\",\"ped_period_special_day_id\":2,\"ped_year\":0},{\"ped_id\":13,\"ped_label\":\"Christmas 2nd day\",\"ped_date_start\":\"2022-12-26\",\"ped_date_end\":\"2022-12-26\",\"ped_period_special_day_id\":2,\"ped_year\":0},{\"ped_id\":14,\"ped_label\":\"Republic Day (Hungary)\",\"ped_date_start\":\"2022-10-23\",\"ped_date_end\":\"2022-10-23\",\"ped_period_special_day_id\":2,\"ped_year\":0},{\"ped_id\":2016,\"ped_label\":\"Christmas (Sunday)\",\"ped_date_start\":\"2022-12-24\",\"ped_date_end\":\"2022-12-24\",\"ped_period_special_day_id\":2,\"ped_year\":2023},{\"ped_id\":2017,\"ped_label\":\"Holiday (Hungary)\",\"ped_date_start\":\"2022-12-27\",\"ped_date_end\":\"2022-12-27\",\"ped_period_special_day_id\":1,\"ped_year\":0},{\"ped_id\":2018,\"ped_label\":\"Holiday (Hungary)\",\"ped_date_start\":\"2022-12-28\",\"ped_date_end\":\"2022-12-28\",\"ped_period_special_day_id\":1,\"ped_year\":0},{\"ped_id\":2019,\"ped_label\":\"Holiday (Hungary)\",\"ped_date_start\":\"2022-12-29\",\"ped_date_end\":\"2022-12-29\",\"ped_period_special_day_id\":1,\"ped_year\":0},{\"ped_id\":2020,\"ped_label\":\"Holiday (Hungary)\",\"ped_date_start\":\"2022-12-30\",\"ped_date_end\":\"2022-12-30\",\"ped_period_special_day_id\":1,\"ped_year\":0},{\"ped_id\":2021,\"ped_label\":\"Holiday (Hungary)\",\"ped_date_start\":\"2022-12-31\",\"ped_date_end\":\"2022-12-31\",\"ped_period_special_day_id\":1,\"ped_year\":0},{\"ped_id\":2022,\"ped_label\":\"NewYear\",\"ped_date_start\":\"2023-01-01\",\"ped_date_end\":\"2023-01-01\",\"ped_period_special_day_id\":2,\"ped_year\":0},{\"ped_id\":2023,\"ped_label\":\"Holiday (Hungary)\",\"ped_date_start\":\"2023-01-02\",\"ped_date_end\":\"2023-01-02\",\"ped_period_special_day_id\":1,\"ped_year\":2024},{\"ped_id\":2024,\"ped_label\":\"Good Friday\",\"ped_date_start\":\"2023-04-07\",\"ped_date_end\":\"2023-04-07\",\"ped_period_special_day_id\":2,\"ped_year\":2023},{\"ped_id\":2025,\"ped_label\":\"Easter Sunday\",\"ped_date_start\":\"2023-04-09\",\"ped_date_end\":\"2023-04-09\",\"ped_period_special_day_id\":2,\"ped_year\":2023},{\"ped_id\":2026,\"ped_label\":\"Easter Monday\",\"ped_date_start\":\"2023-04-10\",\"ped_date_end\":\"2023-04-10\",\"ped_period_special_day_id\":2,\"ped_year\":2023},{\"ped_id\":2027,\"ped_label\":\"Whit Sunday\",\"ped_date_start\":\"2023-05-28\",\"ped_date_end\":\"2023-05-28\",\"ped_period_special_day_id\":2,\"ped_year\":2023},{\"ped_id\":2028,\"ped_label\":\"Whit Monday\",\"ped_date_start\":\"2023-05-29\",\"ped_date_end\":\"2023-05-29\",\"ped_period_special_day_id\":2,\"ped_year\":2023},{\"ped_id\":2029,\"ped_label\":\"Revolution Day (Hungary)\",\"ped_date_start\":\"2023-03-15\",\"ped_date_end\":\"2023-03-15\",\"ped_period_special_day_id\":2,\"ped_year\":0},{\"ped_id\":2030,\"ped_label\":\"Labour Day\",\"ped_date_start\":\"2023-05-01\",\"ped_date_end\":\"2023-05-01\",\"ped_period_special_day_id\":2,\"ped_year\":0},{\"ped_id\":2031,\"ped_label\":\"Saint Stephens Day (Hungary)\",\"ped_date_start\":\"2023-08-20\",\"ped_date_end\":\"2023-08-20\",\"ped_period_special_day_id\":2,\"ped_year\":0},{\"ped_id\":2032,\"ped_label\":\"All Saints Day\",\"ped_date_start\":\"2023-11-01\",\"ped_date_end\":\"2023-11-01\",\"ped_period_special_day_id\":2,\"ped_year\":0},{\"ped_id\":2033,\"ped_label\":\"Christmas (Tuesday)\",\"ped_date_start\":\"2024-12-24\",\"ped_date_end\":\"2024-12-24\",\"ped_period_special_day_id\":2,\"ped_year\":2024},{\"ped_id\":2034,\"ped_label\":\"Good Friday\",\"ped_date_start\":\"2024-03-29\",\"ped_date_end\":\"2024-03-29\",\"ped_period_special_day_id\":2,\"ped_year\":2024},{\"ped_id\":2035,\"ped_label\":\"Easter\",\"ped_date_start\":\"2024-03-31\",\"ped_date_end\":\"2024-03-31\",\"ped_period_special_day_id\":2,\"ped_year\":0},{\"ped_id\":2036,\"ped_label\":\"Easter Monday\",\"ped_date_start\":\"2024-04-01\",\"ped_date_end\":\"2024-04-01\",\"ped_period_special_day_id\":2,\"ped_year\":0},{\"ped_id\":2037,\"ped_label\":\"Whit Monday\",\"ped_date_start\":\"2024-05-20\",\"ped_date_end\":\"2024-05-20\",\"ped_period_special_day_id\":2,\"ped_year\":2024},{\"ped_id\":2038,\"ped_label\":\"Whit Sunday\",\"ped_date_start\":\"2024-05-19\",\"ped_date_end\":\"2024-05-19\",\"ped_period_special_day_id\":2,\"ped_year\":2024},{\"ped_id\":2039,\"ped_label\":\"Christmas 1st Day\",\"ped_date_start\":\"2024-12-25\",\"ped_date_end\":\"2024-12-25\",\"ped_period_special_day_id\":2,\"ped_year\":2024},{\"ped_id\":2040,\"ped_label\":\"Christmas 2nd Day\",\"ped_date_start\":\"2024-12-26\",\"ped_date_end\":\"2024-12-26\",\"ped_period_special_day_id\":2,\"ped_year\":0},{\"ped_id\":2041,\"ped_label\":\"Holiday (Hungary)\",\"ped_date_start\":\"2024-12-27\",\"ped_date_end\":\"2024-12-27\",\"ped_period_special_day_id\":1,\"ped_year\":0},{\"ped_id\":2042,\"ped_label\":\"Holiday (Hungary)\",\"ped_date_start\":\"2024-12-28\",\"ped_date_end\":\"2024-12-28\",\"ped_period_special_day_id\":1,\"ped_year\":0},{\"ped_id\":2043,\"ped_label\":\"Holiday (Hungary)\",\"ped_date_start\":\"2024-12-29\",\"ped_date_end\":\"2024-12-29\",\"ped_period_special_day_id\":1,\"ped_year\":0},{\"ped_id\":2044,\"ped_label\":\"Holiday (Hungary)\",\"ped_date_start\":\"2024-12-30\",\"ped_date_end\":\"2024-12-30\",\"ped_period_special_day_id\":1,\"ped_year\":0},{\"ped_id\":2045,\"ped_label\":\"Holiday (Hungary)\",\"ped_date_start\":\"2024-12-31\",\"ped_date_end\":\"2024-12-31\",\"ped_period_special_day_id\":1,\"ped_year\":0},{\"ped_id\":2046,\"ped_label\":\"Holiday (Hungary)\",\"ped_date_start\":\"2025-01-02\",\"ped_date_end\":\"2025-01-02\",\"ped_period_special_day_id\":1,\"ped_year\":2025}]}";
|
|
|
|
for (int zone = 3; zone < 4; ++zone) {
|
|
// std::string fname("/opt/ptu5/opt/customer_281/szeged/tariff/szeged_winter_sale_zone");
|
|
std::string fname("/opt/ptu5/opt/ATB-CalculatorLinux_21.12.2022/tariff/szeged_winter_sale_zone");
|
|
|
|
fname += std::to_string(zone) + ".json";
|
|
|
|
std::cout << fname << std::endl;
|
|
|
|
std::ifstream input(fname);
|
|
std::stringstream sstr;
|
|
while(input >> sstr.rdbuf());
|
|
std::string json(sstr.str());
|
|
|
|
Calculator calculator;
|
|
Configuration cfg;
|
|
|
|
bool isParsed = cfg.ParseJson(&cfg, json.c_str());
|
|
cout << endl;
|
|
|
|
char const *startDate = "";
|
|
|
|
if (isParsed)
|
|
{
|
|
struct tm now; // = Utilities::DateTimeToStructTm("2023-03-01T16:00:00");
|
|
memset(&now, 0, sizeof(now));
|
|
char buffer[64];
|
|
//#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) {
|
|
|
|
time_t now_t = mktime(&now);
|
|
now_t += 60;
|
|
now = *localtime(&now_t);
|
|
|
|
sprintf(buffer, "%04d-%02d-%02dT%02d:%02d:%02d", now.tm_year + 1900, now.tm_mon + 1, now.tm_mday, now.tm_hour, now.tm_min, now.tm_sec);
|
|
double cost = calculator.GetCostFromDuration(&cfg, PaymentOption::Option1, buffer, 240, false, true);
|
|
memset(buffer, 0, 64);
|
|
|
|
// cout << "======================================================" << endl;
|
|
// cout << "zone " << zone << " ===> " << i << " " << asctime(&now) << " - Total cost is: " << cost << " FT" << endl;
|
|
switch (zone) {
|
|
case 1:
|
|
assert(cost == 879); // expected value: 880
|
|
break;
|
|
case 2:
|
|
/* fall through */
|
|
case 3:
|
|
assert(cost == 1920);
|
|
break;
|
|
}
|
|
// cout << "======================================================" << endl;
|
|
}
|
|
|
|
// zone 3 has problems
|
|
for (int i = 112; i <= 128; ++i)
|
|
{
|
|
startDate = "2022-12-23T17:00:00";
|
|
std::string validity = calculator.GetDurationFromCost(&cfg, PaymentOption::Option1, (char *)startDate, i, false, true);
|
|
cout << "zone " << zone << ", startDate " << startDate << " _price_ "
|
|
<< i << " Total duration is: " << validity << endl;
|
|
}
|
|
|
|
for (int i = 112; i <= 128; ++i)
|
|
{
|
|
startDate = "2022-12-09T18:00:00";
|
|
std::string validity = calculator.GetDurationFromCost(&cfg, PaymentOption::Option1, (char *)startDate, i, false, true);
|
|
cout << "zone " << zone << ", startDate " << startDate << " _price_ "
|
|
<< i << " Total duration is: " << validity << endl;
|
|
}
|
|
|
|
for (int i = 112; i <= 128; ++i) {
|
|
startDate = "2022-12-26T17:00:00";
|
|
std::string validity = calculator.GetDurationFromCost(&cfg, PaymentOption::Option1, (char *)startDate, i, false, true);
|
|
cout << "zone " << zone << ", startDate " << startDate << " _price_ "
|
|
<< i << " Total duration is: " << validity << endl;
|
|
}
|
|
|
|
//std::string validity = calculator.GetDurationFromCost(&cfg, PaymentOption::Option1, (char*)"2022-12-22T05:00:00", 75, false, true);
|
|
//cout << "_price_ " << " Total duration is: " << validity << " min" << endl;
|
|
|
|
startDate = "2022-12-22T05:00:00";
|
|
std::string validity = calculator.GetDurationFromCost(&cfg, PaymentOption::Option1, (char*)startDate, 120, false, true);
|
|
cout << "zone " << zone << ", startDate " << startDate << " _price_ "
|
|
<< " Total duration is: " << validity << " min" << endl;
|
|
// working for all zones
|
|
//
|
|
// test Easter 2023
|
|
//
|
|
memset(&now, 0, sizeof(now));
|
|
strptime("2023-04-07T06:00:00", "%Y-%m-%dT%H:%M:%S", &now);
|
|
for (int i=0; i<6*24; ++i) {
|
|
time_t now_t = mktime(&now);
|
|
now_t += 60*60;
|
|
now = *localtime(&now_t);
|
|
|
|
sprintf(buffer, "%04d-%02d-%02dT%02d:%02d:%02d", now.tm_year + 1900,
|
|
now.tm_mon + 1, now.tm_mday, now.tm_hour, now.tm_min, now.tm_sec);
|
|
|
|
int const duration = 120;
|
|
double cost = calculator.GetCostFromDuration(&cfg,
|
|
PaymentOption::Option1, buffer, duration,
|
|
false, true);
|
|
|
|
switch (zone) {
|
|
case 1:
|
|
cout << "===> [" << i << "] " << asctime(&now) << " - Total cost is: " << cost << " FT" << endl;
|
|
assert(cost == 440);
|
|
break;
|
|
case 2:
|
|
/* fall through */
|
|
case 3:
|
|
assert(cost == 960);
|
|
cout << "===> [" << i << "] " << asctime(&now) << " - Total cost is: " << cost << " FT" << endl;
|
|
break;
|
|
}
|
|
|
|
//if (cost == 960) {
|
|
// cout << "===> [" << i << "] " << asctime(&now) << " - Total cost is: " << cost << " FT" << endl;
|
|
//} else {
|
|
// cout << "ERROR ===> [" << i << "] " << asctime(&now) << " - Total cost is: " << cost << " FT" << endl;
|
|
// assert(cost == 960);
|
|
//}
|
|
}
|
|
// working for all zones
|
|
//
|
|
// test May 1st 2023
|
|
//
|
|
memset(&now, 0, sizeof(now));
|
|
strptime("2023-04-30T06:00:00", "%Y-%m-%dT%H:%M:%S", &now);
|
|
for (int i=0; i<6*24; ++i) {
|
|
time_t now_t = mktime(&now);
|
|
now_t += 60*60;
|
|
now = *localtime(&now_t);
|
|
|
|
sprintf(buffer, "%04d-%02d-%02dT%02d:%02d:%02d", now.tm_year + 1900,
|
|
now.tm_mon + 1, now.tm_mday, now.tm_hour, now.tm_min, now.tm_sec);
|
|
|
|
int const duration = 120;
|
|
double cost = calculator.GetCostFromDuration(&cfg,
|
|
PaymentOption::Option1, buffer, duration,
|
|
false, true);
|
|
|
|
switch (zone) {
|
|
case 1:
|
|
cout << "===> [" << i << "] " << asctime(&now) << " - Total cost is: " << cost << " FT" << endl;
|
|
assert(cost == 440);
|
|
break;
|
|
case 2:
|
|
/* fall through */
|
|
case 3:
|
|
assert(cost == 960);
|
|
cout << "===> [" << i << "] " << asctime(&now) << " - Total cost is: " << cost << " FT" << endl;
|
|
break;
|
|
}
|
|
}
|
|
// only zone 1 has some minor problems
|
|
//
|
|
// test 17/04/2023 - 27/04/2023
|
|
//
|
|
memset(&now, 0, sizeof(now));
|
|
strptime("2023-04-17T06:00:00", "%Y-%m-%dT%H:%M:%S", &now);
|
|
int duration = 0;
|
|
//for (int i=0; i<1440; ++i) {
|
|
for (int i=0; i<1440; ++i) {
|
|
time_t now_t = mktime(&now);
|
|
now_t += 600; // 10 minutes
|
|
now = *localtime(&now_t);
|
|
|
|
sprintf(buffer, "%04d-%02d-%02dT%02d:%02d:%02d", now.tm_year + 1900,
|
|
now.tm_mon + 1, now.tm_mday, now.tm_hour, now.tm_min, now.tm_sec);
|
|
|
|
double const compCost = (duration < 15) ? 0 : duration * ((zone == 1) ? 3.6666 : 8.0);
|
|
double cost = calculator.GetCostFromDuration(&cfg,
|
|
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="
|
|
<< compCost << ")" << endl;
|
|
// assert (cost == compCost);
|
|
}
|
|
|
|
if (++duration > 240) {
|
|
duration = 0;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
#endif
|
|
return 0;
|
|
}
|