Compare commits

...

12 Commits

14 changed files with 869 additions and 39 deletions

View File

@@ -4,20 +4,42 @@
#include <QDateTime>
class ATBTime {
QDateTime const m_end;
static QDateTime const m_end;
mutable QDateTime m_time;
public:
explicit ATBTime();
explicit ATBTime(int h, int m, int s = 0, int ms = 0);
explicit ATBTime(QString const &time);
explicit ATBTime(QTime const &time);
explicit ATBTime(ATBTime const &atbTime) {
m_time = atbTime.m_time;
}
ATBTime &operator=(ATBTime && atbTime) {
m_time = std::move(atbTime.m_time);
return *this;
}
ATBTime &operator=(ATBTime const &atbTime) {
m_time = atbTime.m_time;
return *this;
}
int hour() const { return m_time.time().hour(); }
int minute() const { return m_time.time().minute(); }
int second() const { return m_time.time().second(); }
int msec() const { return m_time.time().msec(); }
int secsTo(QTime t) const { return m_time.time().secsTo(t); }
int secsTo(QString const &t) const {
if (t == "24:00:00") {
return m_time.secsTo(m_end);
}
return m_time.time().secsTo(QTime::fromString(t, Qt::ISODate));
}
int msecsTo(QTime t) const { return m_time.time().msecsTo(t); }
bool setHMS(int h, int m, int s, int ms = 0);
@@ -48,10 +70,12 @@ public:
friend bool operator!=(const ATBTime &lhs, const ATBTime &rhs) noexcept;
friend bool operator<(const ATBTime &lhs, const ATBTime &rhs) noexcept;
friend bool operator<=(const ATBTime &lhs, const ATBTime &rhs) noexcept;
friend bool operator>=(const ATBTime &lhs, const ATBTime &rhs) noexcept;
friend bool operator<(const ATBTime &lhs, const ATBTime &rhs) noexcept;
friend bool operator>(const ATBTime &lhs, const ATBTime &rhs) noexcept;
friend bool operator==(const ATBTime &lhs, const ATBTime &rhs) noexcept;
friend QDataStream &operator<<(QDataStream &out, ATBTime time);
friend QDataStream &operator<<(QDataStream &out, ATBTime const &time);
friend QDebug &operator<<(QDebug &out, ATBTime const &time);
friend QDataStream &operator>>(QDataStream &in, ATBTime &time);
};

View File

@@ -29,6 +29,8 @@
#include "tariff_prepaid.h"
#include "tariff_carryover.h"
#include "tariff_permit_type.h"
#include "tariff_service.h"
#include "tariff_out_of_service.h"
#include <QVector>
#include <optional>
@@ -50,6 +52,10 @@ public:
using TariffPrepaidType = std::multimap<int, ATBPrepaid>;
using TariffCarryOverType = std::multimap<int, ATBCarryOver>;
using TariffDurationType = std::multimap<int, ATBDuration>;
using TariffServiceType = std::multimap<int, ATBTariffService>;
using TariffOutOfServiceType = std::multimap<int, ATBTariffOutOfService>;
using ATBTariffPrepaidType = std::multimap<int, ATBTariffPrepaid>;
using ATBTariffCarryOverType = std::multimap<int, ATBTariffCarryOver>;
ATBProject project;
ATBCurrency Currency;
@@ -73,6 +79,10 @@ public:
TariffInterpolationType TariffInterpolations;
TariffPrepaidType TariffPrepaidOptions;
TariffCarryOverType TariffCarryOverOptions;
TariffServiceType TariffServices;
TariffOutOfServiceType TariffOutOfServices;
ATBTariffPrepaidType TariffPrepaids;
ATBTariffCarryOverType TariffCarryOvers;
/// <summary>
/// Parse JSON string

View File

@@ -3,6 +3,80 @@
#include <QTime>
#include "time_range.h"
enum class ApplyCarryOver {
NEVER = 0,
MATCH_PREV_DAY = 1,
MATCH_NEXT_DAY = 2,
ALWAYS = 3
};
struct ATBTariffCarryOver {
int m_id;
QString m_weekDay;
TimeRange m_range;
QDate m_date;
ApplyCarryOver m_carryOverIf;
explicit ATBTariffCarryOver()
: m_id(-1)
, m_carryOverIf(ApplyCarryOver::NEVER) {
}
void setCarryOverIf(QString const &coif) {
if (coif == "never") {
m_carryOverIf = ApplyCarryOver::NEVER;
} else
if (coif == "match_prev_day") {
m_carryOverIf = ApplyCarryOver::MATCH_PREV_DAY;
} else
if (coif == "match_next_day") {
m_carryOverIf = ApplyCarryOver::MATCH_NEXT_DAY;
} else
if (coif == "always") {
m_carryOverIf = ApplyCarryOver::ALWAYS;
} else {
qCritical() << "ERROR unknown carry over application" << coif;
}
}
ApplyCarryOver carryOverIf() const {
return m_carryOverIf;
}
QString carryOverIfStr() const {
if (m_carryOverIf == ApplyCarryOver::NEVER) {
return "never";
}
if (m_carryOverIf == ApplyCarryOver::ALWAYS) {
return "always";
}
if (m_carryOverIf == ApplyCarryOver::MATCH_PREV_DAY) {
return "match prev day";
}
if (m_carryOverIf == ApplyCarryOver::MATCH_NEXT_DAY) {
return "match next day";
}
return QString("ERROR unknown carry over application: %1").arg(static_cast<int>(m_carryOverIf));
}
friend QDebug operator<<(QDebug debug, ATBTariffCarryOver const &co) {
QDebugStateSaver saver(debug);
debug.nospace()
<< "\nTariffCarryOver:\n"
<< " week day: " << co.m_weekDay << "\n"
<< " date: " << co.m_date.toString(Qt::ISODate) << "\n"
<< " id: " << co.m_id << "\n"
<< " start: " << co.m_range.m_start << "\n"
<< " end: " << co.m_range.m_end << "\n"
<< " duration: " << co.m_range.m_duration << "\n"
<< " carry over if: " << co.carryOverIfStr() << endl;
return debug;
}
};
struct ATBCarryOver {
struct week {
int day;

View File

@@ -1,4 +1,3 @@
#pragma once
#include <variant>
#include <cstddef>
#include <stdio.h>

View File

@@ -0,0 +1,79 @@
#ifndef TARIFF_OUT_OF_SERVICE_H_INCLUDED
#define TARIFF_OUT_OF_SERVICE_H_INCLUDED
#include <QDateTime>
#include <QString>
#include "time_range.h"
enum class ApplyOutOfService {
NEVER = 0,
MATCH_PREV_DAY = 1,
MATCH_NEXT_DAY = 2,
ALWAYS = 3
};
struct ATBTariffOutOfService {
int m_id;
QString m_weekDay;
QDate m_date;
TimeRange m_range;
ApplyOutOfService m_outOfServiceIf;
explicit ATBTariffOutOfService()
: m_id(-1)
, m_outOfServiceIf(ApplyOutOfService::NEVER) {
}
void setOutOfServiceIf(QString const &oosif) {
if (oosif == "never") {
m_outOfServiceIf = ApplyOutOfService::NEVER;
} else
if (oosif == "match_prev_day") {
m_outOfServiceIf = ApplyOutOfService::MATCH_PREV_DAY;
} else
if (oosif == "match_next_day") {
m_outOfServiceIf = ApplyOutOfService::MATCH_NEXT_DAY;
} else
if (oosif == "always") {
m_outOfServiceIf = ApplyOutOfService::ALWAYS;
} else {
qCritical() << "ERROR unknown servcie application" << oosif;
}
}
ApplyOutOfService outOfServiceIf() const {
return m_outOfServiceIf;
}
QString outOfServiceIfStr() const {
if (m_outOfServiceIf == ApplyOutOfService::NEVER) {
return "never";
}
if (m_outOfServiceIf == ApplyOutOfService::ALWAYS) {
return "always";
}
if (m_outOfServiceIf == ApplyOutOfService::MATCH_PREV_DAY) {
return "match prev day";
}
if (m_outOfServiceIf == ApplyOutOfService::MATCH_NEXT_DAY) {
return "match next day";
}
return QString("ERROR unknown out of service application: %1").arg(static_cast<int>(m_outOfServiceIf));
}
friend QDebug operator<<(QDebug debug, ATBTariffOutOfService const &oos) {
QDebugStateSaver saver(debug);
debug.nospace()
<< "\nTariffOutOfService:\n"
<< " week day: " << oos.m_weekDay << "\n"
<< " date: " << oos.m_date.toString(Qt::ISODate) << "\n"
<< " id: " << oos.m_id << "\n"
<< " start: " << oos.m_range.m_start << "\n"
<< " end: " << oos.m_range.m_end << "\n"
<< " duration: " << oos.m_range.m_duration << endl;
return debug;
}
};
#endif // TARIFF_SERVICE_H_INCLUDED

View File

@@ -1,10 +1,84 @@
#ifndef TARIFF_PREPAID_H_INCLUDED
#define TARIFF_PREPAID_H_INCLUDED
#include <QTime>
#include <QDateTime>
#include <QString>
#include "atb_time.h"
#include "time_range.h"
enum class ApplyPrepaid {
NEVER = 0,
MATCH_PREV_DAY = 1,
MATCH_NEXT_DAY = 2,
ALWAYS = 3
};
struct ATBTariffPrepaid {
int m_id;
QString m_weekDay;
QDate m_date;
TimeRange m_range;
ApplyPrepaid m_prepaidIf;
explicit ATBTariffPrepaid()
: m_id(-1)
, m_prepaidIf(ApplyPrepaid::NEVER) {
}
void setPrepaidIf(QString const &ppif) {
if (ppif == "never") {
m_prepaidIf = ApplyPrepaid::NEVER;
} else
if (ppif == "match_prev_day") {
m_prepaidIf = ApplyPrepaid::MATCH_PREV_DAY;
} else
if (ppif == "match_next_day") {
m_prepaidIf = ApplyPrepaid::MATCH_NEXT_DAY;
} else
if (ppif == "always") {
m_prepaidIf = ApplyPrepaid::ALWAYS;
} else {
qCritical() << "ERROR unknown carry over application" << ppif;
}
}
ApplyPrepaid prepaidIf() const {
return m_prepaidIf;
}
QString prepaidIfStr() const {
if (m_prepaidIf == ApplyPrepaid::NEVER) {
return "never";
}
if (m_prepaidIf == ApplyPrepaid::ALWAYS) {
return "always";
}
if (m_prepaidIf == ApplyPrepaid::MATCH_PREV_DAY) {
return "match prev day";
}
if (m_prepaidIf == ApplyPrepaid::MATCH_NEXT_DAY) {
return "match next day";
}
return QString("ERROR unknown prepaid application: %1").arg(static_cast<int>(m_prepaidIf));
}
friend QDebug operator<<(QDebug debug, ATBTariffPrepaid const &pp) {
QDebugStateSaver saver(debug);
debug.nospace()
<< "\nTariffPrepaid:\n"
<< " week day: " << pp.m_weekDay << "\n"
<< " date: " << pp.m_date.toString(Qt::ISODate) << "\n"
<< " id: " << pp.m_id << "\n"
<< " start: " << pp.m_range.m_start << "\n"
<< " end: " << pp.m_range.m_end << "\n"
<< " duration: " << pp.m_range.m_duration << "\n"
<< " prepaid if: " << pp.prepaidIfStr() << endl;
return debug;
}
};
// deprecated
struct ATBPrepaid {
int id;

View File

@@ -0,0 +1,81 @@
#ifndef TARIFF_SERVICE_H_INCLUDED
#define TARIFF_SERVICE_H_INCLUDED
#include <QDateTime>
#include <QString>
#include "time_range.h"
enum class ApplyService {
NEVER = 0,
MATCH_PREV_DAY = 1,
MATCH_NEXT_DAY = 2,
ALWAYS = 3
};
struct ATBTariffService {
int m_id;
QString m_weekDay;
QDate m_date;
TimeRange m_range;
ApplyService m_serviceIf;
explicit ATBTariffService()
: m_id(-1)
, m_serviceIf(ApplyService::NEVER) {
}
void setServiceIf(QString const &sif) {
if (sif == "never") {
m_serviceIf = ApplyService::NEVER;
} else
if (sif == "match_prev_day") {
m_serviceIf = ApplyService::MATCH_PREV_DAY;
} else
if (sif == "match_next_day") {
m_serviceIf = ApplyService::MATCH_NEXT_DAY;
} else
if (sif == "always") {
m_serviceIf = ApplyService::ALWAYS;
} else {
qCritical() << "ERROR unknown servcie application" << sif;
}
}
ApplyService serviceIf() const {
return m_serviceIf;
}
QString serviceIfStr() const {
if (m_serviceIf == ApplyService::NEVER) {
return "never";
}
if (m_serviceIf == ApplyService::ALWAYS) {
return "always";
}
if (m_serviceIf == ApplyService::MATCH_PREV_DAY) {
return "match prev day";
}
if (m_serviceIf == ApplyService::MATCH_NEXT_DAY) {
return "match next day";
}
return QString("ERROR unknown service application: %1").arg(static_cast<int>(m_serviceIf));
}
friend QDebug operator<<(QDebug debug, ATBTariffService const &ts) {
QDebugStateSaver saver(debug);
debug.nospace()
<< "\nTariffService:\n"
<< " week day: " << ts.m_weekDay << "\n"
<< " date: " << ts.m_date.toString(Qt::ISODate) << "\n"
<< " id: " << ts.m_id << "\n"
<< " start: " << ts.m_range.m_start << "\n"
<< " end: " << ts.m_range.m_end << "\n"
<< " duration: " << ts.m_range.m_duration << "\n"
<< " prepaid if: " << ts.serviceIfStr() << endl;
return debug;
}
};
#endif // TARIFF_SERVICE_H_INCLUDED

View File

@@ -1,12 +1,39 @@
#ifndef TIME_RANGE_H_INCLUDED
#define TIME_RANGE_H_INCLUDED
#include "time_range_header.h"
#include "atb_time.h"
#include <QString>
struct TimeRange {
public:
bool IsActive;
ATBTimeRange TimeRangeStructure;
ATBTime m_start;
ATBTime m_end;
int m_duration;
explicit TimeRange() = default;
explicit TimeRange(QString const &start, QString const &end, int duration)
: m_start(start)
, m_end(end)
, m_duration(duration) {
}
explicit TimeRange(ATBTime const &start, ATBTime const &end, int duration)
: m_start(start)
, m_end(end)
, m_duration(duration) {
}
explicit TimeRange(TimeRange const &timeRange) {
m_start = timeRange.m_start;
m_end = timeRange.m_end;
m_duration = timeRange.m_duration;
}
TimeRange &operator=(TimeRange && timeRange) {
m_start = std::move(timeRange.m_start);
m_end = std::move(timeRange.m_end);
m_duration = timeRange.m_duration;
return *this;
}
};
#endif // TIME_RANGE_H_INCLUDED

View File

@@ -91,7 +91,9 @@ HEADERS += \
include/mobilisis/tariff_prepaid.h \
include/mobilisis/tariff_carryover.h \
include/mobilisis/tariff_global_defines.h \
include/mobilisis/atb_time.h
include/mobilisis/atb_time.h \
include/mobilisis/tariff_service.h \
include/mobilisis/tariff_out_of_service.h
OTHER_FILES += src/main.cpp \
../tariffs/tariff_korneuburg.json \

View File

@@ -1,30 +1,40 @@
#include "atb_time.h"
#include <QDebugStateSaver>
QDateTime const ATBTime::m_end(QDateTime::fromString("1970-01-02T00:00:00", Qt::ISODate));
ATBTime::ATBTime()
: m_end(QDateTime::fromString("1970-01-02T00:00:00", Qt::ISODate))
, m_time(QDateTime::fromString("1970-01-01T00:00:00", Qt::ISODate)) {
: m_time(QDateTime::fromString("1970-01-01T00:00:00", Qt::ISODate)) {
}
ATBTime::ATBTime(int h, int m, int s, int ms)
: m_end(QDateTime::fromString("1970-01-02T00:00:00", Qt::ISODate))
, m_time(QDateTime::fromString("1970-01-01T00:00:00", Qt::ISODate)) {
ATBTime::ATBTime(int h, int m, int /*s*/, int /*ms*/)
: m_time(QDateTime::fromString("1970-01-01T00:00:00", Qt::ISODate)) {
QTime t(h, m, s, ms);
m_time.setTime(t);
if (h == 24 && m == 0) {
m_time = m_end;
} else {
QTime const t(h, m, 0, 0);
m_time.setTime(t);
}
}
ATBTime::ATBTime(QString const &t)
: m_end(QDateTime::fromString("1970-01-02T00:00:00"))
, m_time(QDateTime::fromString("1970-01-01T00:00:00")) {
: m_time(QDateTime::fromString("1970-01-01T00:00:00")) {
if (t == "24:00:00") {
m_time = m_end;
} else {
m_time.setTime(QTime::fromString(t, Qt::ISODate));
QTime tmp = QTime::fromString(t, Qt::ISODate);
if (tmp.isValid()) {
m_time.setTime(tmp);
}
}
}
ATBTime::ATBTime(QTime const &t)
: m_time(QDateTime::fromString("1970-01-01T00:00:00")) {
m_time.setTime(t);
}
QTime ATBTime::addMSecs(int ms) const {
return m_time.time().addMSecs(ms);
@@ -78,6 +88,9 @@ bool ATBTime::setHMS(int h, int m, int s, int ms) {
}
QString ATBTime::toString(Qt::DateFormat format) const {
if (m_time == m_end) {
return "24:00:00";
}
return m_time.time().toString(format);
}
@@ -86,11 +99,20 @@ bool operator!=(const ATBTime &lhs, const ATBTime &rhs) noexcept {
}
bool operator<=(const ATBTime &lhs, const ATBTime &rhs) noexcept {
if (rhs.m_time == rhs.m_end) {
return true;
}
return lhs.m_time.time() <= rhs.m_time.time();
}
bool operator>=(const ATBTime &lhs, const ATBTime &rhs) noexcept {
return lhs.m_time.time() >= rhs.m_time.time();
}
bool operator<(const ATBTime &lhs, const ATBTime &rhs) noexcept {
if (rhs.m_time == rhs.m_end) {
return true;
}
return lhs.m_time.time() < rhs.m_time.time();
}
@@ -102,8 +124,22 @@ bool operator==(const ATBTime &lhs, const ATBTime &rhs) noexcept {
return lhs.m_time.time() == rhs.m_time.time();
}
QDataStream &operator<<(QDataStream &out, ATBTime time) {
out << time.m_time.time();
QDebug &operator<<(QDebug &debug, ATBTime const &time) {
QDebugStateSaver saver(debug);
if (time.m_time == time.m_end) {
debug.nospace() << QString("24:00:00");
} else {
debug.nospace() << time.m_time.time().toString(Qt::ISODate);
}
return debug;
}
QDataStream &operator<<(QDataStream &out, ATBTime const &time) {
if (time.m_time == time.m_end) {
out << QString("24:00:00");
} else {
out << time.m_time.time();
}
return out;
}

View File

@@ -10,6 +10,9 @@
#include "tariff_global_defines.h"
#include "tariff_settings.h"
#include "tariff_carryover_settings.h"
#include "atb_time.h"
#include "tariff_prepaid.h"
#include "tariff_carryover.h"
#include <QString>
#include <QDebug>
@@ -61,6 +64,405 @@ ATBWeekDay parseWeekDay(Configuration &cfg,
ATBWeekDay WeekDay;
QTime start, end, parking_time_limit, about_to_exceed_limit;
ATBTariffCarryOverSettings::ParkingTimeLimitChecker parkTimeLimitChecker;
QDate const &d = QDate::fromString(innerObjName, Qt::ISODate);
if (innerObjName == QString("default") ||
(!d.isNull() && d.isValid())) { // special day, given in date-format
// start with new implementation of tariff-calculator
// see for instance: bad neuenahr (249), Zone5
// qCritical() << __func__ << ":" << __LINE__ << innerObjName;
if (k->value.IsObject()) {
auto obj = k->value.GetObject();
for (auto m = obj.MemberBegin(); m != obj.MemberEnd(); ++m) {
QString const &name = m->name.GetString();
if (name == "payment_settings") {
if (m->value.IsArray()) {
auto payment = m->value.GetArray();
if (payment.Size() == 0) {
qCritical() << __func__ << ":" << __LINE__ << "no payment settings for" << weekDayName;
} else {
for (rapidjson::SizeType j = 0; j < payment.Size(); ++j) {
if (payment[j].IsObject()) {
auto paymentSetting = payment[j].GetObject();
for (auto n = paymentSetting.MemberBegin(); n != paymentSetting.MemberEnd(); ++n) {
QString const &name = QString::fromStdString(n->name.GetString());
if (name == "min_time") {
if (n->value.IsInt()) { min_time = n->value.GetInt(); }
} else if (name == "max_time") {
if (n->value.IsInt()) { max_time = n->value.GetInt(); }
} else if (name == "min_price") {
if (n->value.IsInt()) { min_price = n->value.GetInt(); }
} else if (name == "max_price") {
if (n->value.IsInt()) { max_price = n->value.GetInt(); }
}
}
}
}
}
}
} else
if (name == "prepaid_settings") {
if (m->value.IsArray()) {
auto prepaid = m->value.GetArray();
if (prepaid.Size() == 0) {
qCritical() << __func__ << ":" << __LINE__ << "no prepaid-settings for" << weekDayName;
} else {
ATBTariffPrepaid TariffPrepaid;
for (rapidjson::SizeType j = 0; j < prepaid.Size(); ++j) {
if (prepaid[j].IsObject()) {
auto prepaidSetting = prepaid[j].GetObject();
for (auto n = prepaidSetting.MemberBegin(); n != prepaidSetting.MemberEnd(); ++n) {
QString const &name = QString::fromStdString(n->name.GetString());
if (name == "prepaid_ranges") {
if (n->value.IsArray()) {
auto prepaidRanges = n->value.GetArray();
if (prepaidRanges.Size() == 0) {
qCritical() << __func__ << ":" << __LINE__ << "no prepaid-ranges for" << weekDayName;
} else {
QString prepaidStartStr;
QString prepaidEndStr;
QString prepaidIf;
int prepaidDuration = -1;
for (rapidjson::SizeType i = 0; i < prepaidRanges.Size(); ++i) {
if (prepaidRanges[j].IsObject()) {
auto prepaidRange = prepaidRanges[i].GetObject();
for (auto r = prepaidRange.MemberBegin(); r != prepaidRange.MemberEnd(); ++r) {
QString const &memName = QString::fromStdString(r->name.GetString());
if (memName == "prepaid_id") {
if (r->value.IsInt()) {
TariffPrepaid.m_id = r->value.GetInt();
} else {
qCritical() << __func__ << ":" << __LINE__ << "prepaidId not an integer";
}
} else
if (memName == "prepaid_duration") {
if (r->value.IsInt()) {
prepaidDuration = r->value.GetInt();
}
} else
if (memName == "prepaid_start") {
if (r->value.IsString()) {
prepaidStartStr = QString::fromStdString(r->value.GetString());
}
} else
if (memName == "prepaid_end") {
if (r->value.IsString()) {
prepaidEndStr = QString::fromStdString(r->value.GetString());
}
} else
if (memName == "prepaid_if") {
if (r->value.IsString()) {
prepaidIf = QString::fromStdString(r->value.GetString());
}
} else {
qCritical() << __func__ << ":" << __LINE__ << "WARNING unknown prepaid setting" << memName;
}
}
}
if (!prepaidStartStr.isEmpty() && !prepaidEndStr.isEmpty() && prepaidDuration != -1) {
ATBTime prepaidStart(prepaidStartStr);
ATBTime prepaidEnd(prepaidEndStr);
if (prepaidStart.isValid() && prepaidEnd.isValid()) {
TariffPrepaid.m_range = TimeRange(prepaidStart, prepaidEnd, prepaidDuration);
TariffPrepaid.m_weekDay = weekDayName;
if (!d.isNull() && d.isValid()) {
TariffPrepaid.m_date = d;
}
TariffPrepaid.setPrepaidIf(prepaidIf);
qCritical() << TariffPrepaid;
cfg.TariffPrepaids.insert(std::pair<int, ATBTariffPrepaid>(weekDay, TariffPrepaid));
}
}
}
}
}
} else {
}
}
}
}
}
}
} else
if (name == "carry_over_settings") {
if (m->value.IsArray()) {
auto carryOver = m->value.GetArray();
if (carryOver.Size() == 0) {
qCritical() << __func__ << ":" << __LINE__ << "no carry-over-settings for" << weekDayName;
} else {
ATBTariffCarryOver TariffCarryOver;
for (rapidjson::SizeType j = 0; j < carryOver.Size(); ++j) {
if (carryOver[j].IsObject()) {
auto carryOverSetting = carryOver[j].GetObject();
for (auto n = carryOverSetting.MemberBegin(); n != carryOverSetting.MemberEnd(); ++n) {
QString const &name = QString::fromStdString(n->name.GetString());
if (name == "carry_over_ranges") {
if (n->value.IsArray()) {
auto carryOverRanges = n->value.GetArray();
if (carryOverRanges.Size() == 0) {
qCritical() << __func__ << ":" << __LINE__ << "no carry-over-ranges for" << weekDayName;
} else {
QString carryOverStartStr;
QString carryOverEndStr;
QString carryOverIf;
int carryOverDuration = -1;
for (rapidjson::SizeType i = 0; i < carryOverRanges.Size(); ++i) {
if (carryOverRanges[j].IsObject()) {
auto carryOverRange = carryOverRanges[i].GetObject();
for (auto r = carryOverRange.MemberBegin(); r != carryOverRange.MemberEnd(); ++r) {
QString const &memName = QString::fromStdString(r->name.GetString());
if (memName == "carry_over_id") {
if (r->value.IsInt()) {
TariffCarryOver.m_id = r->value.GetInt();
} else {
qCritical() << __func__ << ":" << __LINE__ << "carryOverId not an integer";
}
} else
if (memName == "carry_over_duration") {
if (r->value.IsInt()) {
carryOverDuration = r->value.GetInt();
}
} else
if (memName == "carry_over_start") {
if (r->value.IsString()) {
carryOverStartStr = QString::fromStdString(r->value.GetString());
}
} else
if (memName == "carry_over_end") {
if (r->value.IsString()) {
carryOverEndStr = QString::fromStdString(r->value.GetString());
}
} else
if (memName == "carry_over_if") {
if (r->value.IsString()) {
carryOverIf = QString::fromStdString(r->value.GetString());
}
} else {
qCritical() << __func__ << ":" << __LINE__ << "WARNING unknown carry-over setting" << memName;
}
}
}
if (!carryOverStartStr.isEmpty() && !carryOverEndStr.isEmpty() && carryOverDuration != -1) {
ATBTime carryOverStart(carryOverStartStr);
ATBTime carryOverEnd(carryOverEndStr);
if (carryOverStart.isValid() && carryOverEnd.isValid()) {
TariffCarryOver.m_range = TimeRange(carryOverStart, carryOverEnd, carryOverDuration);
TariffCarryOver.m_weekDay = weekDayName;
if (!d.isNull() && d.isValid()) {
TariffCarryOver.m_date = d;
}
if (!carryOverIf.isEmpty()) {
TariffCarryOver.setCarryOverIf(carryOverIf);
}
// qCritical() << TariffCarryOver;
cfg.TariffCarryOvers.insert(std::pair<int, ATBTariffCarryOver>(weekDay, TariffCarryOver));
}
}
}
}
}
} else {
}
}
}
}
}
}
} else
if (name == "service_settings") {
ATBTariffService TariffService;
if (m->value.IsArray()) {
auto service = m->value.GetArray();
if (service.Size() == 0) {
qCritical() << __func__ << ":" << __LINE__ << "no service settings for" << weekDayName;
} else {
for (rapidjson::SizeType j = 0; j < service.Size(); ++j) {
if (service[j].IsObject()) {
auto serviceSetting = service[j].GetObject();
for (auto n = serviceSetting.MemberBegin(); n != serviceSetting.MemberEnd(); ++n) {
QString const &name = QString::fromStdString(n->name.GetString());
if (name == "service_ranges") {
if (n->value.IsArray()) {
auto serviceRanges = n->value.GetArray();
if (serviceRanges.Size() == 0) {
qCritical() << __func__ << ":" << __LINE__ << "no service ranges for" << weekDayName;
} else {
QString serviceStartStr;
QString serviceEndStr;
QString serviceIf;
int serviceDuration = -1;
for (rapidjson::SizeType i = 0; i < serviceRanges.Size(); ++i) {
if (serviceRanges[j].IsObject()) {
auto serviceRange = serviceRanges[i].GetObject();
for (auto r = serviceRange.MemberBegin(); r != serviceRange.MemberEnd(); ++r) {
QString const &memName = QString::fromStdString(r->name.GetString());
if (memName == "service_id") {
if (r->value.IsInt()) {
TariffService.m_id = r->value.GetInt();
} else {
qCritical() << __func__ << ":" << __LINE__ << "serviceId not an integer";
}
} else
if (memName == "service_duration") {
if (r->value.IsInt()) {
serviceDuration = r->value.GetInt();
}
} else
if (memName == "service_start") {
if (r->value.IsString()) {
serviceStartStr = QString::fromStdString(r->value.GetString());
}
} else
if (memName == "service_end") {
if (r->value.IsString()) {
serviceEndStr = QString::fromStdString(r->value.GetString());
}
} else
if (memName == "service_if") {
if (r->value.IsString()) {
serviceIf = QString::fromStdString(r->value.GetString());
}
} else {
qCritical() << __func__ << ":" << __LINE__ << "WARNING unknown service setting" << memName;
}
}
}
if (!serviceStartStr.isEmpty() && !serviceEndStr.isEmpty() && serviceDuration != -1) {
ATBTime serviceStart(serviceStartStr);
ATBTime serviceEnd(serviceEndStr);
if (serviceStart.isValid() && serviceEnd.isValid()) {
TariffService.m_range = TimeRange(serviceStart, serviceEnd, serviceDuration);
TariffService.m_weekDay = weekDayName;
if (!d.isNull() && d.isValid()) {
TariffService.m_date = d;
}
if (!serviceIf.isEmpty()) {
TariffService.setServiceIf(serviceIf);
}
// qCritical() << TariffService;
cfg.TariffServices.insert(std::pair<int, ATBTariffService>(weekDay, TariffService));
}
}
}
}
}
} else {
}
}
}
}
}
}
} else
if (name == "out_of_service_settings") {
ATBTariffOutOfService TariffOutOfService;
if (m->value.IsArray()) {
auto outOfService = m->value.GetArray();
if (outOfService.Size() == 0) {
qCritical() << __func__ << ":" << __LINE__ << "no out of service settings for" << weekDayName;
} else {
for (rapidjson::SizeType j = 0; j < outOfService.Size(); ++j) {
if (outOfService[j].IsObject()) {
auto outOfServiceSetting = outOfService[j].GetObject();
for (auto n = outOfServiceSetting.MemberBegin(); n != outOfServiceSetting.MemberEnd(); ++n) {
QString const &name = QString::fromStdString(n->name.GetString());
if (name == "out_of_service_ranges") {
if (n->value.IsArray()) {
auto outOfServiceRanges = n->value.GetArray();
if (outOfServiceRanges.Size() == 0) {
qCritical() << __func__ << ":" << __LINE__ << "no out of service ranges for" << weekDayName;
} else {
QString outOfServiceStartStr;
QString outOfServiceEndStr;
QString outOfServiceIf;
int outOfServiceDuration = -1;
for (rapidjson::SizeType i = 0; i < outOfServiceRanges.Size(); ++i) {
if (outOfServiceRanges[j].IsObject()) {
auto outOfServiceRange = outOfServiceRanges[i].GetObject();
for (auto r = outOfServiceRange.MemberBegin(); r != outOfServiceRange.MemberEnd(); ++r) {
QString const &memName = QString::fromStdString(r->name.GetString());
if (memName == "out_of_service_id") {
if (r->value.IsInt()) {
TariffOutOfService.m_id = r->value.GetInt();
} else {
qCritical() << __func__ << ":" << __LINE__ << "outOfServiceId not an integer";
}
} else
if (memName == "out_of_service_duration") {
if (r->value.IsInt()) {
outOfServiceDuration = r->value.GetInt();
}
} else
if (memName == "out_of_service_start") {
if (r->value.IsString()) {
outOfServiceStartStr = QString::fromStdString(r->value.GetString());
}
} else
if (memName == "out_of_service_end") {
if (r->value.IsString()) {
outOfServiceEndStr = QString::fromStdString(r->value.GetString());
}
} else
if (memName == "out_of_service_if") {
if (r->value.IsString()) {
outOfServiceIf = QString::fromStdString(r->value.GetString());
}
} else {
qCritical() << __func__ << ":" << __LINE__ << "WARNING unknown out of service setting" << memName;
}
}
}
if (!outOfServiceStartStr.isEmpty() && !outOfServiceEndStr.isEmpty() && outOfServiceDuration != -1) {
ATBTime outOfServiceStart(outOfServiceStartStr);
ATBTime outOfServiceEnd(outOfServiceEndStr);
if (outOfServiceStart.isValid() && outOfServiceEnd.isValid()) {
TariffOutOfService.m_range = TimeRange(outOfServiceStart, outOfServiceEnd, outOfServiceDuration);
TariffOutOfService.m_weekDay = weekDayName;
if (!d.isNull() && d.isValid()) {
TariffOutOfService.m_date = d;
}
if (!outOfServiceIf.isEmpty()) {
TariffOutOfService.setOutOfServiceIf(outOfServiceIf);
}
// qCritical() << TariffOutOfService;
cfg.TariffOutOfServices.insert(std::pair<int, ATBTariffOutOfService>(weekDay, TariffOutOfService));
}
}
}
}
}
} else {
}
}
}
}
}
}
} else {
}
}
}
} else
if (innerObjName == QString("week_day_default")) {
if (k->value.IsObject()) {
auto obj = k->value.GetObject();

View File

@@ -427,6 +427,8 @@ PaymentMethod Utilities::getPaymentMethodId(Configuration const *cfg) {
return PaymentMethod::Degressive;
case PaymentMethod::Progressive:
return PaymentMethod::Progressive;
case PaymentMethod::Unified:
return PaymentMethod::Unified;
}
}

View File

@@ -755,7 +755,7 @@ int main() {
int pop_max_price;
int pop_daily_card_price;
int zone = 3;
int zone = 1;
if (zone == 1) {
input.open("/opt/ptu5/opt/customer_502/etc/psa_tariff/tariff01.json");
@@ -844,7 +844,7 @@ int main() {
CalcState calcState;
QDateTime s(QDateTime::currentDateTime());
s.setTime(QTime(12, 0, 0));
// s.setTime(QTime(12, 0, 0));
//calcState = compute_duration_for_parking_ticket(&cfg, s,
// (double)1200, end, PermitType(PERMIT_TYPE::SHORT_TERM_PARKING_PKW));
@@ -852,9 +852,26 @@ int main() {
//qCritical() << calcState.toString();
calcState = compute_duration_for_parking_ticket(&cfg, s,
(double)50, end, PermitType(PERMIT_TYPE::SHORT_TERM_PARKING_BUS));
(double)9000, end, PermitType(PERMIT_TYPE::SHORT_TERM_PARKING_BUS));
qCritical() << end.toString(Qt::ISODate);
qCritical() << calcState.toString();
struct price_t costs;
CalcState cs;
for (int i = 0, j=timeSteps.size() ; i < timeSteps.size(); --j, ++i) {
QDateTime end = start.addSecs(timeSteps.at(i)*60);
qCritical() << "XXXXX end" << end.toString(Qt::ISODate);
cs = compute_price_for_parking_ticket(&cfg, s, timeSteps.at(i), end, &costs,
PermitType(PERMIT_TYPE::SHORT_TERM_PARKING));
if (cs.getStatus() != CalcState::State::SUCCESS) {
qCritical() << "ERROR STATUS" << costs.netto;
exit(-1);
}
}
}
if (zone == 2) {
@@ -1391,7 +1408,8 @@ int main() {
case 2: {
qCritical() << " ZONE 2: KURZZEIT 1";
// kuzzeit-1-tarif
input.open("/opt/ptu5/opt/customer_249/etc/psa_tariff/tariff02.json");
//input.open("/opt/ptu5/opt/customer_249/etc/psa_tariff/tariff02.json");
input.open("/opt/ptu5/opt/customer_249/etc/psa_tariff/tariff05.json");
//pop_max_time = 5*60;
} break;
case 3: {
@@ -1583,7 +1601,8 @@ int main() {
break;
case 1:
//start = QDateTime(QDate(2024, 10, 3), QTime(17, 0, 0)); // sunday
start = QDateTime(QDate(2024, 9, 8), QTime(16, 2, 0)); // sunday
//start = QDateTime(QDate(2025, 4, 20), QTime(18, 0, 0)); // sunday
start = QDateTime(QDate(2024, 9, 27), QTime(17, 0, 0)); // friday
fail = false;
break;
case 2:
@@ -1615,8 +1634,8 @@ int main() {
// << "START" << start.toString(Qt::ISODate)
// << "<duration" << *step;
// if (*step != 180)
// continue;
if (*step != 180)
continue;
double cost = 0;

View File

@@ -38,7 +38,8 @@ OTHER_FILES += \
/opt/ptu5/opt/customer_249/etc/psa_tariff/tariff04.json \
/opt/ptu5/opt/customer_249/etc/psa_tariff/tariff05.json \
/opt/ptu5/opt/customer_249/etc/psa_tariff/tariff06.json \
/opt/ptu5/opt/customer_249/etc/psa_tariff/tariff07.json
/opt/ptu5/opt/customer_249/etc/psa_tariff/tariff07.json \
/opt/ptu5/opt/customer_249/etc/psa_tariff/tariff08.json