Merge remote-tracking branch 'origin/schoenau_23112023'

This commit is contained in:
Siegfried Siegert 2023-11-23 09:46:42 +01:00
commit 453ca266a5
Signed by: SiegfriedSiegert
GPG Key ID: 68371E015E8F0B03
2 changed files with 52 additions and 25 deletions

View File

@ -32,18 +32,20 @@ public:
// Daily ticket
QDateTime GetDailyTicketDuration(Configuration* cfg, const QDateTime start_datetime, uint8_t payment_option, bool carry_over);
//
// helper function to find time steps for a tariff with PaymentMethod::Steps
// (e.g. Schoenau/Koenigsee)
//
QList<int> GetTimeSteps(Configuration *cfg) const;
private:
// Introduced for PaymentMethod::Steps (e.g. Schoenau)
// For tariff of following structure: only steps, no special days, nonstop.
uint32_t GetCostFromDuration(Configuration const* cfg, QDateTime const &start, quint64 durationMinutes, uint8_t paymentMethod = PaymentMethod::Steps);
uint32_t GetCostFromDuration(Configuration const* cfg, QDateTime const &start, QDateTime const &end, uint8_t paymentMethod = PaymentMethod::Steps);
uint32_t GetCostFromDuration(Configuration *cfg, QDateTime const &start, quint64 durationMinutes) const;
uint32_t GetCostFromDuration(Configuration *cfg, QDateTime const &start, QDateTime const &end) const;
//
// helper functions for PaymentMethod::Steps
//
QList<int> GetTimeSteps(Configuration const *cfg, int paymentMethod);
//
uint32_t GetPriceForTimeStep(Configuration const *cfg, uint8_t paymentMethod, int timeStep);
uint32_t GetPriceForTimeStep(Configuration *cfg, int timeStep) const;
uint32_t GetDurationForPrice(Configuration *cfg, int price) const;
};

View File

@ -118,6 +118,15 @@ std::string Calculator::GetDurationFromCost(Configuration* cfg,
bool nextDay,
bool prepaid)
{
// use tariff with structure as for instance Schnau, Koenigsee:
// without given YearPeriod, SpecialDays and SpecialDaysWorktime
if (cfg->YearPeriod.size() == 0
&& cfg->SpecialDays.size() == 0
&& cfg->SpecialDaysWorktime.size() == 0)
{
return QString().setNum(GetDurationForPrice(cfg, price)).toStdString();
}
// Get input date
QDateTime inputDate = QDateTime::fromString(start_datetime,Qt::ISODate);
@ -341,30 +350,28 @@ std::string Calculator::GetDurationFromCost(Configuration* cfg,
/// <inheritdoc/>
///
uint32_t Calculator::GetCostFromDuration(Configuration const* cfg,
uint32_t Calculator::GetCostFromDuration(Configuration *cfg,
QDateTime const &start,
quint64 timeStepInMinutes,
uint8_t paymentMethod) {
quint64 timeStepInMinutes) const {
// for instance, a tariff as used in Schoenau, Koenigssee: only steps, no
// special days, nonstop.
if (paymentMethod == PaymentMethod::Steps
if (cfg->YearPeriod.size() == 0
&& cfg->SpecialDays.size() == 0
&& cfg->SpecialDaysWorktime.size() == 0) {
QDateTime const end = start.addSecs(timeStepInMinutes*60);
return GetCostFromDuration(cfg, start, end, paymentMethod);
return GetCostFromDuration(cfg, start, end);
}
return 0;
}
uint32_t Calculator::GetCostFromDuration(Configuration const* cfg,
uint32_t Calculator::GetCostFromDuration(Configuration * cfg,
QDateTime const &start,
QDateTime const &end,
uint8_t paymentMethod) {
if (paymentMethod == PaymentMethod::Steps
QDateTime const &end) const {
if (cfg->YearPeriod.size() == 0
&& cfg->SpecialDays.size() == 0
&& cfg->SpecialDaysWorktime.size() == 0) {
int const timeStepInMinutes = start.secsTo(end) / 60;
return GetPriceForTimeStep(cfg, paymentMethod, timeStepInMinutes);
return GetPriceForTimeStep(cfg, timeStepInMinutes);
}
return 0;
}
@ -377,12 +384,12 @@ uint32_t Calculator::GetCostFromDuration(Configuration const* cfg,
/// <inheritdoc/>
double Calculator::GetCostFromDuration(Configuration* cfg, uint8_t payment_option, const QDateTime start_datetime, QDateTime & end_datetime, double durationMin, bool nextDay, bool prepaid)
{
// condition for 'PaymentMethod::Steps' (e.g. 332/Schoenau):
if (cfg->SpecialDays.size() == 0
if (cfg->YearPeriod.size() == 0
&& cfg->SpecialDays.size() == 0
&& cfg->SpecialDaysWorktime.size() == 0)
{
end_datetime = start_datetime.addSecs(durationMin*60);
return GetCostFromDuration(cfg, start_datetime, end_datetime, PaymentMethod::Steps);
return GetCostFromDuration(cfg, start_datetime, end_datetime);
}
// Get input date
@ -588,10 +595,10 @@ double Calculator::GetCostFromDuration(Configuration* cfg, uint8_t payment_optio
QList<int> Calculator::GetTimeSteps(Configuration const *cfg, int paymentOption) {
QList<int> Calculator::GetTimeSteps(Configuration *cfg) const {
QList<int> timeSteps;
int const pop_id = cfg->PaymentOption.find(paymentOption)->second.pop_id;
int const pop_id = cfg->getPaymentOptions().pop_id;
for (auto[itr, rangeEnd] = cfg->PaymentRate.equal_range(pop_id); itr != rangeEnd; ++itr)
{
@ -603,9 +610,9 @@ QList<int> Calculator::GetTimeSteps(Configuration const *cfg, int paymentOption)
return timeSteps;
}
uint32_t Calculator::GetPriceForTimeStep(Configuration const *cfg, uint8_t paymentOption, int timeStep) {
uint32_t Calculator::GetPriceForTimeStep(Configuration *cfg, int timeStep) const {
int const pop_id = cfg->PaymentOption.find(paymentOption)->second.pop_id;
int const pop_id = cfg->getPaymentOptions().pop_id;
for (auto[itr, rangeEnd] = cfg->PaymentRate.equal_range(pop_id); itr != rangeEnd; ++itr)
{
@ -616,7 +623,25 @@ uint32_t Calculator::GetPriceForTimeStep(Configuration const *cfg, uint8_t payme
int const pun_duration = cfg->Duration.find(payment_unit_id)->second.pun_duration;
if (timeStep == pun_duration) {
return (uint32_t)(itr->second.pra_price);
return (uint32_t)(itr->second.pra_price);
}
}
return 0;
}
uint32_t Calculator::GetDurationForPrice(Configuration *cfg, int price) const {
int const pop_id = cfg->getPaymentOptions().pop_id;
for (auto[itr, rangeEnd] = cfg->PaymentRate.equal_range(pop_id); itr != rangeEnd; ++itr)
{
int const payment_unit_id = itr->second.pra_payment_unit_id;
int const pra_price = cfg->PaymentRate.find(payment_unit_id)->second.pra_price;
if (price == pra_price) {
int const durationId = itr->second.pra_payment_unit_id;
int const durationUnit = cfg->Duration.find(durationId)->second.pun_duration;
return durationUnit;
}
}