Added parsing of new variables from conf-files

This commit is contained in:
Gerhard Hoffmann 2023-02-01 15:07:55 +01:00
parent a8484000cc
commit da762b0441

View File

@ -17,7 +17,12 @@
using namespace rapidjson; using namespace rapidjson;
#define FREE_OF_CHARGE "free_of_charge" #define DAY_TARIFF_START "day_tariff_start"
#define DAY_TARIFF_END "day_tariff_end"
#define NIGHT_TARIFF_START "night_tariff_start"
#define NIGHT_TARIFF_END "night_tariff_end"
#define FREE_OF_CHARGE_DAY_TARIFF "free_of_charge_day_tariff"
#define FREE_OF_CHARGE_NIGHT_TARIFF "free_of_charge_night_tariff"
#define UNIT_SCALE_FACTOR "unit_scale_factor" #define UNIT_SCALE_FACTOR "unit_scale_factor"
#define UNIT_DEFINITION "unit_definition" #define UNIT_DEFINITION "unit_definition"
#define VAT "vat" #define VAT "vat"
@ -29,6 +34,9 @@ using namespace rapidjson;
#define WAITING_PERIOD "waiting_period" #define WAITING_PERIOD "waiting_period"
#define PARKING_TIME_MIN "parking_time_min" #define PARKING_TIME_MIN "parking_time_min"
#define PARKING_TIME_MAX "parking_time_max" #define PARKING_TIME_MAX "parking_time_max"
#define BASIC_TARIFF "basic_tariff"
#define MAX_PRICE_24H_AFTER_ARRIVAL "max_price_24h_after_arrival"
#define MAX_PRICE_AT_MIDNIGHT "max_price_at_midnight"
static const char *weekStr[] { static const char *weekStr[] {
"week1", "week2", "week3" "week1", "week2", "week3"
@ -89,6 +97,34 @@ parking_tariff_t *parking_tariff_t::parseTariff(const char *confFile) {
sizeof(tariff->_tariff_features)); sizeof(tariff->_tariff_features));
} }
} }
if (d.HasMember(DAY_TARIFF_START)) {
Value::MemberIterator o = d.FindMember(DAY_TARIFF_START);
assert(o != d.MemberEnd());
assert(o->value.IsString());
std::string s = o->value.GetString();
tariff->day_tariff_start = std::stoi(s);
}
if (d.HasMember(DAY_TARIFF_END)) {
Value::MemberIterator o = d.FindMember(DAY_TARIFF_END);
assert(o != d.MemberEnd());
assert(o->value.IsString());
std::string s = o->value.GetString();
tariff->day_tariff_end = std::stoi(s);
}
if (d.HasMember(NIGHT_TARIFF_START)) {
Value::MemberIterator o = d.FindMember(NIGHT_TARIFF_START);
assert(o != d.MemberEnd());
assert(o->value.IsString());
std::string s = o->value.GetString();
tariff->night_tariff_start = std::stoi(s);
}
if (d.HasMember(NIGHT_TARIFF_END)) {
Value::MemberIterator o = d.FindMember(NIGHT_TARIFF_END);
assert(o != d.MemberEnd());
assert(o->value.IsString());
std::string s = o->value.GetString();
tariff->night_tariff_end = std::stoi(s);
}
if (d.HasMember(WAITING_PERIOD)) { if (d.HasMember(WAITING_PERIOD)) {
Value::MemberIterator o = d.FindMember(WAITING_PERIOD); Value::MemberIterator o = d.FindMember(WAITING_PERIOD);
assert(o != d.MemberEnd()); assert(o != d.MemberEnd());
@ -96,12 +132,19 @@ parking_tariff_t *parking_tariff_t::parseTariff(const char *confFile) {
std::string wp = o->value.GetString(); std::string wp = o->value.GetString();
tariff->waiting_period = std::stoi(wp); tariff->waiting_period = std::stoi(wp);
} }
if (d.HasMember(FREE_OF_CHARGE)) { if (d.HasMember(FREE_OF_CHARGE_DAY_TARIFF)) {
Value::MemberIterator o = d.FindMember(FREE_OF_CHARGE); Value::MemberIterator o = d.FindMember(FREE_OF_CHARGE_DAY_TARIFF);
assert(o != d.MemberEnd()); assert(o != d.MemberEnd());
assert(o->value.IsString()); assert(o->value.IsString());
std::string foc = o->value.GetString(); std::string foc = o->value.GetString();
tariff->free_of_charge = std::stoi(foc); tariff->free_of_charge_day_tariff = std::stoi(foc);
}
if (d.HasMember(FREE_OF_CHARGE_NIGHT_TARIFF)) {
Value::MemberIterator o = d.FindMember(FREE_OF_CHARGE_NIGHT_TARIFF);
assert(o != d.MemberEnd());
assert(o->value.IsString());
std::string foc = o->value.GetString();
tariff->free_of_charge_night_tariff = std::stoi(foc);
} }
if (d.HasMember(UNIT_SCALE_FACTOR)) { if (d.HasMember(UNIT_SCALE_FACTOR)) {
Value::MemberIterator o = d.FindMember(UNIT_SCALE_FACTOR); Value::MemberIterator o = d.FindMember(UNIT_SCALE_FACTOR);
@ -160,18 +203,40 @@ parking_tariff_t *parking_tariff_t::parseTariff(const char *confFile) {
std::string mp = o->value.GetString(); std::string mp = o->value.GetString();
if (mp == "unlimited") { if (mp == "unlimited") {
tariff->max_price_for_24_hours = ~0; tariff->max_price_for_24_hours = ~0;
} else if (mp == "n/a") {
tariff->max_price_for_24_hours = 0;
} else { } else {
tariff->max_price_for_24_hours = (uint32_t)std::stoul(mp); tariff->max_price_for_24_hours = (uint32_t)std::stoul(mp);
} }
} }
if (d.HasMember(BASIC_TARIFF)) {
Value::MemberIterator o = d.FindMember(BASIC_TARIFF);
assert(o != d.MemberEnd());
assert(o->value.IsString());
std::string s = o->value.GetString();
tariff->basic_tariff = (s == "1");
}
if (d.HasMember(MAX_PRICE_24H_AFTER_ARRIVAL)) {
Value::MemberIterator o = d.FindMember(MAX_PRICE_24H_AFTER_ARRIVAL);
assert(o != d.MemberEnd());
assert(o->value.IsString());
std::string s = o->value.GetString();
tariff->max_price_24h_after_arrival = (uint32_t)std::stoul(s);
}
if (d.HasMember(MAX_PRICE_AT_MIDNIGHT)) {
Value::MemberIterator o = d.FindMember(MAX_PRICE_AT_MIDNIGHT);
assert(o != d.MemberEnd());
assert(o->value.IsString());
std::string s = o->value.GetString();
tariff->max_price_at_midnight = (uint32_t)std::stoul(s);
}
QDate today = QDate::currentDate(); QDate today = QDate::currentDate();
int const todayWeekDay = today.dayOfWeek(); // qt: 1 (mon) - 7 (sun) int const todayWeekDay = today.dayOfWeek(); // qt: 1 (mon) - 7 (sun)
if (todayWeekDay > Qt::Monday) { if (todayWeekDay > Qt::Monday) {
int day = today.day(); today = today.addDays(Qt::Monday - todayWeekDay);
day -= (todayWeekDay - Qt::Monday); if (!today.isValid()) {
if (!today.setDate(today.year(), today.month(), day)) {
qFatal("Setting today failed"); qFatal("Setting today failed");
} }
} }