Added parsing for Interpolation, CarryOver and Prepaid-options. Has to be formatted.w
This commit is contained in:
parent
f2356bec55
commit
2a89f90745
@ -6,6 +6,7 @@
|
||||
#include "tariff_permit_type.h"
|
||||
#include "tariff_business_hours.h"
|
||||
#include "tariff_global_defines.h"
|
||||
#include "tariff_carryover.h"
|
||||
|
||||
#include <QString>
|
||||
#include <QDebug>
|
||||
@ -30,6 +31,9 @@ MemberType Configuration::IdentifyJsonMember(const char* member_name)
|
||||
if (strcmp(member_name, "TimeRange") == 0) return MemberType::TimeRangeType;
|
||||
if (strcmp(member_name, "TimeStepConfig") == 0) return MemberType::TimeStepConfigType;
|
||||
if (strcmp(member_name, "Product") == 0) return MemberType::ProductType;
|
||||
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;
|
||||
else return MemberType::UnknownType;
|
||||
}
|
||||
|
||||
@ -100,6 +104,9 @@ bool Configuration::ParseJson(Configuration* cfg, const char* json)
|
||||
ATBTimeRange TimeRange;
|
||||
ATBTimeStepConfig TimeStepConfig;
|
||||
ATBTariffProduct TariffProduct;
|
||||
ATBInterpolation TariffInterpolation;
|
||||
ATBPrepaid TariffPrepaidOption;
|
||||
ATBCarryOver TariffCarryOver;
|
||||
|
||||
MemberType mb_type = MemberType::UnknownType;
|
||||
this->currentPaymentOptions.clear();
|
||||
@ -164,6 +171,167 @@ bool Configuration::ParseJson(Configuration* cfg, const char* json)
|
||||
{
|
||||
case MemberType::UnknownType:
|
||||
break;
|
||||
case MemberType::CarryOverType: {
|
||||
if (QString(inner_obj_name) == QString("carry_over_id")) {
|
||||
if (k->value.IsInt()) {
|
||||
int const &x = k->value.GetInt();
|
||||
TariffCarryOver.id = x;
|
||||
}
|
||||
} else
|
||||
if (QString(inner_obj_name) == QString("carry_over_week")) {
|
||||
if (k->value.IsArray()) {
|
||||
auto days = k->value.GetArray();
|
||||
for (rapidjson::SizeType j=0; j < days.Size(); ++j) {
|
||||
if (days[j].IsObject()) {
|
||||
auto weekday = days[j].GetObject();
|
||||
for (auto w = weekday.MemberBegin(); w != weekday.MemberEnd(); ++w) {
|
||||
int day = j+1; // 8 entries
|
||||
QString member(QString::fromStdString(w->name.GetString()));
|
||||
if (member == "carry_over_day") {
|
||||
if (w->value.IsInt()) {
|
||||
rapidjson::SizeType const d = w->value.GetInt();
|
||||
if (d != (j+1)) {
|
||||
qCritical() << "ERROR: misconfigured jsonfile" << d << "!=" << (j+1);
|
||||
}
|
||||
TariffCarryOver.carryover[day].day = day;
|
||||
}
|
||||
} else
|
||||
if (member == "carry_over_seemless") {
|
||||
if (w->value.IsBool()) {
|
||||
bool b = w->value.GetBool();
|
||||
TariffCarryOver.carryover[day].seemless = b;
|
||||
}
|
||||
} else
|
||||
if (member == "carry_over_never") {
|
||||
if (w->value.IsBool()) {
|
||||
bool b = w->value.GetBool();
|
||||
TariffCarryOver.carryover[day].never = b;
|
||||
}
|
||||
} else
|
||||
if (member == "carry_over_static_start") {
|
||||
if (w->value.IsString()) {
|
||||
QTime const &t = QTime::fromString(w->value.GetString(), Qt::ISODate);
|
||||
TariffCarryOver.carryover[day].static_start = t;
|
||||
}
|
||||
} else
|
||||
if (member == "carry_over_static_end") {
|
||||
if (w->value.IsString()) {
|
||||
QTime const &t = QTime::fromString(w->value.GetString(), Qt::ISODate);
|
||||
TariffCarryOver.carryover[day].static_end = t;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} break;
|
||||
case MemberType::PrepaidType: {
|
||||
if (QString(inner_obj_name) == QString("prepaid_id")) {
|
||||
if (k->value.IsInt()) {
|
||||
int const &x = k->value.GetInt();
|
||||
TariffPrepaidOption.id = x;
|
||||
}
|
||||
} else
|
||||
if (QString(inner_obj_name) == QString("prepaid_anytime")) {
|
||||
if (k->value.IsBool()) {
|
||||
bool const &x = k->value.GetBool();
|
||||
TariffPrepaidOption.anytime = x;
|
||||
}
|
||||
} else
|
||||
if (QString(inner_obj_name) == QString("prepaid_never")) {
|
||||
if (k->value.IsBool()) {
|
||||
bool const &x = k->value.GetBool();
|
||||
TariffPrepaidOption.never = x;
|
||||
}
|
||||
} else
|
||||
if (QString(inner_obj_name) == QString("prepaid_static_start")) {
|
||||
if (k->value.IsString()) {
|
||||
QTime const &t = QTime::fromString(k->value.GetString(), Qt::ISODate);
|
||||
TariffPrepaidOption.static_start = t;
|
||||
}
|
||||
} else
|
||||
if (QString(inner_obj_name) == QString("prepaid_static_end")) {
|
||||
if (k->value.IsString()) {
|
||||
QTime const &t = QTime::fromString(k->value.GetString(), Qt::ISODate);
|
||||
TariffPrepaidOption.static_end = t;
|
||||
}
|
||||
}
|
||||
} break;
|
||||
case MemberType::InterpolationType: {
|
||||
if (QString(inner_obj_name) == QString("interpol_id")) {
|
||||
if (k->value.IsInt()) {
|
||||
int const &x = k->value.GetInt();
|
||||
TariffInterpolation.id = x;
|
||||
}
|
||||
} else
|
||||
if (QString(inner_obj_name) == QString("interpol_static_start")) {
|
||||
if (k->value.IsString()) {
|
||||
QTime const &t = QTime::fromString(k->value.GetString(), Qt::ISODate);
|
||||
TariffInterpolation.static_start = t;
|
||||
}
|
||||
} else
|
||||
if (QString(inner_obj_name) == QString("interpol_static_end")) {
|
||||
if (k->value.IsString()) {
|
||||
QTime const &t = QTime::fromString(k->value.GetString(), Qt::ISODate);
|
||||
TariffInterpolation.static_end = t;
|
||||
}
|
||||
} else
|
||||
if (QString(inner_obj_name) == QString("interpol_static_start_str")) {
|
||||
if (k->value.IsString()) {
|
||||
QString const &s = k->value.GetString();
|
||||
TariffInterpolation.static_start_str = s;
|
||||
}
|
||||
} else
|
||||
if (QString(inner_obj_name) == QString("interpol_static_end_str")) {
|
||||
if (k->value.IsString()) {
|
||||
QString const &s = k->value.GetString();
|
||||
TariffInterpolation.static_end_str = s;
|
||||
}
|
||||
} else
|
||||
if (QString(inner_obj_name) == QString("interpol_static_duration")) {
|
||||
if (k->value.IsInt()) {
|
||||
int const x = k->value.GetInt();
|
||||
TariffInterpolation.static_duration = x;
|
||||
}
|
||||
} else
|
||||
if (QString(inner_obj_name) == QString("interpol_dynamic_start")) {
|
||||
if (k->value.IsString()) {
|
||||
QTime const &t = QTime::fromString(k->value.GetString(), Qt::ISODate);
|
||||
TariffInterpolation.dynamic_start = t;
|
||||
}
|
||||
} else
|
||||
if (QString(inner_obj_name) == QString("interpol_dynamic_end")) {
|
||||
if (k->value.IsString()) {
|
||||
QTime const &t = QTime::fromString(k->value.GetString(), Qt::ISODate);
|
||||
TariffInterpolation.dynamic_end = t;
|
||||
}
|
||||
} else
|
||||
if (QString(inner_obj_name) == QString("interpol_dynamic_start_str")) {
|
||||
if (k->value.IsString()) {
|
||||
QString const &s = k->value.GetString();
|
||||
TariffInterpolation.dynamic_start_str = s;
|
||||
}
|
||||
} else
|
||||
if (QString(inner_obj_name) == QString("interpol_dynamic_end_str")) {
|
||||
if (k->value.IsString()) {
|
||||
QString const &s = k->value.GetString();
|
||||
TariffInterpolation.dynamic_end_str = s;
|
||||
}
|
||||
} else
|
||||
if (QString(inner_obj_name) == QString("interpol_dynamic_duration")) {
|
||||
if (k->value.IsInt()) {
|
||||
int const x = k->value.GetInt();
|
||||
TariffInterpolation.dynamic_duration = x;
|
||||
}
|
||||
} else
|
||||
if (QString(inner_obj_name) == QString("interpol_dynamic_until_price")) {
|
||||
if (k->value.IsInt()) {
|
||||
int const x = k->value.GetInt();
|
||||
TariffInterpolation.dynamic_until_price = x;
|
||||
}
|
||||
}
|
||||
} break;
|
||||
case MemberType::ProductType: {
|
||||
if (QString(inner_obj_name) == QString("tariff_product_id")) {
|
||||
if (k->value.IsInt()) {
|
||||
@ -413,6 +581,10 @@ bool Configuration::ParseJson(Configuration* cfg, const char* json)
|
||||
this->currentPaymentOptions.last().pop_max_time = k->value.GetDouble();
|
||||
} else if (strcmp(inner_obj_name, "pop_min_price") == 0) {
|
||||
this->currentPaymentOptions.last().pop_min_price = k->value.GetDouble();
|
||||
} else if (strcmp(inner_obj_name, "pop_prepaid_option_id") == 0) {
|
||||
this->currentPaymentOptions.last().pop_prepaid_option_id = k->value.GetInt();
|
||||
} else if (strcmp(inner_obj_name, "pop_carry_over_option_id") == 0) {
|
||||
this->currentPaymentOptions.last().pop_carry_over_option_id = k->value.GetInt();
|
||||
} else if (strcmp(inner_obj_name, "pop_carry_over") == 0) {
|
||||
this->currentPaymentOptions.last().pop_carry_over = k->value.GetInt();
|
||||
} else if (strcmp(inner_obj_name, "pop_carry_over_time_range_id") == 0) {
|
||||
@ -499,6 +671,7 @@ bool Configuration::ParseJson(Configuration* cfg, const char* json)
|
||||
else if (strcmp(inner_obj_name, "pun_duration") == 0) Duration.pun_duration = k->value.GetDouble();
|
||||
else if (strcmp(inner_obj_name, "pun_duration_min") == 0) Duration.pun_duration_min = k->value.GetInt();
|
||||
else if (strcmp(inner_obj_name, "pun_duration_max") == 0) Duration.pun_duration_max = k->value.GetInt();
|
||||
else if (strcmp(inner_obj_name, "pun_interpolation_id") == 0) Duration.pun_interpolation_id = k->value.GetInt();
|
||||
break;
|
||||
case MemberType::SpecialDaysWorktimeType:
|
||||
if (strcmp(inner_obj_name, "pedwt_id") == 0) SpecialDaysWorktime.pedwt_id = k->value.GetInt();
|
||||
@ -562,6 +735,7 @@ bool Configuration::ParseJson(Configuration* cfg, const char* json)
|
||||
} break;
|
||||
case MemberType::DurationType:
|
||||
cfg->Duration.insert(pair<int, ATBDuration>(Duration.pun_id, Duration));
|
||||
// qCritical() << Duration;
|
||||
break;
|
||||
case MemberType::SpecialDaysWorktimeType:
|
||||
cfg->SpecialDaysWorktime.insert(pair<int, ATBSpecialDaysWorktime>(SpecialDaysWorktime.pedwt_period_exc_day_id, SpecialDaysWorktime));
|
||||
@ -602,6 +776,19 @@ bool Configuration::ParseJson(Configuration* cfg, const char* json)
|
||||
case MemberType::ProductType:
|
||||
cfg->TariffProduct.insert(pair<int, ATBTariffProduct>(TariffProduct.m_tariff_product_id, TariffProduct));
|
||||
qCritical() << TariffProduct;
|
||||
break;
|
||||
case MemberType::InterpolationType:
|
||||
cfg->TariffInterpolations.insert(pair<int, ATBInterpolation>(TariffInterpolation.id, TariffInterpolation));
|
||||
qCritical() << TariffInterpolation;
|
||||
break;
|
||||
case MemberType::PrepaidType:
|
||||
cfg->TariffPrepaidOptions.insert(pair<int, ATBPrepaid>(TariffPrepaidOption.id, TariffPrepaidOption));
|
||||
qCritical() << TariffPrepaidOption;
|
||||
break;
|
||||
case MemberType::CarryOverType:
|
||||
cfg->TariffCarryOverOptions.insert(pair<int, ATBCarryOver>(TariffCarryOver.id, TariffCarryOver));
|
||||
qCritical() << TariffCarryOver;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@ -840,6 +1027,47 @@ Configuration::getDailyTicketsForAllKeys() const {
|
||||
return value;
|
||||
}
|
||||
|
||||
std::optional<ATBInterpolation> Configuration::getInterpolationType(int key) const {
|
||||
std::optional<ATBInterpolation> value;
|
||||
for (auto[it, rangeEnd] = this->TariffInterpolations.equal_range(key); it != rangeEnd; ++it) {
|
||||
value = value.value_or(it->second);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
std::optional<ATBPrepaid> Configuration::getPrepaidType(int key) const {
|
||||
std::optional<ATBPrepaid> value;
|
||||
for (auto[it, rangeEnd] = this->TariffPrepaidOptions.equal_range(key); it != rangeEnd; ++it) {
|
||||
value = value.value_or(it->second);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
std::optional<QDateTime> Configuration::adaptStart(QDateTime const &start, int prepaid_option_id) {
|
||||
std::optional<QDateTime> value;
|
||||
QDateTime s = start;
|
||||
|
||||
std::optional<ATBPrepaid> prepaid_option = getPrepaidType(prepaid_option_id);
|
||||
if (prepaid_option.has_value()) {
|
||||
ATBPrepaid prepaid = prepaid_option.value();
|
||||
if (prepaid.anytime == true) {
|
||||
int const weekdayId = s.date().dayOfWeek();
|
||||
QTime worktime_from = QTime::fromString(WeekDaysWorktime.find(weekdayId)->second.pwd_time_from.c_str(), Qt::ISODate);
|
||||
QTime worktime_to = QTime::fromString(WeekDaysWorktime.find(weekdayId)->second.pwd_time_to.c_str(), Qt::ISODate);
|
||||
if (s.time() < worktime_from) {
|
||||
s.setTime(worktime_from);
|
||||
} else
|
||||
if (worktime_to < s.time()) {
|
||||
s = start.addDays(1);
|
||||
s.setTime(worktime_from);
|
||||
}
|
||||
s.setTime(QTime(s.time().hour(), s.time().minute(), 0));
|
||||
value = value.value_or(s);
|
||||
}
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
std::optional<QVector<ATBDailyTicket>>
|
||||
Configuration::getDailyTicketsForKey(int key) const {
|
||||
QVector<ATBDailyTicket> tickets;
|
||||
|
Loading…
Reference in New Issue
Block a user