Compare commits
10 Commits
1c801f1053
...
bd1bdf8a8c
Author | SHA1 | Date | |
---|---|---|---|
bd1bdf8a8c | |||
6d18ce4caa | |||
e980d8c451 | |||
afb0e20dd2 | |||
39ab08a5b7 | |||
c4c0e2fd77 | |||
7a5487aa41 | |||
a8c1caf611 | |||
a22145002c | |||
7b7dd6d103 |
@ -18,6 +18,8 @@
|
||||
#define CALCULATE_LIBRARY_API
|
||||
#endif
|
||||
|
||||
#include "tariff_permit_type.h"
|
||||
|
||||
class Configuration;
|
||||
|
||||
typedef Configuration parking_tariff_t;
|
||||
@ -39,17 +41,6 @@ struct CALCULATE_LIBRARY_API price_t {
|
||||
}
|
||||
};
|
||||
|
||||
enum class PERMIT_TYPE : quint8 {
|
||||
SHORT_TERM_PARKING,
|
||||
DAY_TICKET,
|
||||
SZEGED_START,
|
||||
SZEGED_STOP,
|
||||
DAY_TICKET_ADULT,
|
||||
DAY_TICKET_TEEN,
|
||||
DAY_TICKET_CHILD,
|
||||
INVALID
|
||||
};
|
||||
|
||||
struct CALCULATE_LIBRARY_API CalcState {
|
||||
enum class State : uint8_t {
|
||||
SUCCESS,
|
||||
@ -161,7 +152,7 @@ QList<int> CALCULATE_LIBRARY_API get_time_steps(Configuration *cfg);
|
||||
int CALCULATE_LIBRARY_API get_minimal_parkingtime(Configuration *cfg, PERMIT_TYPE permitType = PERMIT_TYPE::SHORT_TERM_PARKING);
|
||||
int CALCULATE_LIBRARY_API get_maximal_parkingtime(Configuration *cfg, PERMIT_TYPE permitType = PERMIT_TYPE::SHORT_TERM_PARKING);
|
||||
int CALCULATE_LIBRARY_API get_minimal_parkingprice(Configuration *cfg, PERMIT_TYPE permitType = PERMIT_TYPE::SHORT_TERM_PARKING);
|
||||
int CALCULATE_LIBRARY_API get_maximal_parkingprice(Configuration *cfg, PERMIT_TYPE permitType = PERMIT_TYPE::SHORT_TERM_PARKING);
|
||||
int CALCULATE_LIBRARY_API compute_product_price(Configuration const *cfg, PERMIT_TYPE permitType = PERMIT_TYPE::SHORT_TERM_PARKING);
|
||||
|
||||
CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket( // deprecated
|
||||
parking_tariff_t *tariff,
|
||||
|
@ -24,6 +24,7 @@
|
||||
#include "tariff_daily_ticket.h"
|
||||
#include "time_range_header.h"
|
||||
#include "tariff_timestep_config.h"
|
||||
#include "tariff_product.h"
|
||||
|
||||
#include <QVector>
|
||||
#include <optional>
|
||||
@ -53,6 +54,7 @@ public:
|
||||
multimap<int, ATBTimeStepConfig> TimeStepConfig;
|
||||
multimap<int, ATBTimeBase> TimeBase;
|
||||
multimap<int, ATBCustomer> Customer;
|
||||
multimap<int, ATBTariffProduct> TariffProduct;
|
||||
|
||||
/// <summary>
|
||||
/// Parse JSON string
|
||||
@ -69,6 +71,9 @@ public:
|
||||
std::optional<QVector<ATBPaymentRate>> getPaymentRateForKey(int key) const;
|
||||
std::optional<QVector<ATBDailyTicket>> getDailyTicketsForAllKeys() const;
|
||||
std::optional<QVector<ATBDailyTicket>> getDailyTicketsForKey(int key) const;
|
||||
std::optional<QVector<ATBTariffProduct>> getTariffProductForAllKeys() const;
|
||||
std::optional<QVector<ATBTariffProduct>> getTariffProductForProductId(int id) const;
|
||||
std::optional<QVector<ATBTariffProduct>> getTariffProductForProductId(PermitType permitType) const;
|
||||
std::optional<ATBCustomer> getCustomerForType(ATBCustomer::CustomerType customerType);
|
||||
std::optional<ATBWeekDaysWorktime> getWeekDayWorkTime(QTime const &time, Qt::DayOfWeek dayOfWeek);
|
||||
|
||||
|
@ -18,7 +18,8 @@ enum MemberType
|
||||
CustomerType = 0x0B,
|
||||
TimeBaseType = 0x0C,
|
||||
TimeRangeType = 0x0D,
|
||||
TimeStepConfigType = 0x0E
|
||||
TimeStepConfigType = 0x0E,
|
||||
ProductType = 0x0F
|
||||
};
|
||||
|
||||
#endif // MEMBER_TYPE_H_INCLUDED
|
||||
|
101
library/include/mobilisis/tariff_permit_type.h
Normal file
101
library/include/mobilisis/tariff_permit_type.h
Normal file
@ -0,0 +1,101 @@
|
||||
#ifndef TARIFF_PERMIT_TYPE_H_INCLUDED
|
||||
#define TARIFF_PERMIT_TYPE_H_INCLUDED
|
||||
|
||||
#include <QString>
|
||||
|
||||
enum class PERMIT_TYPE : quint8 {
|
||||
SHORT_TERM_PARKING,
|
||||
DAY_TICKET,
|
||||
SZEGED_START,
|
||||
SZEGED_STOP,
|
||||
DAY_TICKET_ADULT,
|
||||
DAY_TICKET_TEEN,
|
||||
DAY_TICKET_CHILD,
|
||||
INVALID
|
||||
};
|
||||
|
||||
struct PermitType {
|
||||
PERMIT_TYPE m_permitType;
|
||||
|
||||
PermitType() { m_permitType = PERMIT_TYPE::INVALID; }
|
||||
PermitType(int permitType) {
|
||||
switch(permitType) {
|
||||
case 0:
|
||||
m_permitType = PERMIT_TYPE::SHORT_TERM_PARKING;
|
||||
break;
|
||||
case 1:
|
||||
m_permitType = PERMIT_TYPE::DAY_TICKET;
|
||||
break;
|
||||
case 2:
|
||||
m_permitType = PERMIT_TYPE::SZEGED_START;
|
||||
break;
|
||||
case 3:
|
||||
m_permitType = PERMIT_TYPE::SZEGED_STOP;
|
||||
break;
|
||||
case 4:
|
||||
m_permitType = PERMIT_TYPE::DAY_TICKET_ADULT;
|
||||
break;
|
||||
case 5:
|
||||
m_permitType = PERMIT_TYPE::DAY_TICKET_TEEN;
|
||||
break;
|
||||
case 6:
|
||||
m_permitType = PERMIT_TYPE::DAY_TICKET_CHILD;
|
||||
break;
|
||||
default:
|
||||
m_permitType = PERMIT_TYPE::INVALID;
|
||||
}
|
||||
}
|
||||
PermitType(PERMIT_TYPE permitType) : m_permitType(permitType) {}
|
||||
|
||||
void set(PERMIT_TYPE p) { m_permitType = p; }
|
||||
PERMIT_TYPE get() const { return m_permitType; }
|
||||
|
||||
operator PERMIT_TYPE() const { return m_permitType; }
|
||||
|
||||
operator int() const {
|
||||
switch(m_permitType) {
|
||||
case PERMIT_TYPE::SHORT_TERM_PARKING:
|
||||
return 0;
|
||||
case PERMIT_TYPE::DAY_TICKET:
|
||||
return 1;
|
||||
case PERMIT_TYPE::SZEGED_START:
|
||||
return 2;
|
||||
case PERMIT_TYPE::SZEGED_STOP:
|
||||
return 3;
|
||||
case PERMIT_TYPE::DAY_TICKET_ADULT:
|
||||
return 4;
|
||||
case PERMIT_TYPE::DAY_TICKET_CHILD:
|
||||
return 5;
|
||||
case PERMIT_TYPE::DAY_TICKET_TEEN:
|
||||
return 6;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return 7;
|
||||
|
||||
}
|
||||
|
||||
operator QString() const {
|
||||
switch(m_permitType) {
|
||||
case PERMIT_TYPE::DAY_TICKET:
|
||||
return QString("DAY_TICKET");
|
||||
case PERMIT_TYPE::DAY_TICKET_ADULT:
|
||||
return QString("DAY_TICKET_ADULT");
|
||||
case PERMIT_TYPE::DAY_TICKET_CHILD:
|
||||
return QString("DAY_TICKET_CHILD");
|
||||
case PERMIT_TYPE::DAY_TICKET_TEEN:
|
||||
return QString("DAY_TICKET_TEEN");
|
||||
case PERMIT_TYPE::SHORT_TERM_PARKING:
|
||||
return QString("SHORT_TERM_PARKING");
|
||||
case PERMIT_TYPE::SZEGED_START:
|
||||
return QString("SZEGED_START");
|
||||
case PERMIT_TYPE::SZEGED_STOP:
|
||||
return QString("SZEGED_STOP");
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return QString("INVALID");
|
||||
}
|
||||
};
|
||||
|
||||
#endif // TARIFF_PERMIT_TYPE_H_INCLUDED
|
64
library/include/mobilisis/tariff_product.h
Normal file
64
library/include/mobilisis/tariff_product.h
Normal file
@ -0,0 +1,64 @@
|
||||
#ifndef TARIFF_PRODUCT_H_INCLUDED
|
||||
#define TARIFF_PRODUCT_H_INCLUDED
|
||||
|
||||
#include <QString>
|
||||
#include <QDateTime>
|
||||
#include <QDebug>
|
||||
#include <QDebugStateSaver>
|
||||
|
||||
#include "tariff_permit_type.h"
|
||||
|
||||
struct ATBTariffProduct {
|
||||
PermitType m_tariff_product_id;
|
||||
uint32_t m_tariff_product_price;
|
||||
QString m_tariff_product_name;
|
||||
QTime m_tariff_product_start;
|
||||
QTime m_tariff_product_end;
|
||||
int m_tariff_product_from_in_minutes_from_start;
|
||||
int m_tariff_product_to_in_minutes_from_start;
|
||||
|
||||
explicit ATBTariffProduct() = default;
|
||||
|
||||
QTime const &getTimeStart() const { return m_tariff_product_start; }
|
||||
QTime const &getTimeEnd() const { return m_tariff_product_end; }
|
||||
|
||||
bool computeQTimeStart(QTime const &t) {
|
||||
if (m_tariff_product_from_in_minutes_from_start != -1) {
|
||||
m_tariff_product_start = t.addSecs(m_tariff_product_from_in_minutes_from_start * 60);
|
||||
return m_tariff_product_start.isValid();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool computeQTimeEnd(QTime const &t) {
|
||||
if (m_tariff_product_to_in_minutes_from_start != -1) {
|
||||
m_tariff_product_end = t.addSecs(m_tariff_product_from_in_minutes_from_start * 60);
|
||||
return m_tariff_product_end.isValid();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool computeQTimes(QTime const &t) {
|
||||
if (!t.isNull() && t.isValid()) {
|
||||
return computeQTimeStart(t) && computeQTimeEnd(t);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
friend QDebug operator<<(QDebug debug, ATBTariffProduct const &product) {
|
||||
QDebugStateSaver saver(debug);
|
||||
|
||||
debug.nospace()
|
||||
<< " m_tariff_product_id: " << QString(product.m_tariff_product_id) << "\n"
|
||||
<< " m_tariff_product_name: " << product.m_tariff_product_name << "\n"
|
||||
<< " m_tariff_product_price: " << product.m_tariff_product_price << "\n"
|
||||
<< " m_tariff_product_start: " << product.m_tariff_product_start << "\n"
|
||||
<< " m_tariff_product_end: " << product.m_tariff_product_end << "\n"
|
||||
<< "m_tariff_product_from_in_minutes_from_start: " << product.m_tariff_product_from_in_minutes_from_start << "\n"
|
||||
<< " m_tariff_product_to_in_minutes_from_start: " << product.m_tariff_product_to_in_minutes_from_start << "\n";
|
||||
|
||||
return debug;
|
||||
}
|
||||
};
|
||||
|
||||
#endif // TARIFF_PRODUCT_H_INCLUDED
|
@ -77,7 +77,9 @@ HEADERS += \
|
||||
include/mobilisis/tariff_daily_ticket.h \
|
||||
include/mobilisis/tariff_customer.h \
|
||||
include/mobilisis/tariff_timebase.h \
|
||||
include/mobilisis/tariff_timestep_config.h
|
||||
include/mobilisis/tariff_timestep_config.h \
|
||||
include/mobilisis/tariff_product.h \
|
||||
include/mobilisis/tariff_permit_type.h
|
||||
|
||||
OTHER_FILES += src/main.cpp \
|
||||
../tariffs/tariff_korneuburg.json \
|
||||
|
@ -76,6 +76,32 @@ int CALCULATE_LIBRARY_API get_minimal_parkingprice(Configuration *cfg, PERMIT_TY
|
||||
return minPrice;
|
||||
}
|
||||
|
||||
int CALCULATE_LIBRARY_API compute_product_price(Configuration const *cfg, PERMIT_TYPE permitType) {
|
||||
|
||||
switch(permitType) {
|
||||
case PERMIT_TYPE::SHORT_TERM_PARKING: { // e.g. szeged (customer_281)
|
||||
} break;
|
||||
case PERMIT_TYPE::DAY_TICKET_CHILD:
|
||||
// [[fallthrough]];
|
||||
case PERMIT_TYPE::DAY_TICKET_TEEN:
|
||||
// [[fallthrough]];
|
||||
case PERMIT_TYPE::DAY_TICKET_ADULT: {
|
||||
std::optional<QVector<ATBTariffProduct>> products = cfg->getTariffProductForProductId(permitType);
|
||||
if (products) {
|
||||
QVector<ATBTariffProduct> product = products.value();
|
||||
if (product.size() > 0) {
|
||||
ATBTariffProduct const &p = product[0];
|
||||
return p.m_tariff_product_price;
|
||||
}
|
||||
}
|
||||
} break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int CALCULATE_LIBRARY_API get_maximal_parkingprice(Configuration *cfg, PERMIT_TYPE permitType) {
|
||||
int maxPrice = -1;
|
||||
static const PaymentMethod paymentMethodId = Utilities::getPaymentMethodId(cfg);
|
||||
|
@ -1423,6 +1423,18 @@ Calculator::GetDailyTicketPrice(Configuration* cfg,
|
||||
case PERMIT_TYPE::INVALID:
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
// for projects which have not defined a daily ticket in their
|
||||
// tariff-files (e.g. szeged)
|
||||
price.netto = cfg->getPaymentOptions().pop_daily_card_price;
|
||||
|
||||
qCritical() << "( GetDailyTicketPrice():" << __LINE__ << ")";
|
||||
qCritical() << " start:" << startDatetime.toString(Qt::ISODate);
|
||||
qCritical() << " workTime from:" << QTime::fromString(QString(wt.pwd_time_from.c_str()), Qt::ISODate);
|
||||
qCritical() << " workTime to:" << QTime::fromString(QString(wt.pwd_time_to.c_str()), Qt::ISODate);
|
||||
qCritical() << "daily_ticket_card_price:" << price.netto;
|
||||
|
||||
value = value.value_or(price);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2,6 +2,7 @@
|
||||
#include "tariff_timebase.h"
|
||||
#include "time_range_header.h"
|
||||
#include "tariff_timestep_config.h"
|
||||
#include "tariff_permit_type.h"
|
||||
|
||||
#include <QString>
|
||||
#include <QDebug>
|
||||
@ -24,6 +25,7 @@ MemberType Configuration::IdentifyJsonMember(const char* member_name)
|
||||
if (strcmp(member_name, "Customer") == 0) return MemberType::CustomerType;
|
||||
if (strcmp(member_name, "TimeRange") == 0) return MemberType::TimeRangeType;
|
||||
if (strcmp(member_name, "TimeStepConfig") == 0) return MemberType::TimeStepConfigType;
|
||||
if (strcmp(member_name, "Product") == 0) return MemberType::ProductType;
|
||||
else return MemberType::UnknownType;
|
||||
}
|
||||
|
||||
@ -93,6 +95,7 @@ bool Configuration::ParseJson(Configuration* cfg, const char* json)
|
||||
ATBCustomer Customer;
|
||||
ATBTimeRange TimeRange;
|
||||
ATBTimeStepConfig TimeStepConfig;
|
||||
ATBTariffProduct TariffProduct;
|
||||
|
||||
MemberType mb_type = MemberType::UnknownType;
|
||||
this->currentPaymentOptions.clear();
|
||||
@ -157,6 +160,50 @@ bool Configuration::ParseJson(Configuration* cfg, const char* json)
|
||||
{
|
||||
case MemberType::UnknownType:
|
||||
break;
|
||||
case MemberType::ProductType: {
|
||||
if (QString(inner_obj_name) == QString("tariff_product_id")) {
|
||||
if (k->value.IsInt()) {
|
||||
int const x = k->value.GetInt();
|
||||
TariffProduct.m_tariff_product_id = PermitType(x);
|
||||
}
|
||||
} else
|
||||
if (QString(inner_obj_name) == QString("tariff_product_price")) {
|
||||
if (k->value.IsInt()) {
|
||||
int const x = k->value.GetInt();
|
||||
TariffProduct.m_tariff_product_price = x;
|
||||
}
|
||||
} else
|
||||
if (QString(inner_obj_name) == QString("tariff_product_name")) {
|
||||
if (k->value.IsString()) {
|
||||
std::string const &s = k->value.GetString();
|
||||
TariffProduct.m_tariff_product_name = QString::fromStdString(s);
|
||||
}
|
||||
} else
|
||||
if (QString(inner_obj_name) == QString("tariff_product_start")) {
|
||||
if (k->value.IsString()) {
|
||||
std::string const &s = k->value.GetString();
|
||||
TariffProduct.m_tariff_product_start = QTime::fromString(QString::fromStdString(s), Qt::ISODate);
|
||||
}
|
||||
} else
|
||||
if (QString(inner_obj_name) == QString("tariff_product_end")) {
|
||||
if (k->value.IsString()) {
|
||||
std::string const &s = k->value.GetString();
|
||||
TariffProduct.m_tariff_product_end = QTime::fromString(QString::fromStdString(s), Qt::ISODate);
|
||||
}
|
||||
} else
|
||||
if (QString(inner_obj_name) == QString("tariff_product_from_in_minutes_from_start")) {
|
||||
if (k->value.IsInt()) {
|
||||
int const x = k->value.GetInt();
|
||||
TariffProduct.m_tariff_product_from_in_minutes_from_start = x;
|
||||
}
|
||||
} else
|
||||
if (QString(inner_obj_name) == QString("tariff_product_to_in_minutes_from_start")) {
|
||||
if (k->value.IsInt()) {
|
||||
int const x = k->value.GetInt();
|
||||
TariffProduct.m_tariff_product_to_in_minutes_from_start = x;
|
||||
}
|
||||
}
|
||||
} break;
|
||||
case MemberType::TimeRangeType:
|
||||
if (QString(inner_obj_name) == QString("time_range_id")) {
|
||||
if (k->value.IsInt()) {
|
||||
@ -479,6 +526,9 @@ bool Configuration::ParseJson(Configuration* cfg, const char* json)
|
||||
cfg->TimeStepConfig.insert(pair<int, ATBTimeStepConfig>(TimeStepConfig.tsconfig_id, TimeStepConfig));
|
||||
// qCritical() << TimeStepConfig;
|
||||
break;
|
||||
case MemberType::ProductType:
|
||||
cfg->TariffProduct.insert(pair<int, ATBTariffProduct>(TariffProduct.m_tariff_product_id, TariffProduct));
|
||||
qCritical() << TariffProduct;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@ -492,6 +542,7 @@ bool Configuration::ParseJson(Configuration* cfg, const char* json)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
ATBPaymentOption const &Configuration::getPaymentOptions() const {
|
||||
Q_ASSERT(!this->currentPaymentOptions.isEmpty());
|
||||
return this->currentPaymentOptions.at(0);
|
||||
@ -510,6 +561,48 @@ QVector<ATBPaymentOption> &Configuration::getAllPaymentOptions() {
|
||||
return this->currentPaymentOptions;
|
||||
}
|
||||
|
||||
std::optional<QVector<ATBTariffProduct>>
|
||||
Configuration::getTariffProductForAllKeys() const {
|
||||
QVector<ATBTariffProduct> products;
|
||||
std::optional<QVector<ATBTariffProduct>> value;
|
||||
|
||||
products.clear();
|
||||
|
||||
for (std::multimap<int, ATBTariffProduct>::const_iterator it = this->TariffProduct.cbegin();
|
||||
it != this->TariffProduct.cend(); ++it) {
|
||||
products.append(it->second);
|
||||
}
|
||||
|
||||
if (products.size() > 0) {
|
||||
value = value.value_or(products);
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
std::optional<QVector<ATBTariffProduct>>
|
||||
Configuration::getTariffProductForProductId(PermitType permitType) const {
|
||||
QVector<ATBTariffProduct> products;
|
||||
std::optional<QVector<ATBTariffProduct>> value;
|
||||
|
||||
products.clear();
|
||||
|
||||
for (auto[it, rangeEnd] = this->TariffProduct.equal_range(permitType); it != rangeEnd; ++it) {
|
||||
products.append(it->second);
|
||||
}
|
||||
|
||||
if (products.size() > 0) {
|
||||
value = value.value_or(products);
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
std::optional<QVector<ATBTariffProduct>>
|
||||
Configuration::getTariffProductForProductId(int id) const {
|
||||
return getTariffProductForProductId(PermitType(id));
|
||||
}
|
||||
|
||||
std::optional<QVector<ATBDailyTicket>>
|
||||
Configuration::getDailyTicketsForAllKeys() const {
|
||||
QVector<ATBDailyTicket> tickets;
|
||||
|
199
main/main.cpp
199
main/main.cpp
@ -37,8 +37,8 @@ extern "C" char* strptime(const char* s,
|
||||
#define SZEGED (0)
|
||||
#define SCHOENAU_KOENIGSEE (0)
|
||||
#define NEUHAUSER_KORNEUBURG (0)
|
||||
#define NEUHAUSER_LINSINGER_MASCHINENBAU (1)
|
||||
#define NEUHAUSER_NORDISCHES_AUSBILDUNGSZENTRUM (0)
|
||||
#define NEUHAUSER_LINSINGER_MASCHINENBAU (0)
|
||||
#define NEUHAUSER_NORDISCHES_AUSBILDUNGSZENTRUM (1)
|
||||
#define NEUHAUSER_BILEXA_GALTUER (0)
|
||||
#define NEUHAUSER_KIRCHDORF (0)
|
||||
|
||||
@ -509,6 +509,17 @@ int main() {
|
||||
cout << endl;
|
||||
|
||||
if (isParsed) {
|
||||
|
||||
int v = compute_product_price(&cfg, PERMIT_TYPE::DAY_TICKET_ADULT);
|
||||
qCritical() << "price adult" << v;
|
||||
|
||||
int w = compute_product_price(&cfg, PERMIT_TYPE::DAY_TICKET_TEEN);
|
||||
qCritical() << "price teen" << w;
|
||||
|
||||
return 0;
|
||||
|
||||
|
||||
|
||||
QDateTime s(QDate(2023, 11, 30), QTime());
|
||||
QDateTime end;
|
||||
struct price_t price;
|
||||
@ -643,10 +654,11 @@ int main() {
|
||||
int pop_max_time;
|
||||
int pop_min_price;
|
||||
int pop_max_price;
|
||||
int pop_daily_card_price;
|
||||
|
||||
for (int t=1; t < 2; ++t) {
|
||||
for (int zone=2; zone < 3; ++zone) {
|
||||
//for (int t=6; t < 7; t+=20) {
|
||||
switch (t) {
|
||||
switch (zone) {
|
||||
case 1: {
|
||||
input.open("/opt/ptu5/opt/customer_281/etc/psa_tariff/tariff01.json");
|
||||
//pop_max_time = 6*60;
|
||||
@ -690,43 +702,186 @@ int main() {
|
||||
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: " << cfg.getPaymentOptions().pop_daily_card_price;
|
||||
qCritical() << "pop_daily_card_price: " << pop_daily_card_price;
|
||||
|
||||
if (pop_min_time > pop_max_time) {
|
||||
qCritical() << "ERROR pop_min_time > pop_max_time"
|
||||
<< pop_min_time << pop_max_time;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (pop_min_price > pop_max_price) {
|
||||
qCritical() << "ERROR pop_min_price > pop_max_price"
|
||||
<< pop_min_price << pop_max_price;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (pop_daily_card_price < pop_max_price) {
|
||||
qCritical() << "ERROR pop_daily_card_price < pop_max_price"
|
||||
<< pop_daily_card_price << pop_max_price;
|
||||
return -1;
|
||||
}
|
||||
|
||||
QMap<int, int> m;
|
||||
|
||||
{
|
||||
// zone 1 (lila)
|
||||
QDateTime s(QDate(2023, 11, 30), QTime());
|
||||
QDateTime end;
|
||||
int cnt = 1;
|
||||
#if 0
|
||||
for (int duration = 15; duration <= pop_max_time; duration += 5) {
|
||||
#if 1
|
||||
if (zone == 1) {
|
||||
m.insert(5, pop_min_price);
|
||||
m.insert(10, pop_min_price);
|
||||
|
||||
m.insert(pop_min_time, pop_min_price);
|
||||
m.insert(20, 55);
|
||||
m.insert(25, 69);
|
||||
m.insert(30, 83);
|
||||
m.insert(35, 97);
|
||||
m.insert(40, 110);
|
||||
m.insert(45, 124);
|
||||
m.insert(50, 138);
|
||||
m.insert(55, 152);
|
||||
m.insert(60, 165);
|
||||
|
||||
m.insert(65, 179);
|
||||
m.insert(70, 193);
|
||||
m.insert(75, 207);
|
||||
m.insert(80, 220);
|
||||
m.insert(85, 234);
|
||||
m.insert(90, 248);
|
||||
m.insert(95, 262);
|
||||
m.insert(100, 275);
|
||||
m.insert(105, 289);
|
||||
m.insert(110, 303);
|
||||
m.insert(115, 317);
|
||||
m.insert(120, 330);
|
||||
|
||||
m.insert(125, 344);
|
||||
m.insert(130, 358);
|
||||
m.insert(135, 372);
|
||||
m.insert(140, 385);
|
||||
m.insert(145, 399);
|
||||
m.insert(150, 413);
|
||||
m.insert(155, 427);
|
||||
m.insert(160, 440);
|
||||
m.insert(165, 454);
|
||||
m.insert(170, 468);
|
||||
m.insert(175, 482);
|
||||
m.insert(180, 495);
|
||||
|
||||
m.insert(185, 509);
|
||||
m.insert(190, 523);
|
||||
m.insert(195, 537);
|
||||
m.insert(200, 550);
|
||||
m.insert(205, 564);
|
||||
m.insert(210, 578);
|
||||
m.insert(215, 592);
|
||||
m.insert(220, 605);
|
||||
m.insert(225, 619);
|
||||
m.insert(230, 633);
|
||||
m.insert(235, 647);
|
||||
m.insert(240, 660);
|
||||
|
||||
m.insert(245, 674);
|
||||
m.insert(250, 688);
|
||||
m.insert(255, 702);
|
||||
m.insert(260, 715);
|
||||
m.insert(265, 729);
|
||||
m.insert(270, 743);
|
||||
m.insert(275, 757);
|
||||
m.insert(280, 770);
|
||||
m.insert(285, 784);
|
||||
m.insert(290, 798);
|
||||
m.insert(295, 812);
|
||||
m.insert(300, 825);
|
||||
|
||||
m.insert(305, 839);
|
||||
m.insert(310, 853);
|
||||
m.insert(315, 867);
|
||||
m.insert(320, 880);
|
||||
m.insert(325, 894);
|
||||
m.insert(330, 908);
|
||||
m.insert(335, 922);
|
||||
m.insert(340, 935);
|
||||
m.insert(345, 949);
|
||||
m.insert(350, 963);
|
||||
m.insert(355, 977);
|
||||
m.insert(360, pop_max_price);
|
||||
|
||||
m.insert(365, pop_max_price);
|
||||
m.insert(370, pop_max_price);
|
||||
m.insert(375, pop_max_price);
|
||||
m.insert(380, pop_max_price);
|
||||
m.insert(385, pop_max_price);
|
||||
m.insert(390, pop_max_price);
|
||||
m.insert(395, pop_max_price);
|
||||
m.insert(400, pop_max_price);
|
||||
m.insert(405, pop_max_price);
|
||||
m.insert(410, pop_max_price);
|
||||
m.insert(415, pop_max_price);
|
||||
m.insert(420, pop_max_price);
|
||||
} else
|
||||
if (zone == 2) {
|
||||
|
||||
}
|
||||
|
||||
struct price_t price;
|
||||
for (int duration = pop_min_time; 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);
|
||||
end = QDateTime();
|
||||
price.netto = 0;
|
||||
if (compute_price_for_parking_ticket(&cfg, start, duration, end, &price)) {
|
||||
double cost = price.netto;
|
||||
|
||||
double cost = Calculator::GetInstance().GetCostFromDuration(&cfg, 3, start, end, duration);
|
||||
// Q_ASSERT(cost == duration*2.5);
|
||||
//qCritical() << "";
|
||||
qCritical() << cnt << "start" << start.toString(Qt::ISODate)
|
||||
<< "end" << end.toString(Qt::ISODate)
|
||||
qCritical() << start.toString(Qt::ISODate) << end.toString(Qt::ISODate)
|
||||
<< duration << cost;
|
||||
|
||||
//if (cost != m[duration]) {
|
||||
// qCritical() << "ERROR computing_price_for_parking_ticket"
|
||||
// << "duration" << duration
|
||||
// << "HAVE cost" << cost
|
||||
// << "SHOULD HAVE cost" << m[duration];
|
||||
// return -1;
|
||||
//}
|
||||
} else {
|
||||
qCritical() << "ERROR computing_price_for_parking_ticket AT"
|
||||
<< cnt << "duration" << duration
|
||||
<< "start" << start.toString(Qt::ISODate);
|
||||
return -1;
|
||||
}
|
||||
start = s.addSecs(offset * 60);
|
||||
end = QDateTime();
|
||||
price.netto = 0;
|
||||
|
||||
if (zone == 1) { // || zone == 2)
|
||||
if (compute_price_for_daily_ticket(&cfg, start, end, PERMIT_TYPE::DAY_TICKET, &price)) {
|
||||
if (price.netto != pop_daily_card_price) {
|
||||
qCritical() << "ERROR computing_price_for_daily_ticket"
|
||||
<< "duration" << duration
|
||||
<< "cost" << cost;
|
||||
<< "HAVE cost" << price.netto
|
||||
<< "SHOULD HAVE cost" << pop_daily_card_price;
|
||||
return -1;
|
||||
}
|
||||
} else {
|
||||
qCritical() << "ERROR computing_price_for_daily_ticket AT"
|
||||
<< "start" << start.toString(Qt::ISODate);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
std::string duration = Calculator::GetInstance().GetDurationFromCost(&cfg,
|
||||
3,
|
||||
start.toString(Qt::ISODate).toStdString().c_str(),
|
||||
cost, false, true);
|
||||
//Q_ASSERT(cost == duration*2.5);
|
||||
qCritical() << cnt << "start" << start.toString(Qt::ISODate)
|
||||
<< "cost" << cost
|
||||
<< "until" << duration.c_str() << start.secsTo(QDateTime::fromString(duration.c_str(), Qt::ISODate)) / 60;
|
||||
++cnt;
|
||||
}
|
||||
}
|
||||
|
||||
#else
|
||||
QDateTime start = s.addSecs(480 * 60); // 8:00:00
|
||||
double cost = 2000;
|
||||
|
Loading…
x
Reference in New Issue
Block a user