Compare commits

...

23 Commits

Author SHA1 Message Date
96aad6b797
Merge branch 'fuchs-muehlbach' of git.mimbach49.de:GerhardHoffmann/MOBILISIS-Calculator into fuchs-muehlbach 2024-08-19 12:41:02 +02:00
648799629a GetTimeSteps():
Fix: check not only if "current" is above carryOverStart, but also
	     if "current" is below carryOverEnd.
2024-08-19 12:19:01 +02:00
84e2530767 Calculator::GetDurationFromCost():
Minor: debug output.
2024-08-19 12:18:05 +02:00
ceb78772dd Minor: debug output 2024-08-19 12:11:47 +02:00
675ba60733 tests for schnals/muehlbach 2024-08-19 12:10:43 +02:00
d86a688836 GetTimeSteps():
unifiy implementation for Fuchs/Muehlbach and Fuchs/Schnals.
2024-08-18 19:29:48 +02:00
171b23eebb added parsing for new duration fields 2024-08-18 19:27:06 +02:00
ae9a54bf02 Added:
pun_mutable:
        duration might be changed during runtime
    pun_round_to_next_24h_boundary
        duration has to be aligned with next possible 24h boundary
    pun_round_to_prev_24h_boundary
        duration has to be aligned with previous 24h boundary
    pun_align_with_timepoint
        duration has to be aligned with dedicated time point

Removed:
    pun_requires_change
        Replaced by pu_mutable
2024-08-18 19:23:12 +02:00
84e61844ab test case schnals 2024-08-18 19:22:07 +02:00
328f7cb712 test cases for fuchs-mue=hlbach 2024-08-15 21:45:53 +02:00
84dbfc7234 GetTimeSteps(): compute time steps and duration values.
For each element in the duration list (and for a given start-date-time)
check if there is a prepaid-option or an carry-over-option to compute the
correct values.
2024-08-15 21:41:09 +02:00
48cc6b1302 Minor: debug output.
duartionUnit as signed int (to see errors in case it becomes negative).
2024-08-15 21:39:22 +02:00
a6007ee89a GetTimeSteps():
Use condition pop_time_step_config == (int)ATBTimeStepConfig::TimeStepConfig::RECOMPUTE_SOME
(set in tariff-file) to decide the alogorithm to compute time-steps.
2024-08-15 21:37:23 +02:00
192a37d93f .GetTimeSteps(): pass parameters tariff, paymentOptionIndex and start_parking_time_); 2024-08-15 21:29:37 +02:00
b17f77b22a Add setting of max-price in case of degressive-tariff.
+            maxPrice = cfg->getPaymentOptions(paymentOptionIndex).pop_max_price;
2024-08-15 21:28:49 +02:00
007978a0f8 Added include/mobilisis/tariff_prepay.h.
OTHER_FILES removed.
2024-08-15 21:26:30 +02:00
80b21ac231 New internal representation for the prepaid option 2024-08-15 21:24:27 +02:00
0a32d60827 Added parsing for new duration members and new prepaid-option. 2024-08-15 21:23:17 +02:00
26a50fb972 Add enum constant RECOMPUTE_SOME=3: some duration values have to be recomputed
at runtime (to determine time steps).
2024-08-15 21:20:18 +02:00
964ee17540 add new prepaid_option_id 2024-08-15 21:19:40 +02:00
6ef57792ce Add PrepaidOptionType.
PrepaidType declared as deprecated.
2024-08-15 21:16:46 +02:00
ec9f7d9262 Introduce bew memebers to control the handling of duration objects
(especially for GetTimeSteps() computation).
2024-08-15 21:14:57 +02:00
a2c40fa32a re-introduce prepay-option for backward compatibility 2024-08-15 21:13:25 +02:00
11 changed files with 583 additions and 80 deletions

@ -28,6 +28,7 @@
#include "tariff_interpolation.h"
#include "tariff_prepaid.h"
#include "tariff_carryover.h"
#include "tariff_prepay.h"
#include "tariff_permit_type.h"
#include <QVector>
@ -47,6 +48,7 @@ public:
using ATBPaymentOptionType = std::multimap<int, ATBPaymentOption>;
using TariffInterpolationType = std::multimap<int, ATBInterpolation>;
using TariffPrepaidType = std::multimap<int, ATBPrepaid>;
using TariffPrepayOptionType = std::multimap<int, ATBPrepay>;
using TariffCarryOverType = std::multimap<int, ATBCarryOver>;
using TariffDurationType = std::multimap<int, ATBDuration>;
@ -54,7 +56,7 @@ public:
ATBCurrency Currency;
ATBDuration duration;
TariffDurationType Duration;
TariffDurationType Duration;
multimap<int, ATBPaymentMethod> PaymentMethod;
multimap<int, ATBPaymentRate> PaymentRate;
SpecialDaysWorktimeType SpecialDaysWorktime;
@ -71,6 +73,7 @@ public:
TariffProductType TariffProduct;
TariffInterpolationType TariffInterpolations;
TariffPrepaidType TariffPrepaidOptions;
TariffPrepayOptionType TariffPrepayOptions;
TariffCarryOverType TariffCarryOverOptions;
/// <summary>

@ -1,6 +1,7 @@
#include <string>
#include <QDebug>
#include <QDateTime>
class ATBDuration
{
@ -12,20 +13,35 @@ public:
, pun_duration_saved(0)
, pun_duration_min(0)
, pun_duration_max(0)
, pun_interpolation_id(-1) {
, pun_interpolation_id(-1)
, pun_netto(false)
, pun_brutto(false)
, pun_fixed(false)
, pun_mutable(false)
, pun_round_to_next_24h_boundary(false)
, pun_round_to_prev_24h_boundary(false)
, pun_align_with_timepoint(QDateTime())
, pun_next_step_correction(0) {
}
friend QDebug operator<<(QDebug debug, ATBDuration const &td) {
QDebugStateSaver saver(debug);
debug.nospace()
<< " pun_id: " << td.pun_id << "\n"
<< " pun_label: " << QString::fromStdString(td.pun_label) << "\n"
<< " pun_duration: " << td.pun_duration << "\n"
<< " pun_duration_saved: " << td.pun_duration_saved << "\n"
<< " pun_duration_min: " << td.pun_duration_min << "\n"
<< " pun_duration_max: " << td.pun_duration_max << "\n"
<< "pun_interpolation_id: " << td.pun_interpolation_id << "\n";
<< " pun_id: " << td.pun_id << "\n"
<< " pun_label: " << QString::fromStdString(td.pun_label) << "\n"
<< " pun_duration: " << td.pun_duration << "\n"
<< " pun_duration_saved: " << td.pun_duration_saved << "\n"
<< " pun_duration_min: " << td.pun_duration_min << "\n"
<< " pun_duration_max: " << td.pun_duration_max << "\n"
<< " pun_interpolation_id: " << td.pun_interpolation_id << "\n"
<< " pun_netto: " << td.pun_netto << "\n"
<< " pun_brutto: " << td.pun_brutto << "\n"
<< " pun_fixed: " << td.pun_fixed << "\n"
<< " pun_mutable: " << td.pun_mutable << "\n"
<< "pun_round_to_next_24h_boundary: " << td.pun_round_to_next_24h_boundary << "\n"
<< "pun_round_to_prev_24h_boundary: " << td.pun_round_to_prev_24h_boundary << "\n"
<< " pun_align_with_timepoint: " << td.pun_align_with_timepoint << endl;
return debug;
}
@ -33,8 +49,16 @@ public:
int pun_id;
std::string pun_label;
int pun_duration;
int pun_duration_saved;
int pun_duration_min;
int pun_duration_max;
int pun_interpolation_id;
int pun_duration_saved;
int pun_duration_min;
int pun_duration_max;
int pun_interpolation_id;
bool pun_netto; // the timestep expressed by this duration is a netto timestep
bool pun_brutto; // the timestep expressed by this duration is a brutto timestep
bool pun_fixed; // the value given in tariff-file is fixed (constant)
bool pun_mutable; // the value could change
bool pun_round_to_next_24h_boundary;
bool pun_round_to_prev_24h_boundary;
QDateTime pun_align_with_timepoint;
int pun_next_step_correction;
};

@ -13,16 +13,17 @@ enum MemberType
WeekDaysWorkTimeType = 0x06,
SpecialDaysWorktimeType = 0x07,
SpecialDaysType = 0x08,
PeriodYearType = 0x09,
DailyTicketType = 0x0A,
CustomerType = 0x0B,
TimeBaseType = 0x0C,
TimeRangeType = 0x0D,
TimeStepConfigType = 0x0E,
ProductType = 0x0F,
InterpolationType = 0x10,
PrepaidType = 0x11,
CarryOverType = 0x12
PeriodYearType = 0x09,
DailyTicketType = 0x0A,
CustomerType = 0x0B,
TimeBaseType = 0x0C,
TimeRangeType = 0x0D,
TimeStepConfigType = 0x0E,
ProductType = 0x0F,
InterpolationType = 0x10,
PrepaidType = 0x11, // deprecated
CarryOverType = 0x12,
PrepaidOptionType = 0x13,
};
#endif // MEMBER_TYPE_H_INCLUDED

@ -28,6 +28,7 @@ public:
pop_carry_over = -1;
pop_carry_over_option_id = -1;
pop_prepaid_option_id = -1;
pop_prepay_option_id = -1;
pop_truncate_last_interpolation_step = false;
pop_accumulate_prices = false;
pop_accumulate_durations = false;
@ -61,7 +62,8 @@ public:
int pop_carry_over;
int pop_carry_over_option_id;
bool pop_truncate_last_interpolation_step;
int pop_prepaid_option_id;
int pop_prepaid_option_id; // deprecated
int pop_prepay_option_id;
bool pop_carry_over_target;
int pop_carry_over_time_range_id;
int pop_carry_over_start_time_range;

@ -0,0 +1,68 @@
#ifndef TARIFF_PREPAY_H_INCLUDED
#define TARIFF_PREPAY_H_INCLUDED
#include <QTime>
struct ATBPrepay {
struct week {
int day;
bool prepaid; // yes/no
QTime start; // only valid if prepaid == true
QTime end;
int duration;
} prepay[8];
int id;
friend QDebug operator<<(QDebug debug, ATBPrepay const &pp) {
QDebugStateSaver saver(debug);
debug.nospace()
<< " id:" << pp.id << "\n"
<< " **** Monday **** \n"
<< " day: " << pp.prepay[(int)Qt::Monday].day << "\n"
<< " start: " << pp.prepay[(int)Qt::Monday].start.toString(Qt::ISODate) << "\n"
<< " end: " << pp.prepay[(int)Qt::Monday].end.toString(Qt::ISODate) << "\n"
<< " duration: " << pp.prepay[(int)Qt::Monday].duration << "\n"
<< " prepaid: " << pp.prepay[(int)Qt::Monday].prepaid << "\n"
<< " **** Tuesday **** \n"
<< " day: " << pp.prepay[(int)Qt::Tuesday].day << "\n"
<< " start: " << pp.prepay[(int)Qt::Tuesday].start.toString(Qt::ISODate) << "\n"
<< " end: " << pp.prepay[(int)Qt::Tuesday].end.toString(Qt::ISODate) << "\n"
<< " duration: " << pp.prepay[(int)Qt::Monday].duration << "\n"
<< " prepaid: " << pp.prepay[(int)Qt::Tuesday].prepaid << "\n"
<< " **** Wednesday **** \n"
<< " day: " << pp.prepay[(int)Qt::Wednesday].day << "\n"
<< " start: " << pp.prepay[(int)Qt::Wednesday].start.toString(Qt::ISODate) << "\n"
<< " end: " << pp.prepay[(int)Qt::Wednesday].end.toString(Qt::ISODate) << "\n"
<< " duration: " << pp.prepay[(int)Qt::Monday].duration << "\n"
<< " prepaid: " << pp.prepay[(int)Qt::Wednesday].prepaid << "\n"
<< " **** Thursday **** \n"
<< " day: " << pp.prepay[(int)Qt::Thursday].day << "\n"
<< " start: " << pp.prepay[(int)Qt::Thursday].start.toString(Qt::ISODate) << "\n"
<< " end: " << pp.prepay[(int)Qt::Thursday].end.toString(Qt::ISODate) << "\n"
<< " duration: " << pp.prepay[(int)Qt::Monday].duration << "\n"
<< " prepaid: " << pp.prepay[(int)Qt::Thursday].prepaid << "\n"
<< " **** Friday **** \n"
<< " day: " << pp.prepay[(int)Qt::Friday].day << "\n"
<< " start: " << pp.prepay[(int)Qt::Friday].start.toString(Qt::ISODate) << "\n"
<< " end: " << pp.prepay[(int)Qt::Friday].end.toString(Qt::ISODate) << "\n"
<< " prepaid: " << pp.prepay[(int)Qt::Friday].prepaid << "\n"
<< " **** Saturday **** \n"
<< " day: " << pp.prepay[(int)Qt::Saturday].day << "\n"
<< " start: " << pp.prepay[(int)Qt::Saturday].start.toString(Qt::ISODate) << "\n"
<< " end: " << pp.prepay[(int)Qt::Saturday].end.toString(Qt::ISODate) << "\n"
<< " duration: " << pp.prepay[(int)Qt::Monday].duration << "\n"
<< " prepaid: " << pp.prepay[(int)Qt::Saturday].prepaid << "\n"
<< " **** Sunday **** \n"
<< " day: " << pp.prepay[(int)Qt::Sunday].day << "\n"
<< " start: " << pp.prepay[(int)Qt::Sunday].start.toString(Qt::ISODate) << "\n"
<< " end: " << pp.prepay[(int)Qt::Sunday].end.toString(Qt::ISODate) << "\n"
<< " duration: " << pp.prepay[(int)Qt::Monday].duration << "\n"
<< " prepaid: " << pp.prepay[(int)Qt::Sunday].prepaid << "\n";
return debug;
}
};
#endif // TARIFF_CARRYOVER_H_INCLUDED

@ -6,7 +6,7 @@
#include <QDebugStateSaver>
struct ATBTimeStepConfig {
enum class TimeStepConfig {STATIC=1, DYNAMIC=2};
enum class TimeStepConfig {STATIC=1, DYNAMIC=2, RECOMPUTE_SOME=3};
ATBTimeStepConfig() = default;
int tsconfig_id;

@ -38,24 +38,24 @@ SOURCES += \
src/tariff_global_defines.cpp
HEADERS += \
include/mobilisis/calculator_functions.h \
include/mobilisis/duration.h \
include/mobilisis/payment_opt.h \
include/mobilisis/spec_days.h \
include/mobilisis/utilities.h \
include/mobilisis/configuration.h \
include/mobilisis/member_type.h \
include/mobilisis/payment_option.h \
include/mobilisis/spec_days_worktime.h \
include/mobilisis/weekdays.h \
include/mobilisis/currency.h \
include/mobilisis/payment_method.h \
include/mobilisis/payment_rate.h \
include/mobilisis/time_range.h \
include/mobilisis/weekdays_worktime.h \
include/mobilisis/day_of_week.h \
include/mobilisis/payment_mtd.h \
include/mobilisis/period_year.h \
include/mobilisis/calculator_functions.h \
include/mobilisis/duration.h \
include/mobilisis/payment_opt.h \
include/mobilisis/spec_days.h \
include/mobilisis/utilities.h \
include/mobilisis/configuration.h \
include/mobilisis/member_type.h \
include/mobilisis/payment_option.h \
include/mobilisis/spec_days_worktime.h \
include/mobilisis/weekdays.h \
include/mobilisis/currency.h \
include/mobilisis/payment_method.h \
include/mobilisis/payment_rate.h \
include/mobilisis/time_range.h \
include/mobilisis/weekdays_worktime.h \
include/mobilisis/day_of_week.h \
include/mobilisis/payment_mtd.h \
include/mobilisis/period_year.h \
include/mobilisis/time_range_header.h \
include/mobilisis/tariff_cfg.h \
include/mobilisis/tariff_calc.h \
@ -89,12 +89,14 @@ HEADERS += \
include/mobilisis/tariff_interpolation.h \
include/mobilisis/tariff_prepaid.h \
include/mobilisis/tariff_carryover.h \
include/mobilisis/tariff_prepay.h \
include/mobilisis/tariff_global_defines.h
OTHER_FILES += src/main.cpp \
../tariffs/tariff_korneuburg.json \
../tariffs/tariff_linsinger_maschinenbau.json \
../tariffs/tariff_naz.json
# OTHER_FILES += src/main.cpp \
# ../tariffs/tariff_korneuburg.json \
# ../tariffs/tariff_linsinger_maschinenbau.json \
# ../tariffs/tariff_naz.json \
# /home/linux/customer_502/etc/psa_tariff/tariff03.json
# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin

@ -327,6 +327,8 @@ int CALCULATE_LIBRARY_API get_maximal_parkingprice(Configuration *cfg,
case PERMIT_TYPE::SHORT_TERM_PARKING: { // e.g. szeged (customer_281)
if (paymentMethodId == PaymentMethod::Progressive || paymentMethodId == PaymentMethod::Steps) {
maxPrice = Utilities::getMaximalParkingPrice(cfg, paymentMethodId);
} else if (paymentMethodId == PaymentMethod::Degressive) {
maxPrice = cfg->getPaymentOptions(paymentOptionIndex).pop_max_price;
} 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
@ -768,7 +770,7 @@ CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket(
return calcState;
}
QList<int> tlist = Calculator::GetInstance().GetTimeSteps(tariff);
QList<int> tlist = Calculator::GetInstance().GetTimeSteps(tariff, paymentOptionIndex, start_parking_time_);
Q_UNUSED(tlist);
// compute cost (price)
@ -921,12 +923,15 @@ 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 (DBG_LEVEL >= DBG_DEBUG) {
qCritical() << "\ncompute_duration_for_parking_ticket(2):";
qCritical() << " start time:" << start_parking_time.toString(Qt::ISODate);
qCritical() << " payment option index:" << paymentOptionIndex;
qCritical() << " prepaid:" << prepaid;
qCritical() << " price:" << price;
qCritical() << " permit type:" << permitType.toString() << endl;
// }
if (start_parking_time.isValid()) {
QString cs = start_parking_time.toString(Qt::ISODate);
@ -1007,9 +1012,10 @@ CalcState CALCULATE_LIBRARY_API compute_duration_for_parking_ticket(
}
// DEBUG
qCritical() << "compute_duration_for_parking_ticket(): ";
qCritical() << " endTime: " << endTime;
qCritical() << " ticketEndTime: " << ticketEndTime;
qCritical() << "\ncompute_duration_for_parking_ticket():";
qCritical() << " start time:" << start_parking_time.toString(Qt::ISODate);
qCritical() << " endTime:" << endTime;
qCritical() << " ticketEndTime:" << ticketEndTime.toString(Qt::ISODate) << endl;
}
} else {
return calcState.set(CalcState::State::INVALID_START_DATE);

@ -10,9 +10,12 @@
#include <sstream>
#include <algorithm>
#include <optional>
#include <iterator>
#include <QDateTime>
#include <QScopedArrayPointer>
#include <QDebug>
#include <QTimeZone>
double total_duration_min = 0.0f;
double total_cost = 0.0f;
@ -159,7 +162,8 @@ std::string Calculator::GetDurationFromCost(Configuration* cfg,
return CalcState::BELOW_MIN_PARKING_PRICE.toStdString();
}
if (prepaid == false) {
int const pop_time_step_config = cfg->getPaymentOptions(paymentOptionIndex).pop_time_step_config;
if (pop_time_step_config == (int)ATBTimeStepConfig::TimeStepConfig::RECOMPUTE_SOME || prepaid == false) {
int const pop_id = cfg->getPaymentOptions(paymentOptionIndex).pop_id;
int const pop_accumulate_prices = cfg->getPaymentOptions(paymentOptionIndex).pop_accumulate_prices;
int const pop_accumulate_durations = cfg->getPaymentOptions(paymentOptionIndex).pop_accumulate_durations;
@ -174,6 +178,9 @@ std::string Calculator::GetDurationFromCost(Configuration* cfg,
for (auto[itr, rangeEnd] = cfg->PaymentRate.equal_range(pop_id); itr != rangeEnd; ++itr) {
int const pra_price = itr->second.pra_price;
// qCritical() << DBG_HEADER << "pra_price" << pra_price;
int const durationId = itr->second.pra_payment_unit_id;
if (pop_accumulate_prices) {
price += pra_price;
@ -191,7 +198,9 @@ std::string Calculator::GetDurationFromCost(Configuration* cfg,
ATBDuration duration = search->second;
if (pop_accumulate_prices) {
uint32_t const durationUnit = cfg->Duration.find(durationId)->second.pun_duration;
int32_t const durationUnit = cfg->Duration.find(durationId)->second.pun_duration;
// qCritical() << DBG_HEADER << " duration unit" << durationUnit;
new_price += pra_price;
// qCritical() << "(" << __func__ << ":" << __LINE__ << ") old price" << price << ", new_price:" << new_price;
@ -2770,6 +2779,243 @@ QList<int> &Calculator::GetTimeSteps(Configuration *cfg, int paymentOptionIndex,
qCritical() << "(" << __func__ << ":" << __LINE__ << ") TODO";
}
}
} else
if (pop_time_step_config == (int)ATBTimeStepConfig::TimeStepConfig::RECOMPUTE_SOME) {
// some durations / timesteps have to be recomputed
qCritical() << "(" << __func__ << ":" << __LINE__ << ") payment option time step config:" << "TimeStepConfig::RECOMPUTE_SOME";
int size = m_timeSteps.size();
while (size <= paymentOptionIndex) {
m_timeSteps.push_back(QList<int>());
size = m_timeSteps.size();
}
int const pop_accumulate_durations = cfg->getPaymentOptions(paymentOptionIndex).pop_accumulate_durations;
m_timeSteps[paymentOptionIndex].clear();
QDateTime const start(s.date(),
QTime(s.time().hour(), s.time().minute(), 0),
s.timeZone());
if (DBG_LEVEL >= DBG_DEBUG) {
qCritical() << "(" << __func__ << ":" << __LINE__ << ") start:" << start.toString(Qt::ISODate);
}
QDateTime current(start);
bool casePrepay = false;
int const weekDay = start.date().dayOfWeek();
int const pop_prepay_option_id = cfg->getPaymentOptions(paymentOptionIndex).pop_prepay_option_id;
// compute prepay settings
// assumption: prepay settings the same for all days
QDateTime prepayStart(start);
QDateTime prepayEnd(start);
prepayStart.setTime(cfg->TariffPrepayOptions.find(pop_prepay_option_id)->second.prepay[weekDay].start);
prepayEnd.setTime(cfg->TariffPrepayOptions.find(pop_prepay_option_id)->second.prepay[weekDay].end);
if (start <= prepayEnd) {
prepayStart = prepayStart.addDays(-1);
} else {
prepayEnd = prepayEnd.addDays(1);
}
if (DBG_LEVEL >= DBG_DEBUG) {
qCritical() << "(" << __func__ << ":" << __LINE__ << ") prepay start" << prepayStart.toString(Qt::ISODate);
qCritical() << "(" << __func__ << ":" << __LINE__ << ") prepay end" << prepayEnd.toString(Qt::ISODate);
}
int const prepayDurationInMinutes = start.secsTo(prepayEnd) / 60;
// compute carryover settings
// assumption: carryover settings the same for all days
int const pop_carry_over_option_id = cfg->getPaymentOptions(paymentOptionIndex).pop_carry_over_option_id;
QDateTime carryOverStart(start);
QDateTime carryOverEnd(start);
carryOverStart.setTime(cfg->TariffCarryOverOptions.find(pop_carry_over_option_id)->second.carryover[weekDay].static_start);
carryOverEnd.setTime(cfg->TariffCarryOverOptions.find(pop_carry_over_option_id)->second.carryover[weekDay].static_end);
if (start <= carryOverEnd) {
carryOverStart = carryOverStart.addDays(-1);
} else {
carryOverEnd = carryOverEnd.addDays(1);
}
if (DBG_LEVEL >= DBG_DEBUG) {
qCritical() << "(" << __func__ << ":" << __LINE__ << ") carry over start" << carryOverStart.toString(Qt::ISODate);
qCritical() << "(" << __func__ << ":" << __LINE__ << ") carry over end" << carryOverEnd.toString(Qt::ISODate);
}
// int cnt = 0;
for (Configuration::TariffDurationType::iterator it = cfg->Duration.begin();
it != cfg->Duration.end();
++it) {
it->second.pun_duration = it->second.pun_duration_saved;
// if (++cnt > 2) continue;
if (DBG_LEVEL >= DBG_DEBUG) {
qCritical() << "(" << __func__ << ":" << __LINE__ << ") pun_id" << it->second.pun_id;
}
if (it->second.pun_mutable) {
if (it->second.pun_netto) {
if (it->second.pun_round_to_next_24h_boundary == false) {
//int weekDay = start.date().dayOfWeek();
if (m_timeSteps[paymentOptionIndex].isEmpty()) {
// handle possible prepay-condition, which applies only
// for the very first step
if (DBG_LEVEL >= DBG_DEBUG) {
qCritical() << "(" << __func__ << ":" << __LINE__ << ") prepay start" << prepayStart.toString(Qt::ISODate);
qCritical() << "(" << __func__ << ":" << __LINE__ << ") prepay end" << prepayEnd.toString(Qt::ISODate);
}
if (prepayStart <= start && start <= prepayEnd) {
it->second.pun_duration = prepayDurationInMinutes;
it->second.pun_duration += it->second.pun_duration_saved ;
casePrepay = true;
}
if (DBG_LEVEL >= DBG_DEBUG) {
qCritical() << "(" << __func__ << ":" << __LINE__ << ")" << it->second.pun_duration;
qCritical() << "(" << __func__ << ":" << __LINE__ << ") prepay" << casePrepay;
}
}
if (!casePrepay) {
// handle possible carryover-condition
int const durationInSecs = it->second.pun_duration_saved * 60;
it->second.pun_duration = it->second.pun_duration_saved;
if (current >= carryOverStart && current < carryOverEnd) {
it->second.pun_duration += current.secsTo(carryOverEnd) / 60;
} else {
// start < carryOverStart
QDateTime const &newCurrent = current.addSecs(durationInSecs);
if (newCurrent > carryOverStart && newCurrent <= carryOverEnd) {
// cross carry over section
it->second.pun_next_step_correction = carryOverStart.secsTo(carryOverEnd) / 60;
it->second.pun_duration += it->second.pun_next_step_correction;
}
}
} else {
// qCritical() << "(" << __func__ << ":" << __LINE__ << ")";
}
if (pop_accumulate_durations) {
m_timeSteps[paymentOptionIndex] << it->second.pun_duration;
} else {
if (!m_timeSteps[paymentOptionIndex].isEmpty()) {
int d = m_timeSteps[paymentOptionIndex].last();
m_timeSteps[paymentOptionIndex] << (d + it->second.pun_duration);
}
}
current = current.addSecs(m_timeSteps[paymentOptionIndex].last() * 60);
if (DBG_LEVEL >= DBG_DEBUG) {
qCritical() << "(" << __func__ << ":" << __LINE__ << ")" << m_timeSteps[paymentOptionIndex];
qCritical() << "(" << __func__ << ":" << __LINE__ << ") current" << current.toString(Qt::ISODate);
}
} else { // if (it->pun_round_to_next_24h_boundary == false) {
if (DBG_LEVEL >= DBG_DEBUG) {
qCritical() << "(" << __func__ << ":" << __LINE__ << ") round-to-next-24h-boundary";
qCritical() << "(" << __func__ << ":" << __LINE__ << ") prepay" << casePrepay;
qCritical() << "(" << __func__ << ":" << __LINE__ << ") current" << current.toString(Qt::ISODate);
}
if (casePrepay) {
// the last time step contains the (dynamic) prepay duration
// so it is possible to compute the last duration
int lastDuration = m_timeSteps[paymentOptionIndex].last() - prepayDurationInMinutes;
// qCritical() << "(" << __func__ << ":" << __LINE__ << ") last duration " << lastDuration;
int const minutesToAdd = 1440 - lastDuration;
current = current.addSecs(minutesToAdd * 60);
if (DBG_LEVEL >= DBG_DEBUG) {
qCritical() << "(" << __func__ << ":" << __LINE__ << ") minutes to add " << minutesToAdd;
qCritical() << "(" << __func__ << ":" << __LINE__ << ") current" << current.toString(Qt::ISODate);
}
if (pop_accumulate_durations) {
m_timeSteps[paymentOptionIndex] << minutesToAdd;
} else {
if (!m_timeSteps[paymentOptionIndex].isEmpty()) {
int d = m_timeSteps[paymentOptionIndex].last();
m_timeSteps[paymentOptionIndex] << (d + minutesToAdd);
}
}
// qCritical() << "(" << __func__ << ":" << __LINE__ << ")" << m_timeSteps[paymentOptionIndex];
casePrepay = false;
} else {
if (DBG_LEVEL >= DBG_DEBUG) {
qCritical() << "(" << __func__ << ":" << __LINE__ << ") pun_id" << it->second.pun_id;
qCritical() << "(" << __func__ << ":" << __LINE__ << ") current" << current.toString(Qt::ISODate);
qCritical() << "(" << __func__ << ":" << __LINE__ << ") pun_duration" << it->second.pun_duration;
}
int secs = s.secsTo(current);
int const dayInSecs = 1440 * 60;
int const rest = secs % dayInSecs;
int const minutesToAdd = (dayInSecs - rest) / 60;
current = current.addSecs(minutesToAdd * 60);
it->second.pun_duration = minutesToAdd;
if (DBG_LEVEL >= DBG_DEBUG) {
qCritical() << "(" << __func__ << ":" << __LINE__ << ") minutes to add " << minutesToAdd;
qCritical() << "(" << __func__ << ":" << __LINE__ << ") current" << current.toString(Qt::ISODate);
}
if (pop_accumulate_durations) {
m_timeSteps[paymentOptionIndex] << minutesToAdd;
} else {
if (!m_timeSteps[paymentOptionIndex].isEmpty()) {
int d = m_timeSteps[paymentOptionIndex].last();
m_timeSteps[paymentOptionIndex] << (d + minutesToAdd);
}
}
// qCritical() << "(" << __func__ << ":" << __LINE__ << ")" << m_timeSteps[paymentOptionIndex];
}
}
} else { // if (it->second.pun_netto) {
qCritical() << "(" << __func__ << ":" << __LINE__ << ") TODO";
qCritical() << "(" << __func__ << ":" << __LINE__ << ")\n" << it->second;
}
} else { // mutable == false
if (it->second.pun_brutto) { // no handling for prepay and carry-over
if (pop_accumulate_durations) {
m_timeSteps[paymentOptionIndex] << it->second.pun_duration;
} else {
if (!m_timeSteps[paymentOptionIndex].isEmpty()) {
int d = m_timeSteps[paymentOptionIndex].last();
m_timeSteps[paymentOptionIndex] << (d + it->second.pun_duration);
}
}
// qCritical() << "(" << __func__ << ":" << __LINE__ << ")" << m_timeSteps[paymentOptionIndex];
} else {
qCritical() << "(" << __func__ << ":" << __LINE__ << ") TODO";
qCritical() << "(" << __func__ << ":" << __LINE__ << ")\n" << it->second;
}
}
}
} else {
qCritical() << "(" << __func__ << ":" << __LINE__ << ") payment option time step config:" << "TimeStepConfig::STATIC";
@ -2788,13 +3034,12 @@ QList<int> &Calculator::GetTimeSteps(Configuration *cfg, int paymentOptionIndex,
}
}
qCritical() << "(" << __func__ << ":" << __LINE__ << ") NEW timeSteps:" << m_timeSteps;
//qCritical() << "(" << __func__ << ":" << __LINE__ << ") NEW timeSteps:" << m_timeSteps;
if (DBG_LEVEL >= DBG_DEBUG) {
qCritical() << "(" << __func__ << ":" << __LINE__ << ") NEW timeSteps:" << m_timeSteps;
QDateTime nextTime(s);
qCritical() << "(" << __func__ << ":" << __LINE__ << ") start" << nextTime.toString(Qt::ISODate);
for (int i = 0; i < m_timeSteps[paymentOptionIndex].size(); ++i) {
QDateTime nextTime = s;
// nextTime.setTime(QTime(0, 0, 0));
int const secs = m_timeSteps[paymentOptionIndex][i] * 60;
nextTime = nextTime.addSecs(secs);
@ -2821,7 +3066,7 @@ uint32_t Calculator::GetPriceForTimeStep(Configuration *cfg, int timeStep, int p
uint32_t price = 0;
int pun_duration = 0;
qCritical() << "(" << __func__ << ":" << __LINE__ << ") paymentOptionIndex" << paymentOptionIndex;
//qCritical() << "(" << __func__ << ":" << __LINE__ << ") paymentOptionIndex" << paymentOptionIndex;
//qCritical() << "(" << __func__ << ":" << __LINE__ << ") timeStep" << timeStep;
//qCritical() << "(" << __func__ << ":" << __LINE__ << ") pop_id" << pop_id;

@ -7,6 +7,7 @@
#include "tariff_business_hours.h"
#include "tariff_global_defines.h"
#include "tariff_carryover.h"
#include "tariff_prepay.h"
#include "tariff_global_defines.h"
#include <QString>
@ -35,6 +36,7 @@ MemberType Configuration::IdentifyJsonMember(const char* member_name)
if (strcmp(member_name, "Interpolation") == 0) return MemberType::InterpolationType;
if (strcmp(member_name, "Prepaid") == 0) return MemberType::PrepaidType;
if (strcmp(member_name, "CarryOver") == 0) return MemberType::CarryOverType;
if (strcmp(member_name, "PrepaidOption") == 0) return MemberType::PrepaidOptionType;
else return MemberType::UnknownType;
}
@ -108,6 +110,7 @@ bool Configuration::ParseJson(Configuration* cfg, const char* json)
ATBInterpolation TariffInterpolation;
ATBPrepaid TariffPrepaidOption;
ATBCarryOver TariffCarryOver;
ATBPrepay TariffPrepayOption;
MemberType mb_type = MemberType::UnknownType;
this->currentPaymentOptions.clear();
@ -141,7 +144,7 @@ bool Configuration::ParseJson(Configuration* cfg, const char* json)
continue;
}
qCritical() << " -" << mb_name;
// qCritical() << " -" << mb_name;
// Get array for each JSON object member
auto mb_array = document[mb_name].GetArray();
@ -171,6 +174,61 @@ bool Configuration::ParseJson(Configuration* cfg, const char* json)
{
case MemberType::UnknownType:
break;
case MemberType::PrepaidOptionType: {
if (QString(inner_obj_name) == QString("prepaid_option_id")) {
if (k->value.IsInt()) {
int const &x = k->value.GetInt();
TariffPrepayOption.id = x;
}
} else
if (QString(inner_obj_name) == QString("prepaid_option_week")) {
if (k->value.IsArray()) {
auto days = k->value.GetArray();
for (rapidjson::SizeType j=0; j < days.Size(); ++j) {
if (days[j].IsObject()) {
auto weekday = days[j].GetObject();
for (auto w = weekday.MemberBegin(); w != weekday.MemberEnd(); ++w) {
int day = j+1; // 8 entries
QString member(QString::fromStdString(w->name.GetString()));
if (member == "prepaid_option_day") {
if (w->value.IsInt()) {
rapidjson::SizeType const d = w->value.GetInt();
if (d != (j+1)) {
qCritical() << "ERROR: misconfigured jsonfile" << d << "!=" << (j+1);
}
TariffPrepayOption.prepay[day].day = day;
}
} else
if (member == "prepaid_option_duration") {
if (w->value.IsInt()) {
TariffPrepayOption.prepay[day].duration = w->value.GetInt();
}
} else
if (member == "prepaid_option_prepaid") {
if (w->value.IsBool()) {
bool b = w->value.GetBool();
TariffPrepayOption.prepay[day].prepaid = b;
}
} else
if (member == "prepaid_option_start") {
if (w->value.IsString()) {
QTime const &t = QTime::fromString(w->value.GetString(), Qt::ISODate);
TariffPrepayOption.prepay[day].start = t;
}
} else
if (member == "prepaid_option_end") {
if (w->value.IsString()) {
QTime const &t = QTime::fromString(w->value.GetString(), Qt::ISODate);
TariffPrepayOption.prepay[day].end = t;
}
}
}
}
}
}
}
} break;
case MemberType::CarryOverType: {
if (QString(inner_obj_name) == QString("carry_over_id")) {
if (k->value.IsInt()) {
@ -231,6 +289,7 @@ bool Configuration::ParseJson(Configuration* cfg, const char* json)
}
}
} break;
// deprecated
case MemberType::PrepaidType: {
if (QString(inner_obj_name) == QString("prepaid_id")) {
if (k->value.IsInt()) {
@ -622,8 +681,10 @@ bool Configuration::ParseJson(Configuration* cfg, const char* json)
this->currentPaymentOptions.last().pop_max_time = k->value.GetDouble();
} else if (strcmp(inner_obj_name, "pop_min_price") == 0) {
this->currentPaymentOptions.last().pop_min_price = k->value.GetDouble();
} else if (strcmp(inner_obj_name, "pop_prepaid_option_id") == 0) {
} else if (strcmp(inner_obj_name, "pop_prepaid_option_id") == 0) { // deprecated
this->currentPaymentOptions.last().pop_prepaid_option_id = k->value.GetInt();
} else if (strcmp(inner_obj_name, "pop_prepay_option_id") == 0) {
this->currentPaymentOptions.last().pop_prepay_option_id = k->value.GetInt();
} else if (strcmp(inner_obj_name, "pop_truncate_last_interpolation_step") == 0) {
this->currentPaymentOptions.last().pop_truncate_last_interpolation_step = k->value.GetBool();
} else if (strcmp(inner_obj_name, "pop_accumulate_prices") == 0) {
@ -721,6 +782,42 @@ bool Configuration::ParseJson(Configuration* cfg, const char* json)
} else if (strcmp(inner_obj_name, "pun_duration_min") == 0) Duration.pun_duration_min = k->value.GetInt();
else if (strcmp(inner_obj_name, "pun_duration_max") == 0) Duration.pun_duration_max = k->value.GetInt();
else if (strcmp(inner_obj_name, "pun_interpolation_id") == 0) Duration.pun_interpolation_id = k->value.GetInt();
else if (strcmp(inner_obj_name, "pun_netto") == 0) {
if (k->value.IsBool()) {
Duration.pun_netto = k->value.GetBool();
}
}
else if (strcmp(inner_obj_name, "pun_brutto") == 0) {
if (k->value.IsBool()) {
Duration.pun_brutto = k->value.GetBool();
}
}
else if (strcmp(inner_obj_name, "pun_fixed") == 0) {
if (k->value.IsBool()) {
Duration.pun_fixed = k->value.GetBool();
}
}
else if (strcmp(inner_obj_name, "pun_mutable") == 0) {
if (k->value.IsBool()) {
Duration.pun_mutable = k->value.GetBool();
}
}
else if (strcmp(inner_obj_name, "pun_round_to_next_24h_boundary") == 0) {
if (k->value.IsBool()) {
Duration.pun_round_to_next_24h_boundary = k->value.GetBool();
}
}
else if (strcmp(inner_obj_name, "pun_round_to_prev_24h_boundary") == 0) {
if (k->value.IsBool()) {
Duration.pun_round_to_prev_24h_boundary = k->value.GetBool();
}
}
else if (strcmp(inner_obj_name, "pun_align_with_timepoint") == 0) {
if (k->value.IsString()) {
QDateTime const &dt = QDateTime::fromString(k->value.GetString(), Qt::ISODate);
Duration.pun_align_with_timepoint = dt;
}
}
break;
case MemberType::SpecialDaysWorktimeType:
if (strcmp(inner_obj_name, "pedwt_id") == 0) SpecialDaysWorktime.pedwt_id = k->value.GetInt();
@ -785,7 +882,7 @@ bool Configuration::ParseJson(Configuration* cfg, const char* json)
} break;
case MemberType::DurationType:
cfg->Duration.insert(pair<int, ATBDuration>(Duration.pun_id, Duration));
// qCritical() << Duration;
//qCritical() << Duration;
break;
case MemberType::SpecialDaysWorktimeType:
cfg->SpecialDaysWorktime.insert(pair<int, ATBSpecialDaysWorktime>(SpecialDaysWorktime.pedwt_period_exc_day_id, SpecialDaysWorktime));
@ -839,6 +936,10 @@ bool Configuration::ParseJson(Configuration* cfg, const char* json)
cfg->TariffCarryOverOptions.insert(pair<int, ATBCarryOver>(TariffCarryOver.id, TariffCarryOver));
// qCritical() << TariffCarryOver;
break;
case MemberType::PrepaidOptionType:
cfg->TariffPrepayOptions.insert(pair<int, ATBPrepay>(TariffPrepayOption.id, TariffPrepayOption));
//qCritical() << TariffPrepayOption;
break;
default:
break;
}

@ -741,7 +741,14 @@ int main() {
input.open("/opt/ptu5/opt/customer_502/etc/psa_tariff/tariff02.json");
}
if (zone == 3) {
input.open("/opt/ptu5/opt/customer_502/etc/psa_tariff/tariff03.json");
//input.open("/opt/ptu5/opt/customer_502/etc/psa_tariff/tariff03.json");
//input.open("/home/linux/customer_502/etc/psa_tariff/tariff01.json");
// schnals
// input.open("/opt/ptu5/opt/customer_505/etc/psa_tariff/tariff01.json");
// muehlbach
input.open("/opt/ptu5/opt/customer_504/etc/psa_tariff/tariff01.json");
}
std::stringstream sstr;
@ -900,7 +907,7 @@ int main() {
int Down = 0;
int Up = 1;
QDateTime const start = QDateTime::currentDateTime();
QDateTime start = QDateTime::currentDateTime();
int paymentOptionIndex = cfg.getPaymentOptionIndex(PERMIT_TYPE::SHORT_TERM_PARKING_PKW);
if (paymentOptionIndex != 0) {
@ -913,17 +920,61 @@ int main() {
//QSet<uint32_t> const prices2{500, 1600, 2400, 3200, 4000, 4800, 5600};
QDateTime end;
CalcState calcState;
QDateTime s(QDateTime::currentDateTime());
s.setTime(QTime(12, 0, 0));
int minimal_parking_price = get_minimal_parkingprice(&cfg,
PermitType(PERMIT_TYPE::SHORT_TERM_PARKING_PKW),
paymentOptionIndex, s);
s.setTime(QTime(10, 0, 0));
#if 0
pop_min_time = get_minimal_parkingtime(&cfg, PermitType(PERMIT_TYPE::SHORT_TERM_PARKING), paymentOptionIndex);
pop_max_time = get_maximal_parkingtime(&cfg, PermitType(PERMIT_TYPE::SHORT_TERM_PARKING), paymentOptionIndex);
pop_min_price = get_minimal_parkingprice(&cfg, PermitType(PERMIT_TYPE::SHORT_TERM_PARKING), paymentOptionIndex, s);
pop_max_price = get_maximal_parkingprice(&cfg, PermitType(PERMIT_TYPE::SHORT_TERM_PARKING), paymentOptionIndex);
pop_daily_card_price = cfg.getPaymentOptions(paymentOptionIndex).pop_daily_card_price;
int h = pop_min_time / 60;
int m = pop_min_time % 60;
qCritical().noquote() << QString(" pop_min_time %1 (%2h, %3m)").arg(pop_min_time).arg(h).arg(m);
h = pop_max_time / 60;
m = pop_max_time % 60;
qCritical().noquote()
<< QString(" pop_max_time %1 (%2h, %3m)").arg(pop_max_time).arg(h).arg(m);
qCritical() << " pop_min_price " << pop_min_price;
qCritical() << " pop_max_price " << pop_max_price;
qCritical() << "pop_daily_card_price " << pop_daily_card_price;
#endif
CalcState calcState;
#if 1
qCritical() << "start" << s.toString(Qt::ISODate);
//for (int i = 1; i < 11; ++i) {
for (int i = 0; i < 21; ++i) {
calcState = compute_duration_for_parking_ticket(&cfg, s,
(double)i*10,
end, PermitType(PERMIT_TYPE::SHORT_TERM_PARKING_PKW));
qCritical() << "RUN" << i << ": start" << s.toString(Qt::ISODate)
<< ": price" << i*10 << "->" << end.toString(Qt::ISODate) << calcState.toString();
}
#else
struct price_t price;
int netto_parking_time = 1440;
start = s;
qCritical() << "RUN" << 0 << ": start" << s.toString(Qt::ISODate);
calcState = compute_price_for_parking_ticket(&cfg, start, netto_parking_time,
end, &price,
PermitType(PERMIT_TYPE::SHORT_TERM_PARKING));
qCritical() << "RUN" << 0 << ": start" << start.toString(Qt::ISODate)
<< ": price for netto-time" << netto_parking_time
<< "->" << price.netto << "->" << end.toString(Qt::ISODate) << calcState.toString();
#endif
#if 0
qCritical() << "minimal parking price" << minimal_parking_price;
for (int i = 0; i < 8; ++i) {
calcState = compute_duration_for_parking_ticket(&cfg, s,
@ -932,11 +983,11 @@ int main() {
qCritical() << "RUN" << i << end.toString(Qt::ISODate) << calcState.toString();
}
#else
s.setTime(QTime(15, 0, 0));
// #else
s.setTime(QTime(12, 0, 0));
minimal_parking_price = get_minimal_parkingprice(&cfg,
PermitType(PERMIT_TYPE::SHORT_TERM_PARKING_PKW),
PermitType(PERMIT_TYPE::SHORT_TERM_PARKING_BUS),
paymentOptionIndex, s);
qCritical() << "minimal parking price" << minimal_parking_price;
@ -944,7 +995,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_BUS));
qCritical() << "RUN" << i << end.toString(Qt::ISODate) << calcState.toString();
}
#endif