Compare commits

...

18 Commits

Author SHA1 Message Date
48fccafe76 Fix: GetDurationFromCost() -> set inputDate if next valid working time-range
in on another day and break the loop iterating through next days.
2024-06-06 14:04:04 +02:00
9394625d35 Minor: show debug output only when compiled in. 2024-06-06 14:02:43 +02:00
7492e37e02 Finished test for Neuhauser/Stockerau/748 2024-06-06 14:01:01 +02:00
f0dca3917c Start test-case for Neuhauser/Stockerau/748w 2024-06-05 17:05:19 +02:00
57ccbc150a compute_duration_for_parking_ticket(): set calcState according to string
returned from tariff calculation.
2024-06-05 17:03:33 +02:00
8fa4335669 Minor: fixed typo. 2024-06-05 17:03:10 +02:00
49298a1821 Extend Calculator::GetDurationFromCost() (needed for Neuhauser/Stockerau/748). 2024-06-05 17:00:27 +02:00
6fb4d245cb Added CalcState &setStatus(QString const &desc); 2024-06-05 16:58:12 +02:00
2dc93271fd Added WORKING_DAYS_WITH_RESTRICTED_HOURS (introduced for Neuhauder/Stockerau/748) 2024-06-05 16:52:54 +02:00
5be5798681 Declared iterator-arguments as const-references to get rid of compiler
warning: parameter passing for argument multi_map changed in gcc7.1
2024-06-04 11:48:50 +02:00
1a24bc4572 Add comment about main-change(s). 2024-06-04 11:39:30 +02:00
068575f8e8 improved tests 2024-06-04 11:27:57 +02:00
e121cef17e Added: uint32_t getDailyTicketCardPrice(Configuration const *cfg, PaymentMethod methodId); 2024-06-04 11:26:36 +02:00
bdaea1106c Fix: read price for daily ticket directly from entry PaymentOptions
in tariff-file if it is not given as part of a Json-Product-Array in tariff-file.
2024-06-04 11:24:15 +02:00
bc17213597 Minor: Add/change some debug putput. 2024-06-04 11:23:35 +02:00
64b2b4bd85 Fix: Handle case if "pop_carry_over_start_time_range" and "pop_carry_over_end_time_range"
is not given in tariff file.
2024-06-04 11:19:39 +02:00
8737508839 Minor: add case for PERMIT_TYPE::TWENTY_FOUR_HOURS_TICKET (TODO). 2024-06-04 11:18:47 +02:00
02f0500eac Minor: Add some (commented-out) debug messages. 2024-06-04 11:18:00 +02:00
8 changed files with 1093 additions and 96 deletions

View File

@@ -42,18 +42,34 @@ struct CALCULATE_LIBRARY_API price_t {
};
struct CALCULATE_LIBRARY_API CalcState {
static QString const SUCCESS;
static QString const ERROR_PARSING_ZONE_NR;
static QString const ERROR_LOADING_TARIFF;
static QString const ERROR_PARSING_TARIFF;
static QString const NEGATIVE_PARKING_TIME;
static QString const INVALID_START_DATE;
static QString const WRONG_PARAM_VALUES;
static QString const WRONG_ISO_TIME_FORMAT;
static QString const ABOVE_MAX_PARKING_TIME;
static QString const BELOW_MIN_PARKING_TIME;
static QString const BELOW_MIN_PARKING_PRICE;
static QString const ABOVE_MAX_PARKING_PRICE;
static QString const OVERPAID;
static QString const OUTSIDE_ALLOWED_PARKING_TIME;
enum class State : uint8_t {
SUCCESS,
ERROR_PARSING_ZONE_NR,
ERROR_LOADING_TARIFF,
ERROR_PARSING_TARIFF,
NEGATIVE_PARING_TIME,
NEGATIVE_PARKING_TIME,
INVALID_START_DATE,
WRONG_PARAM_VALUES,
WRONG_ISO_TIME_FORMAT,
ABOVE_MAX_PARKING_TIME,
BELOW_MIN_PARKING_TIME,
BELOW_MIN_PARKING_PRICE,
ABOVE_MAX_PARKING_PRICE,
OVERPAID,
OUTSIDE_ALLOWED_PARKING_TIME
};
@@ -88,43 +104,47 @@ struct CALCULATE_LIBRARY_API CalcState {
QString s;
switch (m_status) {
case State::SUCCESS:
s = "SUCCESS";
s = CalcState::SUCCESS;
break;
case State::ERROR_PARSING_ZONE_NR:
s = "ERROR_PARSING_ZONE_NR";
s = CalcState::ERROR_PARSING_ZONE_NR;
break;
case State::ERROR_LOADING_TARIFF:
s = "ERROR_LOADING_TARIFF";
s = CalcState::ERROR_LOADING_TARIFF;
break;
case State::ERROR_PARSING_TARIFF:
s = "ERROR_PARSING_TARIFF";
s = CalcState::ERROR_PARSING_TARIFF;
break;
case State::NEGATIVE_PARING_TIME:
s = "NEGATIVE_PARKING_TIME";
case State::NEGATIVE_PARKING_TIME:
s = CalcState::NEGATIVE_PARKING_TIME;
break;
case State::ABOVE_MAX_PARKING_TIME:
s = "ABOVE_MAX_PARKING_TIME";
s = CalcState::ABOVE_MAX_PARKING_TIME;
break;
case State::WRONG_PARAM_VALUES:
s = "WRONG_PARAM_VALUES";
s = CalcState::WRONG_PARAM_VALUES;
break;
case State::BELOW_MIN_PARKING_TIME:
s = "BELOW_MIN_PARKING_TIME";
s = CalcState::BELOW_MIN_PARKING_TIME;
break;
case State::BELOW_MIN_PARKING_PRICE:
s = "BELOW_MIN_PARKING_PRICE";
s = CalcState::BELOW_MIN_PARKING_PRICE;
break;
case State::OVERPAID:
s = "OVERPAID";
s = CalcState::OVERPAID;
break;
case State::INVALID_START_DATE:
s = "INVALID_START_DATE";
s = CalcState::INVALID_START_DATE;
break;
case State::WRONG_ISO_TIME_FORMAT:
s = "WRONG_ISO_TIME_FORMAT";
s = CalcState::WRONG_ISO_TIME_FORMAT;
break;
case State::OUTSIDE_ALLOWED_PARKING_TIME:
s = "OUTSIDE_ALLOWED_PARKING_TIME";
s = CalcState::OUTSIDE_ALLOWED_PARKING_TIME;
break;
case State::ABOVE_MAX_PARKING_PRICE:
s = CalcState::ABOVE_MAX_PARKING_TIME;
break;
}
return s + ":" + m_desc;
}
@@ -133,51 +153,101 @@ struct CALCULATE_LIBRARY_API CalcState {
QString s;
switch (m_status) {
case State::SUCCESS:
s = "SUCCESS";
s = CalcState::SUCCESS;
break;
case State::ERROR_PARSING_ZONE_NR:
s = "ERROR_PARSING_ZONE_NR";
s = CalcState::ERROR_PARSING_ZONE_NR;
break;
case State::ERROR_LOADING_TARIFF:
s = "ERROR_LOADING_TARIFF";
s = CalcState::ERROR_LOADING_TARIFF;
break;
case State::ERROR_PARSING_TARIFF:
s = "ERROR_PARSING_TARIFF";
s = CalcState::ERROR_PARSING_TARIFF;
break;
case State::NEGATIVE_PARING_TIME:
s = "NEGATIVE_PARKING_TIME";
case State::NEGATIVE_PARKING_TIME:
s = CalcState::NEGATIVE_PARKING_TIME;
break;
case State::ABOVE_MAX_PARKING_TIME:
s = "ABOVE_MAX_PARKING_TIME";
s = CalcState::ABOVE_MAX_PARKING_TIME;
break;
case State::WRONG_PARAM_VALUES:
s = "WRONG_PARAM_VALUES";
s = CalcState::WRONG_PARAM_VALUES;
break;
case State::BELOW_MIN_PARKING_TIME:
s = "BELOW_MIN_PARKING_TIME";
s = CalcState::BELOW_MIN_PARKING_TIME;
break;
case State::BELOW_MIN_PARKING_PRICE:
s = "BELOW_MIN_PARKING_PRICE";
s = CalcState::BELOW_MIN_PARKING_PRICE;
break;
case State::OVERPAID:
s = "OVERPAID";
s = CalcState::OVERPAID;
break;
case State::INVALID_START_DATE:
s = "INVALID_START_DATE";
s = CalcState::INVALID_START_DATE;
break;
case State::WRONG_ISO_TIME_FORMAT:
s = "WRONG_ISO_TIME_FORMAT";
s = CalcState::WRONG_ISO_TIME_FORMAT;
break;
case State::OUTSIDE_ALLOWED_PARKING_TIME:
s = "OUTSIDE_ALLOWED_PARKING_TIME";
s = CalcState::OUTSIDE_ALLOWED_PARKING_TIME;
break;
case State::ABOVE_MAX_PARKING_PRICE:
s = CalcState::ABOVE_MAX_PARKING_TIME;
break;
}
return s + ":" + m_desc;
}
CalcState &set(State s) { m_status = s; return *this; }
CalcState &setStatus(State s) { return set(s); }
CalcState &setStatus(QString const &desc) {
if (desc == SUCCESS) {
m_status = State::SUCCESS;
} else
if (desc == ERROR_PARSING_ZONE_NR) {
m_status = State::ERROR_PARSING_ZONE_NR;
} else
if (desc == ERROR_LOADING_TARIFF) {
m_status = State::SUCCESS;
} else
if (desc == ERROR_PARSING_TARIFF) {
m_status = State::ERROR_LOADING_TARIFF;
} else
if (desc == NEGATIVE_PARKING_TIME) {
m_status = State::NEGATIVE_PARKING_TIME;
} else
if (desc == INVALID_START_DATE) {
m_status = State::INVALID_START_DATE;
} else
if (desc == WRONG_PARAM_VALUES) {
m_status = State::WRONG_PARAM_VALUES;
} else
if (desc == WRONG_ISO_TIME_FORMAT) {
m_status = State::WRONG_ISO_TIME_FORMAT;
} else
if (desc == ABOVE_MAX_PARKING_TIME) {
m_status = State::ABOVE_MAX_PARKING_TIME;
} else
if (desc == BELOW_MIN_PARKING_TIME) {
m_status = State::BELOW_MIN_PARKING_TIME;
} else
if (desc == BELOW_MIN_PARKING_PRICE) {
m_status = State::BELOW_MIN_PARKING_PRICE;
} else
if (desc == OVERPAID) {
m_status = State::OVERPAID;
} else
if (desc == OUTSIDE_ALLOWED_PARKING_TIME) {
m_status = State::OUTSIDE_ALLOWED_PARKING_TIME;
} else
if (desc == ABOVE_MAX_PARKING_PRICE) {
m_status = State::ABOVE_MAX_PARKING_PRICE;
}
return *this;
}
State getStatus() const { return m_status; }
CalcState &setDesc(QString s) { m_desc = s; return *this; }
CalcState &setDesc(QString const &s) { m_desc = s; return *this; }
void setAllowedTimeRange(QTime const &from, QTime const &until) {
m_allowedTimeRange.setTimeRange(from, until);

View File

@@ -8,27 +8,28 @@
#include <Qt>
#define _NO_RESTRICTION_24_7_ (uint64_t)(0ULL)
#define _MON_ (uint64_t)(1ULL << 8)
#define _TUE_ (uint64_t)(1ULL << 9)
#define _WED_ (uint64_t)(1ULL << 10)
#define _THU_ (uint64_t)(1ULL << 11)
#define _FRI_ (uint64_t)(1ULL << 12)
#define _SAT_ (uint64_t)(1ULL << 13)
#define _SUN_ (uint64_t)(1ULL << 14)
#define _WEEK_DAYS_ ((_MON_|_TUE_|_WED_|_THU_|_FRI_))
#define _WORKING_DAYS_ ((_MON_|_TUE_|_WED_|_THU_|_FRI_|_SAT_))
#define _ALL_DAYS_ ((_MON_|_TUE_|_WED_|_THU_|_FRI_|_SAT_|_SUN_))
#define _OFFICIAL_HOLIDAY_ (uint64_t)(1ULL << 15)
#define _ONLY_WEEKEND_ ((_SAT_|_SUN_))
#define _ONLY_OPEN_FOR_BUSINESS_DAYS_ (uint64_t)(1ULL << 16) /* verkaufsoffen */
#define _WITH_RESTRICTED_HOURS_ (uint64_t)(1ULL << 17)
#define _ALL_DAYS_WITH_RESTRICTED_HOURS_ ((_WITH_RESTRICTED_HOURS_|_ALL_DAYS_))
#define _WEEKEND_WITH_RESTRICTED_HOURS_ ((_WITH_RESTRICTED_HOURS_|_FRI_|_SAT_|_SUN_))
#define _FRI_WITH_RESTRICTED_HOURS_ ((_WITH_RESTRICTED_HOURS_|_FRI_))
#define _SAT_WITH_RESTRICTED_HOURS_ ((_WITH_RESTRICTED_HOURS_|_SAT_))
#define _SUN_WITH_RESTRICTED_HOURS_ ((_WITH_RESTRICTED_HOURS_|_SUN_))
#define _NOT_DEFINED_ (uint64_t)(~0ULL)
#define _NO_RESTRICTION_24_7_ (uint64_t)(0ULL)
#define _MON_ (uint64_t)(1ULL << 8)
#define _TUE_ (uint64_t)(1ULL << 9)
#define _WED_ (uint64_t)(1ULL << 10)
#define _THU_ (uint64_t)(1ULL << 11)
#define _FRI_ (uint64_t)(1ULL << 12)
#define _SAT_ (uint64_t)(1ULL << 13)
#define _SUN_ (uint64_t)(1ULL << 14)
#define _WEEK_DAYS_ ((_MON_|_TUE_|_WED_|_THU_|_FRI_))
#define _WORKING_DAYS_ ((_MON_|_TUE_|_WED_|_THU_|_FRI_|_SAT_))
#define _ALL_DAYS_ ((_MON_|_TUE_|_WED_|_THU_|_FRI_|_SAT_|_SUN_))
#define _OFFICIAL_HOLIDAY_ (uint64_t)(1ULL << 15)
#define _ONLY_WEEKEND_ ((_SAT_|_SUN_))
#define _ONLY_OPEN_FOR_BUSINESS_DAYS_ (uint64_t)(1ULL << 16) /* verkaufsoffen */
#define _WITH_RESTRICTED_HOURS_ (uint64_t)(1ULL << 17)
#define _ALL_DAYS_WITH_RESTRICTED_HOURS_ ((_WITH_RESTRICTED_HOURS_|_ALL_DAYS_))
#define _WEEKEND_WITH_RESTRICTED_HOURS_ ((_WITH_RESTRICTED_HOURS_|_FRI_|_SAT_|_SUN_))
#define _WORKING_DAYS_WITH_RESTRICTED_HOURS_ ((_WITH_RESTRICTED_HOURS_|_WORKING_DAYS_))
#define _FRI_WITH_RESTRICTED_HOURS_ ((_WITH_RESTRICTED_HOURS_|_FRI_))
#define _SAT_WITH_RESTRICTED_HOURS_ ((_WITH_RESTRICTED_HOURS_|_SAT_))
#define _SUN_WITH_RESTRICTED_HOURS_ ((_WITH_RESTRICTED_HOURS_|_SUN_))
#define _NOT_DEFINED_ (uint64_t)(~0ULL)
enum BusinessHours : std::uint64_t
{
@@ -62,6 +63,7 @@ enum BusinessHours : std::uint64_t
ONLY_OPEN_FOR_BUSINESS_DAYS = _ONLY_OPEN_FOR_BUSINESS_DAYS_,
ALL_DAYS_WITH_RESTRICTED_HOURS = _ALL_DAYS_WITH_RESTRICTED_HOURS_,
WEEKEND_WITH_RESTRICTED_HOURS = _WEEKEND_WITH_RESTRICTED_HOURS_,
WORKING_DAYS_WITH_RESTRICTED_HOURS = _WORKING_DAYS_WITH_RESTRICTED_HOURS_,
FRI_WITH_RESTRICTED_HOURS = _FRI_WITH_RESTRICTED_HOURS_,
SAT_WITH_RESTRICTED_HOURS = _SAT_WITH_RESTRICTED_HOURS_,
SUN_WITH_RESTRICTED_HOURS = _SUN_WITH_RESTRICTED_HOURS_,

View File

@@ -79,12 +79,12 @@ namespace Utilities {
double CalculatePricePerUnit(double pra_price, double durationUnit = -1);
QTime SpecialDaysWorkTimeFrom(Configuration const *cfg, int specialDayId);
QTime SpecialDaysWorkTimeFrom(Configuration::SpecialDaysWorktimeType::const_iterator it);
QTime SpecialDaysWorkTimeFrom(Configuration::SpecialDaysWorktimeType::const_iterator const &it);
QTime SpecialDaysWorkTimeUntil(Configuration const *cfg, int specialDayId);
QTime SpecialDaysWorkTimeUntil(Configuration::SpecialDaysWorktimeType::const_iterator it);
QTime WeekDaysWorkTimeFrom(std::multimap<int, ATBWeekDaysWorktime>::const_iterator itr);
QTime WeekDaysWorkTimeUntil(std::multimap<int, ATBWeekDaysWorktime>::const_iterator itr);
int WeekDayId(std::multimap<int, ATBWeekDaysWorktime>::const_iterator itr);
QTime SpecialDaysWorkTimeUntil(Configuration::SpecialDaysWorktimeType::const_iterator const &it);
QTime WeekDaysWorkTimeFrom(std::multimap<int, ATBWeekDaysWorktime>::const_iterator const &itr);
QTime WeekDaysWorkTimeUntil(std::multimap<int, ATBWeekDaysWorktime>::const_iterator const &itr);
int WeekDayId(std::multimap<int, ATBWeekDaysWorktime>::const_iterator const &itr);
// PaymentRate GetPaymentRate(Configuration const *cfg, );
bool isCarryOverSet(Configuration const *cfg, PaymentMethod paymentMethodId);
bool isCarryOverNotSet(Configuration const *cfg, PaymentMethod paymentMethodId);
@@ -100,4 +100,5 @@ namespace Utilities {
uint32_t computeWeekDaysPrice(Configuration const *cfg, PaymentMethod id);
double computeWeekDaysDurationUnit(Configuration const *cfg, PaymentMethod id);
QStringList dumpBusinessHours(uint64_t businessHours);
uint32_t getDailyTicketCardPrice(Configuration const *cfg, PaymentMethod methodId);
}

View File

@@ -12,6 +12,10 @@ INCLUDEPATH += $$_PRO_FILE_PWD_/include/rapidjson
#Version is set in yocto recipe with "EXTRA_QMAKEVARS_PRE"
#VERSION=1.0.0
# 04.06.2024: Fix for Szeged: read price for daily ticket directly from entry
# PaymentOptions in tariff-file if it is not given as part of a
# Json-Product-Array in tariff-file.
CONFIG(debug, debug|release) {
win32 {
QMAKE_CXXFLAGS += -DCALCULATE_LIBRARY_EXPORTS

View File

@@ -10,6 +10,21 @@
#include <QDebug>
#include <QList>
QString const CalcState::SUCCESS = "SUCCESS";
QString const CalcState::ERROR_PARSING_ZONE_NR = "ERROR_PARSING_ZONE_NR";
QString const CalcState::ERROR_LOADING_TARIFF = "ERROR_LOADING_TARIFF";
QString const CalcState::ERROR_PARSING_TARIFF = "ERROR_PARSING_TARIFF";
QString const CalcState::NEGATIVE_PARKING_TIME = "NEGATIVE_PARKING_TIME";
QString const CalcState::INVALID_START_DATE = "INVALID_START_DATE";
QString const CalcState::WRONG_PARAM_VALUES = "WRONG_PARAM_VALUES";
QString const CalcState::WRONG_ISO_TIME_FORMAT = "WRONG_ISO_TIME_FORMAT";
QString const CalcState::ABOVE_MAX_PARKING_TIME = "ABOVE_MAX_PARKING_TIME";
QString const CalcState::BELOW_MIN_PARKING_TIME = "BELOW_MIN_PARKING_TIME";
QString const CalcState::BELOW_MIN_PARKING_PRICE = "BELOW_MIN_PARKING_PRICE";
QString const CalcState::ABOVE_MAX_PARKING_PRICE = "ABOVE_MAX_PARKING_PRICE";
QString const CalcState::OVERPAID = "OVERPAID";
QString const CalcState::OUTSIDE_ALLOWED_PARKING_TIME = "OUTSIDE_ALLOWED_PARKING_TIME";
QList<int> CALCULATE_LIBRARY_API get_time_steps(Configuration *cfg) {
return Calculator::GetInstance().GetTimeSteps(cfg);
}
@@ -163,6 +178,17 @@ int CALCULATE_LIBRARY_API compute_product_price(Configuration const *cfg,
}
return product_price;
} else {
// SZEGED
int const pop_daily_card_price = cfg->getPaymentOptions().pop_daily_card_price;
qDebug() << QString("(%1:%2) no products defined in tariff-file").arg(__func__).arg(__LINE__);
qDebug() << QString("(%1:%2) pop_daily_card_price=%3").arg(__func__).arg(__LINE__).arg(pop_daily_card_price);
// static const PaymentMethod paymentMethodId = Utilities::getPaymentMethodId(cfg);
// return Utilities::getDailyTicketCardPrice(cfg, paymentMethodId);
return pop_daily_card_price;
}
} break;
case PERMIT_TYPE::TWENTY_FOUR_HOURS_TICKET: {
@@ -427,7 +453,7 @@ CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket(
if (duration < 0) {
calcState.setDesc(QString("end=%1, start=%2")
.arg(end_parking_time, start_parking_time));
return calcState.set(CalcState::State::NEGATIVE_PARING_TIME);
return calcState.set(CalcState::State::NEGATIVE_PARKING_TIME);
}
if (duration > maxMin) {
calcState.setDesc(QString("duration=%1, maxMin=%2").arg(duration).arg(maxMin));
@@ -495,7 +521,7 @@ CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket(
calcState.setDesc(QString("end=%1, start=%2")
.arg(end_parking_time.toString(Qt::ISODate),
start_parking_time.toString(Qt::ISODate)));
return calcState.set(CalcState::State::NEGATIVE_PARING_TIME);
return calcState.set(CalcState::State::NEGATIVE_PARKING_TIME);
}
if (netto_parking_time > maxMin) {
calcState.setDesc(QString("duration=%1, maxMin=%2").arg(netto_parking_time).arg(maxMin));
@@ -542,7 +568,8 @@ CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket(
}
// DEBUG
qCritical() << " -> calculated cost (price->netto) = " << cost;
qCritical() << " end_parking_time: " << end_parking_time;
qCritical() << " -> calculated cost (netto): " << cost;
price->brutto = price->vat = price->vat_percentage = 0;
price->units = cost;
@@ -603,16 +630,76 @@ CalcState CALCULATE_LIBRARY_API compute_duration_for_parking_ticket(
tariff->getPaymentOptions().pop_payment_method_id,
cs.toLocal8Bit().constData(),
price, false, true).c_str();
ticketEndTime = QDateTime::fromString(endTime,Qt::ISODate);
// DEBUG
qCritical() << "compute_duration_for_parking_ticket(): ";
qCritical() << " endTime: " << endTime;
qCritical() << " ticketEndTime: " << ticketEndTime;
if (endTime == CalcState::SUCCESS) {
calcState.setDesc(QString("SUCCESS"));
calcState.setStatus(endTime);
} else
if (endTime == CalcState::ERROR_PARSING_ZONE_NR) {
calcState.setStatus(endTime);
return calcState;
} else
if (endTime == CalcState::ERROR_LOADING_TARIFF) {
calcState.setStatus(endTime);
return calcState;
} else
if (endTime == CalcState::ERROR_PARSING_TARIFF) {
calcState.setStatus(endTime);
return calcState;
} else
if (endTime == CalcState::NEGATIVE_PARKING_TIME) {
calcState.setStatus(endTime);
return calcState;
} else
if (endTime == CalcState::INVALID_START_DATE) {
calcState.setStatus(endTime);
return calcState;
} else
if (endTime == CalcState::WRONG_PARAM_VALUES) {
calcState.setStatus(endTime);
return calcState;
} else
if (endTime == CalcState::WRONG_ISO_TIME_FORMAT) {
calcState.setStatus(endTime);
return calcState;
} else
if (endTime == CalcState::ABOVE_MAX_PARKING_TIME) {
calcState.setStatus(endTime);
return calcState;
} else
if (endTime == CalcState::BELOW_MIN_PARKING_TIME) {
calcState.setStatus(endTime);
return calcState;
} else
if (endTime == CalcState::BELOW_MIN_PARKING_PRICE) {
calcState.setStatus(endTime);
return calcState;
} else
if (endTime == CalcState::ABOVE_MAX_PARKING_PRICE) {
calcState.setDesc(CalcState::ABOVE_MAX_PARKING_PRICE);
calcState.setStatus(CalcState::ABOVE_MAX_PARKING_PRICE);
return calcState;
} else
if (endTime == CalcState::OVERPAID) {
calcState.setDesc(CalcState::OVERPAID);
calcState.setStatus(CalcState::OVERPAID);
return calcState;
} else
if (endTime == CalcState::OUTSIDE_ALLOWED_PARKING_TIME) {
calcState.setStatus(endTime);
return calcState;
} else {
ticketEndTime = QDateTime::fromString(endTime,Qt::ISODate);
if (!ticketEndTime.isValid()) {
calcState.setDesc(QString("ticketEndTime=%1").arg(endTime));
return calcState.set(CalcState::State::WRONG_ISO_TIME_FORMAT);
// DEBUG
//qCritical() << "compute_duration_for_parking_ticket(): ";
//qCritical() << " endTime: " << endTime;
//qCritical() << " ticketEndTime: " << ticketEndTime;
if (!ticketEndTime.isValid()) {
calcState.setDesc(QString("ticketEndTime=%1").arg(endTime));
return calcState.set(CalcState::State::WRONG_ISO_TIME_FORMAT);
}
}
} else {
return calcState.set(CalcState::State::INVALID_START_DATE);

View File

@@ -144,7 +144,228 @@ std::string Calculator::GetDurationFromCost(Configuration* cfg,
}
}
qCritical() << __func__ << ":" << __LINE__ << "NOT YET IMPLEMENTED";
// TODO: man braucht den richtigen Index
int paymentOptionIndex = 0;
int const pop_id = cfg->getPaymentOptions(paymentOptionIndex).pop_id;
int const pop_max_price = cfg->getPaymentOptions(paymentOptionIndex).pop_max_price;
int const pop_min_price = cfg->getPaymentOptions(paymentOptionIndex).pop_min_price;
if (cost > pop_max_price) {
qCritical() << DBG_HEADER << "MAX-PARKING-PRICE" << pop_max_price << ", COST" << cost;
return CalcState::OVERPAID.toStdString();
}
if (cost < pop_min_price) {
qCritical() << DBG_HEADER << "MIN-PARKING-PRICE" << pop_min_price << ", COST" << cost;
return CalcState::BELOW_MIN_PARKING_PRICE.toStdString();
}
// int const pop_pre_paid = 1;
if (prepaid) {
// no limits on pre-pay-option, i.e. pre-pay-ranges are exactly
// the complements of operational-ranges
// find out if we are in a pre-pay-range.
// in this case, adapt inputDate accordingly.
// #define DEBUG_GET_DURATION_FROM_COST 1
#if DEBUG_GET_DURATION_FROM_COST==1
qCritical() << DBG_HEADER << "PRE-PAID-OPTION: ADAPT-INPUT-DATE" << inputDate.toString(Qt::ISODate);
#endif
QTime currentTime = inputDate.time();
int pwd_period_day_in_week_id = inputDate.date().dayOfWeek();
bool useWeekDaysWorkTimeOfOtherDay = true;
for (auto[iter, rEnd] = cfg->WeekDaysWorktime.equal_range(pwd_period_day_in_week_id); iter != rEnd; ++iter) {
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);
if (inputDate.time() < pwd_time_from) {
inputDate.setTime(pwd_time_from);
useWeekDaysWorkTimeOfOtherDay = false;
break;
}
if (currentTime <= pwd_time_to) {
useWeekDaysWorkTimeOfOtherDay = false;
break;
}
}
if (useWeekDaysWorkTimeOfOtherDay) {// for the current day, we are above
// the latest worktime-range -> find the next valid range
QTime pwd_time_from_next_valid_range(0, 0, 0);
int pwd_period_next_day_in_week_id = pwd_period_day_in_week_id;
for (int days = 1; days < 8; ++days) {
pwd_period_next_day_in_week_id += 1;
if (pwd_period_next_day_in_week_id > (int)Qt::Sunday) {
pwd_period_next_day_in_week_id = Qt::Monday;
}
if (cfg->WeekDaysWorktime.count(pwd_period_next_day_in_week_id) > 0) {
for (auto[iter, rEnd] = cfg->WeekDaysWorktime.equal_range(pwd_period_next_day_in_week_id); iter != rEnd; ++iter) {
QTime pwd_time_from = QTime::fromString(QString::fromStdString(iter->second.pwd_time_from), Qt::ISODate);
if (pwd_time_from_next_valid_range < pwd_time_from) {
pwd_time_from_next_valid_range = pwd_time_from;
break;
}
}
inputDate = inputDate.addDays(days);
inputDate.setTime(pwd_time_from_next_valid_range);
break;
}
}
}
}
#if DEBUG_GET_DURATION_FROM_COST==1
qCritical() << DBG_HEADER << "(ADAPTED) INPUT-DATE" << inputDate.toString(Qt::ISODate);
#endif
// inputDate is now located in a valid operational-working-range
// find this working-time-range
int pwd_period_day_in_week_id = inputDate.date().dayOfWeek();
if (cfg->WeekDaysWorktime.count(pwd_period_day_in_week_id) == 0) {
qCritical() << DBG_HEADER
<< "ERROR" << inputDate.toString(Qt::ISODate)
<< "NOT IN VALID WORKING TIME-RANGE";
return "";
}
QTime current_working_time_from;
QTime current_working_time_to;
for (auto[iter, rEnd] = cfg->WeekDaysWorktime.equal_range(pwd_period_day_in_week_id); iter != rEnd; ++iter) {
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);
if (pwd_time_from <= inputDate.time() && inputDate.time() <= pwd_time_to) {
current_working_time_from = pwd_time_from;
current_working_time_to = pwd_time_to;
}
}
if (current_working_time_from.isNull() || current_working_time_to.isNull()) {
// can never happen
qCritical() << DBG_HEADER
<< "ERROR" << inputDate.toString(Qt::ISODate)
<< "NOT IN VALID WORKING TIME-RANGE";
return "";
}
#if DEBUG_GET_DURATION_FROM_COST==1
qCritical() << DBG_HEADER << "CURRENT WORKING-TIME-FROM" << current_working_time_from.toString(Qt::ISODate);
qCritical() << DBG_HEADER << " CURRENT WORKING-TIME-TO" << current_working_time_to.toString(Qt::ISODate);
#endif
for (auto[itr, rangeEnd] = cfg->PaymentRate.equal_range(pop_id); itr != rangeEnd; ++itr) {
int const pra_price = itr->second.pra_price;
if ((double)pra_price == cost) {
int const durationId = itr->second.pra_payment_unit_id;
auto search = cfg->Duration.find(durationId);
if (search != cfg->Duration.end()) {
// found now the duration in minutes
// check if we are still inside the working-time-range
ATBDuration duration = search->second;
int durationInSecs = duration.pun_duration * 60;
QDateTime current_working_date_time_to = inputDate;
current_working_date_time_to.setTime(current_working_time_to);
#if DEBUG_GET_DURATION_FROM_COST==1
qCritical() << DBG_HEADER << "DURATION IN MINUTES" << duration.pun_duration;
qCritical() << DBG_HEADER << "DURATION IN SECONDS" << duration.pun_duration * 60;
qCritical() << DBG_HEADER << "CURRENT-WORKING-DATE-TIME-TO"
<< current_working_date_time_to.toString(Qt::ISODate);
qCritical() << DBG_HEADER << "NEW INPUT DATE" << inputDate.addSecs(durationInSecs).toString(Qt::ISODate);
#endif
if (inputDate.addSecs(durationInSecs) > current_working_date_time_to) {
QTime next_working_time_from;
if (cfg->getPaymentOptions(paymentOptionIndex).pop_carry_over != 0) {
#if DEBUG_GET_DURATION_FROM_COST==1
qCritical() << DBG_HEADER << "CARRY-OVER SET";
#endif
// check for next working-time-range on same day
int day_in_week_id = inputDate.date().dayOfWeek();
for (auto[iter, rEnd] = cfg->WeekDaysWorktime.equal_range(day_in_week_id); iter != rEnd; ++iter) {
QTime pwd_time_from = QTime::fromString(QString::fromStdString(iter->second.pwd_time_from), Qt::ISODate);
if (pwd_time_from > current_working_time_to) {
next_working_time_from = pwd_time_from;
#if DEBUG_GET_DURATION_FROM_COST==1
qCritical() << DBG_HEADER << "NEXT-WORKING-TIME-FROM"
<< next_working_time_from.toString(Qt::ISODate);
#endif
break;
}
}
// check for next working-time-range on following day(s)
if (next_working_time_from.isNull()) {
next_working_time_from = QTime(0, 0, 0);
for (int days = 1; days < 8; ++days) {
day_in_week_id += 1;
if (day_in_week_id > (int)Qt::Sunday) {
day_in_week_id = Qt::Monday;
}
if (cfg->WeekDaysWorktime.count(day_in_week_id) > 0) {
for (auto[iter, rEnd] = cfg->WeekDaysWorktime.equal_range(day_in_week_id); iter != rEnd; ++iter) {
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;
break;
}
}
QDateTime upper = inputDate.addDays(days);
upper.setTime(next_working_time_from);
QDateTime lower = inputDate;
lower.setTime(current_working_time_to);
inputDate = inputDate.addSecs(lower.secsTo(upper) + durationInSecs);
#if DEBUG_GET_DURATION_FROM_COST==1
qCritical() << DBG_HEADER << "TICKET-END" << inputDate.toString(Qt::ISODate);
#endif
break;
}
} // for (int days = 1; days < 8; ++days) {
} else { // next working-time is on same day
QDateTime upper = inputDate;
upper.setTime(next_working_time_from);
QDateTime lower = inputDate;
lower.setTime(current_working_time_to);
inputDate = inputDate.addSecs(lower.secsTo(upper) + durationInSecs);
#if DEBUG_GET_DURATION_FROM_COST==1
qCritical() << DBG_HEADER << "TICKET-END" << inputDate.toString(Qt::ISODate);
#endif
}
}
} else {
inputDate = inputDate.addSecs(duration.pun_duration * 60);
#if DEBUG_GET_DURATION_FROM_COST==1
qCritical() << DBG_HEADER << "INPUT-DATE" << inputDate.toString(Qt::ISODate);
#endif
}
QString const &s = inputDate.toString(Qt::ISODate);
#if DEBUG_GET_DURATION_FROM_COST==1
qCritical() << DBG_HEADER << "TICKET-END" << s;
#endif
return s.toStdString();
}
}
}
return "";
}
}
@@ -628,12 +849,19 @@ CalcState Calculator::isParkingAllowedForWeekDay(Configuration const *cfg,
PaymentMethod const paymentMethodId = Utilities::getPaymentMethodId(cfg);
if (paymentMethodId == PaymentMethod::Steps) {
uint64_t const businessHours = cfg->getPaymentOptions(paymentOptionIndex).pop_business_hours;
if (cfg->isDayIncluded(businessHours, start)) {
if (businessHours == BusinessHours::NO_RESTRICTION_24_7) {
return CalcState(CalcState::State::SUCCESS, "PARKING_ALLOWED",
QTime(0, 0, 0), QTime(23, 59, 59));
}
int const weekdayId = start.date().dayOfWeek();
// qCritical() << DBG_HEADER
// << "weekdayId" << weekdayId
// << "count" << cfg->WeekDaysWorktime.count(weekdayId);
if (cfg->WeekDaysWorktime.count(weekdayId) > 0) {
using WTIterator = std::multimap<int, ATBWeekDaysWorktime>::const_iterator;
std::pair<WTIterator, WTIterator> p = cfg->WeekDaysWorktime.equal_range(weekdayId);
@@ -670,28 +898,59 @@ CalcState Calculator::isParkingAllowedForWeekDay(Configuration const *cfg,
}
int const pop_carry_over = cfg->getPaymentOptions(paymentOptionIndex).pop_carry_over;
// qCritical() << DBG_HEADER
// << "paymentOptionIndex" << paymentOptionIndex
// << "pop_carry_over" << pop_carry_over;
if (pop_carry_over == 1) {
qCritical() << DBG_HEADER
<< "NO. CHECK IF PARKING IS ALLOWED WITH CARRY-OVER ...";
// qCritical() << DBG_HEADER
// << "NO. CHECK IF PARKING IS ALLOWED WITH CARRY-OVER ...";
int const pop_carry_over_start_time_range = cfg->getPaymentOptions(paymentOptionIndex).pop_carry_over_start_time_range;
int const pop_carry_over_end_time_range = cfg->getPaymentOptions(paymentOptionIndex).pop_carry_over_end_time_range;
// qCritical() << DBG_HEADER
// << "pop_carry_over_start_time_range" << pop_carry_over_start_time_range
// << "pop_carry_over_end_time_range" << pop_carry_over_end_time_range;
if ((int)cfg->TimeRange.count(pop_carry_over_start_time_range) <= 0 &&
(int)cfg->TimeRange.count(pop_carry_over_end_time_range) <= 0) {
qCritical() << DBG_HEADER << "PARKING_ALLOWED. startTime" << startTime.toString(Qt::ISODate);
return CalcState(CalcState::State::SUCCESS, "PARKING_ALLOWED", startTime);
} else
// search entry in time-range-field of tariff-file
if (cfg->TimeRange.count(pop_carry_over_start_time_range) == 1 &&
cfg->TimeRange.count(pop_carry_over_end_time_range) == 1) {
ATBTimeRange s = cfg->TimeRange.find(pop_carry_over_start_time_range)->second;
ATBTimeRange e = cfg->TimeRange.find(pop_carry_over_end_time_range)->second;
// qCritical() << DBG_HEADER
// << "startTime" << startTime.toString(Qt::ISODate);
if (startTime >= s.getTimeFrom() && startTime <= s.getTimeUntil()) {
QDateTime sd = start;
sd.setTime(s.getTimeUntil());
// qCritical() << DBG_HEADER << "jumpFrom" << sd.toString(Qt::ISODate);
QDateTime ed = start.addDays(1);
ed.setTime(e.getTimeFrom());
// qCritical() << DBG_HEADER << "to" << ed.toString(Qt::ISODate);
int const jumpSecs = sd.secsTo(ed);
// qCritical() << DBG_HEADER << "jumpSecs" << jumpSecs;
QDateTime const end = start.addSecs(netto_parking_time*60 + jumpSecs);
// qCritical() << DBG_HEADER << "new end" << end.toString(Qt::ISODate);
if (end.time() <= e.getTimeUntil()) {
qCritical() << DBG_HEADER
@@ -701,13 +960,13 @@ CalcState Calculator::isParkingAllowedForWeekDay(Configuration const *cfg,
return CalcState(CalcState::State::SUCCESS, "PARKING_ALLOWED",
startTime, end.time());
} else {
errorStr = QString("endTime %1 exceeds [%2, %3))")
errorStr = QString("endTime %1 outside [%2, %3))")
.arg(end.toString(Qt::ISODate))
.arg(sd.toString(Qt::ISODate))
.arg(ed.toString(Qt::ISODate));
}
} else {
errorStr = QString("startTime %1 exceeds [%2, %3))")
errorStr = QString("startTime %1 outside [%2, %3))")
.arg(startTime.toString(Qt::ISODate))
.arg(s.getTimeFrom().toString(Qt::ISODate))
.arg(s.getTimeUntil().toString(Qt::ISODate));
@@ -730,6 +989,8 @@ CalcState Calculator::isParkingAllowedForWeekDay(Configuration const *cfg,
}
}
qCritical() << DBG_HEADER << "errorStr" << errorStr;
return CalcState(CalcState::State::OUTSIDE_ALLOWED_PARKING_TIME, errorStr,
QTime(), QTime());
}
@@ -2007,6 +2268,9 @@ Calculator::GetDailyTicketPrice(Configuration* cfg,
if (dailyTickets) {
QVector<ATBDailyTicket> const tickets = dailyTickets.value();
switch (permitType) {
case PERMIT_TYPE::TWENTY_FOUR_HOURS_TICKET: {
// TODO
} break;
case PERMIT_TYPE::FOOD_STAMP: {
// TODO
} break;

View File

@@ -334,11 +334,11 @@ QTime Utilities::SpecialDaysWorkTimeFrom(Configuration const *cfg, int specialDa
return QTime::fromString(cfg->SpecialDaysWorktime.find(specialDayId)->second.pedwt_time_from.c_str(), Qt::ISODate);
}
QTime Utilities::SpecialDaysWorkTimeFrom(Configuration::SpecialDaysWorktimeType::const_iterator it) {
QTime Utilities::SpecialDaysWorkTimeFrom(Configuration::SpecialDaysWorktimeType::const_iterator const &it) {
return QTime::fromString(it->second.pedwt_time_from.c_str(), Qt::ISODate);
}
QTime Utilities::SpecialDaysWorkTimeUntil(Configuration::SpecialDaysWorktimeType::const_iterator it) {
QTime Utilities::SpecialDaysWorkTimeUntil(Configuration::SpecialDaysWorktimeType::const_iterator const &it) {
return QTime::fromString(it->second.pedwt_time_to.c_str(), Qt::ISODate);
}
@@ -346,15 +346,15 @@ QTime Utilities::SpecialDaysWorkTimeUntil(Configuration const *cfg, int specialD
return QTime::fromString(cfg->SpecialDaysWorktime.find(specialDayId)->second.pedwt_time_to.c_str(), Qt::ISODate);
}
QTime Utilities::WeekDaysWorkTimeFrom(std::multimap<int, ATBWeekDaysWorktime>::const_iterator itr) {
QTime Utilities::WeekDaysWorkTimeFrom(std::multimap<int, ATBWeekDaysWorktime>::const_iterator const &itr) {
return QTime::fromString(itr->second.pwd_time_from.c_str(), Qt::ISODate);
}
QTime Utilities::WeekDaysWorkTimeUntil(std::multimap<int, ATBWeekDaysWorktime>::const_iterator itr) {
QTime Utilities::WeekDaysWorkTimeUntil(std::multimap<int, ATBWeekDaysWorktime>::const_iterator const &itr) {
return QTime::fromString(itr->second.pwd_time_to.c_str(), Qt::ISODate);
}
int Utilities::WeekDayId(std::multimap<int, ATBWeekDaysWorktime>::const_iterator itr) {
int Utilities::WeekDayId(std::multimap<int, ATBWeekDaysWorktime>::const_iterator const &itr) {
return itr->second.pwd_period_day_in_week_id;
}
@@ -406,6 +406,10 @@ uint32_t Utilities::getMaximalParkingPrice(Configuration const *cfg, PaymentMeth
return std::max((int)cfg->PaymentOption.find(methodId)->second.pop_max_price, 0);
}
uint32_t Utilities::getDailyTicketCardPrice(Configuration const *cfg, PaymentMethod methodId) {
return std::max((int)cfg->PaymentOption.find(methodId)->second.pop_daily_card_price, 0);
}
uint32_t Utilities::getTimeRangeStep(Configuration const *cfg, int step, PaymentMethod methodId) {
if (methodId == PaymentMethod::Progressive) {
Configuration::TimeRangeType::const_iterator it = cfg->TimeRange.find(step);

View File

@@ -28,6 +28,8 @@ extern "C" char* strptime(const char* s,
#include <QDateTime>
#include <QDir>
#include <QFileInfo>
#include <QSet>
#include <initializer_list>
#include <fstream>
#include <sstream>
@@ -40,10 +42,10 @@ extern "C" char* strptime(const char* s,
#define NEUHAUSER_LINSINGER_MASCHINENBAU (0)
#define NEUHAUSER_NORDISCHES_AUSBILDUNGSZENTRUM (0)
#define NEUHAUSER_BILEXA_GALTUER (0)
#define NEUHAUSER_KIRCHDORF (0)
#define BAD_NEUENAHR_AHRWEILER (0)
#define NEUHAUSER_CHRISTOPH_REISEN (0)
#define NEUHAUSER_PERNEGG_AN_DER_MUR (1)
#define NEUHAUSER_PERNEGG_AN_DER_MUR (0)
#define NEUHAUSER_STOCKERAU (1)
#if NEUHAUSER_KIRCHDORF==1
static bool test_neuhauser_kirchdorf(int step, double cost) {
@@ -163,8 +165,187 @@ static bool test_neuhauser_kirchdorf(int step, double cost) {
}
#endif
#include <cmath>
int main() {
#if NEUHAUSER_STOCKERAU==1
std::ifstream input;
int pop_min_time;
int pop_max_time;
int pop_min_price;
int pop_max_price;
int pop_daily_card_price;
input.open("/opt/ptu5/opt/customer_748/etc/psa_tariff/tariff01.json");
std::stringstream sstr;
while(input >> sstr.rdbuf());
std::string json(sstr.str());
Configuration cfg;
bool isParsed = cfg.ParseJson(&cfg, json.c_str());
cout << endl;
if (isParsed) {
pop_min_time = get_minimal_parkingtime(&cfg);
pop_max_time = get_maximal_parkingtime(&cfg);
pop_min_price = get_minimal_parkingprice(&cfg);
pop_max_price = get_maximal_parkingprice(&cfg);
pop_daily_card_price = cfg.getPaymentOptions().pop_daily_card_price;
qCritical() << " pop_min_time: " << pop_min_time;
qCritical() << " pop_max_time: " << pop_max_time;
qCritical() << " pop_min_price: " << pop_min_price;
qCritical() << " pop_max_price: " << pop_max_price;
// tests:
// 1: Mon-Freitag: jeweils
// start 0-8.00
// start 8.00-12.00
// start 12.00-13.30
// start 13.30-18.00
// start 18.00-24.00
// alle kosten durchspielen
// 2. samstag
// start 0-8.00
// start 8.00-12.00
// start nach 12.00
// 2. sonntag
//QDateTime s(QDate(2024, 5, 27), QTime()); // monday
//QDateTime s(QDate(2024, 5, 28), QTime()); // tuesday
//QDateTime s(QDate(2024, 5, 29), QTime()); // wednesday
//QDateTime s(QDate(2024, 5, 30), QTime()); // thursday
CalcState cs;
double const x = 30.0/7.0;
double cost;
int durationInMinutes;
int offsetInMinutes = 0;
for (int day = Qt::Monday; day <= Qt::Sunday; ++day) {
QDateTime s(QDate(2024, 5, 19 + day), QTime()); // 20: (whit) monday,..., 26: sunday
QDateTime end;
for (int minutes = 0; minutes < 1440; ++minutes) {
//for (int minutes = 0; minutes < 1440; ++minutes) {
QDateTime start = s.addSecs(minutes * 60);
QDateTime effectiveStart = start;
if (day >= Qt::Monday && day <= Qt::Friday) {
if (start.time() < QTime(8,0,0)) {
effectiveStart.setTime(QTime(8,0,0));
} else
if (start.time() <= QTime(12,0,0)) {
effectiveStart = start;
} else
if (start.time() < QTime(13,30,0)) {
effectiveStart.setTime(QTime(13,30,0));
} else
if (start.time() <= QTime(18,0,0)) {
effectiveStart = start;
} else {
effectiveStart = start.addDays(1);
effectiveStart.setTime(QTime(8,0,0)); // saturday
}
} else
if (day == Qt::Saturday) {
if (start.time() < QTime(8,0,0)) {
effectiveStart.setTime(QTime(8,0,0));
} else
if (start.time() <= QTime(12,0,0)) {
effectiveStart = start;
} else {
effectiveStart = start.addDays(2);
effectiveStart.setTime(QTime(8,0,0)); // monday
}
} else
if (day == Qt::Sunday) {
effectiveStart = start.addDays(1);
effectiveStart.setTime(QTime(8,0,0)); // monday
}
for (int i = 70; i <= 600; i += 10) {
// for (int i = 70; i <= 70; i += 10) {
cost = i;
if ((cs = compute_duration_for_parking_ticket(&cfg, start, cost, end))) { // return value
durationInMinutes = truncf(x * (i/10));
offsetInMinutes = 0;
if (day >= Qt::Monday && day <= Qt::Friday) {
if (effectiveStart.time() >= QTime(8, 0, 0) && effectiveStart.time() <= QTime(12, 0, 0)) {
if (effectiveStart.date().dayOfWeek() == start.date().dayOfWeek()) {
if (effectiveStart.time().addSecs(durationInMinutes * 60) > QTime(12, 0, 0)) {
offsetInMinutes = 90; // 12:00 - 13:30
}
} else {
offsetInMinutes = 14 * 60; // 18:00 -> next day, 8:00
if (effectiveStart.time().addSecs(durationInMinutes * 60) <= QTime(12, 0, 0)) {
offsetInMinutes = 0;
} else {
if (effectiveStart.date().dayOfWeek() == Qt::Saturday) {
offsetInMinutes = (12 + 24 + 8) * 60;
} else {
offsetInMinutes = 90;
}
}
}
} else
if (effectiveStart.time() >= QTime(13, 30, 0)) {
if (effectiveStart.time().addSecs(durationInMinutes * 60) > QTime(18, 0, 0)) {
offsetInMinutes = 14 * 60; // 18:00 -> next day, 8:00
}
}
} else
if (day == Qt::Saturday) {
if (effectiveStart.time() >= QTime(8, 0, 0) && effectiveStart.time() <= QTime(12, 0, 0)) {
if (effectiveStart.date().dayOfWeek() == start.date().dayOfWeek()) {
if (effectiveStart.time().addSecs(durationInMinutes * 60) > QTime(12, 0, 0)) {
offsetInMinutes = (12 + 24 + 8) * 60; // monday, 8:00
}
} else {
offsetInMinutes = (12 + 24 + 8) * 60; // monday, 8:00
if (effectiveStart.time().addSecs(durationInMinutes * 60) <= QTime(12, 0, 0)) {
offsetInMinutes = 0;
} else {
offsetInMinutes = 90;
}
}
}
} else
if (day == Qt::Sunday) {
if (effectiveStart.time() >= QTime(8, 0, 0) && effectiveStart.time() <= QTime(12, 0, 0)) {
if (effectiveStart.time().addSecs(durationInMinutes * 60) > QTime(12, 0, 0)) {
offsetInMinutes = 90;
}
}
}
if ((durationInMinutes + offsetInMinutes) == (effectiveStart.secsTo(end) / 60)) {
continue;
}
}
if (!cs) {
qCritical() << "ERROR CalcState" << cs.toString() << endl;
} else {
qCritical() << "SUCCESS";
}
qCritical() << "start ............................" << start.toString(Qt::ISODate);
qCritical() << "effectiveStart ..................." << effectiveStart.toString(Qt::ISODate);
qCritical() << "cost ............................." << cost;
qCritical() << "durationMinutes .................." << durationInMinutes;
qCritical() << "offsetInMinutes .................." << offsetInMinutes;
qCritical() << "effectiveStart.secsTo(end) / 60 .." << effectiveStart.secsTo(end) / 60;
qCritical() << "end .............................." << end.toString(Qt::ISODate) << endl;
exit(-1);
}
}
}
}
#endif
#if NEUHAUSER_PERNEGG_AN_DER_MUR==1
std::ifstream input;
int pop_min_time;
@@ -264,6 +445,18 @@ int main() {
price = get_minimal_parkingprice(&cfg, PERMIT_TYPE::DAY_TICKET);
qCritical() << QString("line=%1 get_minimal_parkingprice:").arg(__LINE__) << price;
for (int h = 0; h < 24; ++h) {
start.setTime(QTime(h, 0, 0));
productStart = productEnd = QDateTime();
price = compute_product_price(&cfg, PERMIT_TYPE::DAY_TICKET, start, &productStart, &productEnd);
qCritical() << QString("line=%1 %2 price (%3-%4) :")
.arg(__LINE__)
.arg(start.time().toString(Qt::ISODate))
.arg(productStart.time().toString(Qt::ISODate))
.arg(productEnd.time().toString(Qt::ISODate))
<< price;
}
}
#endif
@@ -344,7 +537,7 @@ int main() {
// 2024-05-05 10:02:30
struct price_t costs;
double const cost[] = {600, 700, 800, 1600, 2400, 3000, 3600};
double const cost[] = {600, 700, 800, 1600, 2400, 3200, 4000};
double price1 = 0;
double price2 = 0;
@@ -391,7 +584,7 @@ int main() {
int pop_carry_over;
int pop_carry_over_time_range_id;
for (int zone=6; zone < 7; ++zone) {
for (int zone=1; zone < 2; ++zone) {
//for (int t=6; t < 7; t+=20) {
switch (zone) {
case 1: {
@@ -1044,9 +1237,179 @@ int main() {
&cfg,
start,
timeSteps.at(i));
qDebug() << "GetCostFromDuration() time: " << timeSteps.at(i)
<< "(" << timeSteps.at(i)/60 << "h)"
<< "price=" << price;
qCritical() << "zone" << zone
<< "GetCostFromDuration() time: " << timeSteps.at(i)
<< "(" << timeSteps.at(i)/60 << "h)"
<< "price=" << price;
switch(timeSteps.at(i)) {
case 60:
if (zone == 1) {
if (price == 300.0) {
continue;
}
}
if (zone == 2) {
if (price == 300.0) {
continue;
}
}
if (zone == 3) {
if (price == 200.0) {
continue;
}
}
break;
case 180:
if (zone == 1) {
if (price == 700.0) {
continue;
}
}
if (zone == 2) {
if (price == 500.0) {
continue;
}
}
if (zone == 3) {
if (price == 400.0) {
continue;
}
}
break;
case 1440:
if (zone == 1) {
if (price == 900.0) {
continue;
}
}
if (zone == 2) {
if (price == 600.0) {
continue;
}
}
if (zone == 3) {
if (price == 500.0) {
continue;
}
}
break;
case 2880:
if (zone == 1) {
if (price == 1800.0) {
continue;
}
}
if (zone == 2) {
if (price == 1200.0) {
continue;
}
}
break;
case 4320:
if (zone == 1) {
if (price == 2700.0) {
continue;
}
}
if (zone == 2) {
if (price == 1800.0) {
continue;
}
}
break;
case 5760:
if (zone == 1) {
if (price == 3600.0) {
continue;
}
}
if (zone == 2) {
if (price == 2400.0) {
continue;
}
}
break;
case 7200:
if (zone == 1) {
if (price == 4500.0) {
continue;
}
}
if (zone == 2) {
if (price == 3000.0) {
continue;
}
}
break;
case 8640:
if (zone == 1) {
if (price == 5400.0) {
continue;
}
}
if (zone == 2) {
if (price == 3600.0) {
continue;
}
}
break;
case 10080:
if (zone == 1) {
if (price == 6300.0) {
continue;
}
}
if (zone == 2) {
if (price == 4200.0) {
continue;
}
}
break;
case 11520:
if (zone == 1) {
if (price == 7200.0) {
continue;
}
}
if (zone == 2) {
if (price == 4800.0) {
continue;
}
}
break;
case 12960:
if (zone == 1) {
if (price == 8100.0) {
continue;
}
}
if (zone == 2) {
if (price == 5400.0) {
continue;
}
}
break;
case 14400:
if (zone == 1) {
if (price == 9000.0) {
continue;
}
}
if (zone == 2) {
if (price == 6000.0) {
continue;
}
}
break;
default:
qCritical() << "ERROR zone" << zone
<< "GetCostFromDuration() time: " << timeSteps.at(i)
<< "(" << timeSteps.at(i)/60 << "h)"
<< "price=" << price;
exit(-1);
}
}
}
}
@@ -1427,15 +1790,25 @@ int main() {
exit(-1);
}
QSet<uint32_t> const prices{700, 1400, 2100, 2800, 3500, 4200, 4900};
for (int i=0; i<timeSteps.size(); ++i) {
int nextTimeStep = compute_next_timestep(&cfg, timeSteps.at(i), Up);
qCritical() << "nextTimeStep" << nextTimeStep;
uint32_t price = Calculator::GetInstance().GetPriceForTimeStep(&cfg, timeSteps.at(i), paymentOptionIndex);
uint32_t duration = Calculator::GetInstance().GetDurationForPrice(&cfg, price);
if (!prices.contains(price)) {
qCritical() << "ERROR nextTimeStep relative to start:"
<< duration << start.addSecs(duration * 60).toString(Qt::ISODate)
<< "(price so far:" << price << ")";
exit(-1);
}
qCritical() << "nextTimeStep relative to start:"
<< duration << start.addSecs(duration * 60).toString(Qt::ISODate)
<< "(price so far:" << price << ")";
}
}
#endif
@@ -1470,6 +1843,11 @@ int main() {
CalcState cs = compute_price_for_daily_ticket(&cfg, start, end,
PERMIT_TYPE::DAY_TICKET_ADULT,
&price);
if (price.netto != 800) {
qCritical() << "ERROR(ADULT) start=" << start.toString(Qt::ISODate)
<< "end" << end.toString(Qt::ISODate) << "price (ADULT)" << price.netto;
exit(-1);
}
qCritical() << "start=" << start.toString(Qt::ISODate)
<< "end" << end.toString(Qt::ISODate) << "price (ADULT)" << price.netto;
}
@@ -1479,6 +1857,11 @@ int main() {
CalcState cs = compute_price_for_daily_ticket(&cfg, start, end,
PERMIT_TYPE::DAY_TICKET_TEEN,
&price);
if (price.netto != 400) {
qCritical() << "ERROR(TEEN) start=" << start.toString(Qt::ISODate)
<< "end" << end.toString(Qt::ISODate) << "price (TEEN)" << price.netto;
exit(-1);
}
qCritical() << "start=" << start.toString(Qt::ISODate)
<< "end" << end.toString(Qt::ISODate) << "price (TEEN)" << price.netto;
}
@@ -1501,6 +1884,11 @@ int main() {
if (isParsed) {
int const price = compute_product_price(&cfg, PERMIT_TYPE::FOOD_STAMP);
if (price != 300) {
qCritical() << "ERROR price food stamp" << price;
exit(-1);
}
qCritical() << "price food stamp" << price;
}
#endif
@@ -1542,6 +1930,170 @@ int main() {
<< "duration" << duration
<< "cost" << cost;
switch(duration) {
case 30:
if (cost == 60.0) {
continue;
}
break;
case 35:
if (cost == 70.0) {
continue;
}
break;
case 40:
if (cost == 80.0) {
continue;
}
break;
case 45:
if (cost == 90.0) {
continue;
}
break;
case 50:
if (cost == 100.0) {
continue;
}
break;
case 55:
if (cost == 110.0) {
continue;
}
break;
case 60:
if (cost == 120.0) {
continue;
}
break;
case 65:
if (cost == 130.0) {
continue;
}
break;
case 70:
if (cost == 140.0) {
continue;
}
break;
case 75:
if (cost == 150.0) {
continue;
}
break;
case 80:
if (cost == 160.0) {
continue;
}
break;
case 85:
if (cost == 170.0) {
continue;
}
break;
case 90:
if (cost == 180.0) {
continue;
}
break;
case 95:
if (cost == 190.0) {
continue;
}
break;
case 100:
if (cost == 200.0) {
continue;
}
break;
case 105:
if (cost == 210.0) {
continue;
}
break;
case 110:
if (cost == 220.0) {
continue;
}
break;
case 115:
if (cost == 230.0) {
continue;
}
break;
case 120:
if (cost == 240.0) {
continue;
}
break;
case 125:
if (cost == 250.0) {
continue;
}
break;
case 130:
if (cost == 260.0) {
continue;
}
break;
case 135:
if (cost == 270.0) {
continue;
}
break;
case 140:
if (cost == 280.0) {
continue;
}
break;
case 145:
if (cost == 290.0) {
continue;
}
break;
case 150:
if (cost == 300.0) {
continue;
}
break;
case 155:
if (cost == 310.0) {
continue;
}
break;
case 160:
if (cost == 320.0) {
continue;
}
break;
case 165:
if (cost == 330.0) {
continue;
}
break;
case 170:
if (cost == 340.0) {
continue;
}
break;
case 175:
if (cost == 350.0) {
continue;
}
break;
case 180:
if (cost == 360.0) {
continue;
}
break;
default:
qCritical() << "ERROR(1) start" << start.toString(Qt::ISODate)
<< "end" << end.toString(Qt::ISODate)
<< "duration" << duration
<< "cost" << cost;
exit(-1);
}
//std::string duration = Calculator::GetInstance().GetDurationFromCost(&cfg, 3, start.toString(Qt::ISODate).toStdString().c_str(), cost);
//Q_ASSERT(cost == duration*2.5);
//qCritical() << "start" << start.toString(Qt::ISODate)
@@ -1558,6 +2110,13 @@ int main() {
s.setTime(QTime(12, 0, 0));
int duration = 30;
double cost = Calculator::GetInstance().GetCostFromDuration(&cfg, 3, s, end, duration, nextDay, prePaid);
if (cost != 60.0) {
qCritical() << "ERROR(2) start" << s.toString(Qt::ISODate)
<< "end" << end.toString(Qt::ISODate)
<< "duration" << duration
<< "cost" << cost;
exit(-1);
}
qCritical() << "start" << s.toString(Qt::ISODate)
<< "end" << end.toString(Qt::ISODate)
<< "duration" << duration
@@ -1578,7 +2137,7 @@ int main() {
int pop_max_price;
int pop_daily_card_price;
for (int zone=1; zone < 2; ++zone) {
for (int zone = 1; zone < 2; ++zone) {
//for (int t=6; t < 7; t+=20) {
switch (zone) {
case 1: {
@@ -1632,6 +2191,10 @@ int main() {
qCritical() << " pop_max_price: " << pop_max_price;
qCritical() << "pop_daily_card_price: " << pop_daily_card_price;
pop_daily_card_price = compute_product_price(&cfg, PERMIT_TYPE::DAY_TICKET);
qCritical() << "pop_daily_card_price: " << pop_daily_card_price;
if (pop_min_time > pop_max_time) {
qCritical() << "ERROR pop_min_time > pop_max_time"
<< pop_min_time << pop_max_time;
@@ -1778,7 +2341,7 @@ int main() {
m.insert(115, 499);
m.insert(120, 520);
m.insert(125, 524);
m.insert(125, 542);
m.insert(130, 564);
m.insert(135, 585);
m.insert(140, 607);
@@ -2197,17 +2760,19 @@ int main() {
return -1;
}
// start = s.addSecs(offset * 60);
// end = QDateTime();
//if (compute_duration_for_daily_ticket(&cfg, start, end)) {
//
// } else {
// qCritical() << "ERROR computing_duration_for_daily_ticket AT"
// << "start" << start.toString(Qt::ISODate);
// return -1;
// }
// this->getDayTicketPrice(PERMIT_TYPE::DAY_TICKET)
++cnt;
// start = s.addSecs(offset * 60);
// end = QDateTime();
// if (compute_duration_for_daily_ticket(&cfg, start, end)) {
//
// } else {
// qCritical() << "ERROR computing_duration_for_daily_ticket AT"
// << "start" << start.toString(Qt::ISODate);
// return -1;
// }
// ++cnt;
}
}
}