Compare commits

..

No commits in common. "9baaca1c8004d7f6cc39408ee7ddec48b2f7ebfb" and "51318927444a0c95b0ac8b3ba394cb16049ba339" have entirely different histories.

5 changed files with 90 additions and 391 deletions

View File

@ -27,13 +27,6 @@ class Calculator {
int netto_parking_time,
int paymentOptionIndex);
int computeBruttoDurationInSecs(Configuration const *cfg,
QDateTime const &from,
int durationInSecs, bool maxBrutto = false);
QDateTime computeBruttoDateTime(Configuration const *cfg,
QDateTime const &from,
int durationInSecs, bool maxBrutto = false);
protected:
explicit Calculator() = default;
@ -77,7 +70,8 @@ public:
/// <param name="start_datetime">Date/time of payment to be conducted in ISO8601 format (e.g. 2022-12-25T08:00:00Z)</param>
/// <param name="price"></param>
/// <returns>Returns duration in seconds (data type: double)</returns>
std::string GetDurationFromCost(Configuration* cfg, uint8_t vehicle_type, char const* start_datetime, double price, PermitType permitType, bool nextDay = false, bool prepaid = false);
std::string GetDurationFromCost(Configuration* cfg, uint8_t vehicle_type, char const* start_datetime, double price,
PermitType permitType, bool nextDay = false, bool prepaid = false);
/// <summary>
/// Gets cost from duration in seconds
@ -85,10 +79,11 @@ public:
/// <param name="tariff_cfg">Pointer to configuration</param>
/// <param name="vehicle_type">Type of vehicle</param>
/// <param name="start_datetime">Date/time of payment to be conducted in ISO8601 format (e.g. 2022-12-25T08:00:00Z) </param>
/// <param name="end_datetime">Date/time of park end to be conducted in ISO8601 format (e.g. 2022-12-25T08:00:00Z) </param>
/// <param name="end_datetime">Date/time of park end to be conducted in ISO8601 format (e.g. 2022-12-25T08:00:00Z) </param>
/// <param name="durationMin">Duration of parking in minutes</param>
/// <returns>Returns cost (data type: double)</returns>
double GetCostFromDuration(Configuration* cfg, uint8_t vehicle_type, QDateTime &start_datetime, QDateTime & end_datetime, int durationMin, PermitType permitType, bool nextDay = false, bool prepaid = false);
double GetCostFromDuration(Configuration* cfg, uint8_t vehicle_type, QDateTime &start_datetime, QDateTime & end_datetime, int durationMin,
PermitType permitType, bool nextDay = false, bool prepaid = false);
// Daily ticket
QDateTime GetDailyTicketDuration(Configuration* cfg, const QDateTime start_datetime, uint8_t payment_option, bool carry_over);

View File

@ -327,8 +327,7 @@ int CALCULATE_LIBRARY_API get_maximal_parkingprice(Configuration *cfg,
switch(permitType) {
case PERMIT_TYPE::SHORT_TERM_PARKING: { // e.g. szeged (customer_281)
if (paymentMethodId == PaymentMethod::Progressive || paymentMethodId == PaymentMethod::Steps) {
paymentOptionIndex = cfg->getPaymentOptionIndex(permitType);
maxPrice = cfg->getPaymentOptions(paymentOptionIndex).pop_max_price;
maxPrice = Utilities::getMaximalParkingPrice(cfg, paymentMethodId);
} else { // PaymentMethod::Linear -> e.g. szeged
int const key = cfg->getPaymentOptions(paymentOptionIndex).pop_id;
int const maxTime = cfg->getPaymentOptions(paymentOptionIndex).pop_max_time; // maxTime is given in minutes
@ -717,14 +716,15 @@ CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket(
QDateTime &end_parking_time,
struct price_t *price,
PermitType permitType,
bool prepaid) {
bool prepaid)
{
CalcState calcState;
QDateTime start_parking_time(start_parking_time_);
int paymentOptionIndex = tariff->getPaymentOptionIndex(permitType);
QList<int> tlist = Calculator::GetInstance().GetTimeSteps(tariff, paymentOptionIndex, start_parking_time);
QList<int> tlist = Calculator::GetInstance().GetTimeSteps(tariff, paymentOptionIndex);
//Q_UNUSED(tlist);
double minMin = tariff->getPaymentOptions(paymentOptionIndex).pop_min_time;
@ -732,18 +732,16 @@ CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket(
// netto_parking_time = minMin;
if (DBG_LEVEL >= DBG_DEBUG) {
qCritical() << "compute_price_for_parking_ticket() " << endl
<< " paymentOptionIndex: " << paymentOptionIndex << endl
<< " start_parking_time: " << start_parking_time << endl
<< " start_parking_time_: " << start_parking_time_ << endl
<< " netto_parking_time: " << netto_parking_time << endl
<< " start + netto: " << start_parking_time.addSecs(netto_parking_time * 60) << endl
<< " minMin: " << minMin << endl
<< " maxMin: " << maxMin << endl
<< " prepaid: " << prepaid << endl
<< " permitType: " << permitType.toString();
}
// DEBUG
qCritical() << "compute_price_for_parking_ticket() " << endl
<< " paymentOptionIndex: " << paymentOptionIndex << endl
<< " start_parking_time: " << start_parking_time << endl
<< " netto_parking_time: " << netto_parking_time << endl
<< " start + netto: " << start_parking_time.addSecs(netto_parking_time * 60) << endl
<< " minMin: " << minMin << endl
<< " maxMin: " << maxMin << endl
<< " prepaid: " << prepaid << endl
<< " permitType: " << permitType.toString();
if (netto_parking_time < 0) {
calcState.setDesc(QString("end=%1, start=%2")
@ -790,14 +788,14 @@ CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket(
if (yperiod.has_value()) {
ATBPeriodYear const &period = yperiod.value();
pop_carry_over_option_id = period.pye_id;
//qCritical() << __func__ << __LINE__ << "re-computed carry-over-id" << pop_carry_over_option_id;
qCritical() << __func__ << __LINE__ << "re-computed carry-over-id" << pop_carry_over_option_id;
}
QTime const carryOverStart = tariff->TariffCarryOverOptions.find(pop_carry_over_option_id)->second.carryover[weekDay].static_start;
int const carryOverDuration = tariff->TariffCarryOverOptions.find(pop_carry_over_option_id)->second.carryover[weekDay].duration;
//qCritical() << __func__ << __LINE__ << "carryOverStart" << carryOverStart.toString(Qt::ISODate);
//qCritical() << __func__ << __LINE__ << "carryOverDuration" << carryOverDuration;
qCritical() << __func__ << __LINE__ << "carryOverStart" << carryOverStart.toString(Qt::ISODate);
qCritical() << __func__ << __LINE__ << "carryOverDuration" << carryOverDuration;
// handle prepaid option
QDateTime effectiveStartTime(start_parking_time);
@ -862,7 +860,7 @@ CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket(
end_parking_time = end_parking_time.addDays(-1);
end_parking_time.setTime(QTime(23, 59, 0));
}
//qCritical() << __func__ << __LINE__ << "end_parking_time" << end_parking_time.toString(Qt::ISODate);
qCritical() << __func__ << __LINE__ << "end_parking_time" << end_parking_time.toString(Qt::ISODate);
return calcState.set(CalcState::State::SUCCESS);
}
@ -1005,20 +1003,15 @@ CalcState CALCULATE_LIBRARY_API compute_duration_for_parking_ticket(
} else {
ticketEndTime = QDateTime::fromString(endTime,Qt::ISODate);
// 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);
}
if (ticketEndTime.time().hour() == 0 && ticketEndTime.time().minute() == 0) {
ticketEndTime = ticketEndTime.addDays(-1);
ticketEndTime.setTime(QTime(23, 59, 0));
}
// DEBUG
qCritical() << "compute_duration_for_parking_ticket(): ";
qCritical() << " endTime: " << endTime;
qCritical() << " ticketEndTime: " << ticketEndTime;
}
} else {
return calcState.set(CalcState::State::INVALID_START_DATE);

View File

@ -117,117 +117,6 @@ QDateTime Calculator::GetDailyTicketDuration(Configuration* cfg, const QDateTime
return QDateTime();
}
int Calculator::computeBruttoDurationInSecs(Configuration const *cfg,
QDateTime const &start,
int nettoDurationInSecs,
bool maxBrutto) {
QDateTime from(start);
int bruttoDurationInSecs = 0;
if (DBG_LEVEL >= DBG_DEBUG) {
qCritical() << DBG_HEADER << "netto duration in secs" << nettoDurationInSecs;
}
while (nettoDurationInSecs > 0) {
int day_in_week_id = from.date().dayOfWeek();
int count = cfg->WeekDaysWorktime.count(day_in_week_id);
if (DBG_LEVEL >= DBG_DEBUG) {
qCritical() << DBG_HEADER << "count for " << day_in_week_id << ": " << count;
}
if (count > 0) {
for (auto[iter, rEnd] = cfg->WeekDaysWorktime.equal_range(day_in_week_id); iter != rEnd; ++iter) {
QTime const &pwd_time_from = QTime::fromString(QString::fromStdString(iter->second.pwd_time_from), Qt::ISODate);
QTime const &pwd_time_to = QTime::fromString(QString::fromStdString(iter->second.pwd_time_to), Qt::ISODate);
QTime fromTime = from.time();
if (DBG_LEVEL >= DBG_DEBUG) {
qCritical() << DBG_HEADER;
qCritical() << DBG_HEADER << " wd-from" << pwd_time_from.toString(Qt::ISODate);
qCritical() << DBG_HEADER << " wd-to" << pwd_time_to.toString(Qt::ISODate);
qCritical() << DBG_HEADER << "fromTime" << fromTime.toString(Qt::ISODate);
qCritical() << DBG_HEADER << " from" << from.toString(Qt::ISODate);
qCritical() << DBG_HEADER;
}
if (fromTime <= pwd_time_from) {
int secs = fromTime.secsTo(pwd_time_from);
bruttoDurationInSecs += secs;
fromTime = pwd_time_from;
from.setTime(pwd_time_from);
}
if (DBG_LEVEL >= DBG_DEBUG) {
qCritical() << DBG_HEADER << "fromTime" << fromTime.toString(Qt::ISODate);
qCritical() << DBG_HEADER << " from" << from.toString(Qt::ISODate);
qCritical() << DBG_HEADER << " netto" << nettoDurationInSecs;
qCritical() << DBG_HEADER << " brutto" << bruttoDurationInSecs;
qCritical() << DBG_HEADER << " br-date" << start.addSecs(bruttoDurationInSecs);
}
while (fromTime < pwd_time_to && nettoDurationInSecs > 0) {
bruttoDurationInSecs += 60;
nettoDurationInSecs -= 60;
fromTime = fromTime.addSecs(60);
from = from.addSecs(60);
}
if (DBG_LEVEL >= DBG_DEBUG) {
qCritical() << DBG_HEADER;
qCritical() << DBG_HEADER << " netto" << nettoDurationInSecs;
qCritical() << DBG_HEADER << " brutto" << bruttoDurationInSecs;
qCritical() << DBG_HEADER << " br-date" << start.addSecs(bruttoDurationInSecs);
qCritical() << DBG_HEADER << "fromTime" << fromTime.toString(Qt::ISODate);
qCritical() << DBG_HEADER << " from" << from.toString(Qt::ISODate);
qCritical() << DBG_HEADER;
}
if (--count == 0 && fromTime == pwd_time_to) {
// handle rest
QDateTime midnight(from);
midnight = midnight.addDays(1);
midnight.setTime(QTime(0, 0, 0));
int secs = from.secsTo(midnight);
bruttoDurationInSecs += secs;
from = midnight;
if (DBG_LEVEL >= DBG_DEBUG) {
qCritical() << DBG_HEADER;
qCritical() << DBG_HEADER << " netto" << nettoDurationInSecs;
qCritical() << DBG_HEADER << " brutto" << bruttoDurationInSecs;
qCritical() << DBG_HEADER << " br-date" << start.addSecs(bruttoDurationInSecs);
qCritical() << DBG_HEADER << " from" << from.toString(Qt::ISODate);
qCritical() << DBG_HEADER;
}
}
}
} else {
bruttoDurationInSecs += (24 * 3600);
from = from.addDays(1);
}
}
if (maxBrutto) {
qCritical() << DBG_HEADER << "TODO";
}
if (DBG_LEVEL >= DBG_DEBUG) {
qCritical() << DBG_HEADER << " br-date" << start.addSecs(bruttoDurationInSecs);
}
return bruttoDurationInSecs;
}
QDateTime Calculator::computeBruttoDateTime(Configuration const *cfg,
QDateTime const &from,
int durationInSecs,
bool maxBrutto) {
return from.addSecs(computeBruttoDurationInSecs(cfg, from, durationInSecs, maxBrutto));
}
/// <inheritdoc/>
std::string Calculator::GetDurationFromCost(Configuration* cfg,
uint8_t payment_option,
@ -318,12 +207,7 @@ std::string Calculator::GetDurationFromCost(Configuration* cfg,
//found = true;
//qCritical() << "(" << __func__ << ":" << __LINE__ << ") duration_previous" << duration_previous;
//qCritical() << "(" << __func__ << ":" << __LINE__ << ") duration in minutes" << durationInMinutes;
QDateTime d;
if (pop_accumulate_durations) {
d = inputDate.addSecs(durationInMinutes * 60);
} else {
d = inputDate.addSecs(duration_previous * 60);
}
QDateTime d(inputDate.addSecs(duration_previous * 60));
qCritical() << DBG_HEADER << " provided price (cost):" << cost;
qCritical() << DBG_HEADER << " computed time for price (minutes):" << duration_previous;
@ -497,11 +381,12 @@ std::string Calculator::GetDurationFromCost(Configuration* cfg,
#endif
int const pop_accumulate_prices = cfg->getPaymentOptions(paymentOptionIndex).pop_accumulate_prices;
int const pop_accumulate_durations = cfg->getPaymentOptions(paymentOptionIndex).pop_accumulate_durations;
// int const pop_accumulate_durations = cfg->getPaymentOptions(paymentOptionIndex).pop_accumulate_durations;
int price = 0;
int new_price = 0;
int durationInSecs = 0;
uint32_t duration_previous = 0;
bool found = false;
for (auto[itr, rangeEnd] = cfg->PaymentRate.equal_range(pop_id); itr != rangeEnd; ++itr) {
int const pra_price = itr->second.pra_price;
@ -524,39 +409,24 @@ std::string Calculator::GetDurationFromCost(Configuration* cfg,
uint32_t const durationUnit = cfg->Duration.find(durationId)->second.pun_duration;
new_price += pra_price;
#if DEBUG_GET_DURATION_FROM_COST==1
qCritical() << "(" << __func__ << ":" << __LINE__ << ") pra_price:" << pra_price;
qCritical() << "(" << __func__ << ":" << __LINE__ << ") price:" << price;
qCritical() << "(" << __func__ << ":" << __LINE__ << ") cost:" << cost;
qCritical() << "(" << __func__ << ":" << __LINE__ << ") new_price:" << new_price;
#endif
//qCritical() << "(" << __func__ << ":" << __LINE__ << ") XXXXXX price:" << price;
//qCritical() << "(" << __func__ << ":" << __LINE__ << ") YYYYYY new_price:" << new_price;
if (new_price <= cost) {
if (pop_accumulate_durations) {
duration_previous += durationUnit;
} else {
duration_previous = durationUnit;
}
durationInSecs = duration_previous * 60;
#if DEBUG_GET_DURATION_FROM_COST==1
qCritical() << "(" << __func__ << ":" << __LINE__ << ") durationUnit" << durationUnit;
qCritical() << "(" << __func__ << ":" << __LINE__ << ") duration_previous" << duration_previous;
qCritical() << "(" << __func__ << ":" << __LINE__ << ") durationInSecs" << durationInSecs;
#endif
duration_previous = durationUnit;
//qCritical() << "(" << __func__ << ":" << __LINE__ << ") ZZZZZZ duration_previous" << duration_previous;
} else {
// qCritical() << "(" << __func__ << ":" << __LINE__ << ") duration_previous" << duration_previous;
found = true;
//qCritical() << "(" << __func__ << ":" << __LINE__ << ") WWWWWW duration_previous" << duration_previous;
QString s = inputDate.toString(Qt::ISODate);
QDateTime d(QDateTime::fromString(s, Qt::ISODate));
d = d.addSecs(duration_previous * 60);
//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;
//qCritical() << DBG_HEADER << "DURATION-SECS" << durationInSecs;
//qCritical() << DBG_HEADER << "DURATION-MINS" << durationInSecs / 60;
}
if ((double)price == cost) {
@ -569,50 +439,25 @@ std::string Calculator::GetDurationFromCost(Configuration* cfg,
qCritical() << DBG_HEADER << "DURATION IN SECONDS" << durationInSecs;
qCritical() << DBG_HEADER << "CURRENT-WORKING-DATE-TIME-TO"
<< current_working_date_time_to.toString(Qt::ISODate);
qCritical() << DBG_HEADER << " INPUT DATE" << inputDate.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) {
int bruttoDurationInSecs = computeBruttoDurationInSecs(cfg, inputDate, durationInSecs);
// qCritical() << DBG_HEADER << "DURATION IN SECONDS (NETTO)" << durationInSecs;
// qCritical() << DBG_HEADER << "DURATION IN SECONDS (BRUTTO)" << bruttoDurationInSecs;
inputDate = inputDate.addSecs(bruttoDurationInSecs);
#if 0
// durationInSecs is a netto time
// needed is the corresponding brutto-time
int day_in_week_id = inputDate.date().dayOfWeek();
int nettoDurationInSecs = 0;
while (nettoDurationInSecs <= durationInSecs) {
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);
QTime pwd_time_to = QTime::fromString(QString::fromStdString(iter->second.pwd_time_to), Qt::ISODate);
nettoDurationInSecs += pwd_time_from.secsTo(pwd_time_to);
if (nettoDurationInSecs > durationInSecs) {
break;
}
}
}
day_in_week_id += 1;
if (day_in_week_id > (int)Qt::Sunday) {
day_in_week_id = Qt::Monday;
}
}
qCritical() << DBG_HEADER;
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;
}
}
@ -629,33 +474,33 @@ 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 << " day in week" << day_in_week_id;
qCritical() << DBG_HEADER << "next working time from" << next_working_time_from.toString(Qt::ISODate);
break;
}
}
qCritical() << DBG_HEADER << "DAYS" << days;
qCritical() << DBG_HEADER << "DURATION-SECS" << durationInSecs;
qCritical() << DBG_HEADER << "DURATION-MINS" << durationInSecs / 60;
//qCritical() << DBG_HEADER << "DAYS" << days;
//qCritical() << DBG_HEADER << "DURATION-SECS" << durationInSecs;
//qCritical() << DBG_HEADER << "DURATION-MINS" << durationInSecs / 60;
QDateTime upper = inputDate.addDays(days);
upper.setTime(next_working_time_from);
qCritical() << DBG_HEADER << "UPPER" << upper.toString(Qt::ISODate);
//qCritical() << DBG_HEADER << "UPPER" << upper.toString(Qt::ISODate);
QDateTime lower = inputDate;
lower.setTime(current_working_time_to);
qCritical() << DBG_HEADER << "LOWER" << lower.toString(Qt::ISODate);
//qCritical() << DBG_HEADER << "LOWER" << lower.toString(Qt::ISODate);
// inputDate = inputDate.addSecs(lower.secsTo(upper));
//qCritical() << DBG_HEADER << "NEW INPUT" << inputDate.toString(Qt::ISODate);
// durationInSecs is a netto-parking-time
inputDate = inputDate.addSecs(durationInSecs + lower.secsTo(upper));
inputDate = inputDate.addSecs(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) {
@ -667,31 +512,36 @@ std::string Calculator::GetDurationFromCost(Configuration* cfg,
lower.setTime(current_working_time_to);
inputDate = inputDate.addSecs(lower.secsTo(upper) + durationInSecs);
//qCritical() << DBG_HEADER << "TICKET-END" << inputDate.toString(Qt::ISODate);
#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
} else { // if (inputDate.addSecs(durationInSecs) > current_working_date_time_to) {
if (pop_accumulate_durations) {
inputDate = inputDate.addSecs(durationInSecs);
} else {
inputDate = inputDate.addSecs(duration.pun_duration * 60);
}
// qCritical() << DBG_HEADER << "INPUT-DATE" << inputDate.toString(Qt::ISODate);
}
QString const &s = inputDate.toString(Qt::ISODate);
// qCritical() << DBG_HEADER << "TICKET-END" << s;
#if DEBUG_GET_DURATION_FROM_COST==1
qCritical() << DBG_HEADER << "TICKET-END" << s;
#endif
return s.toStdString();
} // if ((double)price == cost) {
else {
// qCritical() << DBG_HEADER;
//qCritical() << DBG_HEADER;
}
} else {
// qCritical() << DBG_HEADER;
//qCritical() << __func__ << __LINE__;
}
}
// qCritical() << DBG_HEADER;
return "";
}
}
@ -1165,11 +1015,10 @@ uint32_t Calculator::GetCostFromDuration(Configuration * cfg,
paymentMethodId == PaymentMethod::Degressive) {
int const timeStepInMinutes = start.secsTo(end) / 60;
QList<int> tlist = Calculator::GetInstance().GetTimeSteps(cfg, paymentOptionIndex, start);
Q_UNUSED(tlist);
//qCritical() << DBG_HEADER << " start" << start.toString(Qt::ISODate);
//qCritical() << DBG_HEADER << " end" << end.toString(Qt::ISODate);
//qCritical() << DBG_HEADER << "timeStepList" << timeStepInMinutes << tlist;
//qCritical() << DBG_HEADER << "timeStepInMinutes" << timeStepInMinutes << start.toString(Qt::ISODate);
qCritical() << DBG_HEADER << " start" << start.toString(Qt::ISODate);
qCritical() << DBG_HEADER << " end" << end.toString(Qt::ISODate);
qCritical() << DBG_HEADER << "timeStepList" << timeStepInMinutes << tlist;
qCritical() << DBG_HEADER << "timeStepInMinutes" << timeStepInMinutes << start.toString(Qt::ISODate);
return GetPriceForTimeStep(cfg, timeStepInMinutes, paymentOptionIndex);
}
@ -1457,8 +1306,8 @@ CalcState Calculator::isParkingAllowed(Configuration const *cfg,
int netto_parking_time,
int paymentOptionIndex) {
//qCritical() << DBG_HEADER << "CHECK IF PARKING IS ALLOWED AT"
// << start.toString(Qt::ISODate) << "...";
qCritical() << DBG_HEADER << "CHECK IF PARKING IS ALLOWED AT"
<< start.toString(Qt::ISODate) << "...";
CalcState cs;
@ -2686,8 +2535,6 @@ QList<int> &Calculator::GetTimeSteps(Configuration *cfg, int paymentOptionIndex,
std::optional<QDateTime> prepaidStart = cfg->prepaidStart(start, pop_prepaid_option_id);
// TODO: zusaetzlicher faktor falls vorkauf-option zieht
if (prepaidStart) {
//qCritical() << "(" << __func__ << ":" << __LINE__ << ") start:" << start.toString(Qt::ISODate);
//qCritical() << "(" << __func__ << ":" << __LINE__ << ") prepaid start value:" << prepaidStart.value().toString(Qt::ISODate);
start = prepaidStart.value();
if (DBG_LEVEL >= DBG_DEBUG) {
qCritical() << "(" << __func__ << ":" << __LINE__ << ") prepaid adapted start:" << start.toString(Qt::ISODate);
@ -2705,11 +2552,9 @@ QList<int> &Calculator::GetTimeSteps(Configuration *cfg, int paymentOptionIndex,
qCritical() << "(" << __func__ << ":" << __LINE__ << ") interpolation end:" << interpolationEnd.toString(Qt::ISODate);
}
} else {
qCritical() << "(" << __func__ << ":" << __LINE__ << ") TODO";
// qCritical() << "(" << __func__ << ":" << __LINE__ << ") TODO";
}
// qCritical() << "(" << __func__ << ":" << __LINE__ << ") start:" << start.toString(Qt::ISODate);
// int const start_time = start.time().hour() * 60 + start.time().minute();
QDateTime nextTimeStep = start;
int runtimeInMinutes = 0;
@ -2752,7 +2597,7 @@ QList<int> &Calculator::GetTimeSteps(Configuration *cfg, int paymentOptionIndex,
break;
}
// qCritical() << "(" << __func__ << ":" << __LINE__ << ") runtime in minutes:" << runtimeInMinutes;
//qCritical() << "(" << __func__ << ":" << __LINE__ << ") runtime in minutes:" << runtimeInMinutes;
std::optional<ATBInterpolation> ipolCheck = cfg->getInterpolationType(duration.pun_interpolation_id);
if (ipolCheck) {
@ -2773,12 +2618,11 @@ QList<int> &Calculator::GetTimeSteps(Configuration *cfg, int paymentOptionIndex,
// qCritical() << "(" << __func__ << ":" << __LINE__ << ") interpolation dynamic end time:" << end_time;
int pop_min_time = cfg->getPaymentOptions(paymentOptionIndex).pop_min_time;
bool pop_accumulate_durations = cfg->getPaymentOptions(paymentOptionIndex).pop_accumulate_durations;
runtimeInMinutes += duration.pun_duration;
nextTimeStep = start.addSecs(runtimeInMinutes * 60);
// qCritical() << "(" << __func__ << ":" << __LINE__ << ") runtime in minutes (1):" << runtimeInMinutes;
//qCritical() << "(" << __func__ << ":" << __LINE__ << ") runtime in minutes (1):" << runtimeInMinutes;
if (nextTimeStep.time() > carryOverStart) {
int const backTime = carryOverStart.secsTo(nextTimeStep.time()) / 60;
@ -2803,19 +2647,17 @@ QList<int> &Calculator::GetTimeSteps(Configuration *cfg, int paymentOptionIndex,
//}
} else {
m_timeSteps[paymentOptionIndex] << runtimeInMinutes;
//qCritical() << "(" << __func__ << ":" << __LINE__ << ") :" << m_timeSteps[paymentOptionIndex];
}
}
if (pop_accumulate_durations == false) {
duration.pun_duration = runtimeInMinutes;
qCritical() << "(" << __func__ << ":" << __LINE__ << ") pun_id:" << duration.pun_id;
qCritical() << "(" << __func__ << ":" << __LINE__ << ") pun_duration:" << duration.pun_duration;
search->second = duration;
}
duration.pun_duration = runtimeInMinutes;
//qCritical() << "(" << __func__ << ":" << __LINE__ << ") pun_id:" << duration.pun_id;
//qCritical() << "(" << __func__ << ":" << __LINE__ << ") pun_duration:" << duration.pun_duration;
search->second = duration;
} else
if (duration.pun_interpolation_id == (int)ATBInterpolation::NO_INTERPOLATION) {
qCritical() << "(" << __func__ << ":" << __LINE__ << ")" ;
//qCritical() << "(" << __func__ << ":" << __LINE__ << ") pun_id:" << duration.pun_id;
//qCritical() << "(" << __func__ << ":" << __LINE__ << ") paymentOptionIndex:" << paymentOptionIndex;
@ -2907,7 +2749,7 @@ QList<int> &Calculator::GetTimeSteps(Configuration *cfg, int paymentOptionIndex,
// duration.pun_duration = runtimeInMinutes - carryOverDuration;
m_timeSteps[paymentOptionIndex] << duration.pun_duration;
search->second = duration;
} else { // if (duration.pun_interpolation_id == (int)ATBInterpolation::NO_INTERPOLATION) {
} else {
cfg->Duration.erase(search);
}
}
@ -3014,7 +2856,7 @@ uint32_t Calculator::GetPriceForTimeStep(Configuration *cfg, int timeStep, int p
}
if (timeStep == pun_duration) {
//qCritical() << "(" << __func__ << ":" << __LINE__ << ") return price" << price;
qCritical() << "(" << __func__ << ":" << __LINE__ << ") return price" << price;
return price;
}
}
@ -3026,9 +2868,7 @@ uint32_t Calculator::GetDurationForPrice(Configuration *cfg, int price) const {
int const pop_id = cfg->getPaymentOptions().pop_id;
int const pop_accumulate_prices = cfg->getPaymentOptions().pop_accumulate_prices;
qCritical() << "(" << __func__ << ":" << __LINE__ << ") accumulate prices" << pop_accumulate_prices;
qCritical() << "(" << __func__ << ":" << __LINE__ << ") pop_id" << pop_id;
qCritical() << "(" << __func__ << ":" << __LINE__ << ") price" << price;
//qCritical() << "(" << __func__ << ":" << __LINE__ << ") accumulate prices" << pop_accumulate_prices;
int new_price = 0;
uint32_t duration = 0;

View File

@ -1260,7 +1260,7 @@ std::optional<QDateTime> Configuration::prepaidStart(QDateTime const &start, int
std::optional<QDateTime> value;
QDateTime s = start;
// qCritical() << "(" << __func__ << ":" << __LINE__ << ") prepaid option id:" << prepaid_option_id;
qCritical() << "(" << __func__ << ":" << __LINE__ << ") prepaid option id:" << prepaid_option_id;
std::optional<ATBPrepaid> prepaid_option = getPrepaidType(prepaid_option_id);
if (prepaid_option.has_value()) {

View File

@ -49,10 +49,9 @@ extern "C" char* strptime(const char* s,
#define NEUHAUSER_STOCKERAU (0)
#define KLEIPEDA_LITAUEN (0)
#define SEXTEN (0)
#define SCHNALS_LEITER_KIRCHL (0)
#define SCHNALS_LEITER_KIRCHL (1)
#define SCHNALS_STAUMAUER (SCHNALS_LEITER_KIRCHL)
#define VALSER_ALM (0)
#define FUCHS_MUEHLBACH (1)
#if NEUHAUSER_KIRCHDORF==1
static bool test_neuhauser_kirchdorf(int step, double cost) {
@ -709,134 +708,6 @@ int main() {
}
#endif
#if FUCHS_MUEHLBACH==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("/home/linux/customer_504/etc/psa_tariff/tariff01.json");
//input.open("/opt/ptu5/opt/customer_505/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) {
PermitType permitType(PERMIT_TYPE::SHORT_TERM_PARKING);
pop_min_time = get_minimal_parkingtime(&cfg, permitType);
pop_max_time = get_maximal_parkingtime(&cfg, permitType);
pop_min_price = get_minimal_parkingprice(&cfg, permitType);
pop_max_price = get_maximal_parkingprice(&cfg, permitType);
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;
CalcState cs;
double cost;
int durationInMinutes = 0;
int offsetInMinutes = 0;
// for (int day = Qt::Monday; day <= Qt::Sunday; ++day) {
for (int day = Qt::Monday; day <= Qt::Monday; ++day) {
QDateTime s(QDate(2024, 7, 21 + day), QTime(0, 0, 0));
QDateTime end;
switch (day) {
case (int)Qt::Monday:
qCritical() << "Monday";
break;
case (int)Qt::Tuesday:
qCritical() << "Tuesday";
break;
case (int)Qt::Wednesday:
qCritical() << "Wednesday";
break;
case (int)Qt::Thursday:
qCritical() << "Thursday";
break;
case (int)Qt::Friday:
qCritical() << "Friday";
break;
case (int)Qt::Saturday:
qCritical() << "Saturday";
break;
case (int)Qt::Sunday:
qCritical() << "Sunday";
break;
}
//for (int minutes = 0; minutes < 1440; ++minutes) {
for (int minutes = 420; minutes <= 420; minutes += 1) {
QDateTime start = s.addSecs(minutes * 60);
//qCritical() << "start" << start.toString(Qt::ISODate);
QDateTime effectiveStart = start;
// hier sollte man auch testen was passiert, falls man ausserhalb
// der verkaufsdaten steht
if (start.time() < QTime(7, 0, 0)) {
effectiveStart.setTime(QTime(7, 0, 0));
} else
if (start.time() <= QTime(20, 0, 0)) {
effectiveStart = start;
} else {
effectiveStart = start.addDays(1);
effectiveStart.setTime(QTime(7, 0, 0)); // next day
}
// #if 0
qCritical() << "";
qCritical() << "compute_duration_for_parking_ticket";
qCritical() << "===================================";
for (int i = 0; i <= 600; i += 10) {
cost = i;
if ((cs = compute_duration_for_parking_ticket(&cfg, start, cost, end, permitType))) { // return value
}
if (!cs) {
qCritical() << "ERROR CalcState" << cs.toString() << endl;
} else {
// qCritical() << cs.toString();
}
qCritical() << "start" << start.toString(Qt::ISODate) << "< cost" << cost
<< "> end" << end.toString(Qt::ISODate);
}
// #else
qCritical() << "";
qCritical() << "compute_price_for_parking_ticket";
qCritical() << "================================";
for (int netto_parking_time = 180; netto_parking_time <= (180 + 720*3); netto_parking_time += 36) {
QDateTime end;
struct price_t price;
cs = compute_price_for_parking_ticket(&cfg, start, netto_parking_time, end, &price, permitType, true);
qCritical() << "start" << start.toString(Qt::ISODate) << "end" << end.toString(Qt::ISODate)
<< "price" << price.netto;
}
// #endif
}
}
}
#endif
#if VALSER_ALM==1
std::ifstream input;
int pop_min_time;