Compare commits
8 Commits
54921f0e85
...
35294e99f0
Author | SHA1 | Date | |
---|---|---|---|
35294e99f0 | |||
edfa5dc1b1 | |||
d95741baae | |||
e172e814e7 | |||
37aa10fc85 | |||
4b9edb0f47 | |||
e70e9a8586 | |||
aec290fe26 |
@ -83,6 +83,7 @@ public:
|
|||||||
TariffOutOfServiceType TariffOutOfServices;
|
TariffOutOfServiceType TariffOutOfServices;
|
||||||
ATBTariffPrepaidType TariffPrepaids;
|
ATBTariffPrepaidType TariffPrepaids;
|
||||||
ATBTariffCarryOverType TariffCarryOvers;
|
ATBTariffCarryOverType TariffCarryOvers;
|
||||||
|
QStringList TariffIncludes;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Parse JSON string
|
/// Parse JSON string
|
||||||
@ -123,6 +124,9 @@ public:
|
|||||||
std::optional<ATBWeekDaysWorktime> getWeekDayWorkTime(QTime const &time, Qt::DayOfWeek dayOfWeek);
|
std::optional<ATBWeekDaysWorktime> getWeekDayWorkTime(QTime const &time, Qt::DayOfWeek dayOfWeek);
|
||||||
std::optional<QVector<ATBWeekDaysWorktime>> getAllWeekDayWorkTimes();
|
std::optional<QVector<ATBWeekDaysWorktime>> getAllWeekDayWorkTimes();
|
||||||
|
|
||||||
|
QStringList const &getTariffIncludes() const { return TariffIncludes; }
|
||||||
|
QStringList &getTariffIncludes() { return TariffIncludes; }
|
||||||
|
|
||||||
std::optional<QDateTime> prepaidStart(QDateTime const &start, int prepaid_option_id);
|
std::optional<QDateTime> prepaidStart(QDateTime const &start, int prepaid_option_id);
|
||||||
int getPaymentOptionIndex(PERMIT_TYPE permitType);
|
int getPaymentOptionIndex(PERMIT_TYPE permitType);
|
||||||
int getPaymentOptionIndex(PERMIT_TYPE permitType) const;
|
int getPaymentOptionIndex(PERMIT_TYPE permitType) const;
|
||||||
|
@ -22,7 +22,8 @@ enum MemberType
|
|||||||
ProductType = 0x0F,
|
ProductType = 0x0F,
|
||||||
InterpolationType = 0x10,
|
InterpolationType = 0x10,
|
||||||
PrepaidType = 0x11,
|
PrepaidType = 0x11,
|
||||||
CarryOverType = 0x12
|
CarryOverType = 0x12,
|
||||||
|
IncludesType = 0x13
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // MEMBER_TYPE_H_INCLUDED
|
#endif // MEMBER_TYPE_H_INCLUDED
|
||||||
|
@ -19,7 +19,9 @@ enum class PERMIT_TYPE : quint8 {
|
|||||||
SHORT_TERM_PARKING_CAMPER=12,
|
SHORT_TERM_PARKING_CAMPER=12,
|
||||||
DAY_TICKET_PKW=13,
|
DAY_TICKET_PKW=13,
|
||||||
DAY_TICKET_BUS=14,
|
DAY_TICKET_BUS=14,
|
||||||
DAY_TICKET_CAMPER=15
|
DAY_TICKET_CAMPER=15,
|
||||||
|
FREE_TICKET=16,
|
||||||
|
PRODUCT_MAX
|
||||||
};
|
};
|
||||||
|
|
||||||
struct PermitType {
|
struct PermitType {
|
||||||
@ -73,6 +75,9 @@ struct PermitType {
|
|||||||
case 15:
|
case 15:
|
||||||
m_permitType = PERMIT_TYPE::DAY_TICKET_CAMPER;
|
m_permitType = PERMIT_TYPE::DAY_TICKET_CAMPER;
|
||||||
break;
|
break;
|
||||||
|
case 16:
|
||||||
|
m_permitType = PERMIT_TYPE::FREE_TICKET;
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
m_permitType = PERMIT_TYPE::INVALID;
|
m_permitType = PERMIT_TYPE::INVALID;
|
||||||
}
|
}
|
||||||
@ -116,6 +121,8 @@ struct PermitType {
|
|||||||
return 14;
|
return 14;
|
||||||
case PERMIT_TYPE::DAY_TICKET_CAMPER:
|
case PERMIT_TYPE::DAY_TICKET_CAMPER:
|
||||||
return 15;
|
return 15;
|
||||||
|
case PERMIT_TYPE::FREE_TICKET:
|
||||||
|
return 16;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -132,9 +139,6 @@ struct PermitType {
|
|||||||
if (permitTypeStr == "DAY_TICKET_CHILD") {
|
if (permitTypeStr == "DAY_TICKET_CHILD") {
|
||||||
return PERMIT_TYPE::DAY_TICKET_CHILD;
|
return PERMIT_TYPE::DAY_TICKET_CHILD;
|
||||||
} else
|
} else
|
||||||
if (permitTypeStr == "DAY_TICKET_ADULT") {
|
|
||||||
return PERMIT_TYPE::DAY_TICKET_ADULT;
|
|
||||||
} else
|
|
||||||
if (permitTypeStr == "DAY_TICKET_TEEN") {
|
if (permitTypeStr == "DAY_TICKET_TEEN") {
|
||||||
return PERMIT_TYPE::DAY_TICKET_TEEN;
|
return PERMIT_TYPE::DAY_TICKET_TEEN;
|
||||||
} else
|
} else
|
||||||
@ -170,6 +174,9 @@ struct PermitType {
|
|||||||
} else
|
} else
|
||||||
if (permitTypeStr == "DAY_TICKET_CAMPER") {
|
if (permitTypeStr == "DAY_TICKET_CAMPER") {
|
||||||
return PERMIT_TYPE::DAY_TICKET_CAMPER;
|
return PERMIT_TYPE::DAY_TICKET_CAMPER;
|
||||||
|
} else
|
||||||
|
if (permitTypeStr == "FREE_TICKET") {
|
||||||
|
return PERMIT_TYPE::FREE_TICKET;
|
||||||
}
|
}
|
||||||
|
|
||||||
return PERMIT_TYPE::INVALID;
|
return PERMIT_TYPE::INVALID;
|
||||||
@ -207,6 +214,8 @@ struct PermitType {
|
|||||||
return QString("DAY_TICKET_BUS");
|
return QString("DAY_TICKET_BUS");
|
||||||
case PERMIT_TYPE::DAY_TICKET_CAMPER:
|
case PERMIT_TYPE::DAY_TICKET_CAMPER:
|
||||||
return QString("DAY_TICKET_CAMPER");
|
return QString("DAY_TICKET_CAMPER");
|
||||||
|
case PERMIT_TYPE::FREE_TICKET:
|
||||||
|
return QString("FREE_TICKET");
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -245,6 +254,8 @@ struct PermitType {
|
|||||||
return QString("DAY_TICKET_BUS");
|
return QString("DAY_TICKET_BUS");
|
||||||
case PERMIT_TYPE::DAY_TICKET_CAMPER:
|
case PERMIT_TYPE::DAY_TICKET_CAMPER:
|
||||||
return QString("DAY_TICKET_CAMPER");
|
return QString("DAY_TICKET_CAMPER");
|
||||||
|
case PERMIT_TYPE::FREE_TICKET:
|
||||||
|
return QString("FREE_TICKET");
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -5,12 +5,15 @@
|
|||||||
#include "utilities.h"
|
#include "utilities.h"
|
||||||
#include "tariff_global_defines.h"
|
#include "tariff_global_defines.h"
|
||||||
#include "period_year.h"
|
#include "period_year.h"
|
||||||
|
#include "tariff_permit_type.h"
|
||||||
|
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
#include <QFileInfo>
|
#include <QFileInfo>
|
||||||
#include <QDateTime>
|
#include <QDateTime>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QList>
|
#include <QList>
|
||||||
|
#include <map>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
QString const CalcState::SUCCESS = "SUCCESS";
|
QString const CalcState::SUCCESS = "SUCCESS";
|
||||||
QString const CalcState::ERROR_PARSING_ZONE_NR = "ERROR_PARSING_ZONE_NR";
|
QString const CalcState::ERROR_PARSING_ZONE_NR = "ERROR_PARSING_ZONE_NR";
|
||||||
@ -28,6 +31,9 @@ QString const CalcState::OVERPAID = "OVERPAID";
|
|||||||
QString const CalcState::OUTSIDE_ALLOWED_PARKING_TIME = "OUTSIDE_ALLOWED_PARKING_TIME";
|
QString const CalcState::OUTSIDE_ALLOWED_PARKING_TIME = "OUTSIDE_ALLOWED_PARKING_TIME";
|
||||||
QString const CalcState::SUCCESS_MAXPRICE = "SUCCESS_MAXPRICE";
|
QString const CalcState::SUCCESS_MAXPRICE = "SUCCESS_MAXPRICE";
|
||||||
|
|
||||||
|
|
||||||
|
static std::map<PERMIT_TYPE, std::unique_ptr<parking_tariff_t>> tariffs;
|
||||||
|
|
||||||
QList<int> CALCULATE_LIBRARY_API get_time_steps(Configuration *cfg) {
|
QList<int> CALCULATE_LIBRARY_API get_time_steps(Configuration *cfg) {
|
||||||
return Calculator::GetInstance().GetTimeSteps(cfg);
|
return Calculator::GetInstance().GetTimeSteps(cfg);
|
||||||
}
|
}
|
||||||
@ -464,6 +470,31 @@ CalcState CALCULATE_LIBRARY_API init_tariff(parking_tariff_t **tariff, char cons
|
|||||||
|
|
||||||
qCritical() << "init_tariff: Parsing tariff config (" << confFile << ")";
|
qCritical() << "init_tariff: Parsing tariff config (" << confFile << ")";
|
||||||
|
|
||||||
|
if ((*tariff)->TariffIncludes.size() > 0) {
|
||||||
|
qCritical() << "init_tariff: TariffIncludes" << (*tariff)->TariffIncludes;
|
||||||
|
for (int i = 0 ; i < (*tariff)->TariffIncludes.size(); ++i) {
|
||||||
|
QFile f(QString("/etc/psa_tariff/%1").arg((*tariff)->TariffIncludes.at(i)));
|
||||||
|
if (f.exists() &&
|
||||||
|
f.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
||||||
|
|
||||||
|
QString json = f.readAll();
|
||||||
|
std::unique_ptr<parking_tariff_t> t = std::make_unique<parking_tariff_t>();
|
||||||
|
|
||||||
|
if (! t->ParseJson(t.get(), json.toStdString().c_str())) {
|
||||||
|
qCritical() << " ... error parsing tariff in" << f.fileName();
|
||||||
|
qCritical() << " ... json" << json;
|
||||||
|
} else {
|
||||||
|
PERMIT_TYPE pt = static_cast<PERMIT_TYPE>(t->getPaymentOptions().pop_product_id);
|
||||||
|
if (tariffs.count(pt) == 0) {
|
||||||
|
const auto [it, success] = tariffs.insert(std::make_pair(pt, std::move(t)));
|
||||||
|
qCritical() << " ... insertion" << success;
|
||||||
|
qCritical() << " ... insertion" << (int)it->first << it->second->getPaymentOptions().pop_product_name;
|
||||||
|
qCritical() << " ... insertion" << tariffs[pt]->getPaymentOptions().pop_product_name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
return calcState;
|
return calcState;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1104,6 +1135,10 @@ CalcState CALCULATE_LIBRARY_API compute_duration_for_parking_ticket(
|
|||||||
QDateTime &ticketEndTime,
|
QDateTime &ticketEndTime,
|
||||||
PermitType permitType)
|
PermitType permitType)
|
||||||
{
|
{
|
||||||
|
if (tariffs.count(permitType) > 0) {
|
||||||
|
tariff = tariffs[permitType].get();
|
||||||
|
}
|
||||||
|
|
||||||
tariff->getPaymentOptions(0).pop_max_price
|
tariff->getPaymentOptions(0).pop_max_price
|
||||||
= tariff->getPaymentOptions(0).pop_max_price_save;
|
= tariff->getPaymentOptions(0).pop_max_price_save;
|
||||||
|
|
||||||
@ -1111,8 +1146,15 @@ CalcState CALCULATE_LIBRARY_API compute_duration_for_parking_ticket(
|
|||||||
|
|
||||||
bool prepaid = true;
|
bool prepaid = true;
|
||||||
|
|
||||||
|
qCritical() << __func__ << ":" << __LINE__ << " permit type (int): " << static_cast<int>(permitType);
|
||||||
|
qCritical() << __func__ << ":" << __LINE__ << "permit type (string): " << permitType.toString();
|
||||||
|
qCritical() << __func__ << ":" << __LINE__ << " tariff-includes: " << tariff->getTariffIncludes();
|
||||||
|
|
||||||
int paymentOptionIndex = getPaymentOptionIndex(*tariff, start_parking_time);
|
int paymentOptionIndex = getPaymentOptionIndex(*tariff, start_parking_time);
|
||||||
|
|
||||||
qCritical() << __func__ << ":" << __LINE__ << "payment option index: " << paymentOptionIndex;
|
qCritical() << __func__ << ":" << __LINE__ << "payment option index: " << paymentOptionIndex;
|
||||||
|
|
||||||
|
|
||||||
if (paymentOptionIndex == -1) {
|
if (paymentOptionIndex == -1) {
|
||||||
paymentOptionIndex = tariff->getPaymentOptionIndex(permitType);
|
paymentOptionIndex = tariff->getPaymentOptionIndex(permitType);
|
||||||
}
|
}
|
||||||
|
@ -3696,6 +3696,9 @@ Calculator::GetDailyTicketPrice(Configuration* cfg,
|
|||||||
if (dailyTickets) {
|
if (dailyTickets) {
|
||||||
QVector<ATBDailyTicket> const tickets = dailyTickets.value();
|
QVector<ATBDailyTicket> const tickets = dailyTickets.value();
|
||||||
switch (permitType) {
|
switch (permitType) {
|
||||||
|
case PERMIT_TYPE::FREE_TICKET: {
|
||||||
|
// TODO
|
||||||
|
} break;
|
||||||
case PERMIT_TYPE::TWENTY_FOUR_HOURS_TICKET: {
|
case PERMIT_TYPE::TWENTY_FOUR_HOURS_TICKET: {
|
||||||
// TODO
|
// TODO
|
||||||
} break;
|
} break;
|
||||||
|
@ -46,6 +46,7 @@ MemberType Configuration::IdentifyJsonMember(const char* member_name)
|
|||||||
if (strcmp(member_name, "Interpolation") == 0) return MemberType::InterpolationType;
|
if (strcmp(member_name, "Interpolation") == 0) return MemberType::InterpolationType;
|
||||||
if (strcmp(member_name, "Prepaid") == 0) return MemberType::PrepaidType;
|
if (strcmp(member_name, "Prepaid") == 0) return MemberType::PrepaidType;
|
||||||
if (strcmp(member_name, "CarryOver") == 0) return MemberType::CarryOverType;
|
if (strcmp(member_name, "CarryOver") == 0) return MemberType::CarryOverType;
|
||||||
|
if (strcmp(member_name, "Includes") == 0) return MemberType::IncludesType;
|
||||||
else return MemberType::UnknownType;
|
else return MemberType::UnknownType;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -811,6 +812,7 @@ bool Configuration::ParseJson(Configuration* cfg, const char* json)
|
|||||||
ATBInterpolation TariffInterpolation;
|
ATBInterpolation TariffInterpolation;
|
||||||
ATBPrepaid TariffPrepaidOption;
|
ATBPrepaid TariffPrepaidOption;
|
||||||
ATBCarryOver TariffCarryOver;
|
ATBCarryOver TariffCarryOver;
|
||||||
|
QStringList TariffIncludes;
|
||||||
|
|
||||||
MemberType mb_type = MemberType::UnknownType;
|
MemberType mb_type = MemberType::UnknownType;
|
||||||
this->currentPaymentOptions.clear();
|
this->currentPaymentOptions.clear();
|
||||||
@ -1342,6 +1344,9 @@ bool Configuration::ParseJson(Configuration* cfg, const char* json)
|
|||||||
else if (strcmp(inner_obj_name, "pcu_minor") == 0) Currency.pcu_minor = k->value.GetString();
|
else if (strcmp(inner_obj_name, "pcu_minor") == 0) Currency.pcu_minor = k->value.GetString();
|
||||||
else if (strcmp(inner_obj_name, "pcu_active") == 0) Currency.pcu_active = k->value.GetBool();
|
else if (strcmp(inner_obj_name, "pcu_active") == 0) Currency.pcu_active = k->value.GetBool();
|
||||||
break;
|
break;
|
||||||
|
case MemberType::IncludesType:
|
||||||
|
TariffIncludes << k->value.GetString();
|
||||||
|
break;
|
||||||
case MemberType::PaymentMethodType:
|
case MemberType::PaymentMethodType:
|
||||||
if (strcmp(inner_obj_name, "pme_id") == 0) PaymentMethod.pme_id = k->value.GetInt();
|
if (strcmp(inner_obj_name, "pme_id") == 0) PaymentMethod.pme_id = k->value.GetInt();
|
||||||
else if (strcmp(inner_obj_name, "pme_label") == 0) PaymentMethod.pme_label = k->value.GetString();
|
else if (strcmp(inner_obj_name, "pme_label") == 0) PaymentMethod.pme_label = k->value.GetString();
|
||||||
@ -1631,6 +1636,9 @@ bool Configuration::ParseJson(Configuration* cfg, const char* json)
|
|||||||
cfg->TariffCarryOverOptions.insert(pair<int, ATBCarryOver>(TariffCarryOver.id, TariffCarryOver));
|
cfg->TariffCarryOverOptions.insert(pair<int, ATBCarryOver>(TariffCarryOver.id, TariffCarryOver));
|
||||||
// qCritical() << TariffCarryOver;
|
// qCritical() << TariffCarryOver;
|
||||||
break;
|
break;
|
||||||
|
case MemberType::IncludesType:
|
||||||
|
cfg->TariffIncludes = TariffIncludes;
|
||||||
|
// qCritical() << "TariffIncludes" << cfg->TariffIncludes;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -211,21 +211,73 @@ static bool test_neuhauser_kirchdorf(int step, double cost) {
|
|||||||
return 0;
|
return 0;
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <QProcess>
|
||||||
|
#include <QCoreApplication>
|
||||||
|
QString getCalculatorLibVersion() {
|
||||||
|
static QString v;
|
||||||
|
if (v.isEmpty()) {
|
||||||
|
QProcess shell;
|
||||||
|
QString command = QString("cat /proc/%1/maps | awk '{print $6;}' | grep 'libmobilisis_calc' | uniq").arg(QCoreApplication::applicationPid());
|
||||||
|
|
||||||
|
shell.start("/bin/bash", {"-c", command});
|
||||||
|
if ( shell.waitForFinished( 5000 )) {
|
||||||
|
v = shell.readAllStandardOutput();
|
||||||
|
// /usr/lib/libmobilisis_calc.so.2.3.99-18
|
||||||
|
if (!v.isEmpty()) {
|
||||||
|
QStringList vlst = v.trimmed().split("/", QString::SkipEmptyParts);
|
||||||
|
if (vlst.size() > 0) {
|
||||||
|
vlst = vlst.last().split(".", QString::SkipEmptyParts);
|
||||||
|
if (vlst.size() > 4) {
|
||||||
|
v = QString("%1.%2.%3").arg(vlst[2]).arg(vlst[3]).arg(vlst[4]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return v;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool isProductSupportedInCalculatorLib(QString const &product) {
|
||||||
|
bool supported{false};
|
||||||
|
|
||||||
|
QProcess shell;
|
||||||
|
QString command = QString("cat /proc/%1/maps | awk '{print $6;}' | grep 'libmobilisis_calc' | uniq | xargs strings | grep %2").arg(QCoreApplication::applicationPid()).arg(product);
|
||||||
|
|
||||||
|
shell.start("/bin/bash", {"-c", command});
|
||||||
|
if ( shell.waitForFinished( 5000 )) {
|
||||||
|
QString s = shell.readAllStandardOutput().trimmed();
|
||||||
|
// /usr/lib/libmobilisis_calc.so.2.3.99-18
|
||||||
|
if (!s.isEmpty() && (s == product)) {
|
||||||
|
qCritical() << "product" << s << "supported";
|
||||||
|
supported = true;
|
||||||
|
} else {
|
||||||
|
qCritical() << "product" << product << "not supported";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return supported;
|
||||||
|
}
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
|
|
||||||
|
qCritical() << getCalculatorLibVersion();
|
||||||
|
isProductSupportedInCalculatorLib("FREE_TICKET");
|
||||||
|
return 0;
|
||||||
//487 {
|
//487 {
|
||||||
// 488 "pra_payment_option_id": 1049,
|
// 488 "pra_payment_option_id": 1049,
|
||||||
// 489 "pra_payment_unit_id": 84,
|
// 489 "pra_payment_unit_id": 84,
|
||||||
// 490 "pra_price":"840"
|
// 490 "pra_price":"840"
|
||||||
//>>491 }
|
//>>491 }
|
||||||
|
|
||||||
//for (int i = 1; i < 85; ++i) {
|
//for (int i = 1; i < 346; ++i) {
|
||||||
//printf("{\n \"\pra_payment_option_id\": 1049,\n \"\pra_payment_unit_id\": %d,\n \"pra_price\": %d\n},\n",
|
//printf("{\n \"pun_id\": %i,\n \"pun_duration\": %d\n},\n",
|
||||||
// i, i*10);
|
// i, 60 + i*4);
|
||||||
//}
|
//}
|
||||||
//return 0;
|
for (int i = 1; i < 361; ++i) {
|
||||||
|
printf("{\n \"pra_payment_option_id\": 1049,\n \"pra_payment_unit_id\": %i,\n \"pra_price\":%i\n},\n",
|
||||||
|
i, i*10);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
#if 0
|
#if 0
|
||||||
MessageHelper msgHelp;
|
MessageHelper msgHelp;
|
||||||
// msgHelp.createLoginMessageChunksToSend(0x02);
|
// msgHelp.createLoginMessageChunksToSend(0x02);
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
QT += core
|
||||||
|
|
||||||
TEMPLATE = app
|
TEMPLATE = app
|
||||||
TARGET = main
|
TARGET = main
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user