Compare commits

...

7 Commits

Author SHA1 Message Date
40440e28d3 Read pop_accumulate_prices and pop_accumulate_durations. 2024-07-22 15:56:04 +02:00
ba8e2786fc GetTimeSteps():
updated as well for Schnals (505). Still to  be tested.
2024-07-22 15:54:36 +02:00
b5804408f4 GetDurationFromCost():
expanded. still to be tested.
2024-07-22 15:53:27 +02:00
f7be0e471a getDurationFromCost():
call
		Calculator::GetInstance().GetTimeSteps(cfg, 0, inputDate);
	for its side-effects.
	Timesteps will be used in the following calculation.
2024-07-22 15:50:36 +02:00
45694106a7 GetTimeSteps():
added default parameter 'start'; was set inside the funtion.
2024-07-22 15:48:21 +02:00
6d125c65fe Added flags
pop_accumulate_prices
	pop_accumulate_durations
to decide if values in json files should be accumulated or not.
2024-07-22 15:46:45 +02:00
1c86e1ac40 tests for schnals 2024-07-22 15:46:13 +02:00
5 changed files with 206 additions and 198 deletions

View File

@ -91,8 +91,10 @@ public:
// helper function to find time steps for a tariff with PaymentMethod::Steps // helper function to find time steps for a tariff with PaymentMethod::Steps
// (e.g. Schoenau/Koenigsee) // (e.g. Schoenau/Koenigsee)
// //
QList<int> &GetTimeSteps(Configuration *cfg, int paymentOptionIndex=0) const; QList<int> &GetTimeSteps(Configuration *cfg, int paymentOptionIndex=0, QDateTime const &start = QDateTime::currentDateTime()) const;
QList<int> GetSteps(Configuration *cfg, int paymentOptionIndex=0) const { return GetTimeSteps(cfg, paymentOptionIndex); } QList<int> GetSteps(Configuration *cfg, int paymentOptionIndex=0, QDateTime const &start = QDateTime::currentDateTime()) const {
return GetTimeSteps(cfg, paymentOptionIndex, start);
}
QList<int> GetPriceSteps(Configuration *cfg) const; QList<int> GetPriceSteps(Configuration *cfg) const;

View File

@ -27,6 +27,8 @@ public:
pop_carry_over_option_id = -1; pop_carry_over_option_id = -1;
pop_prepaid_option_id = -1; pop_prepaid_option_id = -1;
pop_truncate_last_interpolation_step = false; pop_truncate_last_interpolation_step = false;
pop_accumulate_prices = false;
pop_accumulate_durations = false;
pop_carry_over_target = false; pop_carry_over_target = false;
pop_carry_over_time_range_id = -1; pop_carry_over_time_range_id = -1;
pop_carry_over_start_time_range = -1; pop_carry_over_start_time_range = -1;
@ -57,6 +59,8 @@ public:
int pop_daily_card_price; int pop_daily_card_price;
uint64_t pop_business_hours; uint64_t pop_business_hours;
int pop_time_step_config; int pop_time_step_config;
bool pop_accumulate_prices;
bool pop_accumulate_durations;
struct ATBMaxDateTime { struct ATBMaxDateTime {
int direction; int direction;

View File

@ -127,8 +127,13 @@ std::string Calculator::GetDurationFromCost(Configuration* cfg,
// Get input date // Get input date
QDateTime inputDate = QDateTime::fromString(startDatetimePassed,Qt::ISODate); QDateTime inputDate = QDateTime::fromString(startDatetimePassed,Qt::ISODate);
static const PaymentMethod paymentMethodId = Utilities::getPaymentMethodId(cfg); static const PaymentMethod paymentMethodId = Utilities::getPaymentMethodId(cfg);
//qCritical() << DBG_HEADER << " start" << inputDate.toString(Qt::ISODate);
//qCritical() << DBG_HEADER << "paymentMethodId" << static_cast<int>(paymentMethodId);
Calculator::GetInstance().GetTimeSteps(cfg, 0, inputDate);
if (paymentMethodId == PaymentMethod::Steps) { if (paymentMethodId == PaymentMethod::Steps) {
if (tariffIs24_7(cfg)) { if (tariffIs24_7(cfg)) {
// use tariff with structure as for instance Schoenau, Koenigsee: // use tariff with structure as for instance Schoenau, Koenigsee:
@ -262,24 +267,41 @@ std::string Calculator::GetDurationFromCost(Configuration* cfg,
qCritical() << DBG_HEADER << " CURRENT WORKING-TIME-TO" << current_working_time_to.toString(Qt::ISODate); qCritical() << DBG_HEADER << " CURRENT WORKING-TIME-TO" << current_working_time_to.toString(Qt::ISODate);
#endif #endif
int const pop_accumulate_prices = cfg->getPaymentOptions(paymentOptionIndex).pop_accumulate_prices;
int const pop_accumulate_durations = cfg->getPaymentOptions(paymentOptionIndex).pop_accumulate_durations;
int price = 0;
int durationInSecs = 0;
for (auto[itr, rangeEnd] = cfg->PaymentRate.equal_range(pop_id); itr != rangeEnd; ++itr) { for (auto[itr, rangeEnd] = cfg->PaymentRate.equal_range(pop_id); itr != rangeEnd; ++itr) {
int const pra_price = itr->second.pra_price; int const pra_price = itr->second.pra_price;
if ((double)pra_price == cost) {
int const durationId = itr->second.pra_payment_unit_id; int const durationId = itr->second.pra_payment_unit_id;
if (pop_accumulate_prices) {
price += pra_price;
} else {
price = pra_price;
}
//qCritical() << DBG_HEADER << " PRICE" << price << "COST" << cost;
auto search = cfg->Duration.find(durationId); auto search = cfg->Duration.find(durationId);
if (search != cfg->Duration.end()) { if (search != cfg->Duration.end()) {
// found now the duration in minutes // found now the duration in minutes
// check if we are still inside the working-time-range // check if we are still inside the working-time-range
ATBDuration duration = search->second; ATBDuration duration = search->second;
//if (pop_accumulate_durations) {
// durationInSecs += duration.pun_duration * 60;
//} else {
durationInSecs = duration.pun_duration * 60;
//}
int durationInSecs = duration.pun_duration * 60; if ((double)price == cost) {
QDateTime current_working_date_time_to = inputDate; QDateTime current_working_date_time_to = inputDate;
current_working_date_time_to.setTime(current_working_time_to); current_working_date_time_to.setTime(current_working_time_to);
#if DEBUG_GET_DURATION_FROM_COST==1 #if DEBUG_GET_DURATION_FROM_COST==1
qCritical() << DBG_HEADER << "DURATION IN MINUTES" << duration.pun_duration; qCritical() << DBG_HEADER << " DURATION ID" << duration.pun_id;
qCritical() << DBG_HEADER << "DURATION IN SECONDS" << duration.pun_duration * 60; qCritical() << DBG_HEADER << "DURATION IN MINUTES" << durationInSecs / 60;
qCritical() << DBG_HEADER << "DURATION IN SECONDS" << durationInSecs;
qCritical() << DBG_HEADER << "CURRENT-WORKING-DATE-TIME-TO" qCritical() << DBG_HEADER << "CURRENT-WORKING-DATE-TIME-TO"
<< current_working_date_time_to.toString(Qt::ISODate); << current_working_date_time_to.toString(Qt::ISODate);
qCritical() << DBG_HEADER << "NEW INPUT DATE" << inputDate.addSecs(durationInSecs).toString(Qt::ISODate); qCritical() << DBG_HEADER << "NEW INPUT DATE" << inputDate.addSecs(durationInSecs).toString(Qt::ISODate);
@ -363,7 +385,7 @@ std::string Calculator::GetDurationFromCost(Configuration* cfg,
#endif #endif
return s.toStdString(); return s.toStdString();
} } // if ((double)price == cost) {
} }
} }
@ -2094,8 +2116,11 @@ QList<int> Calculator::GetPriceSteps(Configuration * /*cfg*/) const {
#define DEBUG_GET_TIME_STEPS (1) #define DEBUG_GET_TIME_STEPS (1)
QList<int> &Calculator::GetTimeSteps(Configuration *cfg, int paymentOptionIndex) const { QList<int> &Calculator::GetTimeSteps(Configuration *cfg, int paymentOptionIndex,
QDateTime const &s) const {
if (DBG_LEVEL >= DBG_DEBUG) {
qCritical() << "(" << __func__ << ":" << __LINE__ << ") paymentOptionIndex:" << paymentOptionIndex; qCritical() << "(" << __func__ << ":" << __LINE__ << ") paymentOptionIndex:" << paymentOptionIndex;
}
if (m_timeSteps.size() > paymentOptionIndex) { if (m_timeSteps.size() > paymentOptionIndex) {
if (!m_timeSteps[paymentOptionIndex].isEmpty()) { if (!m_timeSteps[paymentOptionIndex].isEmpty()) {
@ -2105,9 +2130,8 @@ QList<int> &Calculator::GetTimeSteps(Configuration *cfg, int paymentOptionIndex)
m_timeSteps.push_back(QList<int>()); m_timeSteps.push_back(QList<int>());
} }
QDateTime start = QDateTime::currentDateTime(); QDateTime start = s;
//start.setTime(QTime(start.time().hour(), start.time().minute(), 0)); start.setTime(QTime(s.time().hour(), s.time().minute(), 0));
start.setTime(QTime(7, start.time().minute(), 0));
int const pop_id = cfg->getPaymentOptions(paymentOptionIndex).pop_id; int const pop_id = cfg->getPaymentOptions(paymentOptionIndex).pop_id;
int const pop_carry_over = cfg->getPaymentOptions(paymentOptionIndex).pop_carry_over; int const pop_carry_over = cfg->getPaymentOptions(paymentOptionIndex).pop_carry_over;
@ -2116,10 +2140,14 @@ QList<int> &Calculator::GetTimeSteps(Configuration *cfg, int paymentOptionIndex)
static PaymentMethod const paymentMethodId = Utilities::getPaymentMethodId(cfg); static PaymentMethod const paymentMethodId = Utilities::getPaymentMethodId(cfg);
qCritical() << "(" << __func__ << ":" << __LINE__ << ") start parking time:" << start.toString(Qt::ISODate);
if (DBG_LEVEL >= DBG_DEBUG) {
qCritical() << "(" << __func__ << ":" << __LINE__ << ") start parking time:" << start.toString(Qt::ISODate); qCritical() << "(" << __func__ << ":" << __LINE__ << ") start parking time:" << start.toString(Qt::ISODate);
qCritical() << "(" << __func__ << ":" << __LINE__ << ") payment option id:" << pop_id; qCritical() << "(" << __func__ << ":" << __LINE__ << ") payment option id:" << pop_id;
qCritical() << "(" << __func__ << ":" << __LINE__ << ") time step configuration:" << pop_time_step_config; qCritical() << "(" << __func__ << ":" << __LINE__ << ") time step configuration:" << pop_time_step_config;
qCritical() << "(" << __func__ << ":" << __LINE__ << ") prepaid option id:" << pop_prepaid_option_id; qCritical() << "(" << __func__ << ":" << __LINE__ << ") prepaid option id:" << pop_prepaid_option_id;
}
if (pop_time_step_config == (int)ATBTimeStepConfig::TimeStepConfig::DYNAMIC) { if (pop_time_step_config == (int)ATBTimeStepConfig::TimeStepConfig::DYNAMIC) {
//qCritical() << __PRETTY_FUNCTION__ << "payment option time step config:" << "TimeStepConfig::DYNAMIC"; //qCritical() << __PRETTY_FUNCTION__ << "payment option time step config:" << "TimeStepConfig::DYNAMIC";
@ -2133,25 +2161,34 @@ QList<int> &Calculator::GetTimeSteps(Configuration *cfg, int paymentOptionIndex)
} else { } else {
uint16_t timeStepCompensation = 0; uint16_t timeStepCompensation = 0;
if (DBG_LEVEL >= DBG_DEBUG) {
qCritical() << "(" << __func__ << ":" << __LINE__ << ") payment option carry over:" << pop_carry_over; qCritical() << "(" << __func__ << ":" << __LINE__ << ") payment option carry over:" << pop_carry_over;
}
if (pop_carry_over) { if (pop_carry_over) {
int const pop_carry_over_time_range_id = cfg->getPaymentOptions(paymentOptionIndex).pop_carry_over_time_range_id; int const pop_carry_over_time_range_id = cfg->getPaymentOptions(paymentOptionIndex).pop_carry_over_time_range_id;
int const pop_carry_over_option_id = cfg->getPaymentOptions(paymentOptionIndex).pop_carry_over_option_id; int const pop_carry_over_option_id = cfg->getPaymentOptions(paymentOptionIndex).pop_carry_over_option_id;
int const pop_truncate_last_interpolation_step = cfg->getPaymentOptions(paymentOptionIndex).pop_truncate_last_interpolation_step;
QTime const carryOverTimeRangeFrom = cfg->TimeRange.find(pop_carry_over_time_range_id)->second.time_range_from; 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; QTime const carryOverTimeRangeTo = cfg->TimeRange.find(pop_carry_over_time_range_id)->second.time_range_to;
if (DBG_LEVEL >= DBG_DEBUG) {
qCritical() << "(" << __func__ << ":" << __LINE__ << ") carry over time range id:" << pop_carry_over_time_range_id; qCritical() << "(" << __func__ << ":" << __LINE__ << ") carry over time range id:" << pop_carry_over_time_range_id;
qCritical() << "(" << __func__ << ":" << __LINE__ << ") carry over option id:" << pop_carry_over_time_range_id; qCritical() << "(" << __func__ << ":" << __LINE__ << ") carry over option id:" << pop_carry_over_time_range_id;
qCritical() << "(" << __func__ << ":" << __LINE__ << ") carry over time from:" << carryOverTimeRangeFrom.toString(Qt::ISODate); qCritical() << "(" << __func__ << ":" << __LINE__ << ") carry over time from:" << carryOverTimeRangeFrom.toString(Qt::ISODate);
qCritical() << "(" << __func__ << ":" << __LINE__ << ") carry over time to:" << carryOverTimeRangeTo.toString(Qt::ISODate); qCritical() << "(" << __func__ << ":" << __LINE__ << ") carry over time to:" << carryOverTimeRangeTo.toString(Qt::ISODate);
}
int weekDay = start.date().dayOfWeek(); int weekDay = start.date().dayOfWeek();
QTime const carryOverStart = cfg->TariffCarryOverOptions.find(pop_carry_over_option_id)->second.carryover[weekDay].static_start; QTime const carryOverStart = cfg->TariffCarryOverOptions.find(pop_carry_over_option_id)->second.carryover[weekDay].static_start;
QTime const carryOverEnd = cfg->TariffCarryOverOptions.find(pop_carry_over_option_id)->second.carryover[weekDay].static_end; QTime const carryOverEnd = cfg->TariffCarryOverOptions.find(pop_carry_over_option_id)->second.carryover[weekDay].static_end;
int const carryOverDuration = cfg->TariffCarryOverOptions.find(pop_carry_over_option_id)->second.carryover[weekDay].duration;
if (DBG_LEVEL >= DBG_DEBUG) {
qCritical() << "(" << __func__ << ":" << __LINE__ << ") carry over start:" << carryOverStart.toString(Qt::ISODate); qCritical() << "(" << __func__ << ":" << __LINE__ << ") carry over start:" << carryOverStart.toString(Qt::ISODate);
qCritical() << "(" << __func__ << ":" << __LINE__ << ") carry over end:" << carryOverEnd.toString(Qt::ISODate); qCritical() << "(" << __func__ << ":" << __LINE__ << ") carry over end:" << carryOverEnd.toString(Qt::ISODate);
}
// TODO: reparieren // TODO: reparieren
if (carryOverTimeRangeFrom.secsTo(carryOverTimeRangeTo) <= 60) { // carry over time point, usually 00:00:00 if (carryOverTimeRangeFrom.secsTo(carryOverTimeRangeTo) <= 60) { // carry over time point, usually 00:00:00
@ -2197,8 +2234,10 @@ QList<int> &Calculator::GetTimeSteps(Configuration *cfg, int paymentOptionIndex)
} }
} }
} else { // if (carryOverTimeRangeFrom == QTime(0, 0, 0)) { } else { // if (carryOverTimeRangeFrom == QTime(0, 0, 0)) {
if (DBG_LEVEL >= DBG_DEBUG) {
qCritical() << "(" << __func__ << ":" << __LINE__ << ") carry over time range from:" << carryOverTimeRangeFrom.toString(Qt::ISODate); qCritical() << "(" << __func__ << ":" << __LINE__ << ") carry over time range from:" << carryOverTimeRangeFrom.toString(Qt::ISODate);
qCritical() << "(" << __func__ << ":" << __LINE__ << ") carry over time range to:" << carryOverTimeRangeTo.toString(Qt::ISODate); qCritical() << "(" << __func__ << ":" << __LINE__ << ") carry over time range to:" << carryOverTimeRangeTo.toString(Qt::ISODate);
}
m_timeSteps[paymentOptionIndex].clear(); m_timeSteps[paymentOptionIndex].clear();
@ -2206,7 +2245,9 @@ QList<int> &Calculator::GetTimeSteps(Configuration *cfg, int paymentOptionIndex)
// TODO: zusaetzlicher faktor falls vorkauf-option zieht // TODO: zusaetzlicher faktor falls vorkauf-option zieht
if (prepaidStart) { if (prepaidStart) {
start = prepaidStart.value(); start = prepaidStart.value();
if (DBG_LEVEL >= DBG_DEBUG) {
qCritical() << "(" << __func__ << ":" << __LINE__ << ") prepaid adapted start:" << start.toString(Qt::ISODate); qCritical() << "(" << __func__ << ":" << __LINE__ << ") prepaid adapted start:" << start.toString(Qt::ISODate);
}
} else { } else {
qCritical() << "(" << __func__ << ":" << __LINE__ << ") TODO"; qCritical() << "(" << __func__ << ":" << __LINE__ << ") TODO";
} }
@ -2215,13 +2256,18 @@ QList<int> &Calculator::GetTimeSteps(Configuration *cfg, int paymentOptionIndex)
std::optional<QDateTime> interpolationEndDate = cfg->getInterpolationEnd(start, paymentOptionIndex); std::optional<QDateTime> interpolationEndDate = cfg->getInterpolationEnd(start, paymentOptionIndex);
if (interpolationEndDate) { if (interpolationEndDate) {
interpolationEnd = interpolationEndDate.value(); interpolationEnd = interpolationEndDate.value();
if (DBG_LEVEL >= DBG_DEBUG) {
qCritical() << "(" << __func__ << ":" << __LINE__ << ") interpolation end:" << interpolationEnd.toString(Qt::ISODate); qCritical() << "(" << __func__ << ":" << __LINE__ << ") interpolation end:" << interpolationEnd.toString(Qt::ISODate);
}
} else { } else {
qCritical() << "(" << __func__ << ":" << __LINE__ << ") TODO"; qCritical() << "(" << __func__ << ":" << __LINE__ << ") TODO";
} }
int const start_time = start.time().hour() * 60 + start.time().minute(); // int const start_time = start.time().hour() * 60 + start.time().minute();
QDateTime nextTimeStep = start; QDateTime nextTimeStep = start;
int runtimeInMinutes = 0;
int const pop_truncate_last_interpolation_step = cfg->getPaymentOptions(paymentOptionIndex).pop_truncate_last_interpolation_step;
for (auto[itr, rangeEnd] = cfg->PaymentRate.equal_range(pop_id); itr != rangeEnd; ++itr) { for (auto[itr, rangeEnd] = cfg->PaymentRate.equal_range(pop_id); itr != rangeEnd; ++itr) {
int const durationId = itr->second.pra_payment_unit_id; int const durationId = itr->second.pra_payment_unit_id;
@ -2230,6 +2276,7 @@ QList<int> &Calculator::GetTimeSteps(Configuration *cfg, int paymentOptionIndex)
auto search = cfg->Duration.find(durationId); auto search = cfg->Duration.find(durationId);
if (search != cfg->Duration.end()) { if (search != cfg->Duration.end()) {
ATBDuration duration = search->second; ATBDuration duration = search->second;
ATBDuration &previous = search->second;
if (duration.pun_interpolation_id == -1) { if (duration.pun_interpolation_id == -1) {
@ -2249,118 +2296,102 @@ QList<int> &Calculator::GetTimeSteps(Configuration *cfg, int paymentOptionIndex)
interpolation.dynamic_start = start.time(); interpolation.dynamic_start = start.time();
interpolation.dynamic_start.setHMS(start.time().hour(), start.time().minute(), 0); interpolation.dynamic_start.setHMS(start.time().hour(), start.time().minute(), 0);
int const end_time = interpolation.dynamic_end.hour() * 60 + interpolation.dynamic_end.minute(); // 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_duration:" << duration.pun_duration;
// qCritical() << "(" << __func__ << ":" << __LINE__ << ") pun_interpolation:" << duration.pun_interpolation_id; // 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:" << interpolationEnd.toString(Qt::ISODate);
// qCritical() << "(" << __func__ << ":" << __LINE__ << ") interpolation dynamic end time:" << end_time; // 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 pop_min_time = cfg->getPaymentOptions(paymentOptionIndex).pop_min_time;
nextTimeStep = nextTimeStep.addSecs(duration.pun_duration * 60); runtimeInMinutes += duration.pun_duration;
nextTimeStep = start.addSecs(runtimeInMinutes * 60);
if (nextTimeStep.time() > carryOverStart) {
int const backTime = carryOverStart.secsTo(nextTimeStep.time()) / 60;
runtimeInMinutes -= backTime;
nextTimeStep.setTime(carryOverStart);
nextTimeStep = nextTimeStep.addSecs((backTime + carryOverDuration) * 60);
runtimeInMinutes += (backTime + carryOverDuration);
}
if (DBG_LEVEL >= DBG_DEBUG) {
qCritical() << "(" << __func__ << ":" << __LINE__ << ") next time step:" << nextTimeStep.toString(Qt::ISODate);
qCritical() << "(" << __func__ << ":" << __LINE__ << ") runtime in minutes:" << runtimeInMinutes;
}
// int nextTimeStep = start_time + duration.pun_duration;
//int rest = end_time - nextTimeStep;
int rest = nextTimeStep.secsTo(interpolationEnd); int rest = nextTimeStep.secsTo(interpolationEnd);
if (nextTimeStep <= interpolationEnd) { if (nextTimeStep <= interpolationEnd) {
if (rest > 0 && rest < duration.pun_duration) {
if (durationId == 1) { qCritical() << "(" << __func__ << ":" << __LINE__ << ") TODO TODO:" << rest;
qCritical() << "(" << __func__ << ":" << __LINE__ << ") rest minutes:" << rest;
#if DEBUG_GET_TIME_STEPS==1 // last time step before switching to dayticket (see Schnals 505/506)
qCritical() << "(" << __func__ << ":" << __LINE__ << ") pun_id:" << duration.pun_id; //if (duration.pun_duration > 0) {
qCritical() << "(" << __func__ << ":" << __LINE__ << ") pun_duration:" << duration.pun_duration; // m_timeSteps[paymentOptionIndex] << 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 = start.secsTo(nextTimeStep) / 60;
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 = start.secsTo(interpolationEnd) / 60;
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 { } else {
// duration.pun_duration = nextTimeStep; m_timeSteps[paymentOptionIndex] << runtimeInMinutes;
// HIER WEITER
#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 duration.pun_duration = runtimeInMinutes;
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 //qCritical() << "(" << __func__ << ":" << __LINE__ << ") pun_id:" << duration.pun_id;
QTime nextTime(0, 0, 0); //qCritical() << "(" << __func__ << ":" << __LINE__ << ") pun_duration:" << duration.pun_duration;
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));
search->second = duration;
} else } else
if (duration.pun_interpolation_id == (int)ATBInterpolation::NO_INTERPOLATION) { if (duration.pun_interpolation_id == (int)ATBInterpolation::NO_INTERPOLATION) {
//qCritical() << "(" << __func__ << ":" << __LINE__ << ") runtime in minutes (1):" << runtimeInMinutes;
#if DEBUG_GET_TIME_STEPS==1 QDateTime s = start.addSecs(runtimeInMinutes * 60);
qCritical() << "(" << __func__ << ":" << __LINE__ << ") pun_id:" << duration.pun_id; int const minutes = s.time().secsTo(carryOverStart) / 60;
qCritical() << "(" << __func__ << ":" << __LINE__ << ") pun duration_max:" << duration.pun_duration_max;
//qCritical() << "(" << __func__ << ":" << __LINE__ << ") minutes:" << minutes;
//qCritical() << "(" << __func__ << ":" << __LINE__ << ") s:" << s.toString(Qt::ISODate);
if (minutes > 0) {
runtimeInMinutes += minutes;
previous.pun_duration += minutes;
if (!m_timeSteps[paymentOptionIndex].isEmpty()) {
m_timeSteps[paymentOptionIndex].last() += minutes;
}
}
nextTimeStep = start.addSecs(runtimeInMinutes * 60);
//qCritical() << "(" << __func__ << ":" << __LINE__ << ") next time step:" << nextTimeStep.toString(Qt::ISODate);
//qCritical() << "(" << __func__ << ":" << __LINE__ << ") runtime in minutes (0):" << runtimeInMinutes;
runtimeInMinutes += duration.pun_duration;
nextTimeStep = start.addSecs(runtimeInMinutes * 60);
//qCritical() << "(" << __func__ << ":" << __LINE__ << ") next time step:" << nextTimeStep.toString(Qt::ISODate);
//qCritical() << "(" << __func__ << ":" << __LINE__ << ") carry over start:" << carryOverStart.toString(Qt::ISODate);
// TOOO: truncate-flag == false
if (nextTimeStep.time() > carryOverStart) {
int const backTime = carryOverStart.secsTo(nextTimeStep.time());
runtimeInMinutes -= backTime;
nextTimeStep.setTime(carryOverStart);
nextTimeStep = nextTimeStep.addSecs((backTime + carryOverDuration) * 60);
runtimeInMinutes += (backTime + carryOverDuration);
} else
if (nextTimeStep.time() < carryOverStart) {
int const forwardTime = nextTimeStep.time().secsTo(carryOverStart) / 60;
runtimeInMinutes += forwardTime;
nextTimeStep.setTime(carryOverStart);
}
if (DBG_LEVEL >= DBG_DEBUG) {
qCritical() << "(" << __func__ << ":" << __LINE__ << ") pun duration:" << duration.pun_duration; qCritical() << "(" << __func__ << ":" << __LINE__ << ") pun duration:" << duration.pun_duration;
qCritical() << "(" << __func__ << ":" << __LINE__ << ") time step compensation:" << timeStepCompensation; qCritical() << "(" << __func__ << ":" << __LINE__ << ") next time step:" << nextTimeStep.toString(Qt::ISODate);
#endif qCritical() << "(" << __func__ << ":" << __LINE__ << ") runtime in minutes (2):" << runtimeInMinutes;
}
duration.pun_duration += start_time + timeStepCompensation; duration.pun_duration = runtimeInMinutes;
m_timeSteps[paymentOptionIndex] << duration.pun_duration; m_timeSteps[paymentOptionIndex] << duration.pun_duration;
search->second = duration;
cfg->Duration.erase(search);
cfg->Duration.insert(pair<int, ATBDuration>(duration.pun_id, duration));
} else { } else {
cfg->Duration.erase(search); cfg->Duration.erase(search);
} }
@ -2395,18 +2426,19 @@ QList<int> &Calculator::GetTimeSteps(Configuration *cfg, int paymentOptionIndex)
} }
} }
if (DBG_LEVEL >= DBG_DEBUG) {
qCritical() << "(" << __func__ << ":" << __LINE__ << ") NEW timeSteps:" << m_timeSteps; qCritical() << "(" << __func__ << ":" << __LINE__ << ") NEW timeSteps:" << m_timeSteps;
#if DEBUG_GET_TIME_STEPS==1
for (int i = 0; i < m_timeSteps[paymentOptionIndex].size(); ++i) { for (int i = 0; i < m_timeSteps[paymentOptionIndex].size(); ++i) {
QDateTime nextTime = start; QDateTime nextTime = s;
nextTime.setTime(QTime(0, 0, 0)); // nextTime.setTime(QTime(0, 0, 0));
nextTime = nextTime.addSecs(m_timeSteps[paymentOptionIndex][i] * 60); int const secs = m_timeSteps[paymentOptionIndex][i] * 60;
nextTime = nextTime.addSecs(secs);
qCritical() << "(" << __func__ << ":" << __LINE__ << ") step" qCritical() << "(" << __func__ << ":" << __LINE__ << ") step"
<< i << m_timeSteps[0][i] << "->" << nextTime.toString(Qt::ISODate); << i << secs << m_timeSteps[0][i] << "->" << nextTime.toString(Qt::ISODate);
} }
#endif }
return m_timeSteps[paymentOptionIndex]; return m_timeSteps[paymentOptionIndex];
} }

View File

@ -602,6 +602,10 @@ bool Configuration::ParseJson(Configuration* cfg, const char* json)
this->currentPaymentOptions.last().pop_prepaid_option_id = k->value.GetInt(); this->currentPaymentOptions.last().pop_prepaid_option_id = k->value.GetInt();
} else if (strcmp(inner_obj_name, "pop_truncate_last_interpolation_step") == 0) { } else if (strcmp(inner_obj_name, "pop_truncate_last_interpolation_step") == 0) {
this->currentPaymentOptions.last().pop_truncate_last_interpolation_step = k->value.GetBool(); this->currentPaymentOptions.last().pop_truncate_last_interpolation_step = k->value.GetBool();
} else if (strcmp(inner_obj_name, "pop_accumulate_prices") == 0) {
this->currentPaymentOptions.last().pop_accumulate_prices = k->value.GetBool();
} else if (strcmp(inner_obj_name, "pop_accumulate_durations") == 0) {
this->currentPaymentOptions.last().pop_accumulate_durations = k->value.GetBool();
} else if (strcmp(inner_obj_name, "pop_carry_over_option_id") == 0) { } else if (strcmp(inner_obj_name, "pop_carry_over_option_id") == 0) {
this->currentPaymentOptions.last().pop_carry_over_option_id = k->value.GetInt(); this->currentPaymentOptions.last().pop_carry_over_option_id = k->value.GetInt();
} else if (strcmp(inner_obj_name, "pop_carry_over") == 0) { } else if (strcmp(inner_obj_name, "pop_carry_over") == 0) {
@ -834,6 +838,7 @@ std::optional<QDateTime> Configuration::getInterpolationEnd(QDateTime const &sta
std::optional<QDateTime> value = std::nullopt; std::optional<QDateTime> value = std::nullopt;
QDateTime interpolationEndTime = start; QDateTime interpolationEndTime = start;
//qCritical() << "(" << __func__ << ":" << __LINE__ << ") computed interpol end:" << interpolationEndTime.toString(Qt::ISODate);
int price = 0; int price = 0;
@ -918,8 +923,8 @@ std::optional<QDateTime> Configuration::getInterpolationEnd(QDateTime const &sta
//qCritical() << "(" << __func__ << ":" << __LINE__ << ") price:" << price; //qCritical() << "(" << __func__ << ":" << __LINE__ << ") price:" << price;
if (price >= interpolation.dynamic_until_price) { if (price >= interpolation.dynamic_until_price) {
qCritical() << "(" << __func__ << ":" << __LINE__ << ") price:" << price; // qCritical() << "(" << __func__ << ":" << __LINE__ << ") price:" << price;
qCritical() << "(" << __func__ << ":" << __LINE__ << ") computed interpol endr:" << interpolationEndTime.toString(Qt::ISODate); // qCritical() << "(" << __func__ << ":" << __LINE__ << ") computed interpol end:" << interpolationEndTime.toString(Qt::ISODate);
value = value.value_or(interpolationEndTime); value = value.value_or(interpolationEndTime);
break; break;
} }

View File

@ -643,8 +643,8 @@ int main() {
int pop_max_price; int pop_max_price;
int pop_daily_card_price; int pop_daily_card_price;
input.open("/home/linux/customer_505/etc/psa_tariff/tariff01.json"); //input.open("/home/linux/customer_505/etc/psa_tariff/tariff01.json");
//input.open("/opt/ptu5/opt/customer_506/etc/psa_tariff/tariff01.json"); input.open("/opt/ptu5/opt/customer_505/etc/psa_tariff/tariff01.json");
std::stringstream sstr; std::stringstream sstr;
while(input >> sstr.rdbuf()); while(input >> sstr.rdbuf());
@ -675,10 +675,12 @@ int main() {
//} //}
//return 0; //return 0;
QList<int> timeSteps = Calculator::GetInstance().GetTimeSteps(&cfg); //QDateTime start = QDateTime::currentDateTime();
qCritical() << "TimeSteps" << timeSteps; //start.setTime(QTime(18, 0, 0));
//QList<int> timeSteps = Calculator::GetInstance().GetTimeSteps(&cfg, 0, start);
//qCritical() << "TimeSteps" << timeSteps;
return 0; //return 0;
CalcState cs; CalcState cs;
double cost; double cost;
@ -687,7 +689,7 @@ int main() {
// for (int day = Qt::Monday; day <= Qt::Sunday; ++day) { // for (int day = Qt::Monday; day <= Qt::Sunday; ++day) {
for (int day = Qt::Monday; day <= Qt::Monday; ++day) { for (int day = Qt::Monday; day <= Qt::Monday; ++day) {
QDateTime s(QDate(2024, 7, 14 + day), QTime()); QDateTime s(QDate(2024, 7, 21 + day), QTime(0, 0, 0));
QDateTime end; QDateTime end;
switch (day) { switch (day) {
@ -715,66 +717,30 @@ int main() {
} }
//for (int minutes = 0; minutes < 1440; ++minutes) { //for (int minutes = 0; minutes < 1440; ++minutes) {
for (int minutes = 480; minutes < 480; minutes += 1) { for (int minutes = 420; minutes <= 420; minutes += 1) {
QDateTime start = s.addSecs(minutes * 60); QDateTime start = s.addSecs(minutes * 60);
// qCritical() << "start" << start.toString(Qt::ISODate); qCritical() << "start" << start.toString(Qt::ISODate);
QDateTime effectiveStart = start; QDateTime effectiveStart = start;
// hier sollte man auch testen was passiert, falls man ausserhalb // hier sollte man auch testen was passiert, falls man ausserhalb
// der verkaufsdaten steht // der verkaufsdaten steht
if (start.time() < QTime(8, 0, 0)) { if (start.time() < QTime(7, 0, 0)) {
effectiveStart.setTime(QTime(8, 0, 0)); effectiveStart.setTime(QTime(7, 0, 0));
} else } else
if (start.time() <= QTime(19, 0, 0)) { if (start.time() <= QTime(20, 0, 0)) {
effectiveStart = start; effectiveStart = start;
} else { } else {
effectiveStart = start.addDays(1); effectiveStart = start.addDays(1);
effectiveStart.setTime(QTime(8, 0, 0)); // next day effectiveStart.setTime(QTime(7, 0, 0)); // next day
} }
for (int i = 10; i <= 10; i += 10) { for (int i = 700; i <= 1400; i += 700) {
//for (int i = 2100; i <= 2100; i += 10) { //for (int i = 2100; i <= 2100; i += 10) {
cost = i; cost = i;
if ((cs = compute_duration_for_parking_ticket(&cfg, start, cost, end))) { // return value 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) { if (!cs) {
@ -783,17 +749,16 @@ int main() {
// qCritical() << cs.toString(); // qCritical() << cs.toString();
} }
#if 0 qCritical() << "start" << start.toString(Qt::ISODate) << "< cost" << cost
qCritical() << __LINE__ << "start ............................" << start.toString(Qt::ISODate); << "> end" << end.toString(Qt::ISODate);
qCritical() << __LINE__ << "effectiveStart ..................." << effectiveStart.toString(Qt::ISODate); }
qCritical() << __LINE__ << "cost ............................." << cost; for (int i = 60; i <= 60; i += 6) {
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
QDateTime end;
struct price_t price;
cs = compute_price_for_parking_ticket(&cfg, start, 60, end, &price);
qCritical() << "start" << start.toString(Qt::ISODate) << "end" << end.toString(Qt::ISODate);
} }
} }
} }