Merge branch 'kleipeda-experimental' of /home/siegert/atbfs01entwicklung/Elektronik/PTU/git_bare_repos/libmobilisis-calc into kleipeda-experimental

This commit is contained in:
Siegfried Siegert 2024-08-02 11:29:10 +02:00
commit 8d1cbe7337
Signed by: SiegfriedSiegert
GPG Key ID: 68371E015E8F0B03
7 changed files with 240 additions and 183 deletions

View File

@ -38,8 +38,10 @@ public:
pop_daily_card_price = -1;
pop_business_hours = -1;
pop_time_step_config = -1;
pop_use_only_upto_datetime = "";
pop_use_only_for_duration = 0;
pop_use_only_upto_datetime = ""; // deprecated
pop_use_only_for_duration = 0; // deprecated
pop_plus_steps = 1; // +: jump <x=1> steps forward
pop_minus_steps = 1; // -: jump <x=1> steps backward
}
int pop_id;
@ -69,6 +71,8 @@ public:
int pop_time_step_config;
bool pop_accumulate_prices;
bool pop_accumulate_durations;
int pop_plus_steps;
int pop_minus_steps;
struct ATBMaxDateTime {
int direction;

View File

@ -3,6 +3,7 @@
#include <ctime>
#include <iostream>
#include <cmath>
#include <optional>
#include "day_of_week.h"
#include "configuration.h"
@ -62,6 +63,7 @@ namespace Utilities {
/// <returns></returns>
bool IsYearPeriodActive(Configuration* cfg, struct tm* currentDateTime);
bool IsYearPeriodActive(Configuration const *cfg, QDateTime const &currentDateTime);
std::optional<ATBPeriodYear> GetYearPeriodActive(Configuration const *cfg, QDateTime const &currentDateTime);
/// <summary>
/// Check permissions

View File

@ -3,6 +3,8 @@
#include "calculator_functions.h"
#include "payment_option.h"
#include "utilities.h"
#include "tariff_global_defines.h"
#include "period_year.h"
#include <QFile>
#include <QFileInfo>
@ -462,8 +464,8 @@ int CALCULATE_LIBRARY_API compute_next_timestep(parking_tariff_t *tariff, int cu
int UpDown, PermitType const &permitType)
{
qCritical() << " compute_next_timestep() currentTimeMinutes: " << currentTimeMinutes;
qCritical() << " compute_next_timestep() up/down (1=up, 0=down): " << UpDown;
qCritical() << __LINE__ << "compute_next_timestep() currentTimeMinutes: " << currentTimeMinutes;
qCritical() << __LINE__ << "compute_next_timestep() up/down (1=up, 0=down): " << UpDown;
// FIXME
//std::optional<ATBPaymentOption> paymentOption = tariff->getPaymentOptionForKey(permitType.get());
@ -473,7 +475,12 @@ int CALCULATE_LIBRARY_API compute_next_timestep(parking_tariff_t *tariff, int cu
//}
int const paymentOptionIndex = tariff->getPaymentOptionIndex(permitType);
qCritical() << " compute_next_timestep() payment option index: " << paymentOptionIndex;
int const &pop_plus_steps = tariff->getPaymentOptions(paymentOptionIndex).pop_plus_steps;
int const &pop_minus_steps = tariff->getPaymentOptions(paymentOptionIndex).pop_minus_steps;
qCritical() << __LINE__ << "compute_next_timestep() payment option index: " << paymentOptionIndex;
qCritical() << __LINE__ << "compute_next_timestep() plus steps: " << pop_plus_steps;
qCritical() << __LINE__ << "compute_next_timestep() minus steps: " << pop_minus_steps;
Configuration const *cfg = tariff;
@ -481,19 +488,19 @@ int CALCULATE_LIBRARY_API compute_next_timestep(parking_tariff_t *tariff, int cu
PaymentMethod const paymentMethodId = Utilities::getPaymentMethodId(cfg);
switch (paymentMethodId) {
case PaymentMethod::Progressive:
qCritical() << __LINE__ << " compute_next_timestep() paymentMethodId: Progressive";
qCritical() << __LINE__ << "compute_next_timestep() paymentMethodId: Progressive";
break;
case PaymentMethod::Degressive:
qCritical() << __LINE__ << " compute_next_timestep() paymentMethodId: Degressive";
qCritical() << __LINE__ << "compute_next_timestep() paymentMethodId: Degressive";
break;
case PaymentMethod::Linear:
qCritical() << __LINE__ << " compute_next_timestep() paymentMethodId: Linear";
qCritical() << __LINE__ << "compute_next_timestep() paymentMethodId: Linear";
break;
case PaymentMethod::Steps:
qCritical() << __LINE__ << " compute_next_timestep() paymentMethodId: Steps";
qCritical() << __LINE__ << "compute_next_timestep() paymentMethodId: Steps";
break;
case PaymentMethod::Undefined:
qCritical() << __LINE__ << " compute_next_timestep() paymentMethodId: Undefined";
qCritical() << __LINE__ << "compute_next_timestep() paymentMethodId: Undefined";
break;
}
@ -502,9 +509,8 @@ int CALCULATE_LIBRARY_API compute_next_timestep(parking_tariff_t *tariff, int cu
if ((paymentMethodId == PaymentMethod::Steps) ||
// progressive tariff: e.g. Neuhauser, Kirchdorf (743)
(paymentMethodId == PaymentMethod::Progressive))
// (paymentMethodId == PaymentMethod::Degressive)) degressive tariff: e.g. Fuchs Technik (500)
{
// int paymentOptionIndex = 1;
QList<int> &stepList = Calculator::GetInstance().GetTimeSteps(tariff, paymentOptionIndex);
int const size = stepList.size();
if (size == 0) {
@ -512,52 +518,94 @@ int CALCULATE_LIBRARY_API compute_next_timestep(parking_tariff_t *tariff, int cu
return currentTimeMinutes;
}
qCritical() << " compute_next_timestep() first time step:" << stepList[0];
qCritical() << " compute_next_timestep() timeSteps:" << stepList;
qCritical() << " compute_next_timestep() currentTimeInMinutes:" << currentTimeMinutes;
qCritical() << __LINE__ << "compute_next_timestep() first time step:" << stepList[0];
qCritical() << __LINE__ << "compute_next_timestep() timeSteps:" << stepList;
qCritical() << __LINE__ << "compute_next_timestep() currentTimeInMinutes:" << currentTimeMinutes;
// consider time shift: the step-list might have been computed at a
// slightly different time point
int currentStepIndex = stepList.indexOf(currentTimeMinutes);
if (currentStepIndex == -1) {
unsigned minimalDistance = ~0;
int j = -1;
for (int i = 0; i < stepList.size(); ++i) {
unsigned distance = std::abs(stepList[i] - currentTimeMinutes);
if (distance < minimalDistance) {
minimalDistance = distance;
j = i;
}
}
// max. tolerance set to 3 minutes
unsigned const tolerance = std::min(minimalDistance, (unsigned)(3));
if (j != -1) {
stepList[j] = currentTimeMinutes;
}
}
#if 0
int maxStep = -1;
if (size >= 2) {
maxStep = stepList[1] - stepList[0];
}
int tolerance = (maxStep == -1) ? 5 : std::min(maxStep, 5);
// max. tolerance set to 5 minutes
int const tolerance = (maxStep == -1) ? 5 : std::min(maxStep, 5);
for (int i=0; i < stepList.size(); ++i) {
if (std::abs(stepList[i] - currentTimeMinutes) <= tolerance) {
qCritical().noquote()
<< QString(" compute_next_timestep() correction stepList[%1]=%2 -> %3:")
<< __LINE__ << QString("compute_next_timestep() correction stepList[%1]=%2 -> %3:")
.arg(i).arg(stepList[0]).arg(currentTimeMinutes);
stepList[i] = currentTimeMinutes;
qCritical() << " compute_next_timestep() NEW timeSteps:" << stepList;
qCritical() << __LINE__ << "compute_next_timestep() NEW timeSteps:" << stepList;
}
}
int currentStepIndex = stepList.indexOf(currentTimeMinutes);
#endif
currentStepIndex = stepList.indexOf(currentTimeMinutes);
qCritical() << __LINE__ << "compute_next_timestep() currentStepIndex (" << currentStepIndex << ")";
if (currentStepIndex == -1) {
qCritical() << "compute_next_timestep() *NO STEP* for currentTimeMinutes (" << currentTimeMinutes << ")";
qCritical() << __LINE__ << "compute_next_timestep() *NO STEP* for currentTimeMinutes (" << currentTimeMinutes << ")";
return currentTimeMinutes;
}
if (UpDown == 1) { // UP
if (stepList[currentStepIndex] == stepList.last()) {
qCritical() << "compute_next_timestep() *NO NEXT STEP* for currentTimeMinutes (" << currentTimeMinutes << ")";
qCritical() << __LINE__ << "compute_next_timestep() *NO NEXT STEP* for currentTimeMinutes (" << currentTimeMinutes << ")";
return currentTimeMinutes;
}
else {
qCritical() << " compute_next_timestep() return next time step:" << stepList[currentStepIndex + 1];
return stepList[currentStepIndex + 1];
int const rest = currentStepIndex % pop_plus_steps;
if (rest) {
currentStepIndex -= rest;
}
qCritical() << __LINE__ << "compute_next_timestep() currentStepIndex (" << currentStepIndex << ")";
int const nextStepIndex = currentStepIndex + pop_plus_steps;
qCritical() << __LINE__ << "compute_next_timestep() next step index:" << nextStepIndex;
if (nextStepIndex >= 0 && nextStepIndex < stepList.size()) {
qCritical() << __LINE__ << "compute_next_timestep() return next time step:" << stepList[nextStepIndex];
return stepList[nextStepIndex];
}
}
}
if (UpDown == 0) { // DOWN
if (stepList[currentStepIndex] == stepList.first()) {
qCritical() << "compute_next_timestep() *NO PREVIOUS STEP* for currentTimeMinutes (" << currentTimeMinutes << ")";
qCritical() << __LINE__ << "compute_next_timestep() *NO PREVIOUS STEP* for currentTimeMinutes (" << currentTimeMinutes << ")";
return currentTimeMinutes;
}
else {
qCritical() << " compute_next_timestep() return next time step:" << stepList[currentStepIndex - 1];
return stepList[currentStepIndex - 1];
int const nextStepIndex = currentStepIndex - pop_minus_steps;
qCritical() << __LINE__ << "compute_next_timestep() next step index:" << nextStepIndex;
if (nextStepIndex >= 0 && nextStepIndex < stepList.size()) {
qCritical() << __LINE__ << "compute_next_timestep() return next time step:" << stepList[nextStepIndex];
return stepList[nextStepIndex];
}
}
}
} else
@ -660,7 +708,7 @@ CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket(
CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket(
parking_tariff_t *tariff,
QDateTime &start_parking_time,
QDateTime &start_parking_time_,
int netto_parking_time,
QDateTime &end_parking_time,
struct price_t *price,
@ -669,6 +717,8 @@ CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket(
{
CalcState calcState;
QDateTime start_parking_time(start_parking_time_);
int paymentOptionIndex = tariff->getPaymentOptionIndex(permitType);
double minMin = tariff->getPaymentOptions(paymentOptionIndex).pop_min_time;
@ -682,9 +732,9 @@ CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket(
<< " start + netto: " << start_parking_time.addSecs(netto_parking_time * 60) << endl
<< " minMin: " << minMin << endl
<< " maxMin: " << maxMin
<< " prepaid: " << prepaid
<< " permitType: " << permitType.toString();
if (netto_parking_time < 0) {
calcState.setDesc(QString("end=%1, start=%2")
.arg(end_parking_time.toString(Qt::ISODate),
@ -705,59 +755,65 @@ CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket(
double cost = -1;
if (start_parking_time.isValid()) {
// qCritical() << __func__ << __LINE__;
if (tariff->getPaymentOptions(paymentOptionIndex).pop_payment_method_id == PaymentMethod::Steps ||
tariff->getPaymentOptions(paymentOptionIndex).pop_payment_method_id == PaymentMethod::Degressive) {
// qCritical() << __func__ << __LINE__;
// hier muesste man unterscheiden: uebertrag oder nicht?
calcState = Calculator::GetInstance().isParkingAllowed(tariff, start_parking_time,
netto_parking_time, paymentOptionIndex);
if (calcState.getStatus() == CalcState::State::OUTSIDE_ALLOWED_PARKING_TIME) {
qCritical() << "(" << __func__ << ":" << __LINE__ << ")"
<< calcState.toString();
// qCritical() << __func__ << __LINE__;
return calcState;
}
// qCritical() << __func__ << __LINE__;
QList<int> lll = Calculator::GetInstance().GetTimeSteps(tariff);
QList<int> tlist = Calculator::GetInstance().GetTimeSteps(tariff);
Q_UNUSED(tlist);
// netto_parking_time = compute_next_timestep(tariff, netto_parking_time, 1, permitType);
qCritical() << "LINE" << __LINE__ << "netto" << netto_parking_time << lll;
// qCritical() << __func__ << __LINE__;
cost = Calculator::GetInstance().GetCostFromDuration(tariff, start_parking_time, netto_parking_time, paymentOptionIndex);
int weekDay = start_parking_time.date().dayOfWeek();
int const pop_carry_over_option_id = tariff->getPaymentOptions(paymentOptionIndex).pop_carry_over_option_id;
int pop_carry_over_option_id = tariff->getPaymentOptions(paymentOptionIndex).pop_carry_over_option_id;
std::optional<ATBPeriodYear> yperiod = Utilities::GetYearPeriodActive(tariff, start_parking_time);
if (yperiod.has_value()) {
ATBPeriodYear const &period = yperiod.value();
pop_carry_over_option_id = period.pye_id;
}
qCritical() << __func__ << __LINE__ << "carryOver-id" << pop_carry_over_option_id;
QTime const carryOverStart = tariff->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;
int const carryOverDuration = tariff->TariffCarryOverOptions.find(pop_carry_over_option_id)->second.carryover[weekDay].duration;
qCritical() << "LINE" << __LINE__ << "carryStart" << carryOverStart.toString(Qt::ISODate);
qCritical() << "LINE" << __LINE__ << "carryDur" << carryOverDuration;
qCritical() << "LINE" << __LINE__ << "start" << start_parking_time.toString(Qt::ISODate);
qCritical() << __func__ << __LINE__ << "carryOverStart" << carryOverStart.toString(Qt::ISODate);
qCritical() << __func__ << __LINE__ << "carryOverDuration" << carryOverDuration;
if (start_parking_time.time() > carryOverStart) {
//int const backTime = carryOverStart.secsTo(start_parking_time.time()) / 60;
//qCritical() << "LINE" << __LINE__ << "backTime" << backTime;
//qCritical() << "LINE" << __LINE__ << "backTime + dur" << backTime + carryOverDuration;
start_parking_time.setTime(carryOverStart);
start_parking_time = start_parking_time.addSecs(carryOverDuration * 60);
// handle prepaid option
QDateTime effectiveStartTime(start_parking_time);
int const prepaid_option_id = tariff->getPaymentOptions(paymentOptionIndex).pop_prepaid_option_id;
std::optional<ATBPrepaid> prepaidOption = tariff->getPrepaidType(prepaid_option_id);
if (prepaidOption.has_value()) {
ATBPrepaid const &p = prepaidOption.value();
if (start_parking_time.time() < p.static_end) { // static_end: e.g. 08:00:00
effectiveStartTime.setTime(p.static_end);
} else
if (start_parking_time.time() > p.static_start) { // static_start: e.g. 22:00:00
effectiveStartTime.setTime(p.static_start);
}
}
end_parking_time = start_parking_time.addSecs(netto_parking_time*60);
qCritical() << "LINE" << __LINE__ << "netto" << netto_parking_time;
qCritical() << "LINE" << __LINE__ << "start" << start_parking_time.toString(Qt::ISODate);
qCritical() << "(" << __func__ << ":" << __LINE__ << ")"
<< "end_parking_time" << end_parking_time.toString(Qt::ISODate);
// handle carry over
int minutesUntilCarryOver = effectiveStartTime.time().secsTo(carryOverStart) / 60;
if (netto_parking_time > minutesUntilCarryOver) {
int const rest = netto_parking_time - minutesUntilCarryOver;
QDateTime s(effectiveStartTime);
s = s.addSecs(minutesUntilCarryOver * 60);
s = s.addSecs(carryOverDuration * 60);
end_parking_time = s.addSecs(rest * 60);
} else {
end_parking_time = effectiveStartTime.addSecs(netto_parking_time*60);
}
} else {
// qCritical() << __func__ << __LINE__;
cost = Calculator::GetInstance().GetCostFromDuration(
tariff,
tariff->getPaymentOptions().pop_payment_method_id,
@ -774,8 +830,8 @@ CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket(
}
// DEBUG
qCritical() << __LINE__ << " end_parking_time: " << end_parking_time;
qCritical() << __LINE__ << " -> calculated cost (netto): " << cost;
//qCritical() << __LINE__ << " end_parking_time: " << end_parking_time;
//qCritical() << __LINE__ << " -> calculated cost (netto): " << cost;
price->brutto = price->vat = price->vat_percentage = 0;
price->units = cost;
@ -851,10 +907,12 @@ CalcState CALCULATE_LIBRARY_API compute_duration_for_parking_ticket(
bool const nextDay = false;
// DEBUG
if (DBG_LEVEL >= DBG_DEBUG) {
qCritical() << "compute_duration_for_parking_ticket(2): ";
qCritical() << " payment option index: " << paymentOptionIndex;
qCritical() << " prepaid: " << prepaid;
qCritical() << " price: " << price;
}
if (start_parking_time.isValid()) {
QString cs = start_parking_time.toString(Qt::ISODate);

View File

@ -135,14 +135,20 @@ std::string Calculator::GetDurationFromCost(Configuration* cfg,
static const PaymentMethod paymentMethodId = Utilities::getPaymentMethodId(cfg);
int const paymentOptionIndex = cfg->getPaymentOptionIndex(permitType.get());
if (DBG_LEVEL >= DBG_DEBUG) {
qCritical() << DBG_HEADER << " start:" << inputDate.toString(Qt::ISODate);
qCritical() << DBG_HEADER << " option index:" << paymentOptionIndex;
qCritical() << DBG_HEADER << "paymentMethodId:" << static_cast<int>(paymentMethodId);
qCritical() << DBG_HEADER << " prepaid:" << prepaid;
qCritical() << DBG_HEADER << " cost (price):" << cost;
}
QList<int> tsteps = Calculator::GetInstance().GetTimeSteps(cfg, paymentOptionIndex, inputDate);
if (DBG_LEVEL >= DBG_DEBUG) {
qCritical() << DBG_HEADER << " time steps:" << tsteps;
} else {
Q_UNUSED(tsteps);
}
if (paymentMethodId == PaymentMethod::Degressive) {
@ -287,6 +293,9 @@ std::string Calculator::GetDurationFromCost(Configuration* cfg,
QTime pwd_time_from = QTime::fromString(QString::fromStdString(iter->second.pwd_time_from), Qt::ISODate);
QTime pwd_time_to = QTime::fromString(QString::fromStdString(iter->second.pwd_time_to), Qt::ISODate);
//qCritical() << DBG_HEADER << "from" << pwd_time_from.toString(Qt::ISODate);
//qCritical() << DBG_HEADER << " to" << pwd_time_to.toString(Qt::ISODate);
if (inputDate.time() < pwd_time_from) {
inputDate.setTime(pwd_time_from);
useWeekDaysWorkTimeOfOtherDay = false;
@ -418,6 +427,10 @@ std::string Calculator::GetDurationFromCost(Configuration* cfg,
//qCritical() << DBG_HEADER << "XXXXXXXXXXXXXXXXXXXXX" << d;
return d.toString(Qt::ISODate).toStdString();
}
} else {
durationInSecs = cfg->Duration.find(durationId)->second.pun_duration * 60;
//qCritical() << DBG_HEADER << "DURATION-SECS" << durationInSecs;
//qCritical() << DBG_HEADER << "DURATION-MINS" << durationInSecs / 60;
}
if ((double)price == cost) {
@ -465,6 +478,7 @@ std::string Calculator::GetDurationFromCost(Configuration* cfg,
QTime pwd_time_from = QTime::fromString(QString::fromStdString(iter->second.pwd_time_from), Qt::ISODate);
if (next_working_time_from < pwd_time_from) {
next_working_time_from = pwd_time_from;
qCritical() << DBG_HEADER << "next working time from" << next_working_time_from.toString(Qt::ISODate);
break;
}
}

View File

@ -598,6 +598,14 @@ bool Configuration::ParseJson(Configuration* cfg, const char* json)
if (k->value.IsInt()) {
this->currentPaymentOptions.last().pop_use_only_for_duration = k->value.GetInt();
}
} else if (strcmp(inner_obj_name, "pop_plus_steps") == 0) {
if (k->value.IsInt()) {
this->currentPaymentOptions.last().pop_plus_steps = k->value.GetInt();
}
} else if (strcmp(inner_obj_name, "pop_minus_steps") == 0) {
if (k->value.IsInt()) {
this->currentPaymentOptions.last().pop_minus_steps = k->value.GetInt();
}
} else if (strcmp(inner_obj_name, "pop_payment_method_id") == 0) {
this->currentPaymentOptions.last().pop_payment_method_id = k->value.GetInt();
} else if (strcmp(inner_obj_name, "pop_day_end_time") == 0) {
@ -999,6 +1007,9 @@ int Configuration::getPaymentOptionIndex(QDateTime const &dt) const {
for (int opt=0; opt < numOptions; ++opt) {
uint64_t const pop_business_hours = getPaymentOptions(opt).pop_business_hours;
if (pop_business_hours == 0) { // 0 == 24/7
return opt;
}
uint64_t p = 0;
int const dayOfWeek = dt.date().dayOfWeek();

View File

@ -215,6 +215,43 @@ bool Utilities::IsYearPeriodActive(Configuration const *cfg, QDateTime const &dt
return true;
}
std::optional<ATBPeriodYear>
Utilities::GetYearPeriodActive(Configuration const *cfg, QDateTime const &currentDateTime) {
ATBPeriodYear period;
std::optional<ATBPeriodYear> value;
for (multimap<int, ATBPeriodYear>::const_iterator it = cfg->YearPeriod.cbegin();
it != cfg->YearPeriod.cend();
++it) {
QDate const s(currentDateTime.date().year(), it->second.pye_start_month, it->second.pye_start_day);
QDate const e(currentDateTime.date().year(), it->second.pye_end_month, it->second.pye_end_day);
QDateTime start(currentDateTime);
QDateTime end(currentDateTime);
start.setDate(s);
end.setDate(e);
if (start.date().dayOfYear() < end.date().dayOfYear()) {
// start and end in the same year
if (currentDateTime.date().dayOfYear() >= start.date().dayOfYear() &&
currentDateTime.date().dayOfYear() <= end.date().dayOfYear()) {
value = value.value_or(it->second);
break;
}
} else {
if (currentDateTime.date().dayOfYear() >= start.date().dayOfYear() ||
currentDateTime.date().dayOfYear() <= end.date().dayOfYear()) {
value = value.value_or(it->second);
break;
}
}
}
return value;
}
/// <inheritdoc/>
bool Utilities::CheckSpecialDay(Configuration* cfg, const char* currentDateTimeStr, int* specialDayId, double* specialDayPrice)
{

View File

@ -47,11 +47,11 @@ extern "C" char* strptime(const char* s,
#define NEUHAUSER_CHRISTOPH_REISEN (0)
#define NEUHAUSER_PERNEGG_AN_DER_MUR (0)
#define NEUHAUSER_STOCKERAU (0)
#define KLEIPEDA_LITAUEN (0)
#define KLEIPEDA_LITAUEN (1)
#define SEXTEN (0)
#define SCHNALS_LEITER_KIRCHL (0)
#define SCHNALS_STAUMAUER (SCHNALS_LEITER_KIRCHL)
#define VALSER_ALM (1)
#define VALSER_ALM (0)
#if NEUHAUSER_KIRCHDORF==1
static bool test_neuhauser_kirchdorf(int step, double cost) {
@ -354,7 +354,7 @@ int main() {
QList<int> timeSteps = Calculator::GetInstance().GetTimeSteps(&cfg);
qCritical() << "TimeSteps" << timeSteps;
return 0;
// return 0;
CalcState cs;
double cost;
@ -363,7 +363,7 @@ int main() {
// for (int day = Qt::Monday; day <= Qt::Sunday; ++day) {
for (int day = Qt::Monday; day <= Qt::Monday; ++day) {
QDateTime s(QDate(2024, 5, 19 + day), QTime()); // 20: (whit) monday,..., 26: sunday
QDateTime s(QDate(2024, 7, 29 + day), QTime()); // 20: (whit) monday,..., 26: sunday
QDateTime end;
switch (day) {
@ -401,9 +401,11 @@ int main() {
bool prepaid = true);
*/
for (int minutes = 0; minutes < 1440; ++minutes) {
QDateTime start = s.addSecs(minutes * 60);
QDateTime effectiveStart = start;
//for (int minutes = 0; minutes < 1440; ++minutes) {
for (int minutes = 540; minutes <= 540; ++minutes) {
// QDateTime start = s.addSecs(minutes * 60);
QDateTime start(QDateTime::currentDateTime());
QDateTime effectiveStart(QDateTime::currentDateTime());
if (start.time() < QTime(8, 0, 0)) {
effectiveStart.setTime(QTime(8, 0, 0));
@ -415,55 +417,18 @@ int main() {
effectiveStart.setTime(QTime(8, 0, 0)); // next day
}
for (int i = 0; i <= 2100; i += 10) {
for (int i = 30; i <= 30; 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
durationInMinutes = pop_min_time;
if (i > 0) {
durationInMinutes += (i/10) * 4;
}
offsetInMinutes = 0;
if (effectiveStart.time() >= QTime(8, 0, 0) && effectiveStart.time() <= QTime(22, 0, 0)) {
if (effectiveStart.time().secsTo(QTime(22, 0, 0)) < (durationInMinutes * 60)) {
offsetInMinutes = 600; // 22:00 -> 8:00
}
}
if (i == 0) {
i += 20;
}
if ((durationInMinutes + offsetInMinutes) == (effectiveStart.secsTo(end) / 60)) {
if (day == Qt::Monday && minutes >= 480 && minutes <= 1320) {
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;
}
if ((cs = compute_duration_for_parking_ticket(&cfg, start, cost, end, PermitType(PERMIT_TYPE::SHORT_TERM_PARKING)))) { // return value
qCritical() << "start" << start.toString(Qt::ISODate) << "< cost" << cost
<< "> end" << end.toString(Qt::ISODate);
}
if (!cs) {
qCritical() << "ERROR CalcState" << cs.toString() << endl;
} else {
qCritical() << cs.toString();
}
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);
}
}
}
@ -552,7 +517,7 @@ int main() {
*/
//for (int minutes = 0; minutes < 1440; ++minutes) {
for (int minutes = 0; minutes < 1440; minutes += 1) {
for (int minutes = 480; minutes <= 480; minutes += 1) {
QDateTime start = s.addSecs(minutes * 60);
// qCritical() << "start" << start.toString(Qt::ISODate);
@ -569,66 +534,32 @@ int main() {
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
if ((cs = compute_duration_for_parking_ticket(&cfg, start, cost, end, PermitType(PERMIT_TYPE::SHORT_TERM_PARKING)))) { // 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();
}
}
*/
int netto_parking_time = 60;
struct price_t price;
#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
qCritical() << "start" << start.toString(Qt::ISODate);
QDateTime const s = start;
if ((cs = compute_price_for_parking_ticket(&cfg, start, netto_parking_time, end, &price, PermitType(PERMIT_TYPE::SHORT_TERM_PARKING)))) {
qCritical() << "start" << s.toString(Qt::ISODate)
<< "netto_parking_time" << netto_parking_time
<< "< price" << price.netto
<< "> end" << end.toString(Qt::ISODate);
}
}
}
@ -737,7 +668,7 @@ int main() {
effectiveStart.setTime(QTime(7, 0, 0)); // next day
}
#if 1
#if 0
PermitType permitType(PERMIT_TYPE::SHORT_TERM_PARKING);
for (int i = 200; i <= 200; i += 10) {
cost = i;
@ -760,7 +691,7 @@ int main() {
//for (int i = 2100; i <= 2100; i += 10) {
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, PermitType(PERMIT_TYPE::SHORT_TERM_PARKING_PKW)))) { // return value
}
if (!cs) {
@ -898,7 +829,7 @@ int main() {
//qCritical() << calcState.toString();
calcState = compute_duration_for_parking_ticket(&cfg, s,
(double)9000, end, PermitType(PERMIT_TYPE::SHORT_TERM_PARKING_BUS));
(double)50, end, PermitType(PERMIT_TYPE::SHORT_TERM_PARKING_BUS));
qCritical() << end.toString(Qt::ISODate);
qCritical() << calcState.toString();
}
@ -988,7 +919,7 @@ int main() {
s.setTime(QTime(12, 0, 0));
int minimal_parking_price = get_minimal_parkingprice(&cfg,
PermitType(PERMIT_TYPE::SHORT_TERM_PARKING_PKW),
PermitType(PERMIT_TYPE::SHORT_TERM_PARKING),
paymentOptionIndex, s);
qCritical() << "minimal parking price" << minimal_parking_price;
@ -996,14 +927,14 @@ int main() {
for (int i = 0; i < 8; ++i) {
calcState = compute_duration_for_parking_ticket(&cfg, s,
(double)minimal_parking_price + i*800,
end, PermitType(PERMIT_TYPE::SHORT_TERM_PARKING_PKW));
end, PermitType(PERMIT_TYPE::SHORT_TERM_PARKING));
qCritical() << "RUN" << i << end.toString(Qt::ISODate) << calcState.toString();
}
s.setTime(QTime(15, 0, 0));
minimal_parking_price = get_minimal_parkingprice(&cfg,
PermitType(PERMIT_TYPE::SHORT_TERM_PARKING_PKW),
PermitType(PERMIT_TYPE::SHORT_TERM_PARKING),
paymentOptionIndex, s);
qCritical() << "minimal parking price" << minimal_parking_price;
@ -1011,7 +942,7 @@ int main() {
for (int i = 0; i < 8; ++i) {
calcState = compute_duration_for_parking_ticket(&cfg, s,
(double)minimal_parking_price + i*800,
end, PermitType(PERMIT_TYPE::SHORT_TERM_PARKING_PKW));
end, PermitType(PERMIT_TYPE::SHORT_TERM_PARKING));
qCritical() << "RUN" << i << end.toString(Qt::ISODate) << calcState.toString();
}
}
@ -1532,7 +1463,7 @@ int main() {
for (int i = 0, j=timeSteps.size() ; i < timeSteps.size(); --j, ++i) {
QDateTime end = start.addSecs(timeSteps.at(i)*60);
cs = compute_price_for_parking_ticket(&cfg, start, timeSteps.at(i), end, &costs);
cs = compute_price_for_parking_ticket(&cfg, start, timeSteps.at(i), end, &costs, PermitType(PERMIT_TYPE::SHORT_TERM_PARKING));
if (cs.getStatus() != CalcState::State::SUCCESS) {
if (start.time().hour() >= 8 && start.time().hour() < 18) {
qCritical() << "ERROR CALC-STATE-1=" << QString(cs);
@ -1555,7 +1486,7 @@ int main() {
}
qCritical() << "compute_price_for_parking_ticket()/GetCostFromDuration() TIME: "
<< timeSteps.at(i) << "PRICE=" << price1;
<< timeSteps.at(i) << "PRICE=" << price1 << "end=" << end.toString(Qt::ISODate);
//std::string duration = Calculator::GetInstance().GetDurationFromCost(&cfg, 4,
@ -1639,7 +1570,7 @@ int main() {
double cost = 0;
CalcState cs;
if ((cs = compute_price_for_parking_ticket(&cfg, start, *step, end, &price))) {
if ((cs = compute_price_for_parking_ticket(&cfg, start, *step, end, &price, PermitType(PERMIT_TYPE::SHORT_TERM_PARKING)))) {
cost = price.netto;
qCritical() << "step" << *step << ": cost" << cost;
} else {
@ -1723,7 +1654,7 @@ int main() {
double cost = 0;
CalcState cs;
if ((cs = compute_price_for_parking_ticket(&cfg, start, *step, end, &price))) {
if ((cs = compute_price_for_parking_ticket(&cfg, start, *step, end, &price, PermitType(PERMIT_TYPE::SHORT_TERM_PARKING)))) {
cost = price.netto;
qCritical() << "step" << *step << ": cost" << cost;
} else {
@ -1808,7 +1739,7 @@ int main() {
double cost = 0;
CalcState cs;
if ((cs = compute_price_for_parking_ticket(&cfg, start, *step, end, &price))) {
if ((cs = compute_price_for_parking_ticket(&cfg, start, *step, end, &price, PermitType(PERMIT_TYPE::SHORT_TERM_PARKING)))) {
cost = price.netto;
qCritical() << "step" << *step << ": cost" << cost;
} else {
@ -1866,7 +1797,7 @@ int main() {
double cost = 0;
CalcState cs;
if ((cs = compute_price_for_parking_ticket(&cfg, start, *step, end, &price))) {
if ((cs = compute_price_for_parking_ticket(&cfg, start, *step, end, &price, PermitType(PERMIT_TYPE::SHORT_TERM_PARKING)))) {
cost = price.netto;
qCritical() << "step" << *step << ": cost" << cost;
} else {
@ -1969,7 +1900,7 @@ int main() {
CalcState cs;
for (int i = 13, j=timeSteps.size() ; i < timeSteps.size(); --j, ++i) {
QDateTime end = start.addSecs(timeSteps.at(i)*60);
cs = compute_price_for_parking_ticket(&cfg, start, timeSteps.at(i), end, &costs);
cs = compute_price_for_parking_ticket(&cfg, start, timeSteps.at(i), end, &costs, PermitType(PERMIT_TYPE::SHORT_TERM_PARKING));
qCritical() << endl;
}
@ -1994,7 +1925,7 @@ int main() {
for (int i = 0, j=timeSteps.size() ; i < timeSteps.size(); --j, ++i) {
QDateTime end = start.addSecs(timeSteps.at(i)*60);
cs = compute_price_for_parking_ticket(&cfg, start, timeSteps.at(i), end, &costs);
cs = compute_price_for_parking_ticket(&cfg, start, timeSteps.at(i), end, &costs, PermitType(PERMIT_TYPE::SHORT_TERM_PARKING));
if (cs.getStatus() != CalcState::State::SUCCESS) {
if (start.time().hour() >= 8 && start.time().hour() < 18) {
qCritical() << "ERROR CALC-STATE-1=" << QString(cs);