Compare commits
31 Commits
Author | SHA1 | Date | |
---|---|---|---|
f2156e4650 | |||
338a1a4ebc | |||
b4818a3918 | |||
35294e99f0 | |||
edfa5dc1b1 | |||
d95741baae | |||
e172e814e7 | |||
37aa10fc85 | |||
4b9edb0f47 | |||
e70e9a8586 | |||
aec290fe26 | |||
78cae24389 | |||
de0be1d19b | |||
54921f0e85 | |||
077c2334ca | |||
d605af5c5a | |||
c5900f9f2b | |||
9b137c2873 | |||
dd249a87d5 | |||
575885c19e | |||
d82a732a8d | |||
99dbd7c194 | |||
ae985d25ce | |||
6a215d4cf9 | |||
a3f4a742ce | |||
e6d8c04076 | |||
1f6606f382 | |||
4b9a4319b3 | |||
5e673788b4 | |||
7e2f40a7b5 | |||
44e2ce24a3 |
@ -83,6 +83,7 @@ public:
|
||||
TariffOutOfServiceType TariffOutOfServices;
|
||||
ATBTariffPrepaidType TariffPrepaids;
|
||||
ATBTariffCarryOverType TariffCarryOvers;
|
||||
QStringList TariffIncludes;
|
||||
|
||||
/// <summary>
|
||||
/// Parse JSON string
|
||||
@ -123,6 +124,9 @@ public:
|
||||
std::optional<ATBWeekDaysWorktime> getWeekDayWorkTime(QTime const &time, Qt::DayOfWeek dayOfWeek);
|
||||
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);
|
||||
int getPaymentOptionIndex(PERMIT_TYPE permitType);
|
||||
int getPaymentOptionIndex(PERMIT_TYPE permitType) const;
|
||||
|
@ -22,7 +22,8 @@ enum MemberType
|
||||
ProductType = 0x0F,
|
||||
InterpolationType = 0x10,
|
||||
PrepaidType = 0x11,
|
||||
CarryOverType = 0x12
|
||||
CarryOverType = 0x12,
|
||||
IncludesType = 0x13
|
||||
};
|
||||
|
||||
#endif // MEMBER_TYPE_H_INCLUDED
|
||||
|
@ -37,7 +37,7 @@ struct ATBTariffCarryOver {
|
||||
if (coif == "always") {
|
||||
m_carryOverIf = ApplyCarryOver::ALWAYS;
|
||||
} else {
|
||||
qCritical() << "ERROR unknown carry over application" << coif;
|
||||
qCritical() << __func__ << ":" << __LINE__ << "ERROR unknown carry over application" << coif;
|
||||
}
|
||||
}
|
||||
|
||||
@ -61,6 +61,37 @@ struct ATBTariffCarryOver {
|
||||
return QString("ERROR unknown carry over application: %1").arg(static_cast<int>(m_carryOverIf));
|
||||
}
|
||||
|
||||
int computeMinutesUntilCarryOverEnd(QDateTime const &dt) {
|
||||
int minutes = 0;
|
||||
QString end = m_range.m_end.toString(Qt::ISODate);
|
||||
if (end == "24:00:00") {
|
||||
// note: this did not work
|
||||
// QDateTime t(dt.addDays(1));
|
||||
// t.setTime(QTime(0,0,0));
|
||||
// dt: 2024-10-27T00:00:00 EEST, but t: 2024-10-28T00:00:00 EET (!)
|
||||
// so the difference is 1500 instead of 1440
|
||||
// reason: change from summer to winter time
|
||||
|
||||
// compute minutes directly
|
||||
if (dt.time().isValid()) {
|
||||
minutes = 1440 - (dt.time().hour() * 60 + dt.time().minute());
|
||||
}
|
||||
} else {
|
||||
QTime t(QTime::fromString(end, Qt::ISODate));
|
||||
if (t.isValid() && dt.time().isValid()) {
|
||||
minutes = (t.hour() * 60 + t.minute()) - (dt.time().hour() * 60 + dt.time().minute());
|
||||
}
|
||||
}
|
||||
|
||||
if (minutes < 0 || minutes > m_range.m_duration) {
|
||||
minutes = 0;
|
||||
}
|
||||
|
||||
// qCritical() << __func__ << ":" << __LINE__ << "minutes" << minutes;
|
||||
|
||||
return minutes;
|
||||
}
|
||||
|
||||
friend QDebug operator<<(QDebug debug, ATBTariffCarryOver const &co) {
|
||||
QDebugStateSaver saver(debug);
|
||||
|
||||
|
@ -19,7 +19,9 @@ enum class PERMIT_TYPE : quint8 {
|
||||
SHORT_TERM_PARKING_CAMPER=12,
|
||||
DAY_TICKET_PKW=13,
|
||||
DAY_TICKET_BUS=14,
|
||||
DAY_TICKET_CAMPER=15
|
||||
DAY_TICKET_CAMPER=15,
|
||||
FREE_TICKET=16,
|
||||
PRODUCT_MAX
|
||||
};
|
||||
|
||||
struct PermitType {
|
||||
@ -73,6 +75,9 @@ struct PermitType {
|
||||
case 15:
|
||||
m_permitType = PERMIT_TYPE::DAY_TICKET_CAMPER;
|
||||
break;
|
||||
case 16:
|
||||
m_permitType = PERMIT_TYPE::FREE_TICKET;
|
||||
break;
|
||||
default:
|
||||
m_permitType = PERMIT_TYPE::INVALID;
|
||||
}
|
||||
@ -116,6 +121,8 @@ struct PermitType {
|
||||
return 14;
|
||||
case PERMIT_TYPE::DAY_TICKET_CAMPER:
|
||||
return 15;
|
||||
case PERMIT_TYPE::FREE_TICKET:
|
||||
return 16;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@ -132,9 +139,6 @@ struct PermitType {
|
||||
if (permitTypeStr == "DAY_TICKET_CHILD") {
|
||||
return PERMIT_TYPE::DAY_TICKET_CHILD;
|
||||
} else
|
||||
if (permitTypeStr == "DAY_TICKET_ADULT") {
|
||||
return PERMIT_TYPE::DAY_TICKET_ADULT;
|
||||
} else
|
||||
if (permitTypeStr == "DAY_TICKET_TEEN") {
|
||||
return PERMIT_TYPE::DAY_TICKET_TEEN;
|
||||
} else
|
||||
@ -170,6 +174,9 @@ struct PermitType {
|
||||
} else
|
||||
if (permitTypeStr == "DAY_TICKET_CAMPER") {
|
||||
return PERMIT_TYPE::DAY_TICKET_CAMPER;
|
||||
} else
|
||||
if (permitTypeStr == "FREE_TICKET") {
|
||||
return PERMIT_TYPE::FREE_TICKET;
|
||||
}
|
||||
|
||||
return PERMIT_TYPE::INVALID;
|
||||
@ -207,6 +214,8 @@ struct PermitType {
|
||||
return QString("DAY_TICKET_BUS");
|
||||
case PERMIT_TYPE::DAY_TICKET_CAMPER:
|
||||
return QString("DAY_TICKET_CAMPER");
|
||||
case PERMIT_TYPE::FREE_TICKET:
|
||||
return QString("FREE_TICKET");
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@ -245,6 +254,8 @@ struct PermitType {
|
||||
return QString("DAY_TICKET_BUS");
|
||||
case PERMIT_TYPE::DAY_TICKET_CAMPER:
|
||||
return QString("DAY_TICKET_CAMPER");
|
||||
case PERMIT_TYPE::FREE_TICKET:
|
||||
return QString("FREE_TICKET");
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
@ -38,7 +38,7 @@ struct ATBTariffPrepaid {
|
||||
if (ppif == "always") {
|
||||
m_prepaidIf = ApplyPrepaid::ALWAYS;
|
||||
} else {
|
||||
qCritical() << "ERROR unknown carry over application" << ppif;
|
||||
qCritical() << __func__ << ":" << __LINE__ << "ERROR unknown carry over application" << ppif;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -34,6 +34,13 @@ struct TimeRange {
|
||||
m_duration = timeRange.m_duration;
|
||||
return *this;
|
||||
}
|
||||
|
||||
TimeRange &operator=(TimeRange const &timeRange) {
|
||||
m_start = timeRange.m_start;
|
||||
m_end = timeRange.m_end;
|
||||
m_duration = timeRange.m_duration;
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
|
||||
#endif // TIME_RANGE_H_INCLUDED
|
||||
|
@ -5,12 +5,15 @@
|
||||
#include "utilities.h"
|
||||
#include "tariff_global_defines.h"
|
||||
#include "period_year.h"
|
||||
#include "tariff_permit_type.h"
|
||||
|
||||
#include <QFile>
|
||||
#include <QFileInfo>
|
||||
#include <QDateTime>
|
||||
#include <QDebug>
|
||||
#include <QList>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
|
||||
QString const CalcState::SUCCESS = "SUCCESS";
|
||||
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::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) {
|
||||
return Calculator::GetInstance().GetTimeSteps(cfg);
|
||||
}
|
||||
@ -37,13 +43,24 @@ int CALCULATE_LIBRARY_API get_minimal_parkingtime(Configuration const *cfg,
|
||||
int paymentOptionIndex) {
|
||||
int minTime = 0;
|
||||
|
||||
// tariffs are only set if there is a Includes-section in the tariff-file,
|
||||
// which means the code below will be executed only in such a case.
|
||||
if (tariffs.count(permitType) > 0) {
|
||||
Configuration *c = tariffs[permitType].get();
|
||||
if (c && c != cfg) {
|
||||
cfg = c;
|
||||
}
|
||||
}
|
||||
|
||||
paymentOptionIndex = getPaymentOptionIndex(*cfg);
|
||||
if (paymentOptionIndex == -1) {
|
||||
paymentOptionIndex = cfg->getPaymentOptionIndex(permitType);
|
||||
}
|
||||
|
||||
qCritical() << __func__ << __LINE__ << "paymentOptionIndex" << paymentOptionIndex;
|
||||
qCritical() << __func__ << __LINE__ << "permit" << PermitType(permitType).toString();
|
||||
qCritical() << __func__ << __LINE__ << "permit" << (int)permitType << PermitType(permitType).toString();
|
||||
qCritical() << __func__ << __LINE__ << "min_time" << (int)permitType << cfg->getPaymentOptions(paymentOptionIndex).pop_min_time;
|
||||
qCritical() << __func__ << __LINE__ << "min_price" << (int)permitType << cfg->getPaymentOptions(paymentOptionIndex).pop_min_price;
|
||||
|
||||
switch(permitType) {
|
||||
case PERMIT_TYPE::SHORT_TERM_PARKING: { // e.g. szeged (customer_281)
|
||||
@ -73,6 +90,15 @@ int CALCULATE_LIBRARY_API get_maximal_parkingtime(Configuration const *cfg,
|
||||
PERMIT_TYPE permitType,
|
||||
int paymentOptionIndex) {
|
||||
|
||||
// tariffs are only set if there is a Includes-section in the tariff-file,
|
||||
// which means the code below will be executed only in such a case.
|
||||
if (tariffs.count(permitType) > 0) {
|
||||
Configuration *c = tariffs[permitType].get();
|
||||
if (c && c != cfg) {
|
||||
cfg = c;
|
||||
}
|
||||
}
|
||||
|
||||
paymentOptionIndex = getPaymentOptionIndex(*cfg);
|
||||
if (paymentOptionIndex == -1) {
|
||||
paymentOptionIndex = cfg->getPaymentOptionIndex(permitType);
|
||||
@ -103,6 +129,15 @@ int CALCULATE_LIBRARY_API get_minimal_parkingprice(Configuration *cfg,
|
||||
QDateTime const &start) {
|
||||
int minPrice = -1;
|
||||
|
||||
// tariffs are only set if there is a Includes-section in the tariff-file,
|
||||
// which means the code below will be executed only in such a case.
|
||||
if (tariffs.count(permitType) > 0) {
|
||||
Configuration *c = tariffs[permitType].get();
|
||||
if (c && c != cfg) {
|
||||
cfg = c;
|
||||
}
|
||||
}
|
||||
|
||||
if ((paymentOptionIndex = getPaymentOptionIndex(*cfg, start)) == -1) {
|
||||
paymentOptionIndex = cfg->getPaymentOptionIndex(permitType);
|
||||
}
|
||||
@ -167,6 +202,14 @@ int CALCULATE_LIBRARY_API compute_product_price(Configuration const *cfg,
|
||||
QDateTime const &start,
|
||||
QDateTime *productStart,
|
||||
QDateTime *productEnd) {
|
||||
// tariffs are only set if there is a Includes-section in the tariff-file,
|
||||
// which means the code below will be executed only in such a case.
|
||||
if (tariffs.count(permitType) > 0) {
|
||||
Configuration *c = tariffs[permitType].get();
|
||||
if (c && c != cfg) {
|
||||
cfg = c;
|
||||
}
|
||||
}
|
||||
|
||||
switch(permitType) {
|
||||
case PERMIT_TYPE::SHORT_TERM_PARKING: { // e.g. szeged (customer_281)
|
||||
@ -330,6 +373,16 @@ int CALCULATE_LIBRARY_API get_maximal_parkingprice(Configuration *cfg,
|
||||
PERMIT_TYPE permitType,
|
||||
int paymentOptionIndex) {
|
||||
int maxPrice = -1;
|
||||
|
||||
// tariffs are only set if there is a Includes-section in the tariff-file,
|
||||
// which means the code below will be executed only in such a case.
|
||||
if (tariffs.count(permitType) > 0) {
|
||||
Configuration *c = tariffs[permitType].get();
|
||||
if (c && c != cfg) {
|
||||
cfg = c;
|
||||
}
|
||||
}
|
||||
|
||||
static const PaymentMethod paymentMethodId = Utilities::getPaymentMethodId(cfg);
|
||||
|
||||
if ((paymentOptionIndex = getPaymentOptionIndex(*cfg)) == -1) {
|
||||
@ -396,16 +449,14 @@ int CALCULATE_LIBRARY_API get_zone_nr(int zone)
|
||||
if(zone > -1) return zone;
|
||||
else
|
||||
{
|
||||
QFile zone("/etc/zone_nr");
|
||||
QFile zone("/mnt/system_data/zone_nr");
|
||||
if (zone.exists()) {
|
||||
QFileInfo finfo(zone);
|
||||
if (finfo.size() <= 4) { // decimal 000\n
|
||||
if (zone.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
||||
QTextStream in(&zone);
|
||||
return in.readLine(100).toInt();
|
||||
}
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
@ -466,6 +517,31 @@ CalcState CALCULATE_LIBRARY_API init_tariff(parking_tariff_t **tariff, char cons
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@ -695,6 +771,15 @@ CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket(
|
||||
start = start.toLocalTime().addSecs(start_parking_time * 60);
|
||||
QDateTime end(start);
|
||||
|
||||
// tariffs are only set if there is a Includes-section in the tariff-file,
|
||||
// which means the code below will be executed only in such a case.
|
||||
if (tariffs.count(permitType) > 0) {
|
||||
parking_tariff_t *t = tariffs[permitType].get();
|
||||
if (t && t != tariff) {
|
||||
tariff = t;
|
||||
}
|
||||
}
|
||||
|
||||
int paymentOptionIndex = getPaymentOptionIndex(*tariff, start);
|
||||
if (paymentOptionIndex == -1) {
|
||||
paymentOptionIndex = tariff->getPaymentOptionIndex(permitType.get());
|
||||
@ -770,6 +855,15 @@ CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket(
|
||||
|
||||
QDateTime start_parking_time(start_parking_time_);
|
||||
|
||||
// tariffs are only set if there is a Includes-section in the tariff-file,
|
||||
// which means the code below will be executed only in such a case.
|
||||
if (tariffs.count(permitType) > 0) {
|
||||
parking_tariff_t *t = tariffs[permitType].get();
|
||||
if (t && t != tariff) {
|
||||
tariff = t;
|
||||
}
|
||||
}
|
||||
|
||||
int paymentOptionIndex = getPaymentOptionIndex(*tariff, start_parking_time);
|
||||
if (paymentOptionIndex == -1) {
|
||||
paymentOptionIndex = tariff->getPaymentOptionIndex(permitType);
|
||||
@ -782,7 +876,7 @@ CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket(
|
||||
double maxMin = tariff->getPaymentOptions(paymentOptionIndex).pop_max_time;
|
||||
|
||||
// DEBUG
|
||||
qCritical() << "compute_price_for_parking_ticket() " << endl
|
||||
qCritical() << __func__ << ":" << __LINE__ << endl
|
||||
<< " paymentOptionIndex: " << paymentOptionIndex << endl
|
||||
<< " start_parking_time: " << start_parking_time << endl
|
||||
<< " netto_parking_time: " << netto_parking_time << endl
|
||||
@ -852,6 +946,8 @@ CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket(
|
||||
|
||||
|
||||
QDateTime effectiveStartTime(start_parking_time);
|
||||
qCritical() << __func__ << ":" << __LINE__ << "effectiveStartTime:"
|
||||
<< effectiveStartTime.toString(Qt::ISODate);
|
||||
|
||||
// handle special days
|
||||
int const specialDayId = tariff->specialDayId(start_parking_time);
|
||||
@ -882,6 +978,9 @@ CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket(
|
||||
}
|
||||
}
|
||||
|
||||
qCritical() << __func__ << ":" << __LINE__ << "effectiveStartTime:"
|
||||
<< effectiveStartTime.toString(Qt::ISODate);
|
||||
|
||||
// handle prepaid option
|
||||
int const prepaid_option_id = tariff->getPaymentOptions(paymentOptionIndex).pop_prepaid_option_id;
|
||||
std::optional<ATBPrepaid> prepaidOption = tariff->getPrepaidType(prepaid_option_id);
|
||||
@ -896,17 +995,36 @@ CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket(
|
||||
|
||||
if (start_parking_time.time() < p.prepaid[weekDay].static_end) { // static_end: e.g. 08:00:00
|
||||
effectiveStartTime.setTime(p.prepaid[weekDay].static_end);
|
||||
qCritical() << __func__ << ":" << __LINE__ << "effectiveStartTime:"
|
||||
<< effectiveStartTime.toString(Qt::ISODate);
|
||||
} else
|
||||
if (start_parking_time.time() > p.prepaid[weekDay].static_start) { // static_start: e.g. 22:00:00
|
||||
effectiveStartTime.setTime(p.prepaid[weekDay].static_start);
|
||||
QTime const midnight(23, 59, 59);
|
||||
QTime const midnight24(0, 0, 0);
|
||||
|
||||
if ((p.prepaid[weekDay].static_start <= midnight && midnight24 <= p.prepaid[weekDay].static_end)
|
||||
|| (p.prepaid[weekDay].static_start == midnight && midnight == p.prepaid[weekDay].static_end)
|
||||
|| (p.prepaid[weekDay].static_start == midnight24 && midnight24 == p.prepaid[weekDay].static_end)) {
|
||||
effectiveStartTime = effectiveStartTime.addDays(1);
|
||||
weekDay = effectiveStartTime.date().dayOfWeek();
|
||||
qCritical() << __func__ << ":" << __LINE__
|
||||
<< "effectiveStartTime: new week day [" << weekDay << "] (Mon=1, Tue=2, ..., Sun=7)";
|
||||
}
|
||||
effectiveStartTime.setTime(p.prepaid[weekDay].static_end);
|
||||
qCritical() << __func__ << ":" << __LINE__ << "effectiveStartTime:"
|
||||
<< effectiveStartTime.toString(Qt::ISODate);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
qCritical() << __func__ << ":" << __LINE__ << "no prepaid option set";
|
||||
}
|
||||
|
||||
// set seconds to 0
|
||||
effectiveStartTime.setTime(QTime(effectiveStartTime.time().hour(),
|
||||
effectiveStartTime.time().minute(), 0));
|
||||
|
||||
qCritical() << __func__ << ":" << __LINE__ << "effectiveStartTime:" << effectiveStartTime.toString(Qt::ISODate);
|
||||
qCritical() << __func__ << ":" << __LINE__ << "effectiveStartTime:"
|
||||
<< effectiveStartTime.toString(Qt::ISODate);
|
||||
|
||||
int const carryOver = tariff->getPaymentOptions(paymentOptionIndex).pop_carry_over;
|
||||
|
||||
@ -914,10 +1032,12 @@ CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket(
|
||||
|
||||
if (carryOver == 1) {
|
||||
QTime carryOverStart = tariff->TariffCarryOverOptions.find(pop_carry_over_option_id)->second.carryover[weekDay].static_start;
|
||||
QTime carryOverEnd = tariff->TariffCarryOverOptions.find(pop_carry_over_option_id)->second.carryover[weekDay].static_end;
|
||||
int carryOverDuration = tariff->TariffCarryOverOptions.find(pop_carry_over_option_id)->second.carryover[weekDay].duration;
|
||||
|
||||
qCritical() << __func__ << ":" << __LINE__ << " carryOverStart" << carryOverStart.toString(Qt::ISODate);
|
||||
qCritical() << __func__ << ":" << __LINE__ << "carryOverDuration" << carryOverDuration;
|
||||
qCritical() << __func__ << ":" << __LINE__ << " carryOverStart:" << carryOverStart.toString(Qt::ISODate);
|
||||
qCritical() << __func__ << ":" << __LINE__ << " carryOverEnd:" << carryOverEnd.toString(Qt::ISODate);
|
||||
qCritical() << __func__ << ":" << __LINE__ << "carryOverDuration:" << carryOverDuration;
|
||||
|
||||
// handle carry over
|
||||
int minutesUntilCarryOver = effectiveStartTime.time().secsTo(carryOverStart) / 60;
|
||||
@ -927,11 +1047,11 @@ CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket(
|
||||
s = s.addSecs(minutesUntilCarryOver * 60);
|
||||
s = s.addSecs(carryOverDuration * 60);
|
||||
end_parking_time = s.addSecs(rest * 60);
|
||||
qCritical() << __func__ << ":" << __LINE__ << "end-parking-time:" << end_parking_time.toString(Qt::ISODate);
|
||||
} else {
|
||||
end_parking_time = effectiveStartTime.addSecs(netto_parking_time*60);
|
||||
}
|
||||
|
||||
qCritical() << __func__ << ":" << __LINE__ << "end-parking-time:" << end_parking_time.toString(Qt::ISODate);
|
||||
}
|
||||
|
||||
weekDay = end_parking_time.date().dayOfWeek();
|
||||
|
||||
@ -943,12 +1063,21 @@ CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket(
|
||||
end_parking_time = end_parking_time.addSecs(carryOverDuration * 60);
|
||||
} else
|
||||
if (end_parking_time.time() == carryOverStart) {
|
||||
qCritical() << __func__ << ":" << __LINE__ << "end-parking-time:" << end_parking_time.toString(Qt::ISODate);
|
||||
qCritical() << __func__ << ":" << __LINE__ << " carryOverStart" << carryOverStart.toString(Qt::ISODate);
|
||||
qCritical() << __func__ << ":" << __LINE__ << " end-parking-time:" << end_parking_time.toString(Qt::ISODate);
|
||||
qCritical() << __func__ << ":" << __LINE__ << " carryOverStart:" << carryOverStart.toString(Qt::ISODate);
|
||||
ATBPaymentOption const &po = tariff->getPaymentOptions(paymentOptionIndex);
|
||||
if (po.pop_apply_carry_over_to_ticket_endtime) {
|
||||
end_parking_time = end_parking_time.addSecs(carryOverDuration * 60);
|
||||
qCritical() << __func__ << ":" << __LINE__ << "end-parking-time:" << end_parking_time.toString(Qt::ISODate);
|
||||
qCritical() << __func__ << ":" << __LINE__ << "adapted end-parking-time:" << end_parking_time.toString(Qt::ISODate);
|
||||
}
|
||||
} else
|
||||
if (end_parking_time.time() == carryOverEnd) {
|
||||
qCritical() << __func__ << ":" << __LINE__ << " end-parking-time:" << end_parking_time.toString(Qt::ISODate);
|
||||
qCritical() << __func__ << ":" << __LINE__ << " carryOverEnd:" << carryOverEnd.toString(Qt::ISODate);
|
||||
ATBPaymentOption const &po = tariff->getPaymentOptions(paymentOptionIndex);
|
||||
if (po.pop_apply_carry_over_to_ticket_endtime == false) {
|
||||
end_parking_time = end_parking_time.addSecs(-carryOverDuration * 60);
|
||||
qCritical() << __func__ << ":" << __LINE__ << "adapted end-parking-time:" << end_parking_time.toString(Qt::ISODate);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@ -1037,6 +1166,15 @@ CalcState CALCULATE_LIBRARY_API compute_duration_for_parking_ticket(
|
||||
QString &duration,
|
||||
PermitType permitType) {
|
||||
|
||||
// tariffs are only set if there is a Includes-section in the tariff-file,
|
||||
// which means the code below will be executed only in such a case.
|
||||
if (tariffs.count(permitType) > 0) {
|
||||
parking_tariff_t *t = tariffs[permitType].get();
|
||||
if (t && t != tariff) {
|
||||
tariff = t;
|
||||
}
|
||||
}
|
||||
|
||||
tariff->getPaymentOptions(0).pop_max_price
|
||||
= tariff->getPaymentOptions(0).pop_max_price_save;
|
||||
|
||||
@ -1095,6 +1233,15 @@ CalcState CALCULATE_LIBRARY_API compute_duration_for_parking_ticket(
|
||||
QDateTime &ticketEndTime,
|
||||
PermitType permitType)
|
||||
{
|
||||
// tariffs are only set if there is a Includes-section in the tariff-file,
|
||||
// which means the code below will be executed only in such a case.
|
||||
if (tariffs.count(permitType) > 0) {
|
||||
parking_tariff_t *t = tariffs[permitType].get();
|
||||
if (t && t != tariff) {
|
||||
tariff = t;
|
||||
}
|
||||
}
|
||||
|
||||
tariff->getPaymentOptions(0).pop_max_price
|
||||
= tariff->getPaymentOptions(0).pop_max_price_save;
|
||||
|
||||
@ -1102,8 +1249,15 @@ CalcState CALCULATE_LIBRARY_API compute_duration_for_parking_ticket(
|
||||
|
||||
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);
|
||||
|
||||
qCritical() << __func__ << ":" << __LINE__ << "payment option index: " << paymentOptionIndex;
|
||||
|
||||
|
||||
if (paymentOptionIndex == -1) {
|
||||
paymentOptionIndex = tariff->getPaymentOptionIndex(permitType);
|
||||
}
|
||||
@ -1423,8 +1577,17 @@ CalcState CALCULATE_LIBRARY_API compute_duration_for_parking_ticket(
|
||||
CalcState CALCULATE_LIBRARY_API compute_duration_for_daily_ticket(parking_tariff_t *tariff,
|
||||
QDateTime const &start_parking_time,
|
||||
QDateTime &ticketEndTime,
|
||||
PermitType /* PermitType */)
|
||||
PermitType permitType)
|
||||
{
|
||||
// tariffs are only set if there is a Includes-section in the tariff-file,
|
||||
// which means the code below will be executed only in such a case.
|
||||
if (tariffs.count(permitType) > 0) {
|
||||
parking_tariff_t *t = tariffs[permitType].get();
|
||||
if (t && t != tariff) {
|
||||
tariff = t;
|
||||
}
|
||||
}
|
||||
|
||||
tariff->getPaymentOptions(0).pop_max_price
|
||||
= tariff->getPaymentOptions(0).pop_max_price_save;
|
||||
|
||||
@ -1460,6 +1623,15 @@ CalcState CALCULATE_LIBRARY_API compute_price_for_daily_ticket(
|
||||
PERMIT_TYPE permitType,
|
||||
struct price_t *price) {// return value
|
||||
|
||||
// tariffs are only set if there is a Includes-section in the tariff-file,
|
||||
// which means the code below will be executed only in such a case.
|
||||
if (tariffs.count(permitType) > 0) {
|
||||
parking_tariff_t *t = tariffs[permitType].get();
|
||||
if (t && t != tariff) {
|
||||
tariff = t;
|
||||
}
|
||||
}
|
||||
|
||||
tariff->getPaymentOptions(0).pop_max_price
|
||||
= tariff->getPaymentOptions(0).pop_max_price_save;
|
||||
|
||||
|
@ -379,7 +379,8 @@ Calculator::ComputeDurationFromCost(Configuration *cfg,
|
||||
|
||||
int const pop_id = cfg->getPaymentOptions(paymentOptionIndex).pop_id;
|
||||
int const pop_accumulate_prices = cfg->getPaymentOptions(paymentOptionIndex).pop_accumulate_prices;
|
||||
int const pop_max_price = cfg->getPaymentOptions(paymentOptionIndex).pop_max_price;
|
||||
int const pop_max_price = cfg->getPaymentOptions(paymentOptionIndex).pop_max_price =
|
||||
cfg->getPaymentOptions(paymentOptionIndex).pop_max_price_save;
|
||||
int const pop_max_time = cfg->getPaymentOptions(paymentOptionIndex).pop_max_time;
|
||||
int const pop_min_price = cfg->getPaymentOptions(paymentOptionIndex).pop_min_price;
|
||||
int const pop_allow_overpay = cfg->getPaymentOptions(paymentOptionIndex).pop_allow_overpay;
|
||||
@ -452,13 +453,50 @@ Calculator::ComputeDurationFromCost(Configuration *cfg,
|
||||
netto_parking_time_in_minutes = 0;
|
||||
brutto_parking_time_in_minutes = 0;
|
||||
free_parking_time_in_minutes = 0;
|
||||
int nettoParktimeForCost = 0;
|
||||
|
||||
int const nettoParktimeForCost = priceNettoParktime[int(cost)];
|
||||
if (priceNettoParktime.contains(int(cost))) {
|
||||
nettoParktimeForCost = priceNettoParktime[int(cost)];
|
||||
qCritical() << __func__ << ":" << __LINE__ << QString("cost=%1 nettoParkTimeForCost=%2").
|
||||
arg(cost).arg(nettoParktimeForCost);
|
||||
} else {
|
||||
|
||||
// cannot find netto-parking time for cost (=price)
|
||||
// this happens for direct coin input and should not happen otherwise
|
||||
// take the value for the nearest value of cost and mark result as overpaid
|
||||
|
||||
QList <int> keys = priceNettoParktime.keys(); // keys (=prices) are sorted in ascending order
|
||||
QSet<int> s; // make keys unique
|
||||
for (int k = 0; k < keys.size(); ++k) {
|
||||
if (keys[k] < cost) {
|
||||
s << keys[k];
|
||||
}
|
||||
}
|
||||
keys = s.values();
|
||||
// sort in descending order
|
||||
std::sort(std::begin(keys), std::end(keys), std::greater<>());
|
||||
// qCritical() << __func__ << ":" << __LINE__ << "keys=" << keys;
|
||||
if (!keys.isEmpty()) {
|
||||
int const maxCost = keys[0];
|
||||
auto const p = priceNettoParktime.equal_range(maxCost);
|
||||
for (auto it = p.first; it != p.second; ++it) {
|
||||
nettoParktimeForCost = std::max(nettoParktimeForCost, it.value());
|
||||
}
|
||||
ATBPaymentOption &po = cfg->getPaymentOptions(paymentOptionIndex);
|
||||
po.pop_max_price = maxCost;
|
||||
cfg->getPaymentOptions(paymentOptionIndex).pop_max_price = maxCost;
|
||||
if (pop_allow_overpay) {
|
||||
overPaid = true;
|
||||
}
|
||||
qCritical() << __func__ << ":" << __LINE__ << QString("cost=%1 -> maxCost=%2 nettoParkTimeForCost=%3").
|
||||
arg(cost).arg(maxCost).arg(nettoParktimeForCost);
|
||||
} else {
|
||||
qCritical() << __func__ << ":" << __LINE__ << "ERROR empty keys -> check tariff file";
|
||||
}
|
||||
}
|
||||
|
||||
int cnt = 0;
|
||||
while (++cnt < 1000 && netto_parking_time_in_minutes < nettoParktimeForCost) {
|
||||
while (++cnt < 20 && netto_parking_time_in_minutes < nettoParktimeForCost) {
|
||||
// qCritical() << __func__ << ":" << __LINE__ << "cnt [" << cnt;
|
||||
|
||||
brutto_parking_time_in_minutes = free_parking_time_in_minutes + netto_parking_time_in_minutes;
|
||||
@ -555,8 +593,9 @@ Calculator::ComputeDurationFromCost(Configuration *cfg,
|
||||
.arg(free_parking_time_in_minutes);
|
||||
|
||||
if (std::optional<ATBTariffCarryOver> co = getCarryOver(cfg, dt)) {
|
||||
TimeRange const &carryOverTimeRange = co.value().m_range;
|
||||
free_parking_time_in_minutes += carryOverTimeRange.m_duration;
|
||||
int minutes = co.value().computeMinutesUntilCarryOverEnd(dt);
|
||||
if (minutes > 0) {
|
||||
free_parking_time_in_minutes += minutes;
|
||||
|
||||
brutto_parking_time_in_minutes = free_parking_time_in_minutes + netto_parking_time_in_minutes;
|
||||
dt = inputDate.addSecs(brutto_parking_time_in_minutes * 60);
|
||||
@ -569,6 +608,7 @@ Calculator::ComputeDurationFromCost(Configuration *cfg,
|
||||
.arg(netto_parking_time_in_minutes)
|
||||
.arg(free_parking_time_in_minutes);
|
||||
}
|
||||
}
|
||||
|
||||
if (std::optional<ATBTariffService> serv = getService(cfg, dt)) {
|
||||
TimeRange const &serviceTimeRange = serv.value().m_range;
|
||||
@ -577,6 +617,8 @@ Calculator::ComputeDurationFromCost(Configuration *cfg,
|
||||
int rest_parking_time_in_minutes = nettoParktimeForCost - netto_parking_time_in_minutes;
|
||||
ATBTime t(dt.time().hour(), dt.time().minute(), 0, 0);
|
||||
int timeToServiceEnd = t.secsTo(serviceTimeRange.m_end.toString(Qt::ISODate)) / 60;
|
||||
|
||||
// TODO: wohl aehnlich wie carry-over zu behandlen
|
||||
if (serviceTimeRange.m_duration > 0) {
|
||||
if (timeToServiceEnd < rest_parking_time_in_minutes) {
|
||||
netto_parking_time_in_minutes += timeToServiceEnd;
|
||||
@ -601,20 +643,41 @@ Calculator::ComputeDurationFromCost(Configuration *cfg,
|
||||
// qCritical() << __func__ << ":" << __LINE__ << "cnt" << cnt << "]";
|
||||
}
|
||||
|
||||
if (cnt >= 1000) {
|
||||
if (cnt >= 10) {
|
||||
qCritical() << __func__ << ":" << __LINE__ << "BREAK";
|
||||
}
|
||||
|
||||
// configure if last carry-over ranges shall be added to ticket-end-time
|
||||
dt = inputDate.addSecs(brutto_parking_time_in_minutes * 60);
|
||||
|
||||
cnt = 0;
|
||||
while (std::optional<ATBTariffCarryOver> co = getCarryOver(cfg, inputDate.addSecs(brutto_parking_time_in_minutes * 60))) {
|
||||
if (++cnt > 5) {
|
||||
qCritical() << __func__ << ":" << __LINE__ << "BREAK";
|
||||
QVector<TimeRange> timeRanges;
|
||||
while (std::optional<ATBTariffCarryOver> co = getCarryOver(cfg, dt)) {
|
||||
if (++cnt > 10) {
|
||||
break;
|
||||
}
|
||||
TimeRange const &carryOverTimeRange = co.value().m_range;
|
||||
free_parking_time_in_minutes += carryOverTimeRange.m_duration;
|
||||
if (!timeRanges.isEmpty()) {
|
||||
if (timeRanges.last().m_end != carryOverTimeRange.m_start) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
timeRanges.push_back(carryOverTimeRange);
|
||||
|
||||
int minutes = co.value().computeMinutesUntilCarryOverEnd(dt);
|
||||
if (minutes > 0) {
|
||||
free_parking_time_in_minutes += co.value().computeMinutesUntilCarryOverEnd(dt);
|
||||
brutto_parking_time_in_minutes = free_parking_time_in_minutes + netto_parking_time_in_minutes;
|
||||
|
||||
qCritical() << __func__ << ":" << __LINE__ << QString("%1 (%2): brutto: %3 = netto: %4 + free: %5")
|
||||
.arg(dt.toString(Qt::ISODate))
|
||||
.arg(weekDay)
|
||||
.arg(brutto_parking_time_in_minutes)
|
||||
.arg(netto_parking_time_in_minutes)
|
||||
.arg(free_parking_time_in_minutes);
|
||||
|
||||
dt = inputDate.addSecs(brutto_parking_time_in_minutes * 60);
|
||||
} else break;
|
||||
}
|
||||
|
||||
brutto_parking_time_in_minutes = free_parking_time_in_minutes + netto_parking_time_in_minutes;
|
||||
@ -887,7 +950,8 @@ Calculator::GetDurationFromCost(Configuration* cfg,
|
||||
}
|
||||
|
||||
int const pop_id = cfg->getPaymentOptions(paymentOptionIndex).pop_id;
|
||||
int const pop_max_price = cfg->getPaymentOptions(paymentOptionIndex).pop_max_price;
|
||||
int const pop_max_price = cfg->getPaymentOptions(paymentOptionIndex).pop_max_price
|
||||
= cfg->getPaymentOptions(paymentOptionIndex).pop_max_price_save;
|
||||
//int const pop_max_time = cfg->getPaymentOptions(paymentOptionIndex).pop_max_time;
|
||||
int const pop_min_price = cfg->getPaymentOptions(paymentOptionIndex).pop_min_price;
|
||||
int const pop_allow_overpay = cfg->getPaymentOptions(paymentOptionIndex).pop_allow_overpay;
|
||||
@ -3559,7 +3623,9 @@ uint32_t Calculator::GetPriceForTimeStep(Configuration *cfg, int timeStep, int p
|
||||
qCritical() << "(" << __func__ << ":" << __LINE__ << ") timeStep" << timeStep;
|
||||
}
|
||||
|
||||
if (timeStep == pun_duration) {
|
||||
// allow some tolerance when searching for [timeStep == pun_duration]:
|
||||
// this might happen when crossing minute boundaries
|
||||
if (std::abs(timeStep - pun_duration) < 4) {
|
||||
qCritical() << "(" << __func__ << ":" << __LINE__ << ") return price" << price;
|
||||
return price;
|
||||
}
|
||||
@ -3630,6 +3696,9 @@ Calculator::GetDailyTicketPrice(Configuration* cfg,
|
||||
if (dailyTickets) {
|
||||
QVector<ATBDailyTicket> const tickets = dailyTickets.value();
|
||||
switch (permitType) {
|
||||
case PERMIT_TYPE::FREE_TICKET: {
|
||||
// TODO
|
||||
} break;
|
||||
case PERMIT_TYPE::TWENTY_FOUR_HOURS_TICKET: {
|
||||
// TODO
|
||||
} 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, "Prepaid") == 0) return MemberType::PrepaidType;
|
||||
if (strcmp(member_name, "CarryOver") == 0) return MemberType::CarryOverType;
|
||||
if (strcmp(member_name, "Includes") == 0) return MemberType::IncludesType;
|
||||
else return MemberType::UnknownType;
|
||||
}
|
||||
|
||||
@ -171,8 +172,9 @@ ATBWeekDay parseWeekDay(Configuration &cfg,
|
||||
if (!d.isNull() && d.isValid()) {
|
||||
TariffPrepaid.m_date = d;
|
||||
}
|
||||
if (!prepaidIf.isNull() && !prepaidIf.trimmed().isEmpty()) {
|
||||
TariffPrepaid.setPrepaidIf(prepaidIf);
|
||||
|
||||
}
|
||||
qCritical() << TariffPrepaid;
|
||||
|
||||
cfg.TariffPrepaids.insert(std::pair<int, ATBTariffPrepaid>(weekDay, TariffPrepaid));
|
||||
@ -258,7 +260,7 @@ ATBWeekDay parseWeekDay(Configuration &cfg,
|
||||
if (!d.isNull() && d.isValid()) {
|
||||
TariffCarryOver.m_date = d;
|
||||
}
|
||||
if (!carryOverIf.isEmpty()) {
|
||||
if (!carryOverIf.isNull() && !carryOverIf.trimmed().isEmpty()) {
|
||||
TariffCarryOver.setCarryOverIf(carryOverIf);
|
||||
}
|
||||
|
||||
@ -810,6 +812,7 @@ bool Configuration::ParseJson(Configuration* cfg, const char* json)
|
||||
ATBInterpolation TariffInterpolation;
|
||||
ATBPrepaid TariffPrepaidOption;
|
||||
ATBCarryOver TariffCarryOver;
|
||||
QStringList TariffIncludes;
|
||||
|
||||
MemberType mb_type = MemberType::UnknownType;
|
||||
this->currentPaymentOptions.clear();
|
||||
@ -1341,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_active") == 0) Currency.pcu_active = k->value.GetBool();
|
||||
break;
|
||||
case MemberType::IncludesType:
|
||||
TariffIncludes << k->value.GetString();
|
||||
break;
|
||||
case MemberType::PaymentMethodType:
|
||||
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();
|
||||
@ -1630,6 +1636,9 @@ bool Configuration::ParseJson(Configuration* cfg, const char* json)
|
||||
cfg->TariffCarryOverOptions.insert(pair<int, ATBCarryOver>(TariffCarryOver.id, TariffCarryOver));
|
||||
// qCritical() << TariffCarryOver;
|
||||
break;
|
||||
case MemberType::IncludesType:
|
||||
cfg->TariffIncludes = TariffIncludes;
|
||||
// qCritical() << "TariffIncludes" << cfg->TariffIncludes;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
156
main/main.cpp
156
main/main.cpp
@ -39,11 +39,11 @@ extern "C" char* strptime(const char* s,
|
||||
|
||||
#define SZEGED (0)
|
||||
#define SCHOENAU_KOENIGSEE (0)
|
||||
#define NEUHAUSER_KORNEUBURG (0)
|
||||
#define NEUHAUSER_KORNEUBURG (1)
|
||||
#define NEUHAUSER_LINSINGER_MASCHINENBAU (0)
|
||||
#define NEUHAUSER_NORDISCHES_AUSBILDUNGSZENTRUM (0)
|
||||
#define NEUHAUSER_BILEXA_GALTUER (0)
|
||||
#define BAD_NEUENAHR_AHRWEILER (1)
|
||||
#define BAD_NEUENAHR_AHRWEILER (0)
|
||||
#define NEUHAUSER_CHRISTOPH_REISEN (0)
|
||||
#define NEUHAUSER_PERNEGG_AN_DER_MUR (0)
|
||||
#define NEUHAUSER_STOCKERAU (0)
|
||||
@ -52,6 +52,7 @@ extern "C" char* strptime(const char* s,
|
||||
#define SCHNALS_LEITER_KIRCHL (0)
|
||||
#define SCHNALS_STAUMAUER (SCHNALS_LEITER_KIRCHL)
|
||||
#define VALSER_ALM (0)
|
||||
#define NEUHAUSER_FORCHACH (0)
|
||||
|
||||
#if NEUHAUSER_KIRCHDORF==1
|
||||
static bool test_neuhauser_kirchdorf(int step, double cost) {
|
||||
@ -210,21 +211,73 @@ static bool test_neuhauser_kirchdorf(int step, double cost) {
|
||||
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() {
|
||||
|
||||
|
||||
qCritical() << getCalculatorLibVersion();
|
||||
isProductSupportedInCalculatorLib("FREE_TICKET");
|
||||
return 0;
|
||||
//487 {
|
||||
// 488 "pra_payment_option_id": 1049,
|
||||
// 489 "pra_payment_unit_id": 84,
|
||||
// 490 "pra_price":"840"
|
||||
//>>491 }
|
||||
|
||||
//for (int i = 1; i < 85; ++i) {
|
||||
//printf("{\n \"\pra_payment_option_id\": 1049,\n \"\pra_payment_unit_id\": %d,\n \"pra_price\": %d\n},\n",
|
||||
// i, i*10);
|
||||
//for (int i = 1; i < 346; ++i) {
|
||||
//printf("{\n \"pun_id\": %i,\n \"pun_duration\": %d\n},\n",
|
||||
// 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
|
||||
MessageHelper msgHelp;
|
||||
// msgHelp.createLoginMessageChunksToSend(0x02);
|
||||
@ -1386,6 +1439,29 @@ int main() {
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
#if NEUHAUSER_FORCHACH==1
|
||||
std::ifstream input;
|
||||
input.open("/opt/ptu5/opt/customer_749/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) {
|
||||
compute_product_price(&cfg, PermitType(PERMIT_TYPE::DAY_TICKET_PKW));
|
||||
compute_product_price(&cfg, PermitType(PERMIT_TYPE::DAY_TICKET_CAMPER));
|
||||
|
||||
QDateTime start = QDateTime::currentDateTime();
|
||||
QDateTime ticketEndTime;
|
||||
compute_duration_for_daily_ticket(&cfg, start, ticketEndTime, PermitType(PERMIT_TYPE::DAY_TICKET));
|
||||
}
|
||||
|
||||
#endif
|
||||
#if BAD_NEUENAHR_AHRWEILER==1
|
||||
std::ifstream input;
|
||||
@ -2780,24 +2856,62 @@ int main() {
|
||||
bool nextDay = false;
|
||||
bool prePaid = true;
|
||||
// zone 1 (lila)
|
||||
QDateTime s(QDate(2023, 11, 30), QTime());
|
||||
QDateTime s(QDate(2024, 10, 8), QTime());
|
||||
QDateTime end;
|
||||
|
||||
static QList<int> const timeSteps = Calculator::GetInstance().GetTimeSteps(&cfg);
|
||||
qCritical() << "TimeSteps" << timeSteps;
|
||||
|
||||
for (int duration = 30; duration <= pop_max_time; duration += 5) {
|
||||
for (int offset = 420; offset < 1140; ++offset) {
|
||||
if (offset > 720 && offset < 840) {
|
||||
continue;
|
||||
}
|
||||
int offset = 600;
|
||||
//for (int offset = 720; offset < 601; ++offset) {
|
||||
//if (offset > 720 && offset < 840) {
|
||||
// continue;
|
||||
//}
|
||||
QDateTime start = s.addSecs(offset * 60);
|
||||
//qCritical() << "start" << start.toString(Qt::ISODate);
|
||||
|
||||
double cost = Calculator::GetInstance().GetCostFromDuration(&cfg, 3, start, end, duration, nextDay, prePaid);
|
||||
CalcState cs;
|
||||
#if 1
|
||||
struct price_t costs;
|
||||
for (int i = 0, j=timeSteps.size() ; i < timeSteps.size(); --j, ++i) {
|
||||
QDateTime end = start.addSecs(timeSteps.at(i)*60);
|
||||
|
||||
// if (i != 2) continue;
|
||||
|
||||
cs = compute_price_for_parking_ticket(&cfg, start, timeSteps.at(i), end, &costs, PermitType(PERMIT_TYPE::SHORT_TERM_PARKING));
|
||||
int price1 = costs.netto;
|
||||
|
||||
qCritical() << "compute_price_for_parking_ticket()/GetCostFromDuration() TIME: "
|
||||
<< timeSteps.at(i) << "ZZZZZZZZZZZZZ PRICE=" << price1 << "end=" << end.toString(Qt::ISODate);
|
||||
}
|
||||
exit(0);
|
||||
#else
|
||||
|
||||
double cost = 360;
|
||||
qCritical() << "XXXXXXXX START" << start.toString(Qt::ISODate) << "cost" << cost;
|
||||
QDateTime end;
|
||||
|
||||
cs = compute_duration_for_parking_ticket(&cfg, start, cost, end,
|
||||
PermitType(PERMIT_TYPE::SHORT_TERM_PARKING));
|
||||
qCritical() << __LINE__ << cs.toString()
|
||||
<< "START" << start.toString(Qt::ISODate)
|
||||
<< "<duration" << start.secsTo(end) / 60
|
||||
<< "cost" << cost
|
||||
<< "> end" << end.toString(Qt::ISODate);
|
||||
//}
|
||||
|
||||
exit(0);
|
||||
#endif
|
||||
|
||||
//double cost = Calculator::GetInstance().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;
|
||||
|
||||
//qCritical() << "start" << start.toString(Qt::ISODate)
|
||||
// << "end" << end.toString(Qt::ISODate)
|
||||
// << "duration" << duration
|
||||
// << "cost" << cost;
|
||||
#if 0
|
||||
switch(duration) {
|
||||
case 30:
|
||||
if (cost == 60.0) {
|
||||
@ -2961,15 +3075,17 @@ int main() {
|
||||
<< "cost" << cost;
|
||||
exit(-1);
|
||||
}
|
||||
#endif
|
||||
|
||||
//std::string duration = Calculator::GetInstance().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;
|
||||
}
|
||||
//}
|
||||
}
|
||||
|
||||
#if 0
|
||||
Configuration::SpecialDaysType specialDays = cfg.SpecialDays;
|
||||
for (Configuration::SpecialDaysType::const_iterator it = specialDays.cbegin();
|
||||
it != specialDays.cend(); ++it) {
|
||||
@ -2990,7 +3106,7 @@ int main() {
|
||||
<< "duration" << duration
|
||||
<< "cost" << cost;
|
||||
}
|
||||
|
||||
#endif
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
|
@ -1,3 +1,5 @@
|
||||
QT += core
|
||||
|
||||
TEMPLATE = app
|
||||
TARGET = main
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user