Add parsing for new values in helper-structures.
NOTE: unfortunately switched to Unix-File-Format.
This commit is contained in:
parent
1240abbbec
commit
e2c02420f0
@ -1,9 +1,11 @@
|
||||
#include "configuration.h"
|
||||
#include "utilities.h"
|
||||
#include "tariff_timebase.h"
|
||||
#include "time_range_header.h"
|
||||
#include "tariff_timestep_config.h"
|
||||
#include "tariff_permit_type.h"
|
||||
#include "tariff_business_hours.h"
|
||||
#include "tariff_global_defines.h"
|
||||
|
||||
#include <QString>
|
||||
#include <QDebug>
|
||||
@ -414,10 +416,24 @@ bool Configuration::ParseJson(Configuration* cfg, const char* json)
|
||||
this->currentPaymentOptions.last().pop_carry_over = k->value.GetInt();
|
||||
} else if (strcmp(inner_obj_name, "pop_carry_over_time_range_id") == 0) {
|
||||
this->currentPaymentOptions.last().pop_carry_over_time_range_id = k->value.GetInt();
|
||||
} else if (strcmp(inner_obj_name, "pop_carry_over_start_time_range") == 0) {
|
||||
this->currentPaymentOptions.last().pop_carry_over_start_time_range = k->value.GetInt();
|
||||
} else if (strcmp(inner_obj_name, "pop_carry_over_end_time_range") == 0) {
|
||||
this->currentPaymentOptions.last().pop_carry_over_end_time_range = k->value.GetInt();
|
||||
} else if (strcmp(inner_obj_name, "pop_daily_card_price") == 0) {
|
||||
this->currentPaymentOptions.last().pop_daily_card_price = k->value.GetInt();
|
||||
} else if (strcmp(inner_obj_name, "pop_business_hours") == 0) {
|
||||
this->currentPaymentOptions.last().pop_business_hours = k->value.GetInt();
|
||||
if (k->value.IsInt()) {
|
||||
int const v = k->value.GetInt();
|
||||
this->currentPaymentOptions.last().pop_business_hours = v;
|
||||
} else
|
||||
if (k->value.IsString()) {
|
||||
bool ok;
|
||||
uint64_t const v = QString::fromStdString(k->value.GetString()).toLongLong(&ok);
|
||||
if (ok) {
|
||||
this->currentPaymentOptions.last().pop_business_hours = v;
|
||||
}
|
||||
}
|
||||
} else if (strcmp(inner_obj_name, "pop_time_step_config") == 0) {
|
||||
this->currentPaymentOptions.last().pop_time_step_config = k->value.GetInt();
|
||||
}
|
||||
@ -454,7 +470,8 @@ bool Configuration::ParseJson(Configuration* cfg, const char* json)
|
||||
else if (strcmp(inner_obj_name, "ped_date_start") == 0) SpecialDays.ped_date_start = k->value.GetString();
|
||||
else if (strcmp(inner_obj_name, "ped_date_end") == 0) SpecialDays.ped_date_end = k->value.GetString();
|
||||
else if (strcmp(inner_obj_name, "ped_period_special_day_id") == 0) SpecialDays.ped_period_special_day_id = k->value.GetInt();
|
||||
else if (strcmp(inner_obj_name, "ped_year") == 0) SpecialDays.ped_year = k->value.GetInt();
|
||||
else if (strcmp(inner_obj_name, "ped_payment_option_id") == 0) SpecialDays.ped_payment_option_id = k->value.GetInt();
|
||||
else if (strcmp(inner_obj_name, "ped_year") == 0) SpecialDays.ped_year = k->value.GetInt();
|
||||
break;
|
||||
case MemberType::PeriodYearType:
|
||||
if (strcmp(inner_obj_name, "pye_id") == 0) YearPeriod.pye_id = k->value.GetInt();
|
||||
@ -543,68 +560,126 @@ bool Configuration::ParseJson(Configuration* cfg, const char* json)
|
||||
}
|
||||
}
|
||||
|
||||
int Configuration::getCurrentPaymentOptionIndex(QDateTime const &dt) const {
|
||||
int Configuration::getPaymentOptionIndexIfSpecialDay(QDateTime const &dt) const {
|
||||
if (isSpecialDay(dt)) {
|
||||
int const numOptions = getAllPaymentOptions().size();
|
||||
for (int opt=0; opt < numOptions; ++opt) {
|
||||
uint64_t const pop_business_hours = getPaymentOptions(opt).pop_business_hours;
|
||||
if ((pop_business_hours & BusinessHours::OFFICIAL_HOLIDAY) == BusinessHours::OFFICIAL_HOLIDAY) {
|
||||
return opt;
|
||||
}
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
int Configuration::getPaymentOptionIndex(QDateTime const &dt) const {
|
||||
int const numOptions = getAllPaymentOptions().size();
|
||||
|
||||
// special days are handled before usual week days
|
||||
int const sid = specialDayId(dt);
|
||||
if (sid > 0) {
|
||||
ATBSpecialDays const sd = specialDay(dt);
|
||||
if (sd.ped_id != 0) {
|
||||
for (int opt=0; opt < numOptions; ++opt) {
|
||||
uint64_t const pop_id = getPaymentOptions(opt).pop_id;
|
||||
if (pop_id == sd.ped_payment_option_id) {
|
||||
return opt;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (int opt=0; opt < numOptions; ++opt) {
|
||||
uint64_t const pop_business_hours = getPaymentOptions(opt).pop_business_hours;
|
||||
|
||||
|
||||
uint64_t p = 0;
|
||||
switch (dt.date().dayOfWeek()) {
|
||||
int const dayOfWeek = dt.date().dayOfWeek();
|
||||
|
||||
switch (dayOfWeek) {
|
||||
case (int)Qt::Monday: {
|
||||
p = BusinessHours::MON;
|
||||
if ((pop_business_hours & p) == p) {
|
||||
return opt;
|
||||
}
|
||||
} break;
|
||||
case (int)Qt::Tuesday: {
|
||||
p = BusinessHours::TUE;
|
||||
if ((pop_business_hours & p) == p) {
|
||||
return opt;
|
||||
}
|
||||
} break;
|
||||
case (int)Qt::Wednesday: {
|
||||
p = BusinessHours::WED;
|
||||
if ((pop_business_hours & p) == p) {
|
||||
return opt;
|
||||
}
|
||||
} break;
|
||||
case (int)Qt::Thursday: {
|
||||
p = BusinessHours::THU;
|
||||
if ((pop_business_hours & p) == p) {
|
||||
return opt;
|
||||
}
|
||||
} break;
|
||||
case (int)Qt::Friday: {
|
||||
p = BusinessHours::FRI;
|
||||
if ((pop_business_hours & p) == p) {
|
||||
return opt;
|
||||
}
|
||||
} break;
|
||||
case (int)Qt::Saturday: {
|
||||
p = BusinessHours::SAT;
|
||||
if ((pop_business_hours & p) == p) {
|
||||
return opt;
|
||||
}
|
||||
} break;
|
||||
case (int)Qt::Sunday: {
|
||||
p = BusinessHours::SUN;
|
||||
if (isHoliday(dt)) {
|
||||
p |= BusinessHours::OFFICIAL_HOLIDAY;
|
||||
}
|
||||
if ((pop_business_hours & p) == p) {
|
||||
return opt;
|
||||
}
|
||||
qCritical() << DBG_HEADER << Utilities::dumpBusinessHours(pop_business_hours) << pop_business_hours << p;
|
||||
} break;
|
||||
}
|
||||
|
||||
if ((pop_business_hours & p) == p) {
|
||||
return opt;
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
bool Configuration::isHoliday(QDateTime const &dt) const {
|
||||
ATBSpecialDays Configuration::specialDay(QDateTime const &dt) const {
|
||||
SpecialDaysType::const_iterator it;
|
||||
for (it = SpecialDays.cbegin(); it != SpecialDays.cend(); ++it) {
|
||||
if (dt.date().toString(Qt::ISODate) == QString::fromStdString(it->second.ped_date_start)) {
|
||||
return it->second;
|
||||
}
|
||||
}
|
||||
|
||||
return ATBSpecialDays();
|
||||
}
|
||||
|
||||
int Configuration::specialDayId(QDateTime const &dt) const {
|
||||
SpecialDaysType::const_iterator it;
|
||||
for (it = SpecialDays.cbegin(); it != SpecialDays.cend(); ++it) {
|
||||
if (dt.date().toString(Qt::ISODate) == QString::fromStdString(it->second.ped_date_start)) {
|
||||
int const specialDayId = it->second.ped_id;
|
||||
return specialDayId; // must be > 0
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool Configuration::isSpecialDay(QDateTime const &dt) const {
|
||||
return (specialDayId(dt) > 0);
|
||||
}
|
||||
|
||||
bool Configuration::isDayIncludedAsSpecialDay(uint64_t businessHours, int specialDayId) const {
|
||||
if (specialDayId > 0) {
|
||||
bool const &r = ((businessHours & BusinessHours::OFFICIAL_HOLIDAY) == BusinessHours::OFFICIAL_HOLIDAY);
|
||||
return r;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Configuration::isDayIncludedAsSpecialDay(uint64_t businessHours, QDateTime const &dt) const {
|
||||
// included in 'businessHours'
|
||||
|
||||
if (isSpecialDay(dt)) {
|
||||
bool const &r = ((businessHours & BusinessHours::OFFICIAL_HOLIDAY) == BusinessHours::OFFICIAL_HOLIDAY);
|
||||
qCritical() << "XXXXXXXXXXXXXXXXXX r" << r << businessHours;
|
||||
return r;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Configuration::isDayIncluded(uint64_t businessHours, QDateTime const &dt) const {
|
||||
return Utilities::isDayIncluded(businessHours, dt);
|
||||
}
|
||||
|
||||
ATBPaymentOption const &Configuration::getPaymentOptions(int paymentOptionsIndex) const {
|
||||
Q_ASSERT(!this->currentPaymentOptions.isEmpty());
|
||||
return this->currentPaymentOptions.at(paymentOptionsIndex);
|
||||
|
Loading…
Reference in New Issue
Block a user