Compare commits
10 Commits
c153652b3d
...
977356040c
Author | SHA1 | Date | |
---|---|---|---|
977356040c | |||
2a89f90745 | |||
f2356bec55 | |||
2d6ef2d158 | |||
e5d23d8022 | |||
02927be9c9 | |||
c6d396f34b | |||
026c791c79 | |||
927164e23e | |||
507b5d1b9c |
@ -25,6 +25,9 @@
|
||||
#include "time_range_header.h"
|
||||
#include "tariff_timestep_config.h"
|
||||
#include "tariff_product.h"
|
||||
#include "tariff_interpolation.h"
|
||||
#include "tariff_prepaid.h"
|
||||
#include "tariff_carryover.h"
|
||||
|
||||
#include <QVector>
|
||||
#include <optional>
|
||||
@ -41,6 +44,9 @@ public:
|
||||
using TimeRangeType = std::multimap<int, ATBTimeRange>;
|
||||
using TariffProductType = std::multimap<int, ATBTariffProduct>;
|
||||
using ATBPaymentOptionType = std::multimap<int, ATBPaymentOption>;
|
||||
using TariffInterpolationType = std::multimap<int, ATBInterpolation>;
|
||||
using TariffPrepaidType = std::multimap<int, ATBPrepaid>;
|
||||
using TariffCarryOverType = std::multimap<int, ATBCarryOver>;
|
||||
|
||||
ATBProject project;
|
||||
ATBCurrency Currency;
|
||||
@ -61,6 +67,9 @@ public:
|
||||
multimap<int, ATBTimeBase> TimeBase;
|
||||
multimap<int, ATBCustomer> Customer;
|
||||
TariffProductType TariffProduct;
|
||||
TariffInterpolationType TariffInterpolations;
|
||||
TariffPrepaidType TariffPrepaidOptions;
|
||||
TariffCarryOverType TariffCarryOverOptions;
|
||||
|
||||
/// <summary>
|
||||
/// Parse JSON string
|
||||
@ -85,6 +94,8 @@ public:
|
||||
std::optional<QVector<ATBPaymentRate>> getPaymentRateForKey(int key) const;
|
||||
std::optional<QVector<ATBDailyTicket>> getDailyTicketsForAllKeys() const;
|
||||
std::optional<QVector<ATBDailyTicket>> getDailyTicketsForKey(int key) const;
|
||||
std::optional<ATBInterpolation> getInterpolationType(int type) const;
|
||||
std::optional<ATBPrepaid> getPrepaidType(int type) const;
|
||||
std::optional<QVector<ATBTariffProduct>> getTariffProductForAllKeys() const;
|
||||
std::optional<QVector<ATBTariffProduct>> getTariffProductForProductId(int id) const;
|
||||
std::optional<QVector<ATBTariffProduct>> getTariffProductForProductId(PermitType permitType) const;
|
||||
@ -92,6 +103,8 @@ public:
|
||||
std::optional<ATBCustomer> getCustomerForType(ATBCustomer::CustomerType customerType);
|
||||
std::optional<ATBWeekDaysWorktime> getWeekDayWorkTime(QTime const &time, Qt::DayOfWeek dayOfWeek);
|
||||
|
||||
std::optional<QDateTime> adaptStart(QDateTime const &start, int prepaid_option_id);
|
||||
|
||||
private:
|
||||
/// <summary>
|
||||
/// Identify type of JSON member
|
||||
|
@ -1,11 +1,37 @@
|
||||
#include <string>
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
class ATBDuration
|
||||
{
|
||||
public:
|
||||
explicit ATBDuration()
|
||||
: pun_id(0)
|
||||
, pun_label("")
|
||||
, pun_duration(0)
|
||||
, pun_duration_min(0)
|
||||
, pun_duration_max(0)
|
||||
, pun_interpolation_id(-1) {
|
||||
}
|
||||
|
||||
friend QDebug operator<<(QDebug debug, ATBDuration const &td) {
|
||||
QDebugStateSaver saver(debug);
|
||||
|
||||
debug.nospace()
|
||||
<< " pun_id: " << td.pun_id << "\n"
|
||||
<< " pun_label: " << QString::fromStdString(td.pun_label) << "\n"
|
||||
<< " pun_duration: " << td.pun_duration << "\n"
|
||||
<< " pun_duration_min: " << td.pun_duration_min << "\n"
|
||||
<< " pun_duration_max: " << td.pun_duration_max << "\n"
|
||||
<< "pun_interpolation_id: " << td.pun_interpolation_id << "\n";
|
||||
|
||||
return debug;
|
||||
}
|
||||
|
||||
int pun_id;
|
||||
std::string pun_label;
|
||||
int pun_duration;
|
||||
int pun_duration_min;
|
||||
int pun_duration_max;
|
||||
int pun_interpolation_id;
|
||||
};
|
||||
|
@ -19,7 +19,10 @@ enum MemberType
|
||||
TimeBaseType = 0x0C,
|
||||
TimeRangeType = 0x0D,
|
||||
TimeStepConfigType = 0x0E,
|
||||
ProductType = 0x0F
|
||||
ProductType = 0x0F,
|
||||
InterpolationType = 0x10,
|
||||
PrepaidType = 0x11,
|
||||
CarryOverType = 0x12
|
||||
};
|
||||
|
||||
#endif // MEMBER_TYPE_H_INCLUDED
|
||||
|
@ -24,6 +24,8 @@ public:
|
||||
pop_min_price = 0;
|
||||
pop_max_price = 0;
|
||||
pop_carry_over = -1;
|
||||
pop_carry_over_option_id = -1;
|
||||
pop_prepaid_option_id = -1;
|
||||
pop_carry_over_target = false;
|
||||
pop_carry_over_time_range_id = -1;
|
||||
pop_carry_over_start_time_range = -1;
|
||||
@ -44,6 +46,8 @@ public:
|
||||
double pop_min_price;
|
||||
double pop_max_price;
|
||||
int pop_carry_over;
|
||||
int pop_carry_over_option_id;
|
||||
int pop_prepaid_option_id;
|
||||
bool pop_carry_over_target;
|
||||
int pop_carry_over_time_range_id;
|
||||
int pop_carry_over_start_time_range;
|
||||
|
70
library/include/mobilisis/tariff_carryover.h
Normal file
70
library/include/mobilisis/tariff_carryover.h
Normal file
@ -0,0 +1,70 @@
|
||||
#ifndef TARIFF_CARRYOVER_H_INCLUDED
|
||||
#define TARIFF_CARRYOVER_H_INCLUDED
|
||||
|
||||
#include <QTime>
|
||||
|
||||
struct ATBCarryOver {
|
||||
struct week {
|
||||
int day;
|
||||
bool seemless;
|
||||
bool never;
|
||||
QTime static_start;
|
||||
QTime static_end;
|
||||
} carryover[8];
|
||||
|
||||
int id;
|
||||
|
||||
|
||||
friend QDebug operator<<(QDebug debug, ATBCarryOver const &co) {
|
||||
QDebugStateSaver saver(debug);
|
||||
|
||||
debug.nospace()
|
||||
<< " id:" << co.id << "\n"
|
||||
<< " **** Monday **** \n"
|
||||
<< " day: " << co.carryover[(int)Qt::Monday].day << "\n"
|
||||
<< " static_start: " << co.carryover[(int)Qt::Monday].static_start.toString(Qt::ISODate) << "\n"
|
||||
<< " static_end: " << co.carryover[(int)Qt::Monday].static_end.toString(Qt::ISODate) << "\n"
|
||||
<< " anytime: " << co.carryover[(int)Qt::Monday].seemless << "\n"
|
||||
<< " never: " << co.carryover[(int)Qt::Monday].never << "\n"
|
||||
<< " **** Tuesday **** \n"
|
||||
<< " day: " << co.carryover[(int)Qt::Tuesday].day << "\n"
|
||||
<< " static_start: " << co.carryover[(int)Qt::Tuesday].static_start.toString(Qt::ISODate) << "\n"
|
||||
<< " static_end: " << co.carryover[(int)Qt::Tuesday].static_end.toString(Qt::ISODate) << "\n"
|
||||
<< " anytime: " << co.carryover[(int)Qt::Tuesday].seemless << "\n"
|
||||
<< " never: " << co.carryover[(int)Qt::Tuesday].never << "\n"
|
||||
<< " **** Wednesday **** \n"
|
||||
<< " day: " << co.carryover[(int)Qt::Wednesday].day << "\n"
|
||||
<< " static_start: " << co.carryover[(int)Qt::Wednesday].static_start.toString(Qt::ISODate) << "\n"
|
||||
<< " static_end: " << co.carryover[(int)Qt::Wednesday].static_end.toString(Qt::ISODate) << "\n"
|
||||
<< " anytime: " << co.carryover[(int)Qt::Wednesday].seemless << "\n"
|
||||
<< " never: " << co.carryover[(int)Qt::Wednesday].never << "\n"
|
||||
<< " **** Thursday **** \n"
|
||||
<< " day: " << co.carryover[(int)Qt::Thursday].day << "\n"
|
||||
<< " static_start: " << co.carryover[(int)Qt::Thursday].static_start.toString(Qt::ISODate) << "\n"
|
||||
<< " static_end: " << co.carryover[(int)Qt::Thursday].static_end.toString(Qt::ISODate) << "\n"
|
||||
<< " anytime: " << co.carryover[(int)Qt::Thursday].seemless << "\n"
|
||||
<< " never: " << co.carryover[(int)Qt::Thursday].never << "\n"
|
||||
<< " **** Friday **** \n"
|
||||
<< " day: " << co.carryover[(int)Qt::Friday].day << "\n"
|
||||
<< " static_start: " << co.carryover[(int)Qt::Friday].static_start.toString(Qt::ISODate) << "\n"
|
||||
<< " static_end: " << co.carryover[(int)Qt::Friday].static_end.toString(Qt::ISODate) << "\n"
|
||||
<< " anytime: " << co.carryover[(int)Qt::Friday].seemless << "\n"
|
||||
<< " never: " << co.carryover[(int)Qt::Friday].never << "\n"
|
||||
<< " **** Saturday **** \n"
|
||||
<< " day: " << co.carryover[(int)Qt::Saturday].day << "\n"
|
||||
<< " static_start: " << co.carryover[(int)Qt::Saturday].static_start.toString(Qt::ISODate) << "\n"
|
||||
<< " static_end: " << co.carryover[(int)Qt::Saturday].static_end.toString(Qt::ISODate) << "\n"
|
||||
<< " anytime: " << co.carryover[(int)Qt::Saturday].seemless << "\n"
|
||||
<< " never: " << co.carryover[(int)Qt::Saturday].never << "\n"
|
||||
<< " **** Sunday **** \n"
|
||||
<< " day: " << co.carryover[(int)Qt::Sunday].day << "\n"
|
||||
<< " static_start: " << co.carryover[(int)Qt::Sunday].static_start.toString(Qt::ISODate) << "\n"
|
||||
<< " static_end: " << co.carryover[(int)Qt::Sunday].static_end.toString(Qt::ISODate) << "\n"
|
||||
<< " anytime: " << co.carryover[(int)Qt::Sunday].seemless << "\n"
|
||||
<< " never: " << co.carryover[(int)Qt::Sunday].never << "\n";
|
||||
|
||||
return debug;
|
||||
}
|
||||
};
|
||||
|
||||
#endif // TARIFF_CARRYOVER_H_INCLUDED
|
89
library/include/mobilisis/tariff_interpolation.h
Normal file
89
library/include/mobilisis/tariff_interpolation.h
Normal file
@ -0,0 +1,89 @@
|
||||
#ifndef TARIFF_INTERPOLATION_H_INCLUDED
|
||||
#define TARIFF_INTERPOLATION_H_INCLUDED
|
||||
|
||||
#include <QTime>
|
||||
#include <QString>
|
||||
|
||||
struct ATBInterpolation {
|
||||
|
||||
enum Type {
|
||||
NO_INTERPOLATION = 1,
|
||||
STATIC_WALLCLOCK_TIME_VALUES = 2,
|
||||
STATIC_TIMEPOINT_AND_DURATION = 3,
|
||||
DYNAMIC_TIMEPOINT_AND_STATIC_DURATION = 4,
|
||||
DYNAMIC_ABSTRACT_TIMEPOINT_AND_STATIC_DURATION = 5,
|
||||
DYNAMIC_ABSTRACT_TIMEPOINT_AND_PRICE = 6,
|
||||
DYNAMIC_ABSTRACT_TIMEPOINT_AND_STATIC_END_TIME = 7
|
||||
};
|
||||
|
||||
static QString name(int i) {
|
||||
switch(i) {
|
||||
case (int)(NO_INTERPOLATION):
|
||||
return QString("%1: NO_INTERPOLATION").arg(i);
|
||||
case (int)(STATIC_WALLCLOCK_TIME_VALUES):
|
||||
return QString("%1: STATIC_WALLCLOCK_TIME_VALUES").arg(i);
|
||||
case (int)(STATIC_TIMEPOINT_AND_DURATION):
|
||||
return QString("%1: STATIC_TIMEPOINT_AND_DURATION").arg(i);
|
||||
case (int)(DYNAMIC_TIMEPOINT_AND_STATIC_DURATION):
|
||||
return QString("%1: DYNAMIC_TIMEPOINT_AND_STATIC_DURATION").arg(i);
|
||||
case (int)(DYNAMIC_ABSTRACT_TIMEPOINT_AND_STATIC_DURATION):
|
||||
return QString("%1: DYNAMIC_ABSTRACT_TIMEPOINT_AND_STATIC_DURATION").arg(i);
|
||||
case (int)(DYNAMIC_ABSTRACT_TIMEPOINT_AND_PRICE):
|
||||
return QString("%1: DYNAMIC_ABSTRACT_TIMEPOINT_AND_PRICE").arg(i);
|
||||
case (int)(DYNAMIC_ABSTRACT_TIMEPOINT_AND_STATIC_END_TIME):
|
||||
return QString("%1: DYNAMIC_ABSTRACT_TIMEPOINT_AND_STATIC_END_TIME").arg(i);
|
||||
default:;
|
||||
}
|
||||
return "ERROR";
|
||||
}
|
||||
|
||||
explicit ATBInterpolation()
|
||||
: id(0)
|
||||
, static_start(QTime())
|
||||
, static_end(QTime())
|
||||
, static_start_str(QString())
|
||||
, static_end_str(QString())
|
||||
, static_duration(0)
|
||||
, dynamic_start(QTime())
|
||||
, dynamic_end(QTime())
|
||||
, dynamic_start_str(QString())
|
||||
, dynamic_end_str(QString())
|
||||
, dynamic_duration(0)
|
||||
, dynamic_until_price(0) {
|
||||
}
|
||||
|
||||
int id;
|
||||
QTime static_start;
|
||||
QTime static_end;
|
||||
QString static_start_str;
|
||||
QString static_end_str;
|
||||
int static_duration;
|
||||
QTime dynamic_start;
|
||||
QTime dynamic_end;
|
||||
QString dynamic_start_str;
|
||||
QString dynamic_end_str;
|
||||
int dynamic_duration;
|
||||
int dynamic_until_price;
|
||||
|
||||
friend QDebug operator<<(QDebug debug, ATBInterpolation const &i) {
|
||||
QDebugStateSaver saver(debug);
|
||||
|
||||
debug.nospace()
|
||||
<< " id: " << name(i.id) << "\n"
|
||||
<< " static_start: " << i.static_start.toString(Qt::ISODate) << "\n"
|
||||
<< " static_end: " << i.static_end.toString(Qt::ISODate) << "\n"
|
||||
<< " static_start_str: " << i.static_start_str << "\n"
|
||||
<< " static_end_str: " << i.static_end_str << "\n"
|
||||
<< " static_duration: " << i.static_duration << "\n"
|
||||
<< " dynamic_start: " << i.dynamic_start.toString(Qt::ISODate) << "\n"
|
||||
<< " dynamic_end: " << i.dynamic_end.toString(Qt::ISODate) << "\n"
|
||||
<< " dynamic_start_str: " << i.dynamic_start_str << "\n"
|
||||
<< " dynamic_end_str: " << i.dynamic_end_str << "\n"
|
||||
<< " dynamic_duration: " << i.dynamic_duration << "\n"
|
||||
<< "dynamic_until_price: " << i.dynamic_until_price << "\n";
|
||||
|
||||
return debug;
|
||||
}
|
||||
};
|
||||
|
||||
#endif // TARIFF_INTERPOLATION_H_INCLUDED
|
@ -13,7 +13,13 @@ enum class PERMIT_TYPE : quint8 {
|
||||
DAY_TICKET_CHILD=6,
|
||||
INVALID=7,
|
||||
FOOD_STAMP=8,
|
||||
TWENTY_FOUR_HOURS_TICKET=9
|
||||
TWENTY_FOUR_HOURS_TICKET=9,
|
||||
SHORT_TERM_PARKING_PKW=10,
|
||||
SHORT_TERM_PARKING_BUS=11,
|
||||
SHORT_TERM_PARKING_CAMPER=12,
|
||||
DAY_TICKET_PKW=13,
|
||||
DAY_TICKET_BUS=14,
|
||||
DAY_TICKET_CAMPER=15
|
||||
};
|
||||
|
||||
struct PermitType {
|
||||
@ -43,12 +49,30 @@ struct PermitType {
|
||||
case 6:
|
||||
m_permitType = PERMIT_TYPE::DAY_TICKET_CHILD;
|
||||
break;
|
||||
case 7:
|
||||
case 8:
|
||||
m_permitType = PERMIT_TYPE::FOOD_STAMP;
|
||||
break;
|
||||
case 8:
|
||||
case 9:
|
||||
m_permitType = PERMIT_TYPE::TWENTY_FOUR_HOURS_TICKET;
|
||||
break;
|
||||
case 10:
|
||||
m_permitType = PERMIT_TYPE::SHORT_TERM_PARKING_PKW;
|
||||
break;
|
||||
case 11:
|
||||
m_permitType = PERMIT_TYPE::SHORT_TERM_PARKING_BUS;
|
||||
break;
|
||||
case 12:
|
||||
m_permitType = PERMIT_TYPE::SHORT_TERM_PARKING_CAMPER;
|
||||
break;
|
||||
case 13:
|
||||
m_permitType = PERMIT_TYPE::DAY_TICKET_PKW;
|
||||
break;
|
||||
case 14:
|
||||
m_permitType = PERMIT_TYPE::DAY_TICKET_BUS;
|
||||
break;
|
||||
case 15:
|
||||
m_permitType = PERMIT_TYPE::DAY_TICKET_CAMPER;
|
||||
break;
|
||||
default:
|
||||
m_permitType = PERMIT_TYPE::INVALID;
|
||||
}
|
||||
@ -77,14 +101,25 @@ struct PermitType {
|
||||
case PERMIT_TYPE::DAY_TICKET_TEEN:
|
||||
return 6;
|
||||
case PERMIT_TYPE::FOOD_STAMP:
|
||||
return 7;
|
||||
case PERMIT_TYPE::TWENTY_FOUR_HOURS_TICKET:
|
||||
return 8;
|
||||
case PERMIT_TYPE::TWENTY_FOUR_HOURS_TICKET:
|
||||
return 9;
|
||||
case PERMIT_TYPE::SHORT_TERM_PARKING_PKW:
|
||||
return 10;
|
||||
case PERMIT_TYPE::SHORT_TERM_PARKING_BUS:
|
||||
return 11;
|
||||
case PERMIT_TYPE::SHORT_TERM_PARKING_CAMPER:
|
||||
return 12;
|
||||
case PERMIT_TYPE::DAY_TICKET_PKW:
|
||||
return 13;
|
||||
case PERMIT_TYPE::DAY_TICKET_BUS:
|
||||
return 14;
|
||||
case PERMIT_TYPE::DAY_TICKET_CAMPER:
|
||||
return 15;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return 7;
|
||||
|
||||
}
|
||||
|
||||
QString toString() {
|
||||
@ -107,6 +142,18 @@ struct PermitType {
|
||||
return QString("FOOD_STAMP");
|
||||
case PERMIT_TYPE::TWENTY_FOUR_HOURS_TICKET:
|
||||
return QString("TWENTY_FOUR_HOURS_TICKET");
|
||||
case PERMIT_TYPE::SHORT_TERM_PARKING_PKW:
|
||||
return QString("SHORT_TERM_PARKING_PKW");
|
||||
case PERMIT_TYPE::SHORT_TERM_PARKING_BUS:
|
||||
return QString("SHORT_TERM_PARKING_BUS");
|
||||
case PERMIT_TYPE::SHORT_TERM_PARKING_CAMPER:
|
||||
return QString("SHORT_TERM_PARKING_CAMPER");
|
||||
case PERMIT_TYPE::DAY_TICKET_PKW:
|
||||
return QString("DAY_TICKET_PKW");
|
||||
case PERMIT_TYPE::DAY_TICKET_BUS:
|
||||
return QString("DAY_TICKET_BUS");
|
||||
case PERMIT_TYPE::DAY_TICKET_CAMPER:
|
||||
return QString("DAY_TICKET_CAMPER");
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@ -133,6 +180,18 @@ struct PermitType {
|
||||
return QString("FOOD_STAMP");
|
||||
case PERMIT_TYPE::TWENTY_FOUR_HOURS_TICKET:
|
||||
return QString("TWENTY_FOUR_HOURS_TICKET");
|
||||
case PERMIT_TYPE::SHORT_TERM_PARKING_PKW:
|
||||
return QString("SHORT_TERM_PARKING_PKW");
|
||||
case PERMIT_TYPE::SHORT_TERM_PARKING_BUS:
|
||||
return QString("SHORT_TERM_PARKING_BUS");
|
||||
case PERMIT_TYPE::SHORT_TERM_PARKING_CAMPER:
|
||||
return QString("SHORT_TERM_PARKING_CAMPER");
|
||||
case PERMIT_TYPE::DAY_TICKET_PKW:
|
||||
return QString("DAY_TICKET_PKW");
|
||||
case PERMIT_TYPE::DAY_TICKET_BUS:
|
||||
return QString("DAY_TICKET_BUS");
|
||||
case PERMIT_TYPE::DAY_TICKET_CAMPER:
|
||||
return QString("DAY_TICKET_CAMPER");
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
29
library/include/mobilisis/tariff_prepaid.h
Normal file
29
library/include/mobilisis/tariff_prepaid.h
Normal file
@ -0,0 +1,29 @@
|
||||
#ifndef TARIFF_PREPAID_H_INCLUDED
|
||||
#define TARIFF_PREPAID_H_INCLUDED
|
||||
|
||||
#include <QTime>
|
||||
#include <QString>
|
||||
|
||||
struct ATBPrepaid {
|
||||
explicit ATBPrepaid() = default;
|
||||
int id;
|
||||
bool anytime;
|
||||
bool never;
|
||||
QTime static_start;
|
||||
QTime static_end;
|
||||
|
||||
friend QDebug operator<<(QDebug debug, ATBPrepaid const &pp) {
|
||||
QDebugStateSaver saver(debug);
|
||||
|
||||
debug.nospace()
|
||||
<< " id: " << pp.id << "\n"
|
||||
<< " static_start: " << pp.static_start.toString(Qt::ISODate) << "\n"
|
||||
<< " static_end: " << pp.static_end.toString(Qt::ISODate) << "\n"
|
||||
<< " anytime: " << pp.anytime << "\n"
|
||||
<< " never: " << pp.never << "\n";
|
||||
|
||||
return debug;
|
||||
}
|
||||
};
|
||||
|
||||
#endif // TARIFF_PREPAID_H_INCLUDED
|
@ -84,7 +84,10 @@ HEADERS += \
|
||||
include/mobilisis/tariff_timestep_config.h \
|
||||
include/mobilisis/tariff_product.h \
|
||||
include/mobilisis/tariff_permit_type.h \
|
||||
include/mobilisis/tariff_global_defines.h
|
||||
include/mobilisis/tariff_global_defines.h \
|
||||
include/mobilisis/tariff_interpolation.h \
|
||||
include/mobilisis/tariff_prepaid.h \
|
||||
include/mobilisis/tariff_carryover.h
|
||||
|
||||
OTHER_FILES += src/main.cpp \
|
||||
../tariffs/tariff_korneuburg.json \
|
||||
|
@ -5,6 +5,7 @@
|
||||
#include "tariff_time_range.h"
|
||||
#include "ticket.h"
|
||||
#include "tariff_global_defines.h"
|
||||
#include "tariff_prepaid.h"
|
||||
|
||||
#include <sstream>
|
||||
#include <algorithm>
|
||||
@ -2090,6 +2091,9 @@ QList<int> Calculator::GetPriceSteps(Configuration * /*cfg*/) const {
|
||||
return QList<int>();
|
||||
}
|
||||
|
||||
|
||||
#define DEBUG_GET_TIME_STEPS (1)
|
||||
|
||||
QList<int> &Calculator::GetTimeSteps(Configuration *cfg, int paymentOptionIndex) const {
|
||||
qCritical() << "(" << __func__ << ":" << __LINE__ << ") paymentOptionIndex:" << paymentOptionIndex;
|
||||
|
||||
@ -2107,12 +2111,14 @@ QList<int> &Calculator::GetTimeSteps(Configuration *cfg, int paymentOptionIndex)
|
||||
int const pop_id = cfg->getPaymentOptions(paymentOptionIndex).pop_id;
|
||||
int const pop_carry_over = cfg->getPaymentOptions(paymentOptionIndex).pop_carry_over;
|
||||
int const pop_time_step_config = cfg->getPaymentOptions(paymentOptionIndex).pop_time_step_config;
|
||||
int const pop_prepaid_option_id = cfg->getPaymentOptions(paymentOptionIndex).pop_prepaid_option_id;
|
||||
|
||||
static PaymentMethod const paymentMethodId = Utilities::getPaymentMethodId(cfg);
|
||||
|
||||
qCritical() << "(" << __func__ << ":" << __LINE__ << ") start parking time:" << start.toString(Qt::ISODate);
|
||||
qCritical() << "(" << __func__ << ":" << __LINE__ << ") payment option id:" << pop_id;
|
||||
qCritical() << "(" << __func__ << ":" << __LINE__ << ") payment option carry over:" << pop_carry_over;
|
||||
qCritical() << "(" << __func__ << ":" << __LINE__ << ") time step configuration:" << pop_time_step_config;
|
||||
qCritical() << "(" << __func__ << ":" << __LINE__ << ") prepaid option id:" << pop_prepaid_option_id;
|
||||
|
||||
if (pop_time_step_config == (int)ATBTimeStepConfig::TimeStepConfig::DYNAMIC) {
|
||||
//qCritical() << __PRETTY_FUNCTION__ << "payment option time step config:" << "TimeStepConfig::DYNAMIC";
|
||||
@ -2126,11 +2132,15 @@ QList<int> &Calculator::GetTimeSteps(Configuration *cfg, int paymentOptionIndex)
|
||||
} else {
|
||||
uint16_t timeStepCompensation = 0;
|
||||
|
||||
qCritical() << "(" << __func__ << ":" << __LINE__ << ") payment option carry over:" << pop_carry_over;
|
||||
|
||||
if (pop_carry_over) {
|
||||
int const pop_carry_over_time_range_id = cfg->getPaymentOptions(paymentOptionIndex).pop_carry_over_time_range_id;
|
||||
QTime const carryOverTimeRangeFrom = cfg->TimeRange.find(pop_carry_over_time_range_id)->second.time_range_from;
|
||||
QTime const carryOverTimeRangeTo = cfg->TimeRange.find(pop_carry_over_time_range_id)->second.time_range_to;
|
||||
|
||||
qCritical() << "(" << __func__ << ":" << __LINE__ << ") carry over time range id:" << pop_carry_over_time_range_id;
|
||||
|
||||
if (carryOverTimeRangeFrom.secsTo(carryOverTimeRangeTo) <= 60) { // carry over time point, usually 00:00:00
|
||||
if (carryOverTimeRangeFrom == QTime(0, 0, 0)) {
|
||||
for (auto[itr, rangeEnd] = cfg->PaymentRate.equal_range(pop_id); itr != rangeEnd; ++itr) {
|
||||
@ -2163,7 +2173,7 @@ QList<int> &Calculator::GetTimeSteps(Configuration *cfg, int paymentOptionIndex)
|
||||
m_timeSteps[paymentOptionIndex] << duration.pun_duration;
|
||||
} else {
|
||||
duration.pun_duration = duration.pun_duration_max - timeStepCompensation;
|
||||
m_timeSteps[paymentOptionIndex] << duration.pun_duration;;
|
||||
m_timeSteps[paymentOptionIndex] << duration.pun_duration;
|
||||
}
|
||||
|
||||
cfg->Duration.erase(search);
|
||||
@ -2174,7 +2184,157 @@ QList<int> &Calculator::GetTimeSteps(Configuration *cfg, int paymentOptionIndex)
|
||||
}
|
||||
}
|
||||
} else { // if (carryOverTimeRangeFrom == QTime(0, 0, 0)) {
|
||||
// TODO
|
||||
qCritical() << "(" << __func__ << ":" << __LINE__ << ") carry over time range from:" << carryOverTimeRangeFrom.toString(Qt::ISODate);
|
||||
qCritical() << "(" << __func__ << ":" << __LINE__ << ") carry over time range to:" << carryOverTimeRangeTo.toString(Qt::ISODate);
|
||||
|
||||
m_timeSteps[paymentOptionIndex].clear();
|
||||
|
||||
std::optional<QDateTime> adaptedStart = cfg->adaptStart(start, pop_prepaid_option_id);
|
||||
if (adaptedStart) {
|
||||
start = adaptedStart.value();
|
||||
} else {
|
||||
// TODO
|
||||
}
|
||||
|
||||
int const start_time = start.time().hour() * 60 + start.time().minute();
|
||||
|
||||
for (auto[itr, rangeEnd] = cfg->PaymentRate.equal_range(pop_id); itr != rangeEnd; ++itr) {
|
||||
int const durationId = itr->second.pra_payment_unit_id;
|
||||
// int const price = itr->second.pra_price;
|
||||
|
||||
auto search = cfg->Duration.find(durationId);
|
||||
if (search != cfg->Duration.end()) {
|
||||
ATBDuration duration = search->second;
|
||||
|
||||
if (duration.pun_interpolation_id == -1) {
|
||||
|
||||
// should never happen -> misconfigured tariff-file
|
||||
qCritical() << "(" << __func__ << ":" << __LINE__ << ") ERROR pun_interpolation not set!";
|
||||
qCritical() << "(" << __func__ << ":" << __LINE__ << ") See for instance customer_505/6";
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
std::optional<ATBInterpolation> ipolCheck = cfg->getInterpolationType(duration.pun_interpolation_id);
|
||||
if (ipolCheck) {
|
||||
ATBInterpolation interpolation = ipolCheck.value();
|
||||
|
||||
if (duration.pun_interpolation_id == (int)ATBInterpolation::DYNAMIC_ABSTRACT_TIMEPOINT_AND_STATIC_END_TIME) {
|
||||
|
||||
//qCritical() << "(" << __func__ << ":" << __LINE__ << ") pun_id:" << duration.pun_id;
|
||||
int const end_time = interpolation.dynamic_end.hour() * 60 + interpolation.dynamic_end.minute();
|
||||
|
||||
//qCritical() << "(" << __func__ << ":" << __LINE__ << ") pun_duration:" << duration.pun_duration;
|
||||
//qCritical() << "(" << __func__ << ":" << __LINE__ << ") pun_interpolation:" << duration.pun_interpolation_id;
|
||||
//qCritical() << "(" << __func__ << ":" << __LINE__ << ") interpolation dynamic end:" << interpolation.dynamic_end.toString(Qt::ISODate);
|
||||
// qCritical() << "(" << __func__ << ":" << __LINE__ << ") interpolation dynamic end time:" << end_time;
|
||||
|
||||
QDateTime carryOver = start;
|
||||
carryOver.setTime(interpolation.dynamic_end);
|
||||
|
||||
int pop_min_time = cfg->getPaymentOptions(paymentOptionIndex).pop_min_time;
|
||||
|
||||
int nextTimeStep = start_time + duration.pun_duration;
|
||||
int rest = end_time - nextTimeStep;
|
||||
if (nextTimeStep <= end_time) {
|
||||
|
||||
if (durationId == 1) {
|
||||
|
||||
#if DEBUG_GET_TIME_STEPS==1
|
||||
qCritical() << "(" << __func__ << ":" << __LINE__ << ") pun_id:" << duration.pun_id;
|
||||
qCritical() << "(" << __func__ << ":" << __LINE__ << ") pun_duration:" << duration.pun_duration;
|
||||
qCritical() << "(" << __func__ << ":" << __LINE__ << ") pun_interpolation:" << duration.pun_interpolation_id;
|
||||
qCritical() << "(" << __func__ << ":" << __LINE__ << ") interpolation dynamic end:" << interpolation.dynamic_end.toString(Qt::ISODate);
|
||||
#endif
|
||||
|
||||
int const timeStep = nextTimeStep;
|
||||
|
||||
qCritical() << "(" << __func__ << ":" << __LINE__ << ") time step:" << timeStep;
|
||||
|
||||
if (timeStep < duration.pun_duration_min || timeStep > duration.pun_duration_max) {
|
||||
qCritical() << "(" << __func__ << ":" << __LINE__ << ")"
|
||||
<< QString("ERROR timeStep (%1) < durationMin (%2) || timeStep (%3)) > durationMax (%4)")
|
||||
.arg(timeStep).arg(duration.pun_duration_min)
|
||||
.arg(timeStep).arg(duration.pun_duration_max);
|
||||
break;
|
||||
}
|
||||
|
||||
qCritical() << "(" << __func__ << ":" << __LINE__ << ") configured minimal parking time:" << cfg->getPaymentOptions(paymentOptionIndex).pop_min_time;
|
||||
|
||||
// set dynamic minimal parking time
|
||||
cfg->getPaymentOptions(paymentOptionIndex).pop_min_time = timeStep;
|
||||
|
||||
qCritical() << "(" << __func__ << ":" << __LINE__ << ") computed minimal parking time:" << cfg->getPaymentOptions(paymentOptionIndex).pop_min_time;
|
||||
|
||||
duration.pun_duration = timeStep;
|
||||
timeStepCompensation = end_time - start_time;
|
||||
|
||||
if (duration.pun_duration > 0) {
|
||||
m_timeSteps[paymentOptionIndex] << duration.pun_duration;
|
||||
}
|
||||
|
||||
#if DEBUG_GET_TIME_STEPS==1
|
||||
// timeStepComp: added to (otherwise static) time-steps
|
||||
qCritical() << "(" << __func__ << ":" << __LINE__ << ") duration.pun_duration_max:" << duration.pun_duration_max;
|
||||
qCritical() << "(" << __func__ << ":" << __LINE__ << ") duration.pun_duration:" << duration.pun_duration;
|
||||
qCritical() << "(" << __func__ << ":" << __LINE__ << ") time step compensation:" << timeStepCompensation;
|
||||
#endif
|
||||
} else {
|
||||
duration.pun_duration = nextTimeStep;
|
||||
|
||||
#if DEBUG_GET_TIME_STEPS==1
|
||||
QTime nextTime(0, 0, 0);
|
||||
nextTime = nextTime.addSecs(duration.pun_duration * 60);
|
||||
qCritical() << "(" << __func__ << ":" << __LINE__ << ") next time step:" << nextTime.toString(Qt::ISODate);
|
||||
#endif
|
||||
|
||||
if (duration.pun_duration > 0) {
|
||||
m_timeSteps[paymentOptionIndex] << duration.pun_duration;
|
||||
}
|
||||
}
|
||||
|
||||
} else
|
||||
if (rest > 0) {
|
||||
// last time step before swicthing to dayticket (see Schnals 505/506)
|
||||
duration.pun_duration = duration.pun_duration_max;
|
||||
|
||||
#if DEBUG_GET_TIME_STEPS==1
|
||||
QTime nextTime(0, 0, 0);
|
||||
nextTime = nextTime.addSecs(duration.pun_duration * 60);
|
||||
qCritical() << "(" << __func__ << ":" << __LINE__ << ") next time step:" << nextTime.toString(Qt::ISODate);
|
||||
qCritical() << "(" << __func__ << ":" << __LINE__ << ") pun id:" << duration.pun_id;
|
||||
qCritical() << "(" << __func__ << ":" << __LINE__ << ") pun duration:" << duration.pun_duration;
|
||||
#endif
|
||||
|
||||
if (duration.pun_duration > 0) {
|
||||
m_timeSteps[paymentOptionIndex] << duration.pun_duration;
|
||||
}
|
||||
}
|
||||
|
||||
cfg->Duration.erase(search);
|
||||
cfg->Duration.insert(pair<int, ATBDuration>(duration.pun_id, duration));
|
||||
|
||||
} else
|
||||
if (duration.pun_interpolation_id == (int)ATBInterpolation::NO_INTERPOLATION) {
|
||||
|
||||
#if DEBUG_GET_TIME_STEPS==1
|
||||
qCritical() << "(" << __func__ << ":" << __LINE__ << ") pun_id:" << duration.pun_id;
|
||||
qCritical() << "(" << __func__ << ":" << __LINE__ << ") pun duration_max:" << duration.pun_duration_max;
|
||||
qCritical() << "(" << __func__ << ":" << __LINE__ << ") pun duration:" << duration.pun_duration;
|
||||
qCritical() << "(" << __func__ << ":" << __LINE__ << ") time step compensation:" << timeStepCompensation;
|
||||
#endif
|
||||
|
||||
duration.pun_duration += start_time + timeStepCompensation;
|
||||
m_timeSteps[paymentOptionIndex] << duration.pun_duration;
|
||||
|
||||
cfg->Duration.erase(search);
|
||||
cfg->Duration.insert(pair<int, ATBDuration>(duration.pun_id, duration));
|
||||
} else {
|
||||
cfg->Duration.erase(search);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else { // if (carryOverTimeRangeFrom == carryOverTimeRangeTo) {
|
||||
// TODO
|
||||
@ -2203,9 +2363,22 @@ QList<int> &Calculator::GetTimeSteps(Configuration *cfg, int paymentOptionIndex)
|
||||
|
||||
qCritical() << "(" << __func__ << ":" << __LINE__ << ") NEW timeSteps:" << m_timeSteps;
|
||||
|
||||
#if DEBUG_GET_TIME_STEPS==1
|
||||
for (int i = 0; i < m_timeSteps[paymentOptionIndex].size(); ++i) {
|
||||
QDateTime nextTime = start;
|
||||
nextTime.setTime(QTime(0, 0, 0));
|
||||
nextTime = nextTime.addSecs(m_timeSteps[paymentOptionIndex][i] * 60);
|
||||
qCritical() << "(" << __func__ << ":" << __LINE__ << ") step"
|
||||
<< i << m_timeSteps[0][i] << "->" << nextTime.toString(Qt::ISODate);
|
||||
|
||||
}
|
||||
#endif
|
||||
|
||||
return m_timeSteps[paymentOptionIndex];
|
||||
}
|
||||
|
||||
#undef DEBUG_GET_TIME_STEPS
|
||||
|
||||
uint32_t Calculator::GetPriceForTimeStep(Configuration *cfg, int timeStep, int paymentOptionIndex) const {
|
||||
|
||||
int const pop_id = cfg->getPaymentOptions(paymentOptionIndex).pop_id;
|
||||
|
@ -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>
|
||||
@ -14,75 +15,78 @@
|
||||
/// <inheritdoc/>
|
||||
MemberType Configuration::IdentifyJsonMember(const char* member_name)
|
||||
{
|
||||
if (strcmp(member_name, "Currency") == 0) return MemberType::CurrencyType;
|
||||
if (strcmp(member_name, "PaymentMethod") == 0) return MemberType::PaymentMethodType;
|
||||
if (strcmp(member_name, "PaymentRate") == 0) return MemberType::PaymentRateType;
|
||||
if (strcmp(member_name, "PaymentOption") == 0) return MemberType::PaymentOptionType;
|
||||
if (strcmp(member_name, "Duration") == 0) return MemberType::DurationType;
|
||||
//if (strcmp(member_name, "WeekDays") == 0) return MemberType::WeekDaysType;
|
||||
if (strcmp(member_name, "WeekDaysWorktime") == 0) return MemberType::WeekDaysWorkTimeType;
|
||||
if (strcmp(member_name, "SpecialDaysWorktime") == 0) return MemberType::SpecialDaysWorktimeType;
|
||||
if (strcmp(member_name, "SpecialDays") == 0) return MemberType::SpecialDaysType;
|
||||
if (strcmp(member_name, "PeriodYear") == 0) return MemberType::PeriodYearType;
|
||||
if (strcmp(member_name, "Currency") == 0) return MemberType::CurrencyType;
|
||||
if (strcmp(member_name, "PaymentMethod") == 0) return MemberType::PaymentMethodType;
|
||||
if (strcmp(member_name, "PaymentRate") == 0) return MemberType::PaymentRateType;
|
||||
if (strcmp(member_name, "PaymentOption") == 0) return MemberType::PaymentOptionType;
|
||||
if (strcmp(member_name, "Duration") == 0) return MemberType::DurationType;
|
||||
//if (strcmp(member_name, "WeekDays") == 0) return MemberType::WeekDaysType;
|
||||
if (strcmp(member_name, "WeekDaysWorktime") == 0) return MemberType::WeekDaysWorkTimeType;
|
||||
if (strcmp(member_name, "SpecialDaysWorktime") == 0) return MemberType::SpecialDaysWorktimeType;
|
||||
if (strcmp(member_name, "SpecialDays") == 0) return MemberType::SpecialDaysType;
|
||||
if (strcmp(member_name, "PeriodYear") == 0) return MemberType::PeriodYearType;
|
||||
if (strcmp(member_name, "DailyTicket") == 0) return MemberType::DailyTicketType;
|
||||
if (strcmp(member_name, "TimeBase") == 0) return MemberType::TimeBaseType;
|
||||
if (strcmp(member_name, "Customer") == 0) return MemberType::CustomerType;
|
||||
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;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
bool Configuration::ParseJson(Configuration* cfg, const char* json)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (cfg == nullptr)
|
||||
{
|
||||
printf("TariffConfiguration pointer not set\n");
|
||||
return false;
|
||||
}
|
||||
if (json == NULL)
|
||||
{
|
||||
printf("%s", "Input JSON string is NULL\n");
|
||||
return false;
|
||||
}
|
||||
try
|
||||
{
|
||||
if (cfg == nullptr)
|
||||
{
|
||||
printf("TariffConfiguration pointer not set\n");
|
||||
return false;
|
||||
}
|
||||
if (json == NULL)
|
||||
{
|
||||
printf("%s", "Input JSON string is NULL\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Parse JSON to document
|
||||
Document document;
|
||||
document.Parse(json);
|
||||
// Parse JSON to document
|
||||
Document document;
|
||||
document.Parse(json);
|
||||
|
||||
// Return if parse error has been found
|
||||
ParseErrorCode err = document.GetParseError();
|
||||
if (err != 0)
|
||||
{
|
||||
printf("%s %d (%s)\n", "Unable to parse JSON, error code:", err, GetParseError_En(err));
|
||||
return false;
|
||||
}
|
||||
// Return if parse error has been found
|
||||
ParseErrorCode err = document.GetParseError();
|
||||
if (err != 0)
|
||||
{
|
||||
printf("%s %d (%s)\n", "Unable to parse JSON, error code:", err, GetParseError_En(err));
|
||||
return false;
|
||||
}
|
||||
|
||||
// Validate JSON, check if it's a JSON object
|
||||
// Validate JSON, check if it's a JSON object
|
||||
qCritical() << "JSON parsing has been successful";
|
||||
if (!document.IsObject()) {
|
||||
printf("%s", "Error: not a (valid) JSON object\n");
|
||||
return false;
|
||||
}
|
||||
if (!document.IsObject()) {
|
||||
printf("%s", "Error: not a (valid) JSON object\n");
|
||||
return false;
|
||||
}
|
||||
qCritical() << "Valid JSON object identified";
|
||||
|
||||
// Validate JSON, check configuration members
|
||||
if (!document.HasMember("Currency")
|
||||
|| !document.HasMember("PaymentMethod")
|
||||
|| !document.HasMember("PaymentOption")
|
||||
|| !document.HasMember("PaymentRate")
|
||||
|| !document.HasMember("Duration")
|
||||
//|| !document.HasMember("WeekDays")
|
||||
// Validate JSON, check configuration members
|
||||
if (!document.HasMember("Currency")
|
||||
|| !document.HasMember("PaymentMethod")
|
||||
|| !document.HasMember("PaymentOption")
|
||||
|| !document.HasMember("PaymentRate")
|
||||
|| !document.HasMember("Duration")
|
||||
//|| !document.HasMember("WeekDays")
|
||||
//|| !document.HasMember("SpecialDaysWorktime")
|
||||
//|| !document.HasMember("SpecialDays")
|
||||
)
|
||||
{
|
||||
printf("%s", "Error: not a valid configuration JSON\n");
|
||||
return false;
|
||||
}
|
||||
{
|
||||
printf("%s", "Error: not a valid configuration JSON\n");
|
||||
return false;
|
||||
}
|
||||
qCritical() << "Valid JSON configuration identified";
|
||||
|
||||
ATBCurrency Currency;
|
||||
@ -100,16 +104,19 @@ 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();
|
||||
|
||||
// Get all JSON object members
|
||||
// This code should run only once (to load JSON variables into memory)
|
||||
for (auto i = document.MemberBegin(); i != document.MemberEnd(); i++)
|
||||
{
|
||||
// Get name of all general members of JSON, don't print name if NULL
|
||||
const char* mb_name = i->name.GetString();
|
||||
// Get all JSON object members
|
||||
// This code should run only once (to load JSON variables into memory)
|
||||
for (auto i = document.MemberBegin(); i != document.MemberEnd(); i++)
|
||||
{
|
||||
// Get name of all general members of JSON, don't print name if NULL
|
||||
const char* mb_name = i->name.GetString();
|
||||
if (mb_name == NULL) continue;
|
||||
|
||||
if (document[mb_name].IsString()) {
|
||||
@ -135,35 +142,196 @@ bool Configuration::ParseJson(Configuration* cfg, const char* json)
|
||||
|
||||
qCritical() << " -" << mb_name;
|
||||
|
||||
// Get array for each JSON object member
|
||||
auto mb_array = document[mb_name].GetArray();
|
||||
if (mb_array.Size() <= 0) break;
|
||||
// Get array for each JSON object member
|
||||
auto mb_array = document[mb_name].GetArray();
|
||||
if (mb_array.Size() <= 0) break;
|
||||
|
||||
//Iterate over provided array
|
||||
//Iterate over provided array
|
||||
for (rapidjson::SizeType j = 0; j < mb_array.Size(); j++)
|
||||
{
|
||||
// Get all inner objects, don't print name if NULL
|
||||
auto inner_obj = mb_array[j].GetObject();
|
||||
if (inner_obj.MemberCount() <= 0) break;
|
||||
{
|
||||
// Get all inner objects, don't print name if NULL
|
||||
auto inner_obj = mb_array[j].GetObject();
|
||||
if (inner_obj.MemberCount() <= 0) break;
|
||||
|
||||
// Iterate over inner object JSON members
|
||||
for (auto k = inner_obj.MemberBegin(); k != inner_obj.MemberEnd(); k++)
|
||||
{
|
||||
// Get inner object JSON member, don't print name if NULL
|
||||
const char* inner_obj_name = k->name.GetString();
|
||||
if (inner_obj_name == NULL)
|
||||
{
|
||||
printf("Inner object name is NULL\n");
|
||||
continue;
|
||||
}
|
||||
// Iterate over inner object JSON members
|
||||
for (auto k = inner_obj.MemberBegin(); k != inner_obj.MemberEnd(); k++)
|
||||
{
|
||||
// Get inner object JSON member, don't print name if NULL
|
||||
const char* inner_obj_name = k->name.GetString();
|
||||
if (inner_obj_name == NULL)
|
||||
{
|
||||
printf("Inner object name is NULL\n");
|
||||
continue;
|
||||
}
|
||||
|
||||
// Identify member type
|
||||
mb_type = IdentifyJsonMember(mb_name);
|
||||
// Identify member type
|
||||
mb_type = IdentifyJsonMember(mb_name);
|
||||
|
||||
switch (mb_type)
|
||||
{
|
||||
case MemberType::UnknownType:
|
||||
break;
|
||||
switch (mb_type)
|
||||
{
|
||||
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()) {
|
||||
@ -375,22 +543,22 @@ bool Configuration::ParseJson(Configuration* cfg, const char* json)
|
||||
}
|
||||
break;
|
||||
case MemberType::CurrencyType:
|
||||
if (strcmp(inner_obj_name, "pcu_id") == 0) Currency.pcu_id = k->value.GetInt();
|
||||
else if (strcmp(inner_obj_name, "pcu_sign") == 0) Currency.pcu_sign = k->value.GetString();
|
||||
else if (strcmp(inner_obj_name, "pcu_major") == 0) Currency.pcu_major = k->value.GetString();
|
||||
else if (strcmp(inner_obj_name, "pcu_minor") == 0) Currency.pcu_minor = k->value.GetString();
|
||||
else if (strcmp(inner_obj_name, "pcu_active") == 0) Currency.pcu_active = k->value.GetBool();
|
||||
break;
|
||||
case MemberType::PaymentMethodType:
|
||||
if (strcmp(inner_obj_name, "pme_id") == 0) PaymentMethod.pme_id = k->value.GetInt();
|
||||
else if (strcmp(inner_obj_name, "pme_label") == 0) PaymentMethod.pme_label = k->value.GetString();
|
||||
break;
|
||||
case MemberType::PaymentRateType:
|
||||
if (strcmp(inner_obj_name, "pra_payment_option_id") == 0) PaymentRate.pra_payment_option_id = k->value.GetInt();
|
||||
else if (strcmp(inner_obj_name, "pra_payment_unit_id") == 0) PaymentRate.pra_payment_unit_id = k->value.GetInt();
|
||||
else if (strcmp(inner_obj_name, "pra_price") == 0) PaymentRate.pra_price = k->value.GetDouble();
|
||||
break;
|
||||
case MemberType::PaymentOptionType:
|
||||
if (strcmp(inner_obj_name, "pcu_id") == 0) Currency.pcu_id = k->value.GetInt();
|
||||
else if (strcmp(inner_obj_name, "pcu_sign") == 0) Currency.pcu_sign = k->value.GetString();
|
||||
else if (strcmp(inner_obj_name, "pcu_major") == 0) Currency.pcu_major = k->value.GetString();
|
||||
else if (strcmp(inner_obj_name, "pcu_minor") == 0) Currency.pcu_minor = k->value.GetString();
|
||||
else if (strcmp(inner_obj_name, "pcu_active") == 0) Currency.pcu_active = k->value.GetBool();
|
||||
break;
|
||||
case MemberType::PaymentMethodType:
|
||||
if (strcmp(inner_obj_name, "pme_id") == 0) PaymentMethod.pme_id = k->value.GetInt();
|
||||
else if (strcmp(inner_obj_name, "pme_label") == 0) PaymentMethod.pme_label = k->value.GetString();
|
||||
break;
|
||||
case MemberType::PaymentRateType:
|
||||
if (strcmp(inner_obj_name, "pra_payment_option_id") == 0) PaymentRate.pra_payment_option_id = k->value.GetInt();
|
||||
else if (strcmp(inner_obj_name, "pra_payment_unit_id") == 0) PaymentRate.pra_payment_unit_id = k->value.GetInt();
|
||||
else if (strcmp(inner_obj_name, "pra_price") == 0) PaymentRate.pra_price = k->value.GetDouble();
|
||||
break;
|
||||
case MemberType::PaymentOptionType:
|
||||
if (strcmp(inner_obj_name, "pop_id") == 0) {
|
||||
this->currentPaymentOptions.append(ATBPaymentOption());
|
||||
this->currentPaymentOptions.last().reset();
|
||||
@ -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) {
|
||||
@ -493,91 +665,93 @@ bool Configuration::ParseJson(Configuration* cfg, const char* json)
|
||||
}
|
||||
}
|
||||
break;
|
||||
case MemberType::DurationType:
|
||||
if (strcmp(inner_obj_name, "pun_id") == 0) Duration.pun_id = k->value.GetInt();
|
||||
else if (strcmp(inner_obj_name, "pun_label") == 0) Duration.pun_label = k->value.GetString();
|
||||
else if (strcmp(inner_obj_name, "pun_duration") == 0) Duration.pun_duration = k->value.GetDouble();
|
||||
case MemberType::DurationType:
|
||||
if (strcmp(inner_obj_name, "pun_id") == 0) Duration.pun_id = k->value.GetInt();
|
||||
else if (strcmp(inner_obj_name, "pun_label") == 0) Duration.pun_label = k->value.GetString();
|
||||
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();
|
||||
else if (strcmp(inner_obj_name, "pedwt_period_exc_day_id") == 0) SpecialDaysWorktime.pedwt_period_exc_day_id = k->value.GetInt();
|
||||
else if (strcmp(inner_obj_name, "pedwt_time_from") == 0) SpecialDaysWorktime.pedwt_time_from = k->value.GetString();
|
||||
else if (strcmp(inner_obj_name, "pedwt_time_to") == 0) SpecialDaysWorktime.pedwt_time_to = k->value.GetString();
|
||||
else if (strcmp(inner_obj_name, "pedwt_price") == 0) SpecialDaysWorktime.pedwt_price = k->value.GetDouble();
|
||||
break;
|
||||
/*case MemberType::WeekDaysType:
|
||||
if (strcmp(inner_obj_name, "pdiw_id") == 0) WeekDays.pdiw_id = k->value.GetInt();
|
||||
else if (strcmp(inner_obj_name, "pdiw_label") == 0) WeekDays.pdiw_label = k->value.GetString();
|
||||
else if (strcmp(inner_obj_name, "pdiw_index") == 0) WeekDays.pdiw_index = k->value.GetInt();
|
||||
break;*/
|
||||
case MemberType::WeekDaysWorkTimeType:
|
||||
if (strcmp(inner_obj_name, "pwd_id") == 0) WeekDaysWorktime.pwd_id = k->value.GetInt();
|
||||
else if (strcmp(inner_obj_name, "pwd_period_week_day_id") == 0) WeekDaysWorktime.pwd_period_week_day_id = k->value.GetInt();
|
||||
else if (strcmp(inner_obj_name, "pwd_period_day_in_week_id") == 0) WeekDaysWorktime.pwd_period_day_in_week_id = k->value.GetInt();
|
||||
else if (strcmp(inner_obj_name, "pwd_time_from") == 0) WeekDaysWorktime.pwd_time_from = k->value.GetString();
|
||||
case MemberType::SpecialDaysWorktimeType:
|
||||
if (strcmp(inner_obj_name, "pedwt_id") == 0) SpecialDaysWorktime.pedwt_id = k->value.GetInt();
|
||||
else if (strcmp(inner_obj_name, "pedwt_period_exc_day_id") == 0) SpecialDaysWorktime.pedwt_period_exc_day_id = k->value.GetInt();
|
||||
else if (strcmp(inner_obj_name, "pedwt_time_from") == 0) SpecialDaysWorktime.pedwt_time_from = k->value.GetString();
|
||||
else if (strcmp(inner_obj_name, "pedwt_time_to") == 0) SpecialDaysWorktime.pedwt_time_to = k->value.GetString();
|
||||
else if (strcmp(inner_obj_name, "pedwt_price") == 0) SpecialDaysWorktime.pedwt_price = k->value.GetDouble();
|
||||
break;
|
||||
/*case MemberType::WeekDaysType:
|
||||
if (strcmp(inner_obj_name, "pdiw_id") == 0) WeekDays.pdiw_id = k->value.GetInt();
|
||||
else if (strcmp(inner_obj_name, "pdiw_label") == 0) WeekDays.pdiw_label = k->value.GetString();
|
||||
else if (strcmp(inner_obj_name, "pdiw_index") == 0) WeekDays.pdiw_index = k->value.GetInt();
|
||||
break;*/
|
||||
case MemberType::WeekDaysWorkTimeType:
|
||||
if (strcmp(inner_obj_name, "pwd_id") == 0) WeekDaysWorktime.pwd_id = k->value.GetInt();
|
||||
else if (strcmp(inner_obj_name, "pwd_period_week_day_id") == 0) WeekDaysWorktime.pwd_period_week_day_id = k->value.GetInt();
|
||||
else if (strcmp(inner_obj_name, "pwd_period_day_in_week_id") == 0) WeekDaysWorktime.pwd_period_day_in_week_id = k->value.GetInt();
|
||||
else if (strcmp(inner_obj_name, "pwd_time_from") == 0) WeekDaysWorktime.pwd_time_from = k->value.GetString();
|
||||
else if (strcmp(inner_obj_name, "pwd_time_to") == 0) WeekDaysWorktime.pwd_time_to = k->value.GetString();
|
||||
break;
|
||||
case MemberType::SpecialDaysType:
|
||||
if (strcmp(inner_obj_name, "ped_id") == 0) SpecialDays.ped_id = k->value.GetInt();
|
||||
else if (strcmp(inner_obj_name, "ped_label") == 0) SpecialDays.ped_label = k->value.GetString();
|
||||
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();
|
||||
case MemberType::SpecialDaysType:
|
||||
if (strcmp(inner_obj_name, "ped_id") == 0) SpecialDays.ped_id = k->value.GetInt();
|
||||
else if (strcmp(inner_obj_name, "ped_label") == 0) SpecialDays.ped_label = k->value.GetString();
|
||||
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_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();
|
||||
else if (strcmp(inner_obj_name, "pye_label") == 0) YearPeriod.pye_label = k->value.GetString();
|
||||
else if (strcmp(inner_obj_name, "pye_start_month") == 0) YearPeriod.pye_start_month = k->value.GetInt();
|
||||
else if (strcmp(inner_obj_name, "pye_start_day") == 0) YearPeriod.pye_start_day = k->value.GetInt();
|
||||
else if (strcmp(inner_obj_name, "pye_end_month") == 0) YearPeriod.pye_end_month = k->value.GetInt();
|
||||
else if (strcmp(inner_obj_name, "pye_end_day") == 0) YearPeriod.pye_end_day = k->value.GetInt();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case MemberType::PeriodYearType:
|
||||
if (strcmp(inner_obj_name, "pye_id") == 0) YearPeriod.pye_id = k->value.GetInt();
|
||||
else if (strcmp(inner_obj_name, "pye_label") == 0) YearPeriod.pye_label = k->value.GetString();
|
||||
else if (strcmp(inner_obj_name, "pye_start_month") == 0) YearPeriod.pye_start_month = k->value.GetInt();
|
||||
else if (strcmp(inner_obj_name, "pye_start_day") == 0) YearPeriod.pye_start_day = k->value.GetInt();
|
||||
else if (strcmp(inner_obj_name, "pye_end_month") == 0) YearPeriod.pye_end_month = k->value.GetInt();
|
||||
else if (strcmp(inner_obj_name, "pye_end_day") == 0) YearPeriod.pye_end_day = k->value.GetInt();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
//#pragma endregion
|
||||
}
|
||||
}
|
||||
|
||||
// Push to specific list depending on member type
|
||||
switch (mb_type)
|
||||
{
|
||||
case MemberType::UnknownType:
|
||||
break;
|
||||
case MemberType::PaymentMethodType:
|
||||
cfg->PaymentMethod.insert(pair<int, ATBPaymentMethod>(PaymentMethod.pme_id, PaymentMethod));
|
||||
break;
|
||||
// Push to specific list depending on member type
|
||||
switch (mb_type)
|
||||
{
|
||||
case MemberType::UnknownType:
|
||||
break;
|
||||
case MemberType::PaymentMethodType:
|
||||
cfg->PaymentMethod.insert(pair<int, ATBPaymentMethod>(PaymentMethod.pme_id, PaymentMethod));
|
||||
break;
|
||||
case MemberType::PaymentRateType:
|
||||
// qCritical() << "PaymentRate" << PaymentRate;
|
||||
cfg->PaymentRate.insert(pair<int, ATBPaymentRate>(PaymentRate.pra_payment_option_id, PaymentRate));
|
||||
break;
|
||||
break;
|
||||
case MemberType::PaymentOptionType: {
|
||||
if (!this->currentPaymentOptions.isEmpty()) {
|
||||
ATBPaymentOption const &PaymentOption = this->currentPaymentOptions.last();
|
||||
cfg->PaymentOption.insert(pair<int, ATBPaymentOption>(PaymentOption.pop_payment_method_id, PaymentOption));
|
||||
}
|
||||
} break;
|
||||
case MemberType::DurationType:
|
||||
cfg->Duration.insert(pair<int, ATBDuration>(Duration.pun_id, Duration));
|
||||
break;
|
||||
case MemberType::SpecialDaysWorktimeType:
|
||||
cfg->SpecialDaysWorktime.insert(pair<int, ATBSpecialDaysWorktime>(SpecialDaysWorktime.pedwt_period_exc_day_id, SpecialDaysWorktime));
|
||||
break;
|
||||
//case MemberType::WeekDaysType:
|
||||
// cfg->WeekDays.insert(pair<int, ATBWeekDays>(WeekDays.pdiw_index, WeekDays));
|
||||
// break;
|
||||
case MemberType::WeekDaysWorkTimeType:
|
||||
cfg->WeekDaysWorktime.insert(pair<int, ATBWeekDaysWorktime>(WeekDaysWorktime.pwd_period_day_in_week_id, WeekDaysWorktime));
|
||||
break;
|
||||
case MemberType::SpecialDaysType:
|
||||
cfg->SpecialDays.insert(pair<int, ATBSpecialDays>(SpecialDays.ped_id, SpecialDays));
|
||||
break;
|
||||
case MemberType::PeriodYearType:
|
||||
cfg->YearPeriod.insert(pair<int, ATBPeriodYear>(YearPeriod.pye_id, YearPeriod));
|
||||
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));
|
||||
break;
|
||||
//case MemberType::WeekDaysType:
|
||||
// cfg->WeekDays.insert(pair<int, ATBWeekDays>(WeekDays.pdiw_index, WeekDays));
|
||||
// break;
|
||||
case MemberType::WeekDaysWorkTimeType:
|
||||
cfg->WeekDaysWorktime.insert(pair<int, ATBWeekDaysWorktime>(WeekDaysWorktime.pwd_period_day_in_week_id, WeekDaysWorktime));
|
||||
break;
|
||||
case MemberType::SpecialDaysType:
|
||||
cfg->SpecialDays.insert(pair<int, ATBSpecialDays>(SpecialDays.ped_id, SpecialDays));
|
||||
break;
|
||||
case MemberType::PeriodYearType:
|
||||
cfg->YearPeriod.insert(pair<int, ATBPeriodYear>(YearPeriod.pye_id, YearPeriod));
|
||||
break;
|
||||
case MemberType::DailyTicketType:
|
||||
cfg->DailyTicket.insert(pair<int, ATBDailyTicket>(DailyTicket.daily_ticket_id, DailyTicket));
|
||||
qCritical() << DailyTicket;
|
||||
@ -602,17 +776,30 @@ 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
catch (...) {
|
||||
printf("%s\n", "General exception has occurred while parsing JSON\n");
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
catch (...) {
|
||||
printf("%s\n", "General exception has occurred while parsing JSON\n");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
int Configuration::getPaymentOptionIndexIfSpecialDay(QDateTime const &dt) const {
|
||||
@ -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;
|
||||
|
186
main/main.cpp
186
main/main.cpp
@ -48,7 +48,9 @@ extern "C" char* strptime(const char* s,
|
||||
#define NEUHAUSER_PERNEGG_AN_DER_MUR (0)
|
||||
#define NEUHAUSER_STOCKERAU (0)
|
||||
#define KLEIPEDA_LITAUEN (0)
|
||||
#define SEXTEN (1)
|
||||
#define SEXTEN (0)
|
||||
#define SCHNALS_LEITER_KIRCHL (1)
|
||||
#define SCHNALS_STAUMAUER (SCHNALS_LEITER_KIRCHL)
|
||||
|
||||
#if NEUHAUSER_KIRCHDORF==1
|
||||
static bool test_neuhauser_kirchdorf(int step, double cost) {
|
||||
@ -209,8 +211,20 @@ static bool test_neuhauser_kirchdorf(int step, double cost) {
|
||||
|
||||
|
||||
int main() {
|
||||
#if 0
|
||||
|
||||
|
||||
//487 {
|
||||
// 488 "pra_payment_option_id": 1049,
|
||||
// 489 "pra_payment_unit_id": 84,
|
||||
// 490 "pra_price":"840"
|
||||
//>>491 }
|
||||
|
||||
//for (int i = 1; i < 85; ++i) {
|
||||
//printf("{\n \"\pra_payment_option_id\": 1049,\n \"\pra_payment_unit_id\": %d,\n \"pra_price\": %d\n},\n",
|
||||
// i, i*10);
|
||||
//}
|
||||
//return 0;
|
||||
#if 0
|
||||
MessageHelper msgHelp;
|
||||
// msgHelp.createLoginMessageChunksToSend(0x02);
|
||||
msgHelp.createAuthorizeMessageChunksToSend(0x02);
|
||||
@ -537,10 +551,10 @@ int main() {
|
||||
*/
|
||||
|
||||
//for (int minutes = 0; minutes < 1440; ++minutes) {
|
||||
for (int minutes = 480; minutes < 481; minutes += 1) {
|
||||
for (int minutes = 0; minutes < 1440; minutes += 1) {
|
||||
QDateTime start = s.addSecs(minutes * 60);
|
||||
|
||||
qCritical() << "start" << start.toString(Qt::ISODate);
|
||||
// qCritical() << "start" << start.toString(Qt::ISODate);
|
||||
|
||||
QDateTime effectiveStart = start;
|
||||
|
||||
@ -554,14 +568,15 @@ int main() {
|
||||
effectiveStart.setTime(QTime(8, 0, 0)); // next day
|
||||
}
|
||||
|
||||
for (int i = 100; i <= 100; i += 10) {
|
||||
for (int i = 10; i <= 400; i += 10) {
|
||||
//for (int i = 2100; i <= 2100; i += 10) {
|
||||
cost = i;
|
||||
|
||||
if ((cs = compute_duration_for_parking_ticket(&cfg, start, cost, end))) { // return value
|
||||
|
||||
|
||||
qCritical() << "end" << end.toString(Qt::ISODate);
|
||||
qCritical() << "start" << start.toString(Qt::ISODate) << "< cost" << cost
|
||||
<< "> end" << end.toString(Qt::ISODate);
|
||||
|
||||
durationInMinutes = pop_min_time;
|
||||
if (i > 0) {
|
||||
@ -599,7 +614,7 @@ int main() {
|
||||
if (!cs) {
|
||||
qCritical() << "ERROR CalcState" << cs.toString() << endl;
|
||||
} else {
|
||||
qCritical() << cs.toString();
|
||||
// qCritical() << cs.toString();
|
||||
}
|
||||
|
||||
#if 0
|
||||
@ -620,6 +635,163 @@ int main() {
|
||||
|
||||
#endif
|
||||
|
||||
#if (SCHNALS_LEITER_KIRCHL==1 || SCHNALS_STAUMAUER==1)
|
||||
std::ifstream input;
|
||||
int pop_min_time;
|
||||
int pop_max_time;
|
||||
int pop_min_price;
|
||||
int pop_max_price;
|
||||
int pop_daily_card_price;
|
||||
|
||||
input.open("/opt/ptu5/opt/customer_505/etc/psa_tariff/tariff01.json");
|
||||
//input.open("/opt/ptu5/opt/customer_506/etc/psa_tariff/tariff01.json");
|
||||
|
||||
std::stringstream sstr;
|
||||
while(input >> sstr.rdbuf());
|
||||
std::string json(sstr.str());
|
||||
|
||||
Configuration cfg;
|
||||
|
||||
bool isParsed = cfg.ParseJson(&cfg, json.c_str());
|
||||
cout << endl;
|
||||
|
||||
if (isParsed) {
|
||||
pop_min_time = get_minimal_parkingtime(&cfg);
|
||||
pop_max_time = get_maximal_parkingtime(&cfg);
|
||||
pop_min_price = get_minimal_parkingprice(&cfg);
|
||||
pop_max_price = get_maximal_parkingprice(&cfg);
|
||||
pop_daily_card_price = cfg.getPaymentOptions().pop_daily_card_price;
|
||||
|
||||
qCritical() << " pop_min_time: " << pop_min_time;
|
||||
qCritical() << " pop_max_time: " << pop_max_time;
|
||||
qCritical() << " pop_min_price: " << pop_min_price;
|
||||
qCritical() << " pop_max_price: " << pop_max_price;
|
||||
|
||||
QList<int> timeSteps = Calculator::GetInstance().GetTimeSteps(&cfg);
|
||||
qCritical() << "TimeSteps" << timeSteps;
|
||||
|
||||
return 0;
|
||||
|
||||
CalcState cs;
|
||||
double cost;
|
||||
int durationInMinutes = 0;
|
||||
int offsetInMinutes = 0;
|
||||
|
||||
// for (int day = Qt::Monday; day <= Qt::Sunday; ++day) {
|
||||
for (int day = Qt::Monday; day <= Qt::Monday; ++day) {
|
||||
QDateTime s(QDate(2024, 7, 14 + day), QTime());
|
||||
QDateTime end;
|
||||
|
||||
switch (day) {
|
||||
case (int)Qt::Monday:
|
||||
qCritical() << "Monday";
|
||||
break;
|
||||
case (int)Qt::Tuesday:
|
||||
qCritical() << "Tuesday";
|
||||
break;
|
||||
case (int)Qt::Wednesday:
|
||||
qCritical() << "Wednesday";
|
||||
break;
|
||||
case (int)Qt::Thursday:
|
||||
qCritical() << "Thursday";
|
||||
break;
|
||||
case (int)Qt::Friday:
|
||||
qCritical() << "Friday";
|
||||
break;
|
||||
case (int)Qt::Saturday:
|
||||
qCritical() << "Saturday";
|
||||
break;
|
||||
case (int)Qt::Sunday:
|
||||
qCritical() << "Sunday";
|
||||
break;
|
||||
}
|
||||
|
||||
//for (int minutes = 0; minutes < 1440; ++minutes) {
|
||||
for (int minutes = 420; minutes < 420; minutes += 1) {
|
||||
QDateTime start = s.addSecs(minutes * 60);
|
||||
|
||||
// qCritical() << "start" << start.toString(Qt::ISODate);
|
||||
|
||||
QDateTime effectiveStart = start;
|
||||
|
||||
// hier sollte man auch testen was passiert, falls man ausserhalb
|
||||
// der verkaufsdaten steht
|
||||
if (start.time() < QTime(8, 0, 0)) {
|
||||
effectiveStart.setTime(QTime(8, 0, 0));
|
||||
} else
|
||||
if (start.time() <= QTime(19, 0, 0)) {
|
||||
effectiveStart = start;
|
||||
} else {
|
||||
effectiveStart = start.addDays(1);
|
||||
effectiveStart.setTime(QTime(8, 0, 0)); // next day
|
||||
}
|
||||
|
||||
for (int i = 10; i <= 400; i += 10) {
|
||||
//for (int i = 2100; i <= 2100; i += 10) {
|
||||
cost = i;
|
||||
|
||||
if ((cs = compute_duration_for_parking_ticket(&cfg, start, cost, end))) { // return value
|
||||
|
||||
|
||||
qCritical() << "start" << start.toString(Qt::ISODate) << "< cost" << cost
|
||||
<< "> end" << end.toString(Qt::ISODate);
|
||||
|
||||
durationInMinutes = pop_min_time;
|
||||
if (i > 0) {
|
||||
durationInMinutes += (i/10) * 4;
|
||||
}
|
||||
offsetInMinutes = 0;
|
||||
|
||||
if (effectiveStart.time() >= QTime(8, 0, 0) && effectiveStart.time() <= QTime(19, 0, 0)) {
|
||||
if (effectiveStart.time().secsTo(QTime(19, 0, 0)) < (durationInMinutes * 60)) {
|
||||
offsetInMinutes = 780; // 19:00 -> 8:00
|
||||
}
|
||||
}
|
||||
|
||||
if (i == 0) {
|
||||
i += 20;
|
||||
}
|
||||
|
||||
#if 0
|
||||
if ((durationInMinutes + offsetInMinutes) == (effectiveStart.secsTo(end) / 60)) {
|
||||
|
||||
if (day == Qt::Monday && minutes >= 480 && minutes <= 1140) {
|
||||
qCritical() << "| start ............................" << start.toString(Qt::ISODate);
|
||||
qCritical() << "| cost ............................." << cost;
|
||||
qCritical() << "| durationInMinutes ................" << durationInMinutes
|
||||
<< "(" << (durationInMinutes - 60) << "+ 60 )";
|
||||
qCritical() << "| offsetInMinutes .................." << offsetInMinutes;
|
||||
qCritical() << "| end .............................." << end.toString(Qt::ISODate) << endl;
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
if (!cs) {
|
||||
qCritical() << "ERROR CalcState" << cs.toString() << endl;
|
||||
} else {
|
||||
// qCritical() << cs.toString();
|
||||
}
|
||||
|
||||
#if 0
|
||||
qCritical() << __LINE__ << "start ............................" << start.toString(Qt::ISODate);
|
||||
qCritical() << __LINE__ << "effectiveStart ..................." << effectiveStart.toString(Qt::ISODate);
|
||||
qCritical() << __LINE__ << "cost ............................." << cost;
|
||||
qCritical() << __LINE__ << "durationInMinutes ................" << durationInMinutes;
|
||||
qCritical() << __LINE__ << "offsetInMinutes .................." << offsetInMinutes;
|
||||
qCritical() << __LINE__ << "effectiveStart.secsTo(end) / 60 .." << effectiveStart.secsTo(end) / 60;
|
||||
qCritical() << __LINE__ << "end .............................." << end.toString(Qt::ISODate) << endl;
|
||||
exit(-1);
|
||||
#endif
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if NEUHAUSER_STOCKERAU==1
|
||||
std::ifstream input;
|
||||
int pop_min_time;
|
||||
|
Loading…
Reference in New Issue
Block a user