Added parsing for tariff05.json (bad neuenarh (249))
This commit is contained in:
parent
576c3fefdd
commit
1347f1f208
@ -10,6 +10,9 @@
|
|||||||
#include "tariff_global_defines.h"
|
#include "tariff_global_defines.h"
|
||||||
#include "tariff_settings.h"
|
#include "tariff_settings.h"
|
||||||
#include "tariff_carryover_settings.h"
|
#include "tariff_carryover_settings.h"
|
||||||
|
#include "atb_time.h"
|
||||||
|
#include "tariff_prepaid.h"
|
||||||
|
#include "tariff_carryover.h"
|
||||||
|
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
@ -61,6 +64,405 @@ ATBWeekDay parseWeekDay(Configuration &cfg,
|
|||||||
ATBWeekDay WeekDay;
|
ATBWeekDay WeekDay;
|
||||||
QTime start, end, parking_time_limit, about_to_exceed_limit;
|
QTime start, end, parking_time_limit, about_to_exceed_limit;
|
||||||
ATBTariffCarryOverSettings::ParkingTimeLimitChecker parkTimeLimitChecker;
|
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 (innerObjName == QString("week_day_default")) {
|
||||||
if (k->value.IsObject()) {
|
if (k->value.IsObject()) {
|
||||||
auto obj = k->value.GetObject();
|
auto obj = k->value.GetObject();
|
||||||
|
Loading…
Reference in New Issue
Block a user