Compare commits
4 Commits
7679eb9481
...
e9b10166d2
Author | SHA1 | Date | |
---|---|---|---|
e9b10166d2 | |||
33731faba9 | |||
15700a363d | |||
506a665592 |
@ -13,36 +13,8 @@
|
||||
using namespace std;
|
||||
|
||||
class Calculator {
|
||||
QDateTime m_start;
|
||||
mutable uint16_t m_timeStepCompensation = 0;
|
||||
public:
|
||||
explicit Calculator() = default;
|
||||
explicit Calculator(QDateTime const start) : m_start(start) {
|
||||
m_start.setTime(QTime(start.time().hour(), start.time().minute(), 0));
|
||||
qCritical() << "init m_start time:" << m_start.toString(Qt::ISODate);
|
||||
}
|
||||
|
||||
void setStartDateTime(QDateTime const &start) {
|
||||
m_start = start;
|
||||
m_start.setTime(QTime(start.time().hour(), start.time().minute(), 0));
|
||||
qCritical() << "set m_start time:" << m_start.toString(Qt::ISODate);
|
||||
}
|
||||
|
||||
QDateTime const &getStartDateTime() const {
|
||||
return m_start;
|
||||
}
|
||||
|
||||
QDateTime &getStartDateTime() {
|
||||
return m_start;
|
||||
}
|
||||
|
||||
void setTimeStepCompensation(uint16_t timeStepCompensation) {
|
||||
m_timeStepCompensation = timeStepCompensation;
|
||||
}
|
||||
|
||||
uint16_t getTimeStepCompensation() const {
|
||||
return m_timeStepCompensation;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets duration in seconds from cost
|
||||
@ -72,7 +44,7 @@ public:
|
||||
// helper function to find time steps for a tariff with PaymentMethod::Steps
|
||||
// (e.g. Schoenau/Koenigsee)
|
||||
//
|
||||
QList<int> GetTimeSteps(Configuration *cfg) const;
|
||||
QList<int> GetTimeSteps(Configuration *cfg, quint64 startInMinutes = QDateTime::currentSecsSinceEpoch() / 60) const;
|
||||
QList<int> GetSteps(Configuration *cfg) const { return GetTimeSteps(cfg); }
|
||||
|
||||
// additional helper functions
|
||||
@ -89,7 +61,7 @@ public:
|
||||
}
|
||||
|
||||
// testing public:
|
||||
private:
|
||||
//private:
|
||||
// Introduced for PaymentMethod::Steps (e.g. Schoenau)
|
||||
// For tariff of following structure: only steps, no special days, nonstop.
|
||||
uint32_t GetCostFromDuration(Configuration *cfg, QDateTime const &start, quint64 durationMinutes) const;
|
||||
|
@ -58,7 +58,8 @@ public:
|
||||
/// <returns>Returns operation status bool (OK | FAIL) </returns>
|
||||
bool ParseJson(Configuration* cfg, const char* json);
|
||||
|
||||
ATBPaymentOption const &getPaymentOptions();
|
||||
ATBPaymentOption &getPaymentOptions();
|
||||
ATBPaymentOption const &getPaymentOptions() const;
|
||||
QVector<ATBDailyTicket> const &getDailyTickets() const;
|
||||
|
||||
private:
|
||||
|
@ -695,72 +695,86 @@ Ticket Calculator::private_GetDurationFromCost(Configuration *cfg,
|
||||
cost, Ticket::s[VALID]);
|
||||
}
|
||||
|
||||
QList<int> Calculator::GetTimeSteps(Configuration *cfg) const {
|
||||
QList<int> timeSteps;
|
||||
QList<int> Calculator::GetTimeSteps(Configuration *cfg, quint64 startInMinutes) const {
|
||||
static QList<int> timeSteps;
|
||||
|
||||
int const pop_id = cfg->getPaymentOptions().pop_id;
|
||||
int const pop_carry_over = cfg->getPaymentOptions().pop_carry_over;
|
||||
int const pop_time_step_config = cfg->getPaymentOptions().pop_time_step_config;
|
||||
if (timeSteps.size() == 0) {
|
||||
int const pop_id = cfg->getPaymentOptions().pop_id;
|
||||
int const pop_carry_over = cfg->getPaymentOptions().pop_carry_over;
|
||||
int const pop_time_step_config = cfg->getPaymentOptions().pop_time_step_config;
|
||||
|
||||
if (pop_time_step_config == (int)ATBTimeStepConfig::TimeStepConfig::DYNAMIC) {
|
||||
if (pop_carry_over) {
|
||||
int const pop_carry_over_time_range_id = cfg->getPaymentOptions().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() << " payment option id:" << pop_id;
|
||||
qCritical() << " payment option carry over:" << pop_carry_over;
|
||||
qCritical() << "payment option time step config:" << pop_time_step_config;
|
||||
|
||||
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) {
|
||||
int const durationId = itr->second.pra_payment_unit_id;
|
||||
auto search = cfg->Duration.find(durationId);
|
||||
if (search != cfg->Duration.end()) {
|
||||
ATBDuration duration = search->second;
|
||||
if (durationId == 1) {
|
||||
//duration.pun_duration_min = search->second.pun_duration_min;
|
||||
//duration.pun_duration_max = search->second.pun_duration_max;
|
||||
if (pop_time_step_config == (int)ATBTimeStepConfig::TimeStepConfig::DYNAMIC) {
|
||||
QDateTime start;
|
||||
start.setSecsSinceEpoch(startInMinutes * 60);
|
||||
uint16_t timeStepCompensation = 0;
|
||||
|
||||
QDateTime carryOver = m_start;
|
||||
carryOver = carryOver.addDays(1);
|
||||
carryOver.setTime(QTime(0, 0, 0));
|
||||
if (pop_carry_over) {
|
||||
int const pop_carry_over_time_range_id = cfg->getPaymentOptions().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;
|
||||
|
||||
int const timeStep = std::ceil(m_start.secsTo(carryOver) / 60.0);
|
||||
if (timeStep < duration.pun_duration_min || timeStep > duration.pun_duration_max) {
|
||||
qCritical()
|
||||
<< 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;
|
||||
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) {
|
||||
int const durationId = itr->second.pra_payment_unit_id;
|
||||
auto search = cfg->Duration.find(durationId);
|
||||
if (search != cfg->Duration.end()) {
|
||||
ATBDuration duration = search->second;
|
||||
if (durationId == 1) {
|
||||
QDateTime carryOver = start;
|
||||
carryOver = carryOver.addDays(1);
|
||||
carryOver.setTime(QTime(0, 0, 0));
|
||||
|
||||
int const timeStep = std::ceil(start.secsTo(carryOver) / 60.0);
|
||||
if (timeStep < duration.pun_duration_min || timeStep > duration.pun_duration_max) {
|
||||
qCritical()
|
||||
<< 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() << "configured minimal parking time:" << cfg->getPaymentOptions().pop_min_time;
|
||||
|
||||
// set dynamic minimal parking time
|
||||
cfg->getPaymentOptions().pop_min_time = timeStep;
|
||||
|
||||
qCritical() << " computed minimal parking time:" << cfg->getPaymentOptions().pop_min_time;
|
||||
|
||||
duration.pun_duration = timeStep;
|
||||
timeStepCompensation = duration.pun_duration_max - duration.pun_duration;
|
||||
timeSteps << duration.pun_duration;
|
||||
} else {
|
||||
duration.pun_duration = duration.pun_duration_max - timeStepCompensation;
|
||||
timeSteps << duration.pun_duration;;
|
||||
}
|
||||
duration.pun_duration = timeStep;
|
||||
m_timeStepCompensation = duration.pun_duration_max - duration.pun_duration;
|
||||
timeSteps << duration.pun_duration;
|
||||
} else {
|
||||
duration.pun_duration = duration.pun_duration_max - m_timeStepCompensation;
|
||||
timeSteps << duration.pun_duration;;
|
||||
|
||||
cfg->Duration.erase(search);
|
||||
cfg->Duration.insert(pair<int, ATBDuration>(duration.pun_id, duration));
|
||||
|
||||
} else { // if (search != cfg->Duration.end()) {
|
||||
// TODO
|
||||
}
|
||||
|
||||
cfg->Duration.erase(search);
|
||||
cfg->Duration.insert(pair<int, ATBDuration>(duration.pun_id, duration));
|
||||
|
||||
} else { // if (search != cfg->Duration.end()) {
|
||||
// TODO
|
||||
}
|
||||
} else { // if (carryOverTimeRangeFrom == QTime(0, 0, 0)) {
|
||||
// TODO
|
||||
}
|
||||
} else { // if (carryOverTimeRangeFrom == QTime(0, 0, 0)) {
|
||||
} else { // if (carryOverTimeRangeFrom == carryOverTimeRangeTo) {
|
||||
// TODO
|
||||
}
|
||||
} else { // if (carryOverTimeRangeFrom == carryOverTimeRangeTo) {
|
||||
} else { // if (pop_carry_over) {
|
||||
// TODO
|
||||
}
|
||||
} else { // if (pop_carry_over) {
|
||||
// TODO
|
||||
}
|
||||
} else {
|
||||
for (auto[itr, rangeEnd] = cfg->PaymentRate.equal_range(pop_id); itr != rangeEnd; ++itr)
|
||||
{
|
||||
int const durationId = itr->second.pra_payment_unit_id;
|
||||
int const durationUnit = cfg->Duration.find(durationId)->second.pun_duration;
|
||||
timeSteps << durationUnit;
|
||||
} else {
|
||||
for (auto[itr, rangeEnd] = cfg->PaymentRate.equal_range(pop_id); itr != rangeEnd; ++itr)
|
||||
{
|
||||
int const durationId = itr->second.pra_payment_unit_id;
|
||||
int const durationUnit = cfg->Duration.find(durationId)->second.pun_duration;
|
||||
timeSteps << durationUnit;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -442,7 +442,10 @@ bool Configuration::ParseJson(Configuration* cfg, const char* json)
|
||||
|
||||
|
||||
|
||||
const ATBPaymentOption & Configuration::getPaymentOptions()
|
||||
{
|
||||
ATBPaymentOption const &Configuration::getPaymentOptions() const {
|
||||
return this->currentPaymentOptions;
|
||||
}
|
||||
|
||||
ATBPaymentOption &Configuration::getPaymentOptions() {
|
||||
return this->currentPaymentOptions;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user