Compare commits
5 Commits
b0c4ad0e2e
...
b70094abb5
Author | SHA1 | Date | |
---|---|---|---|
b70094abb5 | |||
aa15d1c126 | |||
cd159f2bbd | |||
475487c2ce | |||
8ff5b8e2b5 |
@ -214,7 +214,10 @@ int CALCULATE_LIBRARY_API get_maximal_parkingprice(Configuration *cfg,
|
|||||||
int paymentOptionIndex=0);
|
int paymentOptionIndex=0);
|
||||||
|
|
||||||
int CALCULATE_LIBRARY_API compute_product_price(Configuration const *cfg,
|
int CALCULATE_LIBRARY_API compute_product_price(Configuration const *cfg,
|
||||||
PERMIT_TYPE permitType = PERMIT_TYPE::SHORT_TERM_PARKING);
|
PERMIT_TYPE permitType = PERMIT_TYPE::SHORT_TERM_PARKING,
|
||||||
|
QDateTime const &start = QDateTime::currentDateTime(),
|
||||||
|
QDateTime *productStart = nullptr,
|
||||||
|
QDateTime *productEnd = nullptr);
|
||||||
|
|
||||||
CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket( // deprecated
|
CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket( // deprecated
|
||||||
parking_tariff_t *tariff,
|
parking_tariff_t *tariff,
|
||||||
|
@ -45,6 +45,8 @@ struct ATBTariffProduct {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint32_t getProductPrice() const { return m_tariff_product_price; }
|
||||||
|
|
||||||
friend QDebug operator<<(QDebug debug, ATBTariffProduct const &product) {
|
friend QDebug operator<<(QDebug debug, ATBTariffProduct const &product) {
|
||||||
QDebugStateSaver saver(debug);
|
QDebugStateSaver saver(debug);
|
||||||
|
|
||||||
|
@ -82,7 +82,11 @@ int CALCULATE_LIBRARY_API get_minimal_parkingprice(Configuration *cfg,
|
|||||||
return minPrice;
|
return minPrice;
|
||||||
}
|
}
|
||||||
|
|
||||||
int CALCULATE_LIBRARY_API compute_product_price(Configuration const *cfg, PERMIT_TYPE permitType) {
|
int CALCULATE_LIBRARY_API compute_product_price(Configuration const *cfg,
|
||||||
|
PERMIT_TYPE permitType,
|
||||||
|
QDateTime const &start,
|
||||||
|
QDateTime *productStart,
|
||||||
|
QDateTime *productEnd) {
|
||||||
|
|
||||||
switch(permitType) {
|
switch(permitType) {
|
||||||
case PERMIT_TYPE::SHORT_TERM_PARKING: { // e.g. szeged (customer_281)
|
case PERMIT_TYPE::SHORT_TERM_PARKING: { // e.g. szeged (customer_281)
|
||||||
@ -118,6 +122,40 @@ int CALCULATE_LIBRARY_API compute_product_price(Configuration const *cfg, PERMIT
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} break;
|
} break;
|
||||||
|
case PERMIT_TYPE::INVALID:
|
||||||
|
// [[fallthrough]];
|
||||||
|
case PERMIT_TYPE::DAY_TICKET: {
|
||||||
|
std::optional<QVector<ATBTariffProduct>> products = cfg->getTariffProductForProductId(permitType);
|
||||||
|
if (products) {
|
||||||
|
QVector<ATBTariffProduct> product = products.value();
|
||||||
|
int product_price = 0;
|
||||||
|
|
||||||
|
if (productStart && productEnd) {
|
||||||
|
*productStart = start;
|
||||||
|
*productEnd = start;
|
||||||
|
if (product.size() > 0) {
|
||||||
|
productStart->setTime(product[0].getTimeStart());
|
||||||
|
productEnd->setTime(product[0].getTimeEnd());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (QVector<ATBTariffProduct>::size_type i=0; i<product.size(); ++i) {
|
||||||
|
ATBTariffProduct const &p = product[i];
|
||||||
|
QTime const &startTime = p.getTimeStart();
|
||||||
|
QTime const &endTime = p.getTimeEnd();
|
||||||
|
|
||||||
|
if (start.time() >= startTime && start.time() < endTime) {
|
||||||
|
product_price = p.getProductPrice();
|
||||||
|
if (productStart && productEnd) {
|
||||||
|
productStart->setTime(startTime);
|
||||||
|
productEnd->setTime(endTime);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return product_price;
|
||||||
|
}
|
||||||
|
} break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -619,6 +619,10 @@ CalcState Calculator::isParkingAllowed(Configuration const *cfg, QDateTime const
|
|||||||
if (paymentMethodId == PaymentMethod::Steps) {
|
if (paymentMethodId == PaymentMethod::Steps) {
|
||||||
int const weekdayId = start.date().dayOfWeek();
|
int const weekdayId = start.date().dayOfWeek();
|
||||||
BusinessHours businessHours = Utilities::getBusinessHours(cfg, paymentMethodId);
|
BusinessHours businessHours = Utilities::getBusinessHours(cfg, paymentMethodId);
|
||||||
|
if (businessHours == BusinessHours::NoRestriction_24_7) {
|
||||||
|
return CalcState(CalcState::State::SUCCESS, "PARKING_ALLOWED",
|
||||||
|
QTime(0, 0, 0), QTime(23, 59, 59));
|
||||||
|
} else
|
||||||
if (businessHours == BusinessHours::OnlyWeekDays) {
|
if (businessHours == BusinessHours::OnlyWeekDays) {
|
||||||
if (weekdayId != (int)Qt::Saturday && weekdayId != (int)Qt::Sunday) { // e.g. Neuhauser, Linsinger Maschinenbau (741)
|
if (weekdayId != (int)Qt::Saturday && weekdayId != (int)Qt::Sunday) { // e.g. Neuhauser, Linsinger Maschinenbau (741)
|
||||||
if (cfg->WeekDaysWorktime.count(weekdayId) > 0) {
|
if (cfg->WeekDaysWorktime.count(weekdayId) > 0) {
|
||||||
|
189
main/main.cpp
189
main/main.cpp
@ -41,9 +41,196 @@ extern "C" char* strptime(const char* s,
|
|||||||
#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 (0)
|
||||||
#define BAD_NEUENAHR_AHRWEILER (1)
|
#define BAD_NEUENAHR_AHRWEILER (0)
|
||||||
|
#define NEUHAUSER_CHRISTOPH_REISEN (0)
|
||||||
|
#define NEUHAUSER_PERNEGG_AN_DER_MUR (1)
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
|
#if NEUHAUSER_PERNEGG_AN_DER_MUR==1
|
||||||
|
std::ifstream input;
|
||||||
|
int pop_min_time;
|
||||||
|
int pop_max_time;
|
||||||
|
int pop_min_price;
|
||||||
|
int pop_max_price;
|
||||||
|
int pop_daily_card_price;
|
||||||
|
|
||||||
|
input.open("/opt/ptu5/opt/customer_747/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) {
|
||||||
|
pop_min_time = get_minimal_parkingtime(&cfg);
|
||||||
|
pop_max_time = get_maximal_parkingtime(&cfg);
|
||||||
|
pop_min_price = get_minimal_parkingprice(&cfg);
|
||||||
|
pop_max_price = get_maximal_parkingprice(&cfg);
|
||||||
|
pop_daily_card_price = cfg.getPaymentOptions().pop_daily_card_price;
|
||||||
|
|
||||||
|
qCritical() << " pop_min_time: " << pop_min_time;
|
||||||
|
qCritical() << " pop_max_time: " << pop_max_time;
|
||||||
|
qCritical() << " pop_min_price: " << pop_min_price;
|
||||||
|
qCritical() << " pop_max_price: " << pop_max_price;
|
||||||
|
qCritical() << "pop_daily_card_price: " << pop_daily_card_price;
|
||||||
|
|
||||||
|
int price;
|
||||||
|
QDateTime productStart;
|
||||||
|
QDateTime productEnd;
|
||||||
|
QDateTime start = QDateTime::currentDateTime();
|
||||||
|
start.setTime(QTime(0, 0, 0));
|
||||||
|
price = compute_product_price(&cfg, PERMIT_TYPE::DAY_TICKET, start);
|
||||||
|
qCritical() << QString("price (%1) :").arg(start.time().toString(Qt::ISODate)) << price;
|
||||||
|
|
||||||
|
start.setTime(QTime(6, 0, 0));
|
||||||
|
productStart = productEnd = QDateTime();
|
||||||
|
price = compute_product_price(&cfg, PERMIT_TYPE::DAY_TICKET, start, &productStart, &productEnd);
|
||||||
|
qCritical() << QString("price (%1-%2) :")
|
||||||
|
.arg(productStart.time().toString(Qt::ISODate))
|
||||||
|
.arg(productEnd.time().toString(Qt::ISODate))
|
||||||
|
<< price;
|
||||||
|
|
||||||
|
start.setTime(QTime(15, 0, 0));
|
||||||
|
productStart = productEnd = QDateTime();
|
||||||
|
price = compute_product_price(&cfg, PERMIT_TYPE::DAY_TICKET, start, &productStart, &productEnd);
|
||||||
|
qCritical() << QString("price (%1-%2) :")
|
||||||
|
.arg(productStart.time().toString(Qt::ISODate))
|
||||||
|
.arg(productEnd.time().toString(Qt::ISODate))
|
||||||
|
<< price;
|
||||||
|
|
||||||
|
start.setTime(QTime(16, 0, 0));
|
||||||
|
productStart = productEnd = QDateTime();
|
||||||
|
price = compute_product_price(&cfg, PERMIT_TYPE::DAY_TICKET, start, &productStart, &productEnd);
|
||||||
|
qCritical() << QString("price (%1-%2) :")
|
||||||
|
.arg(productStart.time().toString(Qt::ISODate))
|
||||||
|
.arg(productEnd.time().toString(Qt::ISODate))
|
||||||
|
<< price;
|
||||||
|
|
||||||
|
start.setTime(QTime(17, 0, 0));
|
||||||
|
productStart = productEnd = QDateTime();
|
||||||
|
price = compute_product_price(&cfg, PERMIT_TYPE::INVALID, start, &productStart, &productEnd);
|
||||||
|
qCritical() << QString("price (%1-%2) :")
|
||||||
|
.arg(productStart.time().toString(Qt::ISODate))
|
||||||
|
.arg(productEnd.time().toString(Qt::ISODate))
|
||||||
|
<< price;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if NEUHAUSER_CHRISTOPH_REISEN==1
|
||||||
|
std::ifstream input;
|
||||||
|
int pop_min_time;
|
||||||
|
int pop_max_time;
|
||||||
|
int pop_min_price;
|
||||||
|
int pop_max_price;
|
||||||
|
int pop_daily_card_price;
|
||||||
|
|
||||||
|
input.open("/opt/ptu5/opt/customer_746/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) {
|
||||||
|
pop_min_time = get_minimal_parkingtime(&cfg);
|
||||||
|
pop_max_time = get_maximal_parkingtime(&cfg);
|
||||||
|
pop_min_price = get_minimal_parkingprice(&cfg);
|
||||||
|
pop_max_price = get_maximal_parkingprice(&cfg);
|
||||||
|
pop_daily_card_price = cfg.getPaymentOptions().pop_daily_card_price;
|
||||||
|
|
||||||
|
qCritical() << " pop_min_time: " << pop_min_time;
|
||||||
|
qCritical() << " pop_max_time: " << pop_max_time;
|
||||||
|
qCritical() << " pop_min_price: " << pop_min_price;
|
||||||
|
qCritical() << " pop_max_price: " << pop_max_price;
|
||||||
|
qCritical() << "pop_daily_card_price: " << pop_daily_card_price;
|
||||||
|
|
||||||
|
static QList<int> stepsConfigured
|
||||||
|
= QList(std::initializer_list<int>{
|
||||||
|
360, 420, 1440, 2880, 4320, 5400, 7440});
|
||||||
|
|
||||||
|
QList<int> timeSteps = Calculator::GetInstance().GetTimeSteps(&cfg);
|
||||||
|
qCritical() << "TimeSteps" << timeSteps;
|
||||||
|
|
||||||
|
if (stepsConfigured != timeSteps) {
|
||||||
|
qCritical() << "TIME-STEPS SHOULD BE" << stepsConfigured;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
stepsConfigured.push_front(360); // for test run
|
||||||
|
stepsConfigured.push_back(7440);
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
static const int Down = 0;
|
||||||
|
static const int Up = 1;
|
||||||
|
|
||||||
|
for (int i = 0, j=timeSteps.size() ; i < timeSteps.size(); --j, ++i) {
|
||||||
|
int nextTimeStep = compute_next_timestep(&cfg, timeSteps.at(i), Up);
|
||||||
|
if (nextTimeStep != stepsConfigured.at(i+2)) {
|
||||||
|
qCritical() << "(" << __func__ << ":" << __LINE__ << ") ERROR"
|
||||||
|
<< nextTimeStep << stepsConfigured.at(i+2);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
qCritical() << "curTimeStep" << timeSteps.at(i) << ", nextTimeStep" << nextTimeStep;
|
||||||
|
|
||||||
|
|
||||||
|
int prevTimeStep = compute_next_timestep(&cfg, timeSteps.at(i), Down);
|
||||||
|
if (prevTimeStep != stepsConfigured.at(i)) {
|
||||||
|
qCritical() << "(" << __func__ << ":" << __LINE__ << ") ERROR"
|
||||||
|
<< prevTimeStep << stepsConfigured.at(i);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
qCritical() << "curTimeStep" << timeSteps.at(i) << ", prevTimeStep" << prevTimeStep;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
QDateTime start = QDateTime::currentDateTime();
|
||||||
|
//start.setTime(QTime(0, 0, 0));
|
||||||
|
|
||||||
|
struct price_t costs;
|
||||||
|
double const cost[] = {600, 700, 800, 1600, 2400, 3000, 3600};
|
||||||
|
double price1 = 0;
|
||||||
|
double price2 = 0;
|
||||||
|
|
||||||
|
CalcState cs;
|
||||||
|
|
||||||
|
for (int i = 0, j=timeSteps.size() ; i < timeSteps.size(); --j, ++i) {
|
||||||
|
QDateTime end = start.addSecs(timeSteps.at(i)*60);
|
||||||
|
|
||||||
|
cs = compute_price_for_parking_ticket(&cfg, start, timeSteps.at(i), end, &costs);
|
||||||
|
if (cs.getStatus() != CalcState::State::SUCCESS) {
|
||||||
|
qCritical() << "ERROR STATUS" << costs.netto;
|
||||||
|
exit(-1);
|
||||||
|
}
|
||||||
|
price1 = costs.netto;
|
||||||
|
price2 = Calculator::GetInstance().GetCostFromDuration(&cfg, start, timeSteps.at(i));
|
||||||
|
|
||||||
|
if (price1 != price2) {
|
||||||
|
qCritical() << "ERROR DIFFERENT PRICES" << price1 << price2;
|
||||||
|
exit(-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
qCritical() << "compute_price_for_parking_ticket()/GetCostFromDuration() TIME: "
|
||||||
|
<< timeSteps.at(i) << "PRICE=" << price1;
|
||||||
|
|
||||||
|
|
||||||
|
std::string duration = Calculator::GetInstance().GetDurationFromCost(&cfg, 4,
|
||||||
|
start.toString(Qt::ISODate).toStdString().c_str(),
|
||||||
|
cost[i], false, true);
|
||||||
|
QDateTime d(QDateTime::fromString(QString(duration.c_str()), Qt::ISODate));
|
||||||
|
|
||||||
|
qCritical() << "start" << start.toString(Qt::ISODate)
|
||||||
|
<< "cost[" << i << "]" << cost[i] << "duration" << d.toString(Qt::ISODate) << (start.secsTo(d) + 59) / 60;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
#if BAD_NEUENAHR_AHRWEILER==1
|
#if BAD_NEUENAHR_AHRWEILER==1
|
||||||
std::ifstream input;
|
std::ifstream input;
|
||||||
int pop_min_time;
|
int pop_min_time;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user