Compare commits

..

31 Commits

Author SHA1 Message Date
d0e0699906 Add tests for linsinger maschinenbau. 2023-12-12 10:59:49 +01:00
3006e64b37 private_GetDurationFromCost():
set static variables using helpers moved to namespace Utilities.
2023-12-12 10:58:08 +01:00
c8218bd7af private_GetDurationFromCost():
remove superfluous check if there are special days listed in
json-tariff-file.
2023-12-12 10:56:58 +01:00
ba3dfcd3d6 Minor: private_GetCostFromDuration():
define static variables using helpers moved to namespace Utilities.
2023-12-12 10:55:19 +01:00
c51d350618 Minor: Moved
getMinimalParkingTime(), getMaximalParkingTime(), getMinimalParkingPrice()
computeWeekDaysPrice() and   computeWeekDaysDurationUnit() to Utilities
namespace.
2023-12-12 10:53:10 +01:00
a95a39a557 GetCostFromDuration():
1: Get payment method from tariff file.
  2: Use tariffIs24_7() helper (Tariff for Schoenau is such a case)
  3: Add new code for neuhauser/linsinger maschinenbau:
     Very similar to Schoenau, but here there are extra operating times
     6.00-18.00 during the week, 6-12 on Saturday.
     Check if the current time is inside such time ranges and return
     associated price.
2023-12-12 10:52:16 +01:00
67b12f4b33 Private GetCostFromDuration() and GetCostFromDuration() helpers:
Use pyament method id (=4) as condition for if(...).
The other condition (tariffIs24_7()) is used in calling functions.
2023-12-12 10:49:51 +01:00
60002404da GetDurationFromCost():
1: Get payment method from tariff file.
2: Use tariffIs24_7() helper (Tariff for Schoenau is such a case)
3: Add new code for neuhauser/linsinger maschinenbau:
   Very similar to Schoenau, but here there are extra operating times
   6.00-18.00 during the week, 6-12 on Saturday.
   Check if the current time is inside such time ranges and return
   associated price.
2023-12-12 10:43:16 +01:00
d4e03a51dd Moved
uint32_t computeWeekDaysPrice(Configuration const *cfg, PaymentMethod id) const;
    double computeWeekDaysDurationUnit(Configuration const *cfg, PaymentMethod id) const;
to namespace Utilities.
2023-12-12 10:41:21 +01:00
723b3530cc Added helpers GetPriceForStep() and GetStepForPrice() to make source
more readable.
2023-12-12 10:40:20 +01:00
63f508fb95 Moved
PaymentMethod getPaymentMethodId(Configuration const *cfg);
    int getMinimalParkingTime(Configuration const *cfg, PaymentMethod methodId);
    int getMaximalParkingTime(Configuration const *cfg, PaymentMethod methodId);
    uint32_t getMinimalParkingPrice(Configuration const *cfg, PaymentMethod methodId);

to namespace Utilities.
2023-12-12 10:38:31 +01:00
6e0a74c8cc Add helpers GetSteps(), noSpecialDays(), specialDays() and tariffIs24_7()
to make the source more readable.
2023-12-12 10:36:22 +01:00
d11cffb8bd Set pop_business_hours when parsing json-tariff-file. 2023-12-12 10:34:39 +01:00
15f552a973 Minor: Add header tariff_business_hours.h 2023-12-12 10:33:03 +01:00
52ad1c3ba8 Minor: add constructor taking some parameters.. 2023-12-12 10:31:54 +01:00
43b8a8d3bf Add member pop_business_hours. Add default constructor. 2023-12-12 10:30:55 +01:00
ceef73195d Add helper structure
enum BusinessHours
{
    NoRestriction_24_7          = 0,
    OnlyWorkingDays             = 1,    // [Monday-Friday]
    OnlyWeekDays                = 2,    // [Monday-Saturday]
    OnlyWeekEnd                 = 4,    // [Saturday+Sunday]
    OnlyOfficialHolidays        = 8,
    OnlySpecialDays             = 16,
    OnlySchoolHolidays          = 32,
    SpecialAndSchoolHolidays    = 48,
    OnlyOpenForBusinessDays     = 64,   // verkaufsoffen
    NoBusinessHoursDefined      = 255
};

to define inside of tariff-file what operating hours a PSA has.
2023-12-12 10:26:13 +01:00
282a412ef5 IsYearPeriodActive(): return true, even if no YearPeriod is given in tariff-json-file. 2023-12-12 10:23:45 +01:00
9dcf7a8f30 Implement added helpers. 2023-12-12 10:22:34 +01:00
4187598edf Add helpers for collecting them in Utilities namespave.
BusinessHours getBusinessHours(Configuration const *cfg, PaymentMethod methodId);
uint32_t computeWeekDaysPrice(Configuration const *cfg, PaymentMethod id);
double computeWeekDaysDurationUnit(Configuration const *cfg, PaymentMethod id);
2023-12-12 10:20:02 +01:00
88e92dddb9 Fix: nextTimeStep must be between minParkingTime and maxParkingTime. 2023-12-11 09:00:24 +01:00
0f05a1a784 (1) Fix debug output.
(2) Use UpDown-Argument for calculation of next tiem step.
2023-12-08 10:16:52 +01:00
2d696941a5 Fix: use second.pun_duration instead of second.pun_id
Minor: add debug output.
2023-12-08 10:14:48 +01:00
5598b02816 Make distinction base on PaymentMethod, not on some
other data contained in json-tariff-file.
2023-12-07 17:00:28 +01:00
548447af1f set -O option to calm down compiler because of FORTIFY_SOURCE=2 option 2023-12-07 17:00:03 +01:00
b9a7c04db9 Add compute_next_timestep() computing timesteps if PaymentMethod = Steps.
Add additional code for computing time steps dynamically if PaymentMethod = Linear.
2023-12-07 16:28:17 +01:00
5b8d9c62cc Add and implement utilities:
int getMinimalParkingTime(Configuration const *cfg, PaymentMethod methodId);
    int getMaximalParkingTime(Configuration const *cfg, PaymentMethod methodId);
    uint32_t getMinimalParkingPrice(Configuration const *cfg, PaymentMethod methodId);
    uint32_t getFirstDurationStep(Configuration const *cfg, PaymentMethod methodId);
2023-12-07 16:27:09 +01:00
56e2843ddb Add compute_next_timestep(). 2023-12-07 16:26:09 +01:00
6b76c4c2dd Add test cases for neuhauser. 2023-12-06 10:52:35 +01:00
54e9a0f86d Minor: add debug ouput (and commnt it out) 2023-12-06 10:51:46 +01:00
d7beb3b41b Fix: replace 'continue' with 'break' to return first fitting time-range
in findNextWorkTimeRange().
2023-12-06 10:49:33 +01:00
12 changed files with 411 additions and 94 deletions

View File

@@ -109,6 +109,8 @@ CalcState CALCULATE_LIBRARY_API init_tariff(parking_tariff_t **tariff,
void CALCULATE_LIBRARY_API free_tariff(parking_tariff_t *tariff); void CALCULATE_LIBRARY_API free_tariff(parking_tariff_t *tariff);
int CALCULATE_LIBRARY_API get_zone_nr(int zone = -1); int CALCULATE_LIBRARY_API get_zone_nr(int zone = -1);
int CALCULATE_LIBRARY_API compute_next_timestep(parking_tariff_t *tariff, int currentTimeMinutes, int UpDown);
CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket( // deprecated CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket( // deprecated
parking_tariff_t *tariff, parking_tariff_t *tariff,
time_t start_parking_time, time_t start_parking_time,

View File

@@ -45,6 +45,20 @@ public:
// (e.g. Schoenau/Koenigsee) // (e.g. Schoenau/Koenigsee)
// //
QList<int> GetTimeSteps(Configuration *cfg) const; QList<int> GetTimeSteps(Configuration *cfg) const;
QList<int> GetSteps(Configuration *cfg) const { return GetTimeSteps(cfg); }
// additional helper functions
bool noSpecialDays(Configuration const *cfg) const {
return (cfg->SpecialDays.size() == 0) && (cfg->SpecialDaysWorktime.size() == 0);
}
bool specialDays(Configuration const *cfg) const {
return !noSpecialDays(cfg);
}
bool tariffIs24_7(Configuration const *cfg) const {
return (cfg->YearPeriod.size() == 0 &&
cfg->SpecialDays.size() == 0 &&
cfg->SpecialDaysWorktime.size() == 0);
}
private: private:
// Introduced for PaymentMethod::Steps (e.g. Schoenau) // Introduced for PaymentMethod::Steps (e.g. Schoenau)
@@ -52,11 +66,6 @@ private:
uint32_t GetCostFromDuration(Configuration *cfg, QDateTime const &start, quint64 durationMinutes) const; uint32_t GetCostFromDuration(Configuration *cfg, QDateTime const &start, quint64 durationMinutes) const;
uint32_t GetCostFromDuration(Configuration *cfg, QDateTime const &start, QDateTime const &end) const; uint32_t GetCostFromDuration(Configuration *cfg, QDateTime const &start, QDateTime const &end) const;
PaymentMethod getPaymentMethodId(Configuration const *cfg);
int getMinimalParkingTime(Configuration const *cfg, PaymentMethod methodId);
int getMaximalParkingTime(Configuration const *cfg, PaymentMethod methodId);
uint32_t getMinimalParkingPrice(Configuration const *cfg, PaymentMethod methodId);
Ticket private_GetCostFromDuration(Configuration const* cfg, Ticket private_GetCostFromDuration(Configuration const* cfg,
QDateTime const &start, QDateTime const &start,
int durationMinutes, int durationMinutes,
@@ -71,7 +80,13 @@ private:
// //
uint32_t GetPriceForTimeStep(Configuration *cfg, int timeStep) const; uint32_t GetPriceForTimeStep(Configuration *cfg, int timeStep) const;
uint32_t GetPriceForStep(Configuration *cfg, int step) const {
return GetPriceForTimeStep(cfg, step);
}
uint32_t GetDurationForPrice(Configuration *cfg, int price) const; uint32_t GetDurationForPrice(Configuration *cfg, int price) const;
uint32_t GetStepForPrice(Configuration *cfg, int price) const {
return GetDurationForPrice(cfg, price);
}
int findWorkTimeRange(QDateTime const &dt, int findWorkTimeRange(QDateTime const &dt,
QScopedArrayPointer<TariffTimeRange> const &worktime, QScopedArrayPointer<TariffTimeRange> const &worktime,
@@ -79,9 +94,6 @@ private:
int findNextWorkTimeRange(QDateTime const &dt, int findNextWorkTimeRange(QDateTime const &dt,
QScopedArrayPointer<TariffTimeRange> const &worktime, QScopedArrayPointer<TariffTimeRange> const &worktime,
size_t size); size_t size);
uint32_t computeWeekDaysPrice(Configuration const *cfg, PaymentMethod id) const;
double computeWeekDaysDurationUnit(Configuration const *cfg, PaymentMethod id) const;
}; };
#endif // CALCULATOR_FUNCTIONS_H_INCLUDED #endif // CALCULATOR_FUNCTIONS_H_INCLUDED

View File

@@ -4,15 +4,18 @@
class ATBPaymentOption class ATBPaymentOption
{ {
public: public:
int pop_id; ATBPaymentOption() = default;
std::string pop_label;
int pop_payment_method_id; int pop_id;
std::string pop_day_end_time; std::string pop_label;
std::string pop_day_night_end_time; int pop_payment_method_id;
double pop_price_night; std::string pop_day_end_time;
double pop_min_time; std::string pop_day_night_end_time;
double pop_max_time; double pop_price_night;
double pop_min_price; double pop_min_time;
int pop_carry_over; double pop_max_time;
double pop_min_price;
int pop_carry_over;
int pop_daily_card_price; int pop_daily_card_price;
int pop_business_hours;
}; };

View File

@@ -0,0 +1,21 @@
#ifndef TARIFF_BUSINESS_HOURS_H_INCLUDED
#define TARIFF_BUSINESS_HOURS_H_INCLUDED
/// <summary>
/// Business hours (byte represents payment option id)
/// </summary>
enum BusinessHours
{
NoRestriction_24_7 = 0,
OnlyWorkingDays = 1, // [Monday-Friday]
OnlyWeekDays = 2, // [Monday-Saturday]
OnlyWeekEnd = 4, // [Saturday+Sunday]
OnlyOfficialHolidays = 8,
OnlySpecialDays = 16,
OnlySchoolHolidays = 32,
SpecialAndSchoolHolidays = 48,
OnlyOpenForBusinessDays = 64, // verkaufsoffen
NoBusinessHoursDefined = 255
};
#endif // TARIFF_BUSINESS_HOURS_H_INCLUDED

View File

@@ -16,6 +16,12 @@ public:
: m_time_from(QTime()) : m_time_from(QTime())
, m_time_until(QTime()) {} , m_time_until(QTime()) {}
TariffTimeRange(QTime const& from, QTime const &until)
: m_time_from(from)
, m_time_until(until) {
}
void setTimeRange(QTime const& from, QTime const &until) { void setTimeRange(QTime const& from, QTime const &until) {
m_time_from = from; m_time_from = from;
m_time_until = until; m_time_until = until;

View File

@@ -1,6 +1,5 @@
#pragma once #pragma once
#include <cstring> #include <cstring>
#include <string.h>
#include <ctime> #include <ctime>
#include <iostream> #include <iostream>
#include <cmath> #include <cmath>
@@ -9,6 +8,7 @@
#include "configuration.h" #include "configuration.h"
#include "time_range.h" #include "time_range.h"
#include "payment_method.h" #include "payment_method.h"
#include "tariff_business_hours.h"
#include <QDateTime> #include <QDateTime>
@@ -82,4 +82,12 @@ namespace Utilities {
bool isCarryOverSet(Configuration const *cfg, PaymentMethod paymentMethodId); bool isCarryOverSet(Configuration const *cfg, PaymentMethod paymentMethodId);
bool isCarryOverNotSet(Configuration const *cfg, PaymentMethod paymentMethodId); bool isCarryOverNotSet(Configuration const *cfg, PaymentMethod paymentMethodId);
PaymentMethod getPaymentMethodId(Configuration const *cfg); PaymentMethod getPaymentMethodId(Configuration const *cfg);
int getMinimalParkingTime(Configuration const *cfg, PaymentMethod methodId);
int getMaximalParkingTime(Configuration const *cfg, PaymentMethod methodId);
uint32_t getMinimalParkingPrice(Configuration const *cfg, PaymentMethod methodId);
uint32_t getFirstDurationStep(Configuration const *cfg, PaymentMethod methodId);
BusinessHours getBusinessHours(Configuration const *cfg, PaymentMethod methodId);
uint32_t computeWeekDaysPrice(Configuration const *cfg, PaymentMethod id);
double computeWeekDaysDurationUnit(Configuration const *cfg, PaymentMethod id);
} }

View File

@@ -2,7 +2,7 @@ TEMPLATE = lib
TARGET = mobilisis_calc TARGET = mobilisis_calc
#CONFIG += staticlib #CONFIG += staticlib
QMAKE_CXXFLAGS += -std=c++17 -g -O0 QMAKE_CXXFLAGS += -std=c++17 -g -O
INCLUDEPATH += $$_PRO_FILE_PWD_/include INCLUDEPATH += $$_PRO_FILE_PWD_/include
INCLUDEPATH += $$_PRO_FILE_PWD_/include/mobilisis INCLUDEPATH += $$_PRO_FILE_PWD_/include/mobilisis
@@ -68,7 +68,8 @@ HEADERS += \
include/mobilisis/tariff_log.h \ include/mobilisis/tariff_log.h \
include/mobilisis/calculate_price.h \ include/mobilisis/calculate_price.h \
include/mobilisis/atb_project.h \ include/mobilisis/atb_project.h \
include/mobilisis/ticket.h include/mobilisis/ticket.h \
include/mobilisis/tariff_business_hours.h
OTHER_FILES += src/main.cpp OTHER_FILES += src/main.cpp

View File

@@ -2,6 +2,7 @@
#include "configuration.h" #include "configuration.h"
#include "calculator_functions.h" #include "calculator_functions.h"
#include "payment_option.h" #include "payment_option.h"
#include "utilities.h"
#include <QFile> #include <QFile>
#include <QFileInfo> #include <QFileInfo>
@@ -92,6 +93,97 @@ void CALCULATE_LIBRARY_API free_tariff(parking_tariff_t *tariff) {
} }
} }
//
// UpDown 1 -> up; 0 -> down
int CALCULATE_LIBRARY_API compute_next_timestep(parking_tariff_t *tariff, int currentTimeMinutes, int UpDown)
{
qCritical() << " compute_next_timestep() currentTimeMinutes: " << currentTimeMinutes;
Configuration const *cfg = tariff;
// compute payment method id (e.g. Linear=3, Steps=4)
PaymentMethod const paymentMethodId = Utilities::getPaymentMethodId(cfg);
switch (paymentMethodId) {
case PaymentMethod::Progressive:
qCritical() << " compute_next_timestep() paymentMethodId: Progressive";
break;
case PaymentMethod::Degressive:
qCritical() << " compute_next_timestep() paymentMethodId: Degressive";
break;
case PaymentMethod::Linear:
qCritical() << " compute_next_timestep() paymentMethodId: Linear";
break;
case PaymentMethod::Steps:
qCritical() << " compute_next_timestep() paymentMethodId: Steps";
break;
case PaymentMethod::Undefined:
qCritical() << " compute_next_timestep() paymentMethodId: Undefined";
break;
}
// use tariff with structure as for instance Schnau, Koenigsee:
// without given YearPeriod, SpecialDays and SpecialDaysWorktime
if (paymentMethodId == PaymentMethod::Steps)
{
static const QList<int> stepList = calculator.GetTimeSteps(tariff);
int currentStepIndex = stepList.indexOf(currentTimeMinutes);
if (currentStepIndex == -1) {
qCritical() << "compute_next_timestep() *NO STEP* for currentTimeMinutes (" << currentTimeMinutes << ")";
return currentTimeMinutes;
}
if (UpDown == 1) { // UP
if (stepList[currentStepIndex] == stepList.last()) {
qCritical() << "compute_next_timestep() *NO NEXT STEP* for currentTimeMinutes (" << currentTimeMinutes << ")";
return currentTimeMinutes;
}
else {
return stepList[currentStepIndex + 1];
}
}
if (UpDown == 0) { // DOWN
if (stepList[currentStepIndex] == stepList.first()) {
qCritical() << "compute_next_timestep() *NO PREVIOUS STEP* for currentTimeMinutes (" << currentTimeMinutes << ")";
return currentTimeMinutes;
}
else {
return stepList[currentStepIndex - 1];
}
}
} else
if (paymentMethodId == PaymentMethod::Linear) {
// currentTimeMinutes is the number of minutes actually used. This
// value is an offset from the start time and cannot be used as a
// QDateTime.
qCritical() << "compute_next_timestep() up/down (1=up, 0=down):" << UpDown;
// get minimal and maximal parking times
int const minParkingTime = Utilities::getMinimalParkingTime(cfg, paymentMethodId);
int const maxParkingTime = Utilities::getMaximalParkingTime(cfg, paymentMethodId);
qCritical() << " compute_next_timestep() maxParkingTime:" << maxParkingTime;
qCritical() << " compute_next_timestep() minParkingTime:" << minParkingTime;
// use the first (i.e. main duration step contained in the tariff json-file)
int firstDurationStep = Utilities::getFirstDurationStep(cfg, paymentMethodId);
firstDurationStep = ((UpDown == 1) ? firstDurationStep : -firstDurationStep);
qCritical() << " compute_next_timestep() firstDurationStep:" << firstDurationStep;
int const nextTimeStep = currentTimeMinutes + firstDurationStep;
if (nextTimeStep >= minParkingTime && nextTimeStep <= maxParkingTime) {
qCritical() << " compute_next_timestep() nextTimeStep:" << nextTimeStep;
return nextTimeStep;
}
}
qCritical() << "compute_next_timestep() *CAN NOT COMPUTE* for currentTimeMinutes (" << currentTimeMinutes << ")";
return currentTimeMinutes;
}
// this is currently not used // this is currently not used
CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket( CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket(

View File

@@ -128,14 +128,40 @@ std::string Calculator::GetDurationFromCost(Configuration* cfg,
// Get input date // Get input date
QDateTime inputDate = QDateTime::fromString(start_datetime,Qt::ISODate); QDateTime inputDate = QDateTime::fromString(start_datetime,Qt::ISODate);
// use tariff with structure as for instance Schnau, Koenigsee: static const PaymentMethod paymentMethodId = Utilities::getPaymentMethodId(cfg);
// without given YearPeriod, SpecialDays and SpecialDaysWorktime if (paymentMethodId == PaymentMethod::Steps) {
if (cfg->YearPeriod.size() == 0 if (tariffIs24_7(cfg)) {
&& cfg->SpecialDays.size() == 0 // use tariff with structure as for instance Schoenau, Koenigsee:
&& cfg->SpecialDaysWorktime.size() == 0) // without given YearPeriod, SpecialDays and SpecialDaysWorktime
{ inputDate = inputDate.addSecs(GetDurationForPrice(cfg, price) * 60);
inputDate = inputDate.addSecs(GetDurationForPrice(cfg, price) * 60); return inputDate.toString(Qt::ISODate).toStdString();
return inputDate.toString(Qt::ISODate).toStdString(); } else {
QDateTime const &start = QDateTime::fromString(start_datetime, Qt::ISODate);
if (Utilities::IsYearPeriodActive(cfg, start)) {
if (!prepaid) {
BusinessHours businessHours = Utilities::getBusinessHours(cfg, paymentMethodId);
if (businessHours == BusinessHours::OnlyWeekDays) {
int const weekdayId = start.date().dayOfWeek();
using WTIterator = std::multimap<int, ATBWeekDaysWorktime>::const_iterator;
std::pair<WTIterator, WTIterator> p = cfg->WeekDaysWorktime.equal_range(weekdayId);
for (WTIterator itr = p.first; itr != p.second; ++itr) {
QTime const &from = Utilities::WeekDaysWorkTimeFrom(itr);
QTime const &until = Utilities::WeekDaysWorkTimeUntil(itr);
QTime const& startTime = start.time();
if (from <= startTime && startTime <= until) {
return inputDate.addSecs(GetDurationForPrice(cfg, price) * 60).toString(Qt::ISODate).toStdString();
}
}
}
}
qCritical() << __PRETTY_FUNCTION__ << "NOT YET IMPLEMENTED";
return 0;
}
}
} }
Ticket t = private_GetDurationFromCost(cfg, inputDate, price, prepaid); Ticket t = private_GetDurationFromCost(cfg, inputDate, price, prepaid);
@@ -156,9 +182,8 @@ uint32_t Calculator::GetCostFromDuration(Configuration *cfg,
quint64 timeStepInMinutes) const { quint64 timeStepInMinutes) const {
// for instance, a tariff as used in Schoenau, Koenigssee: only steps, no // for instance, a tariff as used in Schoenau, Koenigssee: only steps, no
// special days, nonstop. // special days, nonstop.
if (cfg->YearPeriod.size() == 0 static const PaymentMethod paymentMethodId = Utilities::getPaymentMethodId(cfg);
&& cfg->SpecialDays.size() == 0 if (paymentMethodId == PaymentMethod::Steps) {
&& cfg->SpecialDaysWorktime.size() == 0) {
QDateTime const end = start.addSecs(timeStepInMinutes*60); QDateTime const end = start.addSecs(timeStepInMinutes*60);
return GetCostFromDuration(cfg, start, end); return GetCostFromDuration(cfg, start, end);
} }
@@ -168,9 +193,8 @@ uint32_t Calculator::GetCostFromDuration(Configuration *cfg,
uint32_t Calculator::GetCostFromDuration(Configuration * cfg, uint32_t Calculator::GetCostFromDuration(Configuration * cfg,
QDateTime const &start, QDateTime const &start,
QDateTime const &end) const { QDateTime const &end) const {
if (cfg->YearPeriod.size() == 0 static const PaymentMethod paymentMethodId = Utilities::getPaymentMethodId(cfg);
&& cfg->SpecialDays.size() == 0 if (paymentMethodId == PaymentMethod::Steps) {
&& cfg->SpecialDaysWorktime.size() == 0) {
int const timeStepInMinutes = start.secsTo(end) / 60; int const timeStepInMinutes = start.secsTo(end) / 60;
return GetPriceForTimeStep(cfg, timeStepInMinutes); return GetPriceForTimeStep(cfg, timeStepInMinutes);
} }
@@ -193,12 +217,39 @@ double Calculator::GetCostFromDuration(Configuration* cfg,
Q_UNUSED(payment_option); Q_UNUSED(payment_option);
Q_UNUSED(nextDay); Q_UNUSED(nextDay);
if (cfg->YearPeriod.size() == 0 static const PaymentMethod paymentMethodId = Utilities::getPaymentMethodId(cfg);
&& cfg->SpecialDays.size() == 0 if (paymentMethodId == PaymentMethod::Steps) {
&& cfg->SpecialDaysWorktime.size() == 0) if (tariffIs24_7(cfg)) {
{ end_datetime = start_datetime.addSecs(durationMinutes*60);
end_datetime = start_datetime.addSecs(durationMinutes*60); return GetCostFromDuration(cfg, start_datetime, end_datetime);
return GetCostFromDuration(cfg, start_datetime, end_datetime); } else {
if (Utilities::IsYearPeriodActive(cfg, start_datetime)) {
if (!prepaid) {
BusinessHours businessHours = Utilities::getBusinessHours(cfg, paymentMethodId);
if (businessHours == BusinessHours::OnlyWeekDays) {
int const weekdayId = start_datetime.date().dayOfWeek();
using WTIterator = std::multimap<int, ATBWeekDaysWorktime>::const_iterator;
std::pair<WTIterator, WTIterator> p = cfg->WeekDaysWorktime.equal_range(weekdayId);
for (WTIterator itr = p.first; itr != p.second; ++itr) {
QTime const &from = Utilities::WeekDaysWorkTimeFrom(itr);
QTime const &until = Utilities::WeekDaysWorkTimeUntil(itr);
QTime const &startTime = start_datetime.time();
if (from <= startTime && startTime <= until) {
end_datetime = start_datetime.addSecs(durationMinutes*60);
return GetCostFromDuration(cfg, start_datetime, end_datetime);
}
}
}
}
qCritical() << __PRETTY_FUNCTION__ << "NOT YET IMPLEMENTED";
end_datetime = QDateTime();
return 0;
}
}
} }
QDateTime start = start_datetime; QDateTime start = start_datetime;
@@ -215,18 +266,6 @@ double Calculator::GetCostFromDuration(Configuration* cfg,
return t.getPrice(); return t.getPrice();
} }
int Calculator::getMinimalParkingTime(Configuration const *cfg, PaymentMethod methodId) {
return std::max((int)cfg->PaymentOption.find(methodId)->second.pop_min_time, 0);
}
int Calculator::getMaximalParkingTime(Configuration const *cfg, PaymentMethod methodId) {
return std::max((int)cfg->PaymentOption.find(methodId)->second.pop_max_time, 0);
}
uint32_t Calculator::getMinimalParkingPrice(Configuration const *cfg, PaymentMethod methodId) {
return std::max((int)cfg->PaymentOption.find(methodId)->second.pop_min_price, 0);
}
bool Calculator::checkDurationMinutes(int minParkingTime, bool Calculator::checkDurationMinutes(int minParkingTime,
int maxParkingTime, int maxParkingTime,
int durationMinutes) { int durationMinutes) {
@@ -265,23 +304,12 @@ int Calculator::findNextWorkTimeRange(QDateTime const &dt,
if (dt.time() < worktime_from) { if (dt.time() < worktime_from) {
nextWorkTimeRange = w; nextWorkTimeRange = w;
continue; break;
} }
} }
return nextWorkTimeRange; return nextWorkTimeRange;
} }
uint32_t Calculator::computeWeekDaysPrice(Configuration const *cfg, PaymentMethod id) const {
int pop_id = cfg->PaymentOption.find(id)->second.pop_id;
return cfg->PaymentRate.find(pop_id)->second.pra_price;
}
double Calculator::computeWeekDaysDurationUnit(Configuration const *cfg, PaymentMethod id) const {
int pop_id = cfg->PaymentOption.find(id)->second.pop_id;
int durationId = cfg->PaymentRate.find(pop_id)->second.pra_payment_unit_id;
return (double)(cfg->Duration.find(durationId)->second.pun_duration);
}
using namespace Utilities; using namespace Utilities;
Ticket Calculator::private_GetCostFromDuration(Configuration const* cfg, Ticket Calculator::private_GetCostFromDuration(Configuration const* cfg,
@@ -291,12 +319,12 @@ Ticket Calculator::private_GetCostFromDuration(Configuration const* cfg,
static const PaymentMethod paymentMethodId = Utilities::getPaymentMethodId(cfg); static const PaymentMethod paymentMethodId = Utilities::getPaymentMethodId(cfg);
static const bool carryOverNotSet = isCarryOverNotSet(cfg, paymentMethodId); static const bool carryOverNotSet = isCarryOverNotSet(cfg, paymentMethodId);
static const int minParkingTimeMinutes = getMinimalParkingTime(cfg, paymentMethodId); static const int minParkingTimeMinutes = Utilities::getMinimalParkingTime(cfg, paymentMethodId);
static const int maxParkingTimeMinutes = getMaximalParkingTime(cfg, paymentMethodId); static const int maxParkingTimeMinutes = Utilities::getMaximalParkingTime(cfg, paymentMethodId);
static const bool checkMinMaxMinutes = (minParkingTimeMinutes < maxParkingTimeMinutes); static const bool checkMinMaxMinutes = (minParkingTimeMinutes < maxParkingTimeMinutes);
static const int durationMinutesNetto = durationMinutes; static const int durationMinutesNetto = durationMinutes;
static const uint32_t weekDaysPrice = computeWeekDaysPrice(cfg, paymentMethodId); static const uint32_t weekDaysPrice = Utilities::computeWeekDaysPrice(cfg, paymentMethodId);
static const double weekDaysDurationUnit = computeWeekDaysDurationUnit(cfg, paymentMethodId); static const double weekDaysDurationUnit = Utilities::computeWeekDaysDurationUnit(cfg, paymentMethodId);
static const double specialDaysDurationUnit = 60.0; static const double specialDaysDurationUnit = 60.0;
if (!checkMinMaxMinutes) { if (!checkMinMaxMinutes) {
@@ -364,6 +392,9 @@ Ticket Calculator::private_GetCostFromDuration(Configuration const* cfg,
QTime const &lastWorktimeTo = worktime[ranges-1].getTimeUntil(); QTime const &lastWorktimeTo = worktime[ranges-1].getTimeUntil();
// qCritical() << "start" << start.toString(Qt::ISODate)
// << "current" << current.toString(Qt::ISODate) << lastWorktimeTo;
// find worktime range to start with // find worktime range to start with
int currentRange = 0; int currentRange = 0;
if (!isSpecialDay) { if (!isSpecialDay) {
@@ -386,6 +417,8 @@ Ticket Calculator::private_GetCostFromDuration(Configuration const* cfg,
} }
} }
// qCritical() << "current" << current.toString(Qt::ISODate);
for (int w = currentRange; w < ranges; ++w, ++totalTimeRanges) { for (int w = currentRange; w < ranges; ++w, ++totalTimeRanges) {
if (durationMinutes > 0) { if (durationMinutes > 0) {
QTime const &worktime_from = worktime[w].getTimeFrom(); QTime const &worktime_from = worktime[w].getTimeFrom();
@@ -416,12 +449,13 @@ Ticket Calculator::private_GetCostFromDuration(Configuration const* cfg,
return Ticket(); return Ticket();
} }
} else { } else {
qDebug() << "* PREPAID MODE ACTIVE *"; //qDebug() << "* PREPAID MODE ACTIVE *";
//qCritical() << "current" << current.toString(Qt::ISODate) << worktime_from << lastWorktimeTo;
if (current.time() < worktime_from) { if (current.time() < worktime_from) {
current.setTime(worktime_from); current.setTime(worktime_from);
end = current; end = current;
} else if(current.time() > lastWorktimeTo) { } else if(current.time() > lastWorktimeTo) {
qDebug() << " *** PREPAID *** Current time is past the time range end, searching for next available day"; //qDebug() << " *** PREPAID *** Current time is past the time range end, searching for next available day";
end = current; end = current;
current.setTime(QTime()); current.setTime(QTime());
continue; continue;
@@ -442,6 +476,7 @@ Ticket Calculator::private_GetCostFromDuration(Configuration const* cfg,
current.setTime(QTime()); current.setTime(QTime());
break; // stop while, and continue in outer loop break; // stop while, and continue in outer loop
} else { } else {
//qCritical() << "current" << current.toString(Qt::ISODate) << worktime_to;
if(current.time() < worktime_to) { if(current.time() < worktime_to) {
// Increment input date minutes for each monetary unit // Increment input date minutes for each monetary unit
current = current.addSecs(60); current = current.addSecs(60);
@@ -449,6 +484,7 @@ Ticket Calculator::private_GetCostFromDuration(Configuration const* cfg,
durationMinutes -= 1; durationMinutes -= 1;
//costFromDuration += price_per_unit; //costFromDuration += price_per_unit;
costFromDuration += price; costFromDuration += price;
//qCritical() << "current" << current.toString(Qt::ISODate);
} else break; } else break;
} }
} // while(durationMinutes > 0) { } // while(durationMinutes > 0) {
@@ -472,29 +508,14 @@ Ticket Calculator::private_GetDurationFromCost(Configuration *cfg,
// Get input date // Get input date
QDateTime current = start; QDateTime current = start;
// 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)
{
uint64_t const durationMinutes = GetDurationForPrice(cfg, cost);
uint64_t const durationSeconds = durationMinutes * 60;
current = current.addSecs(durationSeconds);
return
Ticket(start, current, durationMinutes, durationMinutes,
cost, Ticket::s[VALID]);
}
static const PaymentMethod paymentMethodId = Utilities::getPaymentMethodId(cfg); static const PaymentMethod paymentMethodId = Utilities::getPaymentMethodId(cfg);
static const bool carryOverNotSet = isCarryOverNotSet(cfg, paymentMethodId); static const bool carryOverNotSet = isCarryOverNotSet(cfg, paymentMethodId);
static const uint32_t minParkingTimeMinutes = std::max(getMinimalParkingTime(cfg, paymentMethodId), 0); static const uint32_t minParkingTimeMinutes = std::max(Utilities::getMinimalParkingTime(cfg, paymentMethodId), 0);
static const uint32_t maxParkingTimeMinutes = std::max(getMaximalParkingTime(cfg, paymentMethodId), 0); static const uint32_t maxParkingTimeMinutes = std::max(Utilities::getMaximalParkingTime(cfg, paymentMethodId), 0);
static const uint32_t minParkingPrice = getMinimalParkingPrice(cfg, paymentMethodId); static const uint32_t minParkingPrice = getMinimalParkingPrice(cfg, paymentMethodId);
// static const bool checkMinMaxMinutes = (minParkingTimeMinutes < maxParkingTimeMinutes); // static const bool checkMinMaxMinutes = (minParkingTimeMinutes < maxParkingTimeMinutes);
static const uint32_t weekDaysPrice = computeWeekDaysPrice(cfg, paymentMethodId); static const uint32_t weekDaysPrice = Utilities::computeWeekDaysPrice(cfg, paymentMethodId);
static const uint32_t weekDaysDurationUnit = computeWeekDaysDurationUnit(cfg, paymentMethodId); static const uint32_t weekDaysDurationUnit = Utilities::computeWeekDaysDurationUnit(cfg, paymentMethodId);
static const uint32_t specialDaysDurationUnit = 60; static const uint32_t specialDaysDurationUnit = 60;
if(cost < minParkingPrice) { if(cost < minParkingPrice) {

View File

@@ -78,7 +78,7 @@ bool Configuration::ParseJson(Configuration* cfg, const char* json)
ATBWeekDaysWorktime WeekDaysWorktime; ATBWeekDaysWorktime WeekDaysWorktime;
ATBPaymentOption PaymentOption; ATBPaymentOption PaymentOption;
ATBPeriodYear YearPeriod; ATBPeriodYear YearPeriod;
MemberType mb_type; MemberType mb_type = MemberType::UnknownType;
// Get all JSON object members // Get all JSON object members
// This code should run only once (to load JSON variables into memory) // This code should run only once (to load JSON variables into memory)
@@ -169,6 +169,7 @@ bool Configuration::ParseJson(Configuration* cfg, const char* json)
else if (strcmp(inner_obj_name, "pop_min_price") == 0) PaymentOption.pop_min_price = k->value.GetDouble(); else if (strcmp(inner_obj_name, "pop_min_price") == 0) PaymentOption.pop_min_price = k->value.GetDouble();
else if (strcmp(inner_obj_name, "pop_carry_over") == 0) PaymentOption.pop_carry_over = k->value.GetInt(); else if (strcmp(inner_obj_name, "pop_carry_over") == 0) PaymentOption.pop_carry_over = k->value.GetInt();
else if (strcmp(inner_obj_name, "pop_daily_card_price") == 0) PaymentOption.pop_daily_card_price = k->value.GetInt(); else if (strcmp(inner_obj_name, "pop_daily_card_price") == 0) PaymentOption.pop_daily_card_price = k->value.GetInt();
else if (strcmp(inner_obj_name, "pop_business_hours") == 0) PaymentOption.pop_business_hours = k->value.GetInt();
this->currentPaymentOptions = PaymentOption; this->currentPaymentOptions = PaymentOption;
break; break;
case MemberType::DurationType: case MemberType::DurationType:

View File

@@ -197,7 +197,8 @@ bool Utilities::IsYearPeriodActive(Configuration* cfg, struct tm* currentDateTim
} }
bool Utilities::IsYearPeriodActive(Configuration const *cfg, QDateTime const &dt) { bool Utilities::IsYearPeriodActive(Configuration const *cfg, QDateTime const &dt) {
if (std::none_of(cfg->YearPeriod.cbegin(), if ((cfg->YearPeriod.size() > 0) &&
std::none_of(cfg->YearPeriod.cbegin(),
cfg->YearPeriod.cend(), cfg->YearPeriod.cend(),
[&dt](std::pair<int, ATBPeriodYear> const &year) { [&dt](std::pair<int, ATBPeriodYear> const &year) {
QDate const d(2004, // 2004 is a leap year QDate const d(2004, // 2004 is a leap year
@@ -373,3 +374,56 @@ PaymentMethod Utilities::getPaymentMethodId(Configuration const *cfg) {
return PaymentMethod::Undefined; return PaymentMethod::Undefined;
} }
int Utilities::getMinimalParkingTime(Configuration const *cfg, PaymentMethod methodId) {
return std::max((int)cfg->PaymentOption.find(methodId)->second.pop_min_time, 0);
}
int Utilities::getMaximalParkingTime(Configuration const *cfg, PaymentMethod methodId) {
return std::max((int)cfg->PaymentOption.find(methodId)->second.pop_max_time, 0);
}
uint32_t Utilities::getMinimalParkingPrice(Configuration const *cfg, PaymentMethod methodId) {
return std::max((int)cfg->PaymentOption.find(methodId)->second.pop_min_price, 0);
}
uint32_t Utilities::getFirstDurationStep(Configuration const *cfg, PaymentMethod methodId) {
int const popId = cfg->PaymentOption.find(methodId)->second.pop_id;
int const punId = cfg->PaymentRate.find(popId)->second.pra_payment_unit_id;
uint32_t const firstDurationStep= cfg->Duration.find(punId)->second.pun_duration;
qCritical() << "getFirstDurationStep() payment-method-id:" << (int)methodId;
qCritical() << "getFirstDurationStep() pop-id:" << popId;
qCritical() << "getFirstDurationStep() pun-id:" << punId;
qCritical() << "getFirstDurationStep() first-step:" << firstDurationStep;
return firstDurationStep;
}
BusinessHours Utilities::getBusinessHours(Configuration const *cfg, PaymentMethod methodId) {
int businessHours = cfg->PaymentOption.find(methodId)->second.pop_business_hours;
switch (businessHours) {
case NoRestriction_24_7: return NoRestriction_24_7;
case OnlyWorkingDays: return OnlyWorkingDays;
case OnlyWeekDays: return OnlyWeekDays;
case OnlyWeekEnd: return OnlyWeekEnd;
case OnlyOfficialHolidays: return OnlyOfficialHolidays;
case OnlySpecialDays: return OnlySpecialDays;
case OnlySchoolHolidays: return OnlySchoolHolidays;
case SpecialAndSchoolHolidays: return SpecialAndSchoolHolidays;
case OnlyOpenForBusinessDays: return OnlyOpenForBusinessDays;
}
return NoBusinessHoursDefined;
}
uint32_t Utilities::computeWeekDaysPrice(Configuration const *cfg, PaymentMethod id) {
int pop_id = cfg->PaymentOption.find(id)->second.pop_id;
return cfg->PaymentRate.find(pop_id)->second.pra_price;
}
double Utilities::computeWeekDaysDurationUnit(Configuration const *cfg, PaymentMethod id) {
int pop_id = cfg->PaymentOption.find(id)->second.pop_id;
int durationId = cfg->PaymentRate.find(pop_id)->second.pra_payment_unit_id;
return (double)(cfg->Duration.find(durationId)->second.pun_duration);
}

View File

@@ -33,13 +33,108 @@ extern "C" char* strptime(const char* s,
#include "calculator_functions.h" #include "calculator_functions.h"
#include <calculate_price.h> #include <calculate_price.h>
#define SZEGED (0)
#define NEUHAUSER_KORNEUBURG (0)
#define NEUHAUSER_LINSINGER_MASCHINENBAU (1)
int main() { int main() {
#if NEUHAUSER_LINSINGER_MASCHINENBAU==1
std::ifstream input("/tmp/tariff_linsinger_maschinenbau.json");
//std::ifstream input("/tmp/tariff_korneuburg.json"); std::stringstream sstr;
while(input >> sstr.rdbuf());
std::string json(sstr.str());
Calculator calculator;
Configuration cfg;
bool isParsed = cfg.ParseJson(&cfg, json.c_str());
cout << endl;
if (isParsed) {
bool nextDay = false;
bool prePaid = false;
// zone 1 (lila)
QDateTime s(QDate(2023, 11, 30), QTime());
QDateTime end;
int marken[] = { 3*60, 5*60, 10*60};
for (int duration = 0; duration < 3; ++duration) {
for (int offset = 360; offset <= 1080; ++offset) {
QDateTime start = s.addSecs(offset * 60);
//qCritical() << "start" << start.toString(Qt::ISODate);
double cost = calculator.GetCostFromDuration(&cfg, 4, start, end, marken[duration], nextDay, prePaid);
//qCritical() << "";
//qCritical() << "start" << start.toString(Qt::ISODate)
// << "end" << end.toString(Qt::ISODate)
// << "duration" << marken[duration]
// << "cost" << cost;
std::string d = calculator.GetDurationFromCost(&cfg, 4, start.toString(Qt::ISODate).toStdString().c_str(), cost);
qCritical() << "start" << start.toString(Qt::ISODate)
<< "cost" << cost
<< "until" << d.c_str() << start.secsTo(QDateTime::fromString(d.c_str(), Qt::ISODate)) / 60;
}
}
}
#endif
#if NEUHAUSER_KORNEUBURG==1
std::ifstream input("/tmp/tariff_korneuburg.json");
int pop_max_time; int pop_max_time;
std::stringstream sstr;
while(input >> sstr.rdbuf());
std::string json(sstr.str());
Calculator calculator;
Configuration cfg;
bool isParsed = cfg.ParseJson(&cfg, json.c_str());
cout << endl;
if (isParsed) {
{
pop_max_time = 3*60;
bool nextDay = false;
bool prePaid = true;
// zone 1 (lila)
QDateTime s(QDate(2023, 11, 30), QTime());
QDateTime end;
for (int duration = 30; duration <= pop_max_time; duration += 5) {
for (int offset = 420; offset < 1140; ++offset) {
if (offset > 720 && offset < 840) {
continue;
}
QDateTime start = s.addSecs(offset * 60);
//qCritical() << "start" << start.toString(Qt::ISODate);
double cost = calculator.GetCostFromDuration(&cfg, 3, start, end, duration, nextDay, prePaid);
//Q_ASSERT(cost == duration*2.5);
//qCritical() << "";
//qCritical() << "start" << start.toString(Qt::ISODate)
// << "end" << end.toString(Qt::ISODate)
// << "duration" << duration
// << "cost" << cost;
std::string duration = calculator.GetDurationFromCost(&cfg, 3, start.toString(Qt::ISODate).toStdString().c_str(), cost);
//Q_ASSERT(cost == duration*2.5);
qCritical() << "start" << start.toString(Qt::ISODate)
<< "cost" << cost
<< "until" << duration.c_str() << start.secsTo(QDateTime::fromString(duration.c_str(), Qt::ISODate)) / 60;
}
}
}
}
return 0;
#elif SZEGED==1
std::ifstream input; std::ifstream input;
for (int t=1; t < 7; t+=20) { int pop_max_time;
for (int t=6; t < 7; t+=20) {
switch (t) { switch (t) {
case 1: { case 1: {
input.open("/opt/ptu5/opt/customer_281/etc/psa_tariff/tariff01.json"); input.open("/opt/ptu5/opt/customer_281/etc/psa_tariff/tariff01.json");
@@ -123,6 +218,7 @@ int main() {
return 0; return 0;
#endif
#if 0 #if 0