Compare commits

..

No commits in common. "d86a688836bfdec2e0c7eacc4129651802e12b1b" and "328f7cb712210f5396272f22aea08c3becc6d66a" have entirely different histories.

4 changed files with 135 additions and 247 deletions

View File

@ -1,7 +1,6 @@
#include <string>
#include <QDebug>
#include <QDateTime>
class ATBDuration
{
@ -17,10 +16,7 @@ public:
, pun_netto(false)
, pun_brutto(false)
, pun_fixed(false)
, pun_mutable(false)
, pun_round_to_next_24h_boundary(false)
, pun_round_to_prev_24h_boundary(false)
, pun_align_with_timepoint(QDateTime())
, pun_requires_change(false)
, pun_next_step_correction(0) {
}
@ -28,20 +24,17 @@ public:
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_saved: " << td.pun_duration_saved << "\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"
<< " pun_netto: " << td.pun_netto << "\n"
<< " pun_brutto: " << td.pun_brutto << "\n"
<< " pun_fixed: " << td.pun_fixed << "\n"
<< " pun_mutable: " << td.pun_mutable << "\n"
<< "pun_round_to_next_24h_boundary: " << td.pun_round_to_next_24h_boundary << "\n"
<< "pun_round_to_prev_24h_boundary: " << td.pun_round_to_prev_24h_boundary << "\n"
<< " pun_align_with_timepoint: " << td.pun_align_with_timepoint << endl;
<< " pun_id: " << td.pun_id << "\n"
<< " pun_label: " << QString::fromStdString(td.pun_label) << "\n"
<< " pun_duration: " << td.pun_duration << "\n"
<< " pun_duration_saved: " << td.pun_duration_saved << "\n"
<< " pun_duration_min: " << td.pun_duration_min << "\n"
<< " pun_duration_max: " << td.pun_duration_max << "\n"
<< " pun_netto: " << td.pun_netto << "\n"
<< " pun_brutto: " << td.pun_brutto << "\n"
<< " pun_fixed: " << td.pun_fixed << "\n"
<< " pun_requires_change: " << td.pun_requires_change << "\n"
<< "pun_interpolation_id: " << td.pun_interpolation_id << "\n";
return debug;
}
@ -56,9 +49,6 @@ public:
bool pun_netto; // the timestep expressed by this duration is a netto timestep
bool pun_brutto; // the timestep expressed by this duration is a brutto timestep
bool pun_fixed; // the value given in tariff-file is fixed (constant)
bool pun_mutable; // the value could change
bool pun_round_to_next_24h_boundary;
bool pun_round_to_prev_24h_boundary;
QDateTime pun_align_with_timepoint;
bool pun_requires_change; // the value has to be changes (controlled by other parameters)
int pun_next_step_correction;
};

View File

@ -10,12 +10,9 @@
#include <sstream>
#include <algorithm>
#include <optional>
#include <iterator>
#include <QDateTime>
#include <QScopedArrayPointer>
#include <QDebug>
#include <QTimeZone>
double total_duration_min = 0.0f;
double total_cost = 0.0f;
@ -2790,230 +2787,151 @@ QList<int> &Calculator::GetTimeSteps(Configuration *cfg, int paymentOptionIndex,
int const pop_accumulate_durations = cfg->getPaymentOptions(paymentOptionIndex).pop_accumulate_durations;
m_timeSteps[paymentOptionIndex].clear();
Configuration::TariffDurationType::iterator prev_it = cfg->Duration.end();
QDateTime const start(s.date(),
QTime(s.time().hour(), s.time().minute(), 0),
s.timeZone());
start = s;
start.setTime(QTime(s.time().hour(), s.time().minute(), 0));
if (DBG_LEVEL >= DBG_DEBUG) {
qCritical() << "(" << __func__ << ":" << __LINE__ << ") start:" << start.toString(Qt::ISODate);
}
QDateTime current(start);
bool casePrepay = false;
int const weekDay = start.date().dayOfWeek();
int const pop_prepay_option_id = cfg->getPaymentOptions(paymentOptionIndex).pop_prepay_option_id;
// compute prepay settings
// assumption: prepay settings the same for all days
QDateTime prepayStart(start);
QDateTime prepayEnd(start);
prepayStart.setTime(cfg->TariffPrepayOptions.find(pop_prepay_option_id)->second.prepay[weekDay].start);
prepayEnd.setTime(cfg->TariffPrepayOptions.find(pop_prepay_option_id)->second.prepay[weekDay].end);
if (start <= prepayEnd) {
prepayStart = prepayStart.addDays(-1);
} else {
prepayEnd = prepayEnd.addDays(1);
}
if (DBG_LEVEL >= DBG_DEBUG) {
qCritical() << "(" << __func__ << ":" << __LINE__ << ") prepay start" << prepayStart.toString(Qt::ISODate);
qCritical() << "(" << __func__ << ":" << __LINE__ << ") prepay end" << prepayEnd.toString(Qt::ISODate);
}
int const prepayDurationInMinutes = start.secsTo(prepayEnd) / 60;
// compute carryover settings
// assumption: carryover settings the same for all days
int const pop_carry_over_option_id = cfg->getPaymentOptions(paymentOptionIndex).pop_carry_over_option_id;
QDateTime carryOverStart(start);
QDateTime carryOverEnd(start);
carryOverStart.setTime(cfg->TariffCarryOverOptions.find(pop_carry_over_option_id)->second.carryover[weekDay].static_start);
carryOverEnd.setTime(cfg->TariffCarryOverOptions.find(pop_carry_over_option_id)->second.carryover[weekDay].static_end);
if (start <= carryOverEnd) {
carryOverStart = carryOverStart.addDays(-1);
} else {
carryOverEnd = carryOverEnd.addDays(1);
}
if (DBG_LEVEL >= DBG_DEBUG) {
qCritical() << "(" << __func__ << ":" << __LINE__ << ") carry over start" << carryOverStart.toString(Qt::ISODate);
qCritical() << "(" << __func__ << ":" << __LINE__ << ") carry over end" << carryOverEnd.toString(Qt::ISODate);
}
// int cnt = 0;
// qCritical() << "(" << __func__ << ":" << __LINE__ << ") start:" << start.toString(Qt::ISODate);
for (Configuration::TariffDurationType::iterator it = cfg->Duration.begin();
it != cfg->Duration.end();
++it) {
it->second.pun_duration = it->second.pun_duration_saved;
if (it->second.pun_requires_change) {
if (it->second.pun_netto && !it->second.pun_brutto) {
// if (++cnt > 4) continue;
int weekDay = start.date().dayOfWeek();
bool casePrepay = false;
if (m_timeSteps[paymentOptionIndex].isEmpty()) {
// handle possible prepay-condition, which applies only
// for the very first step
if (DBG_LEVEL >= DBG_DEBUG) {
qCritical() << "(" << __func__ << ":" << __LINE__ << ") pun_id" << it->second.pun_id;
}
int const pop_prepay_option_id = cfg->getPaymentOptions(paymentOptionIndex).pop_prepay_option_id;
QDateTime prepayStart(start);
QDateTime prepayEnd(start);
if (it->second.pun_mutable) {
if (it->second.pun_netto) {
if (it->second.pun_round_to_next_24h_boundary == false) {
//int weekDay = start.date().dayOfWeek();
casePrepay = false;
if (m_timeSteps[paymentOptionIndex].isEmpty()) {
// handle possible prepay-condition, which applies only
// for the very first step
if (prepayStart <= start && start <= prepayEnd) {
it->second.pun_duration = prepayDurationInMinutes;
it->second.pun_duration += it->second.pun_duration_saved ;
casePrepay = true;
}
if (DBG_LEVEL >= DBG_DEBUG) {
qCritical() << "(" << __func__ << ":" << __LINE__ << ")" << it->second.pun_duration;
qCritical() << "(" << __func__ << ":" << __LINE__ << ") prepay" << casePrepay;
}
}
if (!casePrepay) {
// handle possible carryover-condition
int durationInSecs = it->second.pun_duration_saved * 60;
if (DBG_LEVEL >= DBG_DEBUG) {
qCritical() << "(" << __func__ << ":" << __LINE__ << ")" << durationInSecs;
qCritical() << "(" << __func__ << ":" << __LINE__ << ") start" << start.toString(Qt::ISODate);
qCritical() << "(" << __func__ << ":" << __LINE__ << ") current" << current.toString(Qt::ISODate);
qCritical() << "(" << __func__ << ":" << __LINE__ << ") current next" << current.addSecs(durationInSecs).toString(Qt::ISODate);
}
it->second.pun_duration = it->second.pun_duration_saved;
if (current >= carryOverStart) {
it->second.pun_duration += current.secsTo(carryOverEnd) / 60;
} else {
// start < carryOverStart
QDateTime const &newCurrent = current.addSecs(durationInSecs);
if (newCurrent > carryOverStart) {
// cross carry over section
it->second.pun_next_step_correction = carryOverStart.secsTo(carryOverEnd) / 60;
it->second.pun_duration += it->second.pun_next_step_correction;
}
}
prepayStart.setTime(cfg->TariffPrepayOptions.find(pop_prepay_option_id)->second.prepay[weekDay].start);
prepayEnd.setTime(cfg->TariffPrepayOptions.find(pop_prepay_option_id)->second.prepay[weekDay].end);
if (start <= prepayEnd) {
prepayStart = prepayStart.addDays(-1);
} else {
// qCritical() << "(" << __func__ << ":" << __LINE__ << ")";
prepayEnd = prepayEnd.addDays(1);
}
if (pop_accumulate_durations) {
m_timeSteps[paymentOptionIndex] << it->second.pun_duration;
qCritical() << "(" << __func__ << ":" << __LINE__ << ")" << start.toString(Qt::ISODate);
qCritical() << "(" << __func__ << ":" << __LINE__ << ")" << prepayStart.toString(Qt::ISODate);
qCritical() << "(" << __func__ << ":" << __LINE__ << ")" << prepayEnd.toString(Qt::ISODate);
if (prepayStart <= start && start <= prepayEnd) {
it->second.pun_duration = start.secsTo(prepayEnd) / 60;
it->second.pun_duration += it->second.pun_duration_saved ;
casePrepay = true;
}
//if (start >= prepayStart && ) {
// it->second.pun_duration = start.secsTo(prepayEnd) / 60;
// it->second.pun_duration += it->second.pun_duration_saved ;
// casePrepay = true;
//}
qCritical() << "(" << __func__ << ":" << __LINE__ << ")" << it->second.pun_duration;
}
if (!casePrepay) {
// handle possible carryover-condition
int const pop_carry_over_option_id = cfg->getPaymentOptions(paymentOptionIndex).pop_carry_over_option_id;
QDateTime carryOverStart(start);
QDateTime carryOverEnd(start);
qCritical() << "(" << __func__ << ":" << __LINE__ << ")" << carryOverStart.toString(Qt::ISODate);
carryOverStart.setTime(cfg->TariffCarryOverOptions.find(pop_carry_over_option_id)->second.carryover[weekDay].static_start);
carryOverEnd.setTime(cfg->TariffCarryOverOptions.find(pop_carry_over_option_id)->second.carryover[weekDay].static_end);
//while (carryOverStart > carryOverEnd) {
// carryOverEnd = carryOverEnd.addDays(1);
//}
if (start <= carryOverEnd) {
carryOverStart = carryOverStart.addDays(-1);
} else {
if (!m_timeSteps[paymentOptionIndex].isEmpty()) {
int d = m_timeSteps[paymentOptionIndex].last();
m_timeSteps[paymentOptionIndex] << (d + it->second.pun_duration);
}
carryOverEnd = carryOverEnd.addDays(1);
}
current = current.addSecs(m_timeSteps[paymentOptionIndex].last() * 60);
int durationInSecs = it->second.pun_duration_saved * 60;
if (DBG_LEVEL >= DBG_DEBUG) {
qCritical() << "(" << __func__ << ":" << __LINE__ << ")" << m_timeSteps[paymentOptionIndex];
qCritical() << "(" << __func__ << ":" << __LINE__ << ") current" << current.toString(Qt::ISODate);
}
} else { // if (it->pun_round_to_next_24h_boundary == false) {
if (DBG_LEVEL >= DBG_DEBUG) {
qCritical() << "(" << __func__ << ":" << __LINE__ << ") round-to-next-24h-boundary";
qCritical() << "(" << __func__ << ":" << __LINE__ << ") prepay" << casePrepay;
qCritical() << "(" << __func__ << ":" << __LINE__ << ") current" << current.toString(Qt::ISODate);
}
if (casePrepay) {
// the last time step contains the (dynamic) prepay duration
// so it is possible to compute the last duration
int lastDuration = m_timeSteps[paymentOptionIndex].last() - prepayDurationInMinutes;
// qCritical() << "(" << __func__ << ":" << __LINE__ << ") last duration " << lastDuration;
int const minutesToAdd = 1440 - lastDuration;
current = current.addSecs(minutesToAdd * 60);
if (DBG_LEVEL >= DBG_DEBUG) {
qCritical() << "(" << __func__ << ":" << __LINE__ << ") minutes to add " << minutesToAdd;
qCritical() << "(" << __func__ << ":" << __LINE__ << ") current" << current.toString(Qt::ISODate);
}
if (pop_accumulate_durations) {
m_timeSteps[paymentOptionIndex] << minutesToAdd;
} else {
if (!m_timeSteps[paymentOptionIndex].isEmpty()) {
int d = m_timeSteps[paymentOptionIndex].last();
m_timeSteps[paymentOptionIndex] << (d + minutesToAdd);
}
}
// qCritical() << "(" << __func__ << ":" << __LINE__ << ")" << m_timeSteps[paymentOptionIndex];
casePrepay = false;
//qCritical() << "(" << __func__ << ":" << __LINE__ << ")" << durationInSecs;
//qCritical() << "(" << __func__ << ":" << __LINE__ << ")" << start.addSecs(durationInSecs).toString(Qt::ISODate);
//qCritical() << "(" << __func__ << ":" << __LINE__ << ")" << carryOverStart.toString(Qt::ISODate);
it->second.pun_duration = it->second.pun_duration_saved;
if (start >= carryOverStart) {
it->second.pun_duration += start.secsTo(carryOverEnd) / 60;
} else {
if (DBG_LEVEL >= DBG_DEBUG) {
qCritical() << "(" << __func__ << ":" << __LINE__ << ") pun_id" << it->second.pun_id;
qCritical() << "(" << __func__ << ":" << __LINE__ << ") current" << current.toString(Qt::ISODate);
qCritical() << "(" << __func__ << ":" << __LINE__ << ") pun_duration" << it->second.pun_duration;
// start < carryOverStart
if (start.addSecs(durationInSecs) >= carryOverStart) {
// cross carry over section
it->second.pun_next_step_correction = carryOverStart.secsTo(carryOverEnd) / 60;
it->second.pun_duration += it->second.pun_next_step_correction;
prev_it = it;
}
int secs = s.secsTo(current);
int const dayInSecs = 1440 * 60;
int const rest = secs % dayInSecs;
int const minutesToAdd = (dayInSecs - rest) / 60;
current = current.addSecs(minutesToAdd * 60);
it->second.pun_duration = minutesToAdd;
if (DBG_LEVEL >= DBG_DEBUG) {
qCritical() << "(" << __func__ << ":" << __LINE__ << ") minutes to add " << minutesToAdd;
qCritical() << "(" << __func__ << ":" << __LINE__ << ") current" << current.toString(Qt::ISODate);
}
if (pop_accumulate_durations) {
m_timeSteps[paymentOptionIndex] << minutesToAdd;
} else {
if (!m_timeSteps[paymentOptionIndex].isEmpty()) {
int d = m_timeSteps[paymentOptionIndex].last();
m_timeSteps[paymentOptionIndex] << (d + minutesToAdd);
}
}
// qCritical() << "(" << __func__ << ":" << __LINE__ << ")" << m_timeSteps[paymentOptionIndex];
}
}
} else { // if (it->second.pun_netto) {
qCritical() << "(" << __func__ << ":" << __LINE__ << ") TODO";
}
} else { // mutable == false
if (it->second.pun_brutto) { // no handling for prepay and carry-over
if (pop_accumulate_durations) {
m_timeSteps[paymentOptionIndex] << it->second.pun_duration;
} else {
if (!m_timeSteps[paymentOptionIndex].isEmpty()) {
int d = m_timeSteps[paymentOptionIndex].last();
m_timeSteps[paymentOptionIndex] << (d + it->second.pun_duration);
} else {
m_timeSteps[paymentOptionIndex] << it->second.pun_duration;
}
}
// qCritical() << "(" << __func__ << ":" << __LINE__ << ")" << m_timeSteps[paymentOptionIndex];
} else {
qCritical() << "(" << __func__ << ":" << __LINE__ << ") TODO";
qCritical() << "(" << __func__ << ":" << __LINE__ << ")"
<< "no change required, but set to brutto, which does not have to be changed";
}
} else {
if (it->second.pun_fixed) { // no change required: must be true
if (it->second.pun_brutto) { // no handling for prepay and carry-over
if (pop_accumulate_durations) {
int correction = 0;
if (prev_it != cfg->Duration.end()) {
correction = prev_it->second.pun_next_step_correction;
prev_it->second.pun_next_step_correction = 0;
}
if (!m_timeSteps[paymentOptionIndex].isEmpty()) {
int d = m_timeSteps[paymentOptionIndex].last();
it->second.pun_duration -= correction;
m_timeSteps[paymentOptionIndex] << (d + it->second.pun_duration);
} else {
it->second.pun_duration -= correction;
m_timeSteps[paymentOptionIndex] << it->second.pun_duration;
}
}
} else
if (it->second.pun_netto) {
qCritical() << "(" << __func__ << ":" << __LINE__ << ")" << "TODO";
}
} else {
qCritical() << "(" << __func__ << ":" << __LINE__ << ")" << "fixed is false, but no change required";
}
}
}
#if 0
for (int i = 0; i < m_timeSteps[paymentOptionIndex].size(); ++i) {
QDateTime nextTime = start;
// nextTime.setTime(QTime(0, 0, 0));
int const secs = m_timeSteps[paymentOptionIndex][i] * 60;
nextTime = nextTime.addSecs(secs);
qCritical() << "(" << __func__ << ":" << __LINE__ << ") step"
<< i << secs << m_timeSteps[0][i] << "->" << nextTime.toString(Qt::ISODate);
}
#endif
} else {
qCritical() << "(" << __func__ << ":" << __LINE__ << ") payment option time step config:" << "TimeStepConfig::STATIC";
@ -3035,9 +2953,10 @@ QList<int> &Calculator::GetTimeSteps(Configuration *cfg, int paymentOptionIndex,
//qCritical() << "(" << __func__ << ":" << __LINE__ << ") NEW timeSteps:" << m_timeSteps;
if (DBG_LEVEL >= DBG_DEBUG) {
QDateTime nextTime(s);
qCritical() << "(" << __func__ << ":" << __LINE__ << ") start" << nextTime.toString(Qt::ISODate);
qCritical() << "(" << __func__ << ":" << __LINE__ << ") NEW timeSteps:" << m_timeSteps;
for (int i = 0; i < m_timeSteps[paymentOptionIndex].size(); ++i) {
QDateTime nextTime = s;
// nextTime.setTime(QTime(0, 0, 0));
int const secs = m_timeSteps[paymentOptionIndex][i] * 60;
nextTime = nextTime.addSecs(secs);

View File

@ -144,7 +144,7 @@ bool Configuration::ParseJson(Configuration* cfg, const char* json)
continue;
}
// qCritical() << " -" << mb_name;
qCritical() << " -" << mb_name;
// Get array for each JSON object member
auto mb_array = document[mb_name].GetArray();
@ -797,25 +797,9 @@ bool Configuration::ParseJson(Configuration* cfg, const char* json)
Duration.pun_fixed = k->value.GetBool();
}
}
else if (strcmp(inner_obj_name, "pun_mutable") == 0) {
else if (strcmp(inner_obj_name, "pun_requires_change") == 0) {
if (k->value.IsBool()) {
Duration.pun_mutable = k->value.GetBool();
}
}
else if (strcmp(inner_obj_name, "pun_round_to_next_24h_boundary") == 0) {
if (k->value.IsBool()) {
Duration.pun_round_to_next_24h_boundary = k->value.GetBool();
}
}
else if (strcmp(inner_obj_name, "pun_round_to_prev_24h_boundary") == 0) {
if (k->value.IsBool()) {
Duration.pun_round_to_prev_24h_boundary = k->value.GetBool();
}
}
else if (strcmp(inner_obj_name, "pun_align_with_timepoint") == 0) {
if (k->value.IsString()) {
QDateTime const &dt = QDateTime::fromString(k->value.GetString(), Qt::ISODate);
Duration.pun_align_with_timepoint = dt;
Duration.pun_requires_change = k->value.GetBool();
}
}
break;
@ -882,7 +866,7 @@ bool Configuration::ParseJson(Configuration* cfg, const char* json)
} break;
case MemberType::DurationType:
cfg->Duration.insert(pair<int, ATBDuration>(Duration.pun_id, Duration));
//qCritical() << Duration;
// qCritical() << Duration;
break;
case MemberType::SpecialDaysWorktimeType:
cfg->SpecialDaysWorktime.insert(pair<int, ATBSpecialDaysWorktime>(SpecialDaysWorktime.pedwt_period_exc_day_id, SpecialDaysWorktime));
@ -938,7 +922,7 @@ bool Configuration::ParseJson(Configuration* cfg, const char* json)
break;
case MemberType::PrepaidOptionType:
cfg->TariffPrepayOptions.insert(pair<int, ATBPrepay>(TariffPrepayOption.id, TariffPrepayOption));
//qCritical() << TariffPrepayOption;
qCritical() << TariffPrepayOption;
break;
default:
break;

View File

@ -741,8 +741,7 @@ int main() {
input.open("/opt/ptu5/opt/customer_502/etc/psa_tariff/tariff02.json");
}
if (zone == 3) {
input.open("/opt/ptu5/opt/customer_502/etc/psa_tariff/tariff03.json");
//input.open("/home/linux/customer_502/etc/psa_tariff/tariff01.json");
//input.open("/opt/ptu5/opt/customer_502/etc/psa_tariff/tariff03.json");
input.open("/home/linux/customer_502/etc/psa_tariff/tariff03.json");
}
@ -917,9 +916,7 @@ int main() {
QDateTime end;
QDateTime s(QDateTime::currentDateTime());
s.setTime(QTime(13, 30, 0));
#if 0
s.setTime(QTime(18, 0, 0));
pop_min_time = get_minimal_parkingtime(&cfg, PermitType(PERMIT_TYPE::SHORT_TERM_PARKING), paymentOptionIndex);
pop_max_time = get_maximal_parkingtime(&cfg, PermitType(PERMIT_TYPE::SHORT_TERM_PARKING), paymentOptionIndex);
@ -941,13 +938,11 @@ int main() {
qCritical() << " pop_min_price " << pop_min_price;
qCritical() << " pop_max_price " << pop_max_price;
qCritical() << "pop_daily_card_price " << pop_daily_card_price;
#endif
CalcState calcState;
#if 1
qCritical() << "start" << s.toString(Qt::ISODate);
//for (int i = 1; i < 11; ++i) {
for (int i = 1; i < 8; ++i) {
#if 0
for (int i = 1; i < 11; ++i) {
calcState = compute_duration_for_parking_ticket(&cfg, s,
(double)i*200,
end, PermitType(PERMIT_TYPE::SHORT_TERM_PARKING_PKW));