Compare commits
3 Commits
praesentat
...
remotes/or
Author | SHA1 | Date | |
---|---|---|---|
49f016cc98 | |||
41a09d882d | |||
5cfca87f3e |
@@ -277,12 +277,6 @@ CalcState CALCULATE_LIBRARY_API init_tariff(parking_tariff_t **tariff,
|
||||
void CALCULATE_LIBRARY_API free_tariff(parking_tariff_t *tariff);
|
||||
int CALCULATE_LIBRARY_API get_zone_nr(int zone = -1);
|
||||
|
||||
|
||||
int CALCULATE_LIBRARY_API isOutOfService(Configuration const *cfg,
|
||||
QDateTime const &dt);
|
||||
|
||||
int CALCULATE_LIBRARY_API isOutOfService(QDateTime const &dt);
|
||||
|
||||
int CALCULATE_LIBRARY_API compute_next_timestep(parking_tariff_t *tariff, int currentTimeMinutes,
|
||||
int UpDown, PermitType const &permitType);
|
||||
|
||||
|
@@ -34,8 +34,6 @@
|
||||
|
||||
#include <QVector>
|
||||
#include <optional>
|
||||
#include <QList>
|
||||
#include <QPair>
|
||||
|
||||
using namespace std;
|
||||
using namespace rapidjson;
|
||||
@@ -85,11 +83,6 @@ public:
|
||||
TariffOutOfServiceType TariffOutOfServices;
|
||||
ATBTariffPrepaidType TariffPrepaids;
|
||||
ATBTariffCarryOverType TariffCarryOvers;
|
||||
QList<QPair<QString, QString>> TariffIncludes;
|
||||
|
||||
QTime ValidFrom;
|
||||
int ValidForWeekDay{};
|
||||
QStringList tariffFileName{};
|
||||
|
||||
/// <summary>
|
||||
/// Parse JSON string
|
||||
@@ -130,9 +123,6 @@ public:
|
||||
std::optional<ATBWeekDaysWorktime> getWeekDayWorkTime(QTime const &time, Qt::DayOfWeek dayOfWeek);
|
||||
std::optional<QVector<ATBWeekDaysWorktime>> getAllWeekDayWorkTimes();
|
||||
|
||||
QList<QPair<QString, QString>> const &getTariffIncludes() const { return TariffIncludes; }
|
||||
QList<QPair<QString, QString>> &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,8 +22,7 @@ enum MemberType
|
||||
ProductType = 0x0F,
|
||||
InterpolationType = 0x10,
|
||||
PrepaidType = 0x11,
|
||||
CarryOverType = 0x12,
|
||||
IncludesType = 0x13
|
||||
CarryOverType = 0x12
|
||||
};
|
||||
|
||||
#endif // MEMBER_TYPE_H_INCLUDED
|
||||
|
@@ -37,7 +37,7 @@ struct ATBTariffCarryOver {
|
||||
if (coif == "always") {
|
||||
m_carryOverIf = ApplyCarryOver::ALWAYS;
|
||||
} else {
|
||||
qCritical() << __func__ << ":" << __LINE__ << "ERROR unknown carry over application" << coif;
|
||||
qCritical() << "ERROR unknown carry over application" << coif;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -65,22 +65,13 @@ struct ATBTariffCarryOver {
|
||||
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());
|
||||
}
|
||||
QDateTime t = dt.addDays(1);
|
||||
t.setTime(QTime(0,0,0));
|
||||
minutes = dt.secsTo(t) / 60;
|
||||
} 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());
|
||||
}
|
||||
QDateTime t(dt);
|
||||
t.setTime(QTime::fromString(end, Qt::ISODate));
|
||||
minutes = dt.secsTo(t) / 60;
|
||||
}
|
||||
|
||||
if (minutes < 0 || minutes > m_range.m_duration) {
|
||||
|
20
library/include/mobilisis/tariff_comp_state.h
Normal file
20
library/include/mobilisis/tariff_comp_state.h
Normal file
@@ -0,0 +1,20 @@
|
||||
#ifndef TARIFF_COMP_STATE_H_INCLUDED
|
||||
#define TARIFF_COMP_STATE_H_INCLUDED
|
||||
|
||||
#include <QDateTime>
|
||||
|
||||
struct TariffCompState {
|
||||
QDateTime const m_start;
|
||||
int m_nettoParkingTimeTotal = 0;
|
||||
int m_bruttoParkingTimeTotal = 0;
|
||||
int m_priceTotal = 0;
|
||||
|
||||
explicit TariffCompState(QDateTime start)
|
||||
: m_start(std::move(start))
|
||||
, m_nettoParkingTimeTotal(0)
|
||||
, m_bruttoParkingTimeTotal(0)
|
||||
, m_priceTotal(0) {
|
||||
}
|
||||
};
|
||||
|
||||
#endif // TARIFF_COMP_STATE_H_INCLUDED
|
29
library/include/mobilisis/tariff_comp_step.h
Normal file
29
library/include/mobilisis/tariff_comp_step.h
Normal file
@@ -0,0 +1,29 @@
|
||||
#ifndef TARIFF_COMP_STEP_H_INCLUDED
|
||||
#define TARIFF_COMP_STEP_H_INCLUDED
|
||||
|
||||
#include <QDateTime>
|
||||
#include "tariff_comp_state.h"
|
||||
|
||||
class TariffCompStep {
|
||||
int m_duration;
|
||||
QDateTime const m_start;
|
||||
QDateTime const m_end;
|
||||
uint64_t const m_handle;
|
||||
TariffCompState m_compState;
|
||||
|
||||
uint64_t hash();
|
||||
|
||||
public:
|
||||
explicit TariffCompStep(int duration, QDateTime start, QDateTime end, TariffCompState &compState)
|
||||
: m_duration(duration)
|
||||
, m_start(std::move(start))
|
||||
, m_end(std::move(end))
|
||||
, m_handle(hash())
|
||||
, m_compState(compState) {
|
||||
}
|
||||
|
||||
uint64_t handle() { return m_handle; }
|
||||
uint64_t handle() const { return m_handle; }
|
||||
};
|
||||
|
||||
#endif // TARIFF_COMP_STEP_H_INCLUDED
|
@@ -19,12 +19,7 @@ enum class PERMIT_TYPE : quint8 {
|
||||
SHORT_TERM_PARKING_CAMPER=12,
|
||||
DAY_TICKET_PKW=13,
|
||||
DAY_TICKET_BUS=14,
|
||||
DAY_TICKET_CAMPER=15,
|
||||
FREE_TICKET=16,
|
||||
|
||||
TEST_PRODUCT_1=17,
|
||||
TEST_PRODUCT_2=18,
|
||||
PRODUCT_MAX
|
||||
DAY_TICKET_CAMPER=15
|
||||
};
|
||||
|
||||
struct PermitType {
|
||||
@@ -78,15 +73,6 @@ struct PermitType {
|
||||
case 15:
|
||||
m_permitType = PERMIT_TYPE::DAY_TICKET_CAMPER;
|
||||
break;
|
||||
case 16:
|
||||
m_permitType = PERMIT_TYPE::FREE_TICKET;
|
||||
break;
|
||||
case 17:
|
||||
m_permitType = PERMIT_TYPE::TEST_PRODUCT_1;
|
||||
break;
|
||||
case 18:
|
||||
m_permitType = PERMIT_TYPE::TEST_PRODUCT_2;
|
||||
break;
|
||||
default:
|
||||
m_permitType = PERMIT_TYPE::INVALID;
|
||||
}
|
||||
@@ -130,12 +116,6 @@ struct PermitType {
|
||||
return 14;
|
||||
case PERMIT_TYPE::DAY_TICKET_CAMPER:
|
||||
return 15;
|
||||
case PERMIT_TYPE::FREE_TICKET:
|
||||
return 16;
|
||||
case PERMIT_TYPE::TEST_PRODUCT_1:
|
||||
return 17;
|
||||
case PERMIT_TYPE::TEST_PRODUCT_2:
|
||||
return 18;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -152,6 +132,9 @@ 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
|
||||
@@ -187,15 +170,6 @@ struct PermitType {
|
||||
} else
|
||||
if (permitTypeStr == "DAY_TICKET_CAMPER") {
|
||||
return PERMIT_TYPE::DAY_TICKET_CAMPER;
|
||||
} else
|
||||
if (permitTypeStr == "FREE_TICKET") {
|
||||
return PERMIT_TYPE::FREE_TICKET;
|
||||
} else
|
||||
if (permitTypeStr == "TEST_PRODUCT_1") {
|
||||
return PERMIT_TYPE::TEST_PRODUCT_1;
|
||||
} else
|
||||
if (permitTypeStr == "TEST_PRODUCT_2") {
|
||||
return PERMIT_TYPE::TEST_PRODUCT_2;
|
||||
}
|
||||
|
||||
return PERMIT_TYPE::INVALID;
|
||||
@@ -233,12 +207,6 @@ 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");
|
||||
case PERMIT_TYPE::TEST_PRODUCT_1:
|
||||
return QString("TEST_PRODUCT_1");
|
||||
case PERMIT_TYPE::TEST_PRODUCT_2:
|
||||
return QString("TEST_PRODUCT_2");
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -277,12 +245,6 @@ 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");
|
||||
case PERMIT_TYPE::TEST_PRODUCT_1:
|
||||
return QString("TEST_PRODUCT_1");
|
||||
case PERMIT_TYPE::TEST_PRODUCT_2:
|
||||
return QString("TEST_PRODUCT_2");
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
@@ -38,7 +38,7 @@ struct ATBTariffPrepaid {
|
||||
if (ppif == "always") {
|
||||
m_prepaidIf = ApplyPrepaid::ALWAYS;
|
||||
} else {
|
||||
qCritical() << __func__ << ":" << __LINE__ << "ERROR unknown carry over application" << ppif;
|
||||
qCritical() << "ERROR unknown carry over application" << ppif;
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -36,7 +36,8 @@ SOURCES += \
|
||||
src/calculate_price.cpp \
|
||||
src/ticket.cpp \
|
||||
src/tariff_global_defines.cpp \
|
||||
src/atb_time.cpp
|
||||
src/atb_time.cpp \
|
||||
src/tariff_comp_step.cpp
|
||||
|
||||
HEADERS += \
|
||||
include/mobilisis/calculator_functions.h \
|
||||
@@ -93,7 +94,9 @@ HEADERS += \
|
||||
include/mobilisis/tariff_global_defines.h \
|
||||
include/mobilisis/atb_time.h \
|
||||
include/mobilisis/tariff_service.h \
|
||||
include/mobilisis/tariff_out_of_service.h
|
||||
include/mobilisis/tariff_out_of_service.h \
|
||||
include/mobilisis/tariff_comp_state.h \
|
||||
include/mobilisis/tariff_comp_step.h
|
||||
|
||||
OTHER_FILES += src/main.cpp \
|
||||
../tariffs/tariff_korneuburg.json \
|
||||
|
File diff suppressed because it is too large
Load Diff
@@ -379,8 +379,7 @@ 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 =
|
||||
cfg->getPaymentOptions(paymentOptionIndex).pop_max_price_save;
|
||||
int const pop_max_price = cfg->getPaymentOptions(paymentOptionIndex).pop_max_price;
|
||||
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;
|
||||
@@ -453,50 +452,13 @@ 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;
|
||||
|
||||
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 const nettoParktimeForCost = priceNettoParktime[int(cost)];
|
||||
qCritical() << __func__ << ":" << __LINE__ << QString("cost=%1 nettoParkTimeForCost=%2").
|
||||
arg(cost).arg(nettoParktimeForCost);
|
||||
|
||||
int cnt = 0;
|
||||
while (++cnt < 20 && netto_parking_time_in_minutes < nettoParktimeForCost) {
|
||||
while (++cnt < 10 && 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;
|
||||
@@ -749,10 +711,6 @@ Calculator::ComputeCostFromDuration(Configuration *cfg, QDateTime const &startDa
|
||||
CalcState returnState;
|
||||
|
||||
QList<int> keys = nettoParktimePrice.keys();
|
||||
|
||||
qCritical() << __func__ << ":" << __LINE__ << "Times Keys" << keys;
|
||||
qCritical() << __func__ << ":" << __LINE__ << "Prices Keys" << priceNettoParktime.keys();
|
||||
|
||||
int index = keys.indexOf(nettoParkingTime);
|
||||
if (index != -1) {
|
||||
int c = nettoParktimePrice[keys.at(index)];
|
||||
@@ -954,8 +912,7 @@ Calculator::GetDurationFromCost(Configuration* cfg,
|
||||
}
|
||||
|
||||
int const pop_id = cfg->getPaymentOptions(paymentOptionIndex).pop_id;
|
||||
int const pop_max_price = cfg->getPaymentOptions(paymentOptionIndex).pop_max_price
|
||||
= cfg->getPaymentOptions(paymentOptionIndex).pop_max_price_save;
|
||||
int const pop_max_price = cfg->getPaymentOptions(paymentOptionIndex).pop_max_price;
|
||||
//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;
|
||||
@@ -3627,9 +3584,7 @@ uint32_t Calculator::GetPriceForTimeStep(Configuration *cfg, int timeStep, int p
|
||||
qCritical() << "(" << __func__ << ":" << __LINE__ << ") timeStep" << timeStep;
|
||||
}
|
||||
|
||||
// allow some tolerance when searching for [timeStep == pun_duration]:
|
||||
// this might happen when crossing minute boundaries
|
||||
if (std::abs(timeStep - pun_duration) < 4) {
|
||||
if (timeStep == pun_duration) {
|
||||
qCritical() << "(" << __func__ << ":" << __LINE__ << ") return price" << price;
|
||||
return price;
|
||||
}
|
||||
@@ -3700,9 +3655,6 @@ 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;
|
||||
@@ -3790,10 +3742,6 @@ Calculator::GetDailyTicketPrice(Configuration* cfg,
|
||||
// [[fallthrough]];
|
||||
case PERMIT_TYPE::SHORT_TERM_PARKING: {
|
||||
}
|
||||
case PERMIT_TYPE::TEST_PRODUCT_1: {
|
||||
}
|
||||
case PERMIT_TYPE::TEST_PRODUCT_2: {
|
||||
}
|
||||
// [[fallthrough]];
|
||||
case PERMIT_TYPE::DAY_TICKET: {
|
||||
} break;
|
||||
|
@@ -17,8 +17,6 @@
|
||||
#include <QString>
|
||||
#include <QDebug>
|
||||
#include <QRegularExpression>
|
||||
#include <QPair>
|
||||
#include <QList>
|
||||
|
||||
/// <inheritdoc/>
|
||||
MemberType Configuration::IdentifyJsonMember(const char* member_name)
|
||||
@@ -48,7 +46,6 @@ 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;
|
||||
}
|
||||
|
||||
@@ -73,7 +70,7 @@ ATBWeekDay parseWeekDay(Configuration &cfg,
|
||||
// start with new implementation of tariff-calculator
|
||||
// see for instance: bad neuenahr (249), Zone5
|
||||
|
||||
qCritical() << __func__ << ":" << __LINE__ << innerObjName;
|
||||
// qCritical() << __func__ << ":" << __LINE__ << innerObjName;
|
||||
|
||||
if (k->value.IsObject()) {
|
||||
auto obj = k->value.GetObject();
|
||||
@@ -174,9 +171,8 @@ ATBWeekDay parseWeekDay(Configuration &cfg,
|
||||
if (!d.isNull() && d.isValid()) {
|
||||
TariffPrepaid.m_date = d;
|
||||
}
|
||||
if (!prepaidIf.isNull() && !prepaidIf.trimmed().isEmpty()) {
|
||||
TariffPrepaid.setPrepaidIf(prepaidIf);
|
||||
}
|
||||
TariffPrepaid.setPrepaidIf(prepaidIf);
|
||||
|
||||
qCritical() << TariffPrepaid;
|
||||
|
||||
cfg.TariffPrepaids.insert(std::pair<int, ATBTariffPrepaid>(weekDay, TariffPrepaid));
|
||||
@@ -262,7 +258,7 @@ ATBWeekDay parseWeekDay(Configuration &cfg,
|
||||
if (!d.isNull() && d.isValid()) {
|
||||
TariffCarryOver.m_date = d;
|
||||
}
|
||||
if (!carryOverIf.isNull() && !carryOverIf.trimmed().isEmpty()) {
|
||||
if (!carryOverIf.isEmpty()) {
|
||||
TariffCarryOver.setCarryOverIf(carryOverIf);
|
||||
}
|
||||
|
||||
@@ -465,14 +461,6 @@ ATBWeekDay parseWeekDay(Configuration &cfg,
|
||||
|
||||
}
|
||||
}
|
||||
ATBTariffSettings ts(max_price, min_price, max_time, min_time);
|
||||
ATBTariffCarryOverSettings cs(duration, start, end, parking_time_limit, about_to_exceed_limit,
|
||||
parkTimeLimitChecker);
|
||||
if (!d.isNull() && d.isValid()) { // special day, given in date-format
|
||||
WeekDay = ATBWeekDay(weekDay, weekDayName, ATBWeekDay::HOLIDAY, QDate(), ts, cs);
|
||||
} else {
|
||||
WeekDay = ATBWeekDay(weekDay, weekDayName, ATBWeekDay::USUAL_WEEKDAY, QDate(), ts, cs);
|
||||
}
|
||||
}
|
||||
} else
|
||||
if (innerObjName == QString("week_day_default")) {
|
||||
@@ -822,7 +810,6 @@ bool Configuration::ParseJson(Configuration* cfg, const char* json)
|
||||
ATBInterpolation TariffInterpolation;
|
||||
ATBPrepaid TariffPrepaidOption;
|
||||
ATBCarryOver TariffCarryOver;
|
||||
QList<QPair<QString, QString>> TariffIncludes;
|
||||
|
||||
MemberType mb_type = MemberType::UnknownType;
|
||||
this->currentPaymentOptions.clear();
|
||||
@@ -888,32 +875,32 @@ bool Configuration::ParseJson(Configuration* cfg, const char* json)
|
||||
break;
|
||||
case MemberType::WeekDaysType: {
|
||||
ATBWeekDay WeekDay;
|
||||
if (QString(mb_name).trimmed() == "Monday") {
|
||||
WeekDay = parseWeekDay(*cfg, k, inner_obj_name, Qt::Monday, QString(mb_name).trimmed());
|
||||
if (QString(mb_name) == "Monday") {
|
||||
WeekDay = parseWeekDay(*cfg, k, inner_obj_name, Qt::Monday, mb_name);
|
||||
} else
|
||||
if (QString(mb_name).trimmed() == "Tuesday") {
|
||||
WeekDay = parseWeekDay(*cfg, k, inner_obj_name, Qt::Tuesday, QString(mb_name).trimmed());
|
||||
if (QString(mb_name) == "Tuesday") {
|
||||
WeekDay = parseWeekDay(*cfg, k, inner_obj_name, Qt::Tuesday, mb_name);
|
||||
} else
|
||||
if (QString(mb_name).trimmed() == "Wednesday") {
|
||||
WeekDay = parseWeekDay(*cfg, k, inner_obj_name, Qt::Wednesday, QString(mb_name).trimmed());
|
||||
if (QString(mb_name) == "Wednesday") {
|
||||
WeekDay = parseWeekDay(*cfg, k, inner_obj_name, Qt::Wednesday, mb_name);
|
||||
} else
|
||||
if (QString(mb_name).trimmed() == "Thursday") {
|
||||
WeekDay = parseWeekDay(*cfg, k, inner_obj_name, Qt::Thursday, QString(mb_name).trimmed());
|
||||
if (QString(mb_name) == "Thursday") {
|
||||
WeekDay = parseWeekDay(*cfg, k, inner_obj_name, Qt::Thursday, mb_name);
|
||||
} else
|
||||
if (QString(mb_name).trimmed() == "Friday") {
|
||||
WeekDay = parseWeekDay(*cfg, k, inner_obj_name, Qt::Friday, QString(mb_name).trimmed());
|
||||
if (QString(mb_name) == "Friday") {
|
||||
WeekDay = parseWeekDay(*cfg, k, inner_obj_name, Qt::Friday, mb_name);
|
||||
} else
|
||||
if (QString(mb_name).trimmed() == "Saturday") {
|
||||
WeekDay = parseWeekDay(*cfg, k, inner_obj_name, Qt::Saturday, QString(mb_name).trimmed());
|
||||
if (QString(mb_name) == "Saturday") {
|
||||
WeekDay = parseWeekDay(*cfg, k, inner_obj_name, Qt::Saturday, mb_name);
|
||||
} else
|
||||
if (QString(mb_name).trimmed() == "Sunday") {
|
||||
WeekDay = parseWeekDay(*cfg, k, inner_obj_name, Qt::Sunday, QString(mb_name).trimmed());
|
||||
if (QString(mb_name) == "Sunday") {
|
||||
WeekDay = parseWeekDay(*cfg, k, inner_obj_name, Qt::Sunday, mb_name);
|
||||
} else {
|
||||
qCritical() << "ERROR: unknown week day" << mb_name;
|
||||
}
|
||||
|
||||
cfg->WeekDays.insert(pair<Qt::DayOfWeek, ATBWeekDay>(WeekDay.m_id, WeekDay));
|
||||
qCritical() << __func__ << ":" << __LINE__ << cfg << "CCCC insert" << (int)WeekDay.m_id << WeekDay.m_name;
|
||||
// qCritical() << WeekDay;
|
||||
|
||||
} break;
|
||||
case MemberType::CarryOverType: {
|
||||
@@ -1354,9 +1341,6 @@ 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 << QPair<QString, QString>(QString(inner_obj_name), 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();
|
||||
@@ -1646,9 +1630,6 @@ 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;
|
||||
}
|
||||
|
17
library/src/tariff_comp_step.cpp
Normal file
17
library/src/tariff_comp_step.cpp
Normal file
@@ -0,0 +1,17 @@
|
||||
#include "tariff_comp_step.h"
|
||||
|
||||
#include <QByteArray>
|
||||
#include <QCryptographicHash>
|
||||
#include <QString>
|
||||
|
||||
uint64_t TariffCompStep::hash() {
|
||||
QString const str(QString("%1%2%3").arg(m_duration).arg(m_start.toString(Qt::ISODate)).arg(m_end.toString(Qt::ISODate)));
|
||||
QByteArray const hash = QCryptographicHash::hash(
|
||||
QByteArray::fromRawData(reinterpret_cast<char const*>(str.utf16()), str.length()*2),
|
||||
QCryptographicHash::Md5
|
||||
);
|
||||
|
||||
uint64_t const &i = hash.left(8).toULongLong(nullptr, 16);
|
||||
uint64_t const &j = hash.right(8).toULongLong(nullptr, 16);
|
||||
return i ^ j;
|
||||
}
|
138
main/main.cpp
138
main/main.cpp
@@ -39,10 +39,10 @@ extern "C" char* strptime(const char* s,
|
||||
|
||||
#define SZEGED (0)
|
||||
#define SCHOENAU_KOENIGSEE (0)
|
||||
#define NEUHAUSER_KORNEUBURG (1)
|
||||
#define NEUHAUSER_KORNEUBURG (0)
|
||||
#define NEUHAUSER_LINSINGER_MASCHINENBAU (0)
|
||||
#define NEUHAUSER_NORDISCHES_AUSBILDUNGSZENTRUM (0)
|
||||
#define NEUHAUSER_BILEXA_GALTUER (0)
|
||||
#define NEUHAUSER_BILEXA_GALTUER (1)
|
||||
#define BAD_NEUENAHR_AHRWEILER (0)
|
||||
#define NEUHAUSER_CHRISTOPH_REISEN (0)
|
||||
#define NEUHAUSER_PERNEGG_AN_DER_MUR (0)
|
||||
@@ -53,6 +53,7 @@ extern "C" char* strptime(const char* s,
|
||||
#define SCHNALS_STAUMAUER (SCHNALS_LEITER_KIRCHL)
|
||||
#define VALSER_ALM (0)
|
||||
#define NEUHAUSER_FORCHACH (0)
|
||||
#define STADT_WEIDEN (0)
|
||||
|
||||
#if NEUHAUSER_KIRCHDORF==1
|
||||
static bool test_neuhauser_kirchdorf(int step, double cost) {
|
||||
@@ -211,73 +212,28 @@ 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 < 346; ++i) {
|
||||
//printf("{\n \"pun_id\": %i,\n \"pun_duration\": %d\n},\n",
|
||||
// i, 60 + i*4);
|
||||
// {
|
||||
// "pun_duration": 0,
|
||||
// "pun_id": 0,
|
||||
// "pun_label": "0 min"
|
||||
// }
|
||||
|
||||
//for (int i = 0; i <= 140; ++i) {
|
||||
//printf("{\n \"\pun_duration\": %d,\n \"\pun_id\": %d,\n \"pun_label\": \"%d min\"\n},\n",
|
||||
// i*6, i, i*6);
|
||||
//}
|
||||
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;
|
||||
|
||||
//return 0;
|
||||
#if 0
|
||||
MessageHelper msgHelp;
|
||||
// msgHelp.createLoginMessageChunksToSend(0x02);
|
||||
@@ -2725,7 +2681,7 @@ int main() {
|
||||
int Up = 1;
|
||||
//compute_next_timestep(&cfg, )
|
||||
|
||||
QDateTime const start = QDateTime::currentDateTime();
|
||||
QDateTime const start = QDateTime::fromString("2024-10-13T12:00:00");
|
||||
int paymentOptionIndex = cfg.getPaymentOptionIndex(start);
|
||||
|
||||
if (paymentOptionIndex < 0) {
|
||||
@@ -2737,7 +2693,7 @@ int main() {
|
||||
QSet<uint32_t> const prices{700, 1400, 2100, 2800, 3500, 4200, 4900};
|
||||
|
||||
for (int i=0; i<timeSteps.size(); ++i) {
|
||||
int nextTimeStep = compute_next_timestep(&cfg, timeSteps.at(i), Up);
|
||||
int nextTimeStep = compute_next_timestep(&cfg, timeSteps.at(i), Up, PermitType(PERMIT_TYPE::SHORT_TERM_PARKING));
|
||||
qCritical() << "nextTimeStep" << nextTimeStep;
|
||||
|
||||
uint32_t price = Calculator::GetInstance().GetPriceForTimeStep(&cfg, timeSteps.at(i), paymentOptionIndex);
|
||||
@@ -2837,6 +2793,66 @@ int main() {
|
||||
}
|
||||
#endif
|
||||
|
||||
#if STADT_WEIDEN==1
|
||||
std::ifstream input("/opt/ptu5/opt/customer_6/etc/psa_tariff/tariff01.json");
|
||||
int pop_max_time;
|
||||
|
||||
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) {
|
||||
qCritical() << __func__ << ":" << __LINE__ << "parsed";
|
||||
|
||||
QDateTime s(QDate(2024, 10, 14), QTime());
|
||||
QDateTime end;
|
||||
|
||||
static QList<int> const timeSteps = Calculator::GetInstance().GetTimeSteps(&cfg);
|
||||
qCritical() << "TimeSteps" << timeSteps;
|
||||
|
||||
int offset = 1150;
|
||||
QDateTime start = s.addSecs(offset * 60);
|
||||
|
||||
|
||||
CalcState cs;
|
||||
#if 0
|
||||
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 = 220;
|
||||
qCritical() << "XXXXXXXX START" << start.toString(Qt::ISODate) << "cost" << cost;
|
||||
|
||||
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
|
||||
#endif // STADT WEIDEN
|
||||
|
||||
#if NEUHAUSER_KORNEUBURG==1
|
||||
std::ifstream input("/opt/ptu5/opt/customer_714/etc/psa_tariff/tariff01.json");
|
||||
int pop_max_time;
|
||||
|
@@ -1,5 +1,3 @@
|
||||
QT += core
|
||||
|
||||
TEMPLATE = app
|
||||
TARGET = main
|
||||
|
||||
|
Reference in New Issue
Block a user