Compare commits

...

54 Commits

Author SHA1 Message Date
62c52fd580 test case for fuchs, fane alm. 2024-08-02 11:13:50 +02:00
1023f6ede1 GetPriceForTimeStep():
Use "pop_accumulate_durations" setting to sum up the durations.
	Otherwise time-step will not be found in time-step-list.
2024-08-02 11:12:07 +02:00
36b3e85d1b GetCostFromDuration():
recompute timestep list to make sure that time step is found in it.
2024-08-02 11:11:20 +02:00
b394ed46cc In case end-parking-time ends with 00:00, set it to 23:59. 2024-08-02 11:09:20 +02:00
3dda2d8355 Check if prepaid-option is set. 2024-08-02 11:08:52 +02:00
1152c3824e Minor: add some debug output. 2024-08-02 11:08:32 +02:00
4271c0fb31 Fixed compute_next_timestep() for degressive tariff:
compute_next_timestep() was actually never called for such a tariff.
2024-08-02 10:50:25 +02:00
24d9d4a0ff test case for kleipeda and fuchs 2024-08-01 16:46:09 +02:00
4bce854d77 GetDurationFromCost():
Set durationInSecs in case 'pop_accumulate_prices' is not configured
        in tariff file.
2024-08-01 16:44:06 +02:00
138221759b GetDurationFromCost():
Minor: removed some debug ouput
2024-08-01 16:43:19 +02:00
9cb7d4aea6 compute_price_for_parking_ticket():
Added handling for prepaid and carry-over.
2024-08-01 16:04:57 +02:00
cde490bab2 compute_next_time_step():
Added handling with pop_plus_steps/pop_minus_steps:
	'+' usually takes more than one time step.
        '-' is usually 1.

	Changed behaviour when current time is not found in the list of time steps:
	Search for the entry with the smallest distance to 'current time'.
	If the distance is smaller than 3 minutes, then use 'current time' as new
 	entry in the list of time steps.
2024-08-01 16:00:10 +02:00
f0677374ec Parsing of pop_plus_steps/pop_minus_steps 2024-08-01 15:46:49 +02:00
89b05ffadc Added GetYearPeriodActive() to get active year period. 2024-08-01 15:45:50 +02:00
260973cd09 Added pop_plus_steps/pop_minus_steps to control step sizes 2024-08-01 15:44:06 +02:00
7bf7108668 GetDurationFromCost():
Check if computed duration is below minimal parking time.
2024-07-31 10:26:47 +02:00
e5629ba4fd GetDurationFromCost():
Check if given price is below minimal parking price.
2024-07-31 10:25:03 +02:00
e4cb992aae GetTimeSteps() for payment-method degressive. introduced for Valser Alm (location: Fane). 2024-07-30 15:39:55 +02:00
cdeb625a15 Minor: Revode debug output. 2024-07-30 15:39:35 +02:00
589d89b73a Calculator::GetDurationFromCost():
Compute duration from cost for PaymentMethod::Degressive: introduced
	for Valser Alm (location: Fane).
2024-07-30 15:37:28 +02:00
7536f89d75 compute_duration_for_parking_ticket():
read prepaid-setting from tariff-file, if possible.
2024-07-30 15:32:58 +02:00
9a6b2b195d get_minimal_parking_price(): compute this price dynamically according to settings
in the tariff-file. Introduced for Fuchs (500) for Valser Alm (Location: Fane)
2024-07-30 15:29:47 +02:00
7233bc55c2 test for valser alm (fane) 2024-07-30 15:24:52 +02:00
52b7c2390a Minor: introduce using-typedef for Duration 2024-07-29 17:33:49 +02:00
894e23332f compute option index using permit type. 2024-07-29 17:32:15 +02:00
fbc255a6f2 Fix: compute_next_time_step(): removed check for product ids. 2024-07-29 17:31:33 +02:00
24ab01695d GetPriceForTimeStep(): remove default parameter. 2024-07-29 17:28:27 +02:00
37652d3b6a Save computed pop_min_time. 2024-07-29 17:27:16 +02:00
14fd7ddd39 Preperationf for Zone3. 2024-07-29 17:26:53 +02:00
ca3c3921d4 Minor: change debug output 2024-07-29 17:26:26 +02:00
37620a06c1 added test case for bus 2024-07-29 11:30:36 +02:00
9f4affca5a Minor: removed debug output 2024-07-29 11:30:00 +02:00
4f2c33cdc2 Minor: added comments and added some debug output. 2024-07-29 11:28:07 +02:00
3cd02296b0 compute_duration_for_parking_ticket():
Fix: pass PERMIT_TYPE explicitly to correct arity of GetDurationFromCost().
2024-07-29 11:25:12 +02:00
f1493f417f get_maximal_parkingprice():
implement for SHORT_TERM_PARKING_BUS and SHORT_TERM_PARKING_PKW.
2024-07-29 11:24:05 +02:00
356e3be178 Pass PERMIT_TYPE to get_minimal_parkingtime() and get_maximal_parkingtime()
to override default parameter value.
2024-07-29 11:22:22 +02:00
31b1dd1690 ResetTimeSteps():
Check paymentOptionIndex for correct value.
2024-07-29 11:20:00 +02:00
dbf5b1f11d remove input correction 2024-07-26 17:34:24 +02:00
29368ea850 Remove correction 2024-07-26 17:04:33 +02:00
b84f80887e Checkin for testing 2024-07-26 17:01:44 +02:00
4a2b15d086 Add some debug output into GetDurationForPrice(). 2024-07-26 13:34:18 +02:00
8dad8f00e8 GetPriceForTimeStep(): Fix: user default payment option 2024-07-26 13:11:29 +02:00
805a732c52 GetPriceForTimeStep(): add prices for computed timesteps. Return maximal
price which is still smaller or equal then (input-)price.
2024-07-26 12:53:42 +02:00
b7facb9d60 checkin for tariff02.json 2024-07-26 10:59:45 +02:00
8344b04b15 Use of permitType in several places 2024-07-25 09:49:16 +02:00
b0ecef0361 Use of permitType in several places 2024-07-25 09:48:12 +02:00
003b7e8e8a getPaymentOption() functions and getPaymentOptionIndex() 2024-07-25 09:46:46 +02:00
7ef2d44fc4 Add parameter PermitType to GetCostForDuration() and GetDurationFromCost() 2024-07-25 09:45:36 +02:00
8f203184b6 Add additional parameter (PermitType) to several functions 2024-07-25 09:44:24 +02:00
0bfec6a938 Added getPaymentOptionIndex() and getPaymentOptionsForAllKeys() 2024-07-25 09:43:16 +02:00
070446d01a Updated test cases for PermitType. 2024-07-24 17:35:46 +02:00
4d7e5263ee Added parsing of pop_product_id and pop_product_name. 2024-07-24 17:34:28 +02:00
7d452c82b7 Added pop_product_id and pop_product_name 2024-07-24 17:33:53 +02:00
0a08221381 Added conversion from QString to PermitType 2024-07-24 17:33:06 +02:00
13 changed files with 1262 additions and 352 deletions

View File

@ -266,7 +266,8 @@ CalcState CALCULATE_LIBRARY_API init_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 compute_next_timestep(parking_tariff_t *tariff, int currentTimeMinutes, int UpDown);
int CALCULATE_LIBRARY_API compute_next_timestep(parking_tariff_t *tariff, int currentTimeMinutes,
int UpDown, PermitType const &permitType);
QList<int> CALCULATE_LIBRARY_API get_time_steps(Configuration *cfg);
@ -297,7 +298,8 @@ CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket( // depre
parking_tariff_t *tariff,
time_t start_parking_time,
time_t end_parking_time,
struct price_t *price);
struct price_t *price,
PermitType permitType);
CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket(
parking_tariff_t *tariff,
@ -305,24 +307,28 @@ CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket(
int netto_parking_time,
QDateTime &end_parking_time, // return value
struct price_t *price, // return value
PermitType permitType,
bool prepaid = true);
CalcState CALCULATE_LIBRARY_API compute_duration_for_parking_ticket( // deprecated
parking_tariff_t *tariff,
time_t start_parking_time,
double cost,
QString &duration);
QString &duration,
PermitType permitType);
CalcState CALCULATE_LIBRARY_API compute_duration_for_parking_ticket(
parking_tariff_t *tariff,
QDateTime const &start_parking_time,
double cost,
QDateTime &ticketEndTime); // return value
QDateTime &ticketEndTime,
PermitType permitType); // return value
CalcState CALCULATE_LIBRARY_API compute_duration_for_daily_ticket(
parking_tariff_t *tariff,
QDateTime const &start_parking_time,
QDateTime &ticketEndTime);
QDateTime &ticketEndTime,
PermitType permitType);
CalcState CALCULATE_LIBRARY_API compute_price_for_daily_ticket(
parking_tariff_t *tariff,

View File

@ -40,12 +40,12 @@ public:
}
void ResetTimeSteps(int paymentOptionIndex) {
if (m_timeSteps.size() > 0) {
if (m_timeSteps.size() > 0 && paymentOptionIndex < m_timeSteps.size()) {
m_timeSteps[paymentOptionIndex].clear();
}
}
QList<int> timeSteps(int paymentOptionIndex=0) const {
if (m_timeSteps.size() > 0) {
if (m_timeSteps.size() > 0 && paymentOptionIndex < m_timeSteps.size()) {
return m_timeSteps[paymentOptionIndex];
}
return QList<int>();
@ -70,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, 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
@ -81,7 +82,8 @@ public:
/// <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, 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);
@ -131,10 +133,10 @@ private:
int durationMinutes);
//
uint32_t GetPriceForTimeStep(Configuration *cfg, int timeStep, int paymentOptionIndex=0) const;
uint32_t GetPriceForStep(Configuration *cfg, int step) const {
return GetPriceForTimeStep(cfg, step);
}
uint32_t GetPriceForTimeStep(Configuration *cfg, int timeStep, int paymentOptionIndex) const;
//uint32_t GetPriceForStep(Configuration *cfg, int step) const {
// return GetPriceForTimeStep(cfg, step, 0);
//}
uint32_t GetDurationForPrice(Configuration *cfg, int price) const;
uint32_t GetStepForPrice(Configuration *cfg, int price) const {
return GetDurationForPrice(cfg, price);

View File

@ -28,6 +28,7 @@
#include "tariff_interpolation.h"
#include "tariff_prepaid.h"
#include "tariff_carryover.h"
#include "tariff_permit_type.h"
#include <QVector>
#include <optional>
@ -47,12 +48,13 @@ public:
using TariffInterpolationType = std::multimap<int, ATBInterpolation>;
using TariffPrepaidType = std::multimap<int, ATBPrepaid>;
using TariffCarryOverType = std::multimap<int, ATBCarryOver>;
using TariffDurationType = std::multimap<int, ATBDuration>;
ATBProject project;
ATBCurrency Currency;
ATBDuration duration;
multimap<int, ATBDuration> Duration;
TariffDurationType Duration;
multimap<int, ATBPaymentMethod> PaymentMethod;
multimap<int, ATBPaymentRate> PaymentRate;
SpecialDaysWorktimeType SpecialDaysWorktime;
@ -91,7 +93,12 @@ public:
bool isDayIncludedAsSpecialDay(uint64_t businessHours, QDateTime const &dt) const;
bool isDayIncludedAsSpecialDay(uint64_t businessHours, int specialDayId) const;
std::optional<QVector<ATBPaymentRate>> getPaymentRateForAllKeys() const;
std::optional<QVector<ATBPaymentOption>> getPaymentOptionsForAllKeys() const;
std::optional<ATBPaymentOption> getPaymentOptionForId(int key) const;
std::optional<QVector<ATBPaymentRate>> getPaymentRateForKey(int key) const;
std::optional<ATBPaymentOption> getPaymentOptionForKey(PERMIT_TYPE permitType) const;
std::optional<ATBPaymentOption> getPaymentOptionForKey(int permitType) const;
std::optional<ATBPaymentOption> getPaymentOptionForKey(QString const &permitType) const;
std::optional<QVector<ATBDailyTicket>> getDailyTicketsForAllKeys() const;
std::optional<QVector<ATBDailyTicket>> getDailyTicketsForKey(int key) const;
std::optional<ATBInterpolation> getInterpolationType(int type) const;
@ -103,8 +110,11 @@ public:
std::optional<QVector<ATBTariffProduct>> getTariffProductForProductTypeName(QString const &permitTypeName) const;
std::optional<ATBCustomer> getCustomerForType(ATBCustomer::CustomerType customerType);
std::optional<ATBWeekDaysWorktime> getWeekDayWorkTime(QTime const &time, Qt::DayOfWeek dayOfWeek);
std::optional<QVector<ATBWeekDaysWorktime>> getAllWeekDayWorkTimes();
std::optional<QDateTime> prepaidStart(QDateTime const &start, int prepaid_option_id);
int getPaymentOptionIndex(PERMIT_TYPE permitType);
int getPaymentOptionIndex(PERMIT_TYPE permitType) const;
private:
/// <summary>

View File

@ -15,6 +15,8 @@ public:
void reset() {
pop_id = 0;
pop_label = "";
pop_product_id = -1;
pop_product_name = "";
pop_payment_method_id = 0;
pop_day_end_time = "";
pop_day_night_end_time = "";
@ -36,11 +38,19 @@ public:
pop_daily_card_price = -1;
pop_business_hours = -1;
pop_time_step_config = -1;
pop_use_only_upto_datetime = ""; // deprecated
pop_use_only_for_duration = 0; // deprecated
pop_plus_steps = 1; // +: jump <x=1> steps forward
pop_minus_steps = 1; // -: jump <x=1> steps backward
}
int pop_id;
std::string pop_label;
int pop_product_id;
QString pop_product_name;
int pop_payment_method_id;
QString pop_use_only_upto_datetime;
int pop_use_only_for_duration;
std::string pop_day_end_time;
std::string pop_day_night_end_time;
double pop_price_night;
@ -61,6 +71,8 @@ public:
int pop_time_step_config;
bool pop_accumulate_prices;
bool pop_accumulate_durations;
int pop_plus_steps;
int pop_minus_steps;
struct ATBMaxDateTime {
int direction;

View File

@ -122,6 +122,59 @@ struct PermitType {
return 7;
}
static PERMIT_TYPE toPermitType(QString const permitTypeStr) {
if (permitTypeStr == "DAY_TICKET") {
return PERMIT_TYPE::DAY_TICKET;
} else
if (permitTypeStr == "DAY_TICKET_ADULT") {
return PERMIT_TYPE::DAY_TICKET_ADULT;
} else
if (permitTypeStr == "DAY_TICKET_CHILD") {
return PERMIT_TYPE::DAY_TICKET_CHILD;
} else
if (permitTypeStr == "DAY_TICKET_ADULT") {
return PERMIT_TYPE::DAY_TICKET_ADULT;
} else
if (permitTypeStr == "DAY_TICKET_TEEN") {
return PERMIT_TYPE::DAY_TICKET_TEEN;
} else
if (permitTypeStr == "SHORT_TERM_PARKING") {
return PERMIT_TYPE::SHORT_TERM_PARKING;
} else
if (permitTypeStr == "SZEGED_START") {
return PERMIT_TYPE::SZEGED_START;
} else
if (permitTypeStr == "SZEGED_STOP") {
return PERMIT_TYPE::SZEGED_STOP;
} else
if (permitTypeStr == "FOOD_STAMP") {
return PERMIT_TYPE::FOOD_STAMP;
} else
if (permitTypeStr == "TWENTY_FOUR_HOURS_TICKET") {
return PERMIT_TYPE::TWENTY_FOUR_HOURS_TICKET;
} else
if (permitTypeStr == "SHORT_TERM_PARKING_PKW") {
return PERMIT_TYPE::SHORT_TERM_PARKING_PKW;
} else
if (permitTypeStr == "SHORT_TERM_PARKING_BUS") {
return PERMIT_TYPE::SHORT_TERM_PARKING_BUS;
} else
if (permitTypeStr == "SHORT_TERM_PARKING_CAMPER") {
return PERMIT_TYPE::SHORT_TERM_PARKING_CAMPER;
} else
if (permitTypeStr == "DAY_TICKET_PKW") {
return PERMIT_TYPE::DAY_TICKET_PKW;
} else
if (permitTypeStr == "DAY_TICKET_BUS") {
return PERMIT_TYPE::DAY_TICKET_BUS;
} else
if (permitTypeStr == "DAY_TICKET_CAMPER") {
return PERMIT_TYPE::DAY_TICKET_CAMPER;
}
return PERMIT_TYPE::INVALID;
}
QString toString() {
switch(m_permitType) {
case PERMIT_TYPE::DAY_TICKET:

View File

@ -3,6 +3,7 @@
#include <ctime>
#include <iostream>
#include <cmath>
#include <optional>
#include "day_of_week.h"
#include "configuration.h"
@ -62,6 +63,7 @@ namespace Utilities {
/// <returns></returns>
bool IsYearPeriodActive(Configuration* cfg, struct tm* currentDateTime);
bool IsYearPeriodActive(Configuration const *cfg, QDateTime const &currentDateTime);
std::optional<ATBPeriodYear> GetYearPeriodActive(Configuration const *cfg, QDateTime const &currentDateTime);
/// <summary>
/// Check permissions

View File

@ -4,8 +4,10 @@
class ATBWeekDaysWorktime
{
public:
int pwd_id;
int pwd_period_week_day_id;
int pwd_id;
int pwd_pop_id;
int pwd_next_id;
int pwd_period_week_day_id;
int pwd_period_day_in_week_id;
std::string pwd_time_from;
std::string pwd_time_to;

View File

@ -3,6 +3,8 @@
#include "calculator_functions.h"
#include "payment_option.h"
#include "utilities.h"
#include "tariff_global_defines.h"
#include "period_year.h"
#include <QFile>
#include <QFileInfo>
@ -34,9 +36,16 @@ int CALCULATE_LIBRARY_API get_minimal_parkingtime(Configuration const *cfg,
int paymentOptionIndex) {
int minTime = 0;
paymentOptionIndex = cfg->getPaymentOptionIndex(permitType);
qCritical() << __func__ << __LINE__ << "paymentOptionIndex" << paymentOptionIndex;
qCritical() << __func__ << __LINE__ << "permit" << PermitType(permitType).toString();
switch(permitType) {
case PERMIT_TYPE::SHORT_TERM_PARKING: { // e.g. szeged (customer_281)
qCritical() << __LINE__ << Calculator::GetInstance().GetTimeSteps((Configuration *)cfg, paymentOptionIndex);
minTime = cfg->getPaymentOptions(paymentOptionIndex).pop_min_time;
qCritical() << __func__ << __LINE__ << minTime;
} break;
case PERMIT_TYPE::DAY_TICKET_ADULT: {
} break;
@ -48,16 +57,19 @@ int CALCULATE_LIBRARY_API get_minimal_parkingtime(Configuration const *cfg,
// for each new sell-procedure, recomute the timesteps. implicitly, set
// the minimal parking time.
Calculator::GetInstance().ResetTimeSteps(paymentOptionIndex);
Calculator::GetInstance().GetTimeSteps((Configuration *)cfg, paymentOptionIndex);
qCritical() << __LINE__ << Calculator::GetInstance().GetTimeSteps((Configuration *)cfg, paymentOptionIndex);
minTime = qRound(cfg->getPaymentOptions(paymentOptionIndex).pop_min_time);
}
qCritical() << "minTime" << minTime;
return minTime;
}
int CALCULATE_LIBRARY_API get_maximal_parkingtime(Configuration const *cfg,
PERMIT_TYPE permitType,
int paymentOptionIndex) {
paymentOptionIndex = cfg->getPaymentOptionIndex(permitType);
int maxTime = 0;
switch(permitType) {
@ -71,10 +83,10 @@ int CALCULATE_LIBRARY_API get_maximal_parkingtime(Configuration const *cfg,
case PERMIT_TYPE::DAY_TICKET_CHILD: {
} break;
default: ;
maxTime = cfg->getPaymentOptions(paymentOptionIndex).pop_max_time;
}
return maxTime;
}
int CALCULATE_LIBRARY_API get_minimal_parkingprice(Configuration *cfg,
@ -82,21 +94,58 @@ int CALCULATE_LIBRARY_API get_minimal_parkingprice(Configuration *cfg,
int paymentOptionIndex,
QDateTime const &start) {
int minPrice = -1;
paymentOptionIndex = cfg->getPaymentOptionIndex(permitType);
switch(permitType) {
case PERMIT_TYPE::SHORT_TERM_PARKING: { // e.g. szeged (customer_281)
minPrice = cfg->getPaymentOptions(paymentOptionIndex).pop_min_price;
} break;
case PERMIT_TYPE::DAY_TICKET_ADULT: {
} break;
case PERMIT_TYPE::DAY_TICKET_TEEN: {
} break;
case PERMIT_TYPE::DAY_TICKET_CHILD: {
} break;
case PERMIT_TYPE::DAY_TICKET: {
minPrice = compute_product_price(cfg, permitType, start);
} break;
default: ;
int payment_method_id = cfg->getPaymentOptions(paymentOptionIndex).pop_payment_method_id;
if (payment_method_id == PaymentMethod::Degressive) {
// Degressive: new for Fuchs Technik (500), ValserAlm (Fane):
// the minimal price has to be calculated, in cannot be hard coded into
// the tariff file.
// The working times have a reference into the payment rates. Two special
// entries (with the numbers 1000/1001) point to the respective prices.
switch(permitType) {
default: {
// find the correct work time range
int weekDay = start.date().dayOfWeek();
std::optional<QVector<ATBWeekDaysWorktime>> const &wd = cfg->getAllWeekDayWorkTimes();
if (wd.has_value()) {
QVector<ATBWeekDaysWorktime> const &vec = wd.value();
for (int i = 0; i < vec.size(); ++i) {
ATBWeekDaysWorktime const &wt = vec[i];
if (wt.pwd_period_day_in_week_id == weekDay) {
if (start.time() >= QTime::fromString(QString::fromStdString(wt.pwd_time_from), Qt::ISODate)
&& start.time() <= QTime::fromString(QString::fromStdString(wt.pwd_time_to), Qt::ISODate)) {
// found worktime range
int pop_id = wt.pwd_pop_id; // 1000 or 1001
for (auto[itr, rangeEnd] = cfg->PaymentRate.equal_range(pop_id); itr != rangeEnd; ++itr) {
i = vec.size(); // to leave outer loop
minPrice = itr->second.pra_price; // this is now the minimal price
break;
}
}
}
}
}
}
}
} else {
switch(permitType) {
case PERMIT_TYPE::SHORT_TERM_PARKING: { // e.g. szeged (customer_281)
minPrice = cfg->getPaymentOptions(paymentOptionIndex).pop_min_price;
} break;
case PERMIT_TYPE::DAY_TICKET_ADULT: {
} break;
case PERMIT_TYPE::DAY_TICKET_TEEN: {
} break;
case PERMIT_TYPE::DAY_TICKET_CHILD: {
} break;
case PERMIT_TYPE::DAY_TICKET: {
minPrice = compute_product_price(cfg, permitType, start);
} break;
default:
minPrice = cfg->getPaymentOptions(paymentOptionIndex).pop_min_price;
}
}
return minPrice;
@ -199,8 +248,8 @@ int CALCULATE_LIBRARY_API compute_product_price(Configuration const *cfg,
if (product.size() > 0) {
if (productStart && productEnd) {
int pop_min_time = get_minimal_parkingtime(cfg); // in minutes
int pop_max_time = get_maximal_parkingtime(cfg); // in minutes
int pop_min_time = get_minimal_parkingtime(cfg, PERMIT_TYPE::TWENTY_FOUR_HOURS_TICKET); // in minutes
int pop_max_time = get_maximal_parkingtime(cfg, PERMIT_TYPE::TWENTY_FOUR_HOURS_TICKET); // in minutes
if (pop_max_time >= pop_min_time) {
*productStart = start;
*productEnd = start.addSecs(pop_max_time*60);
@ -214,7 +263,14 @@ int CALCULATE_LIBRARY_API compute_product_price(Configuration const *cfg,
} break;
case PERMIT_TYPE::SHORT_TERM_PARKING_PKW: {
qCritical() << "TODO: SHORT_TERM_PARKING_PKW";
PermitType p(permitType);
std::optional<ATBPaymentOption> const paymentOption = cfg->getPaymentOptionForKey(p.get());
if (paymentOption.has_value()) {
ATBPaymentOption option = paymentOption.value();
int const pop_daily_card_price = option.pop_daily_card_price;
qCritical() << "SHORT_TERM_PARKING_PKW: daily ticket price" << pop_daily_card_price;
return pop_daily_card_price;
}
} break;
case PERMIT_TYPE::SHORT_TERM_PARKING_BUS: {
qCritical() << "TODO: SHORT_TERM_PARKING_BUS";
@ -223,15 +279,34 @@ int CALCULATE_LIBRARY_API compute_product_price(Configuration const *cfg,
qCritical() << "TODO: SHORT_TERM_PARKING_CAMPER";
} break;
case PERMIT_TYPE::DAY_TICKET_PKW: {
int const pop_daily_card_price = cfg->getPaymentOptions().pop_daily_card_price;
qCritical() << "DAY_TICKET_PKW: daily ticket price" << pop_daily_card_price;
return pop_daily_card_price;
PermitType p(permitType);
std::optional<ATBPaymentOption> const paymentOption = cfg->getPaymentOptionForKey(p.get());
if (paymentOption.has_value()) {
ATBPaymentOption option = paymentOption.value();
int const pop_daily_card_price = option.pop_daily_card_price;
qCritical() << "DAY_TICKET_PKW: daily ticket price" << pop_daily_card_price;
return pop_daily_card_price;
}
} break;
case PERMIT_TYPE::DAY_TICKET_BUS: {
qCritical() << "TODO: DAY_TICKET_BUS";
PermitType p(permitType);
std::optional<ATBPaymentOption> const paymentOption = cfg->getPaymentOptionForKey(p.get());
if (paymentOption.has_value()) {
ATBPaymentOption option = paymentOption.value();
int const pop_daily_card_price = option.pop_daily_card_price;
qCritical() << "DAY_TICKET_BUS: daily ticket price" << pop_daily_card_price;
return pop_daily_card_price;
}
} break;
case PERMIT_TYPE::DAY_TICKET_CAMPER: {
qCritical() << "TODO: DAY_TICKET_CAMPER";
PermitType p(permitType);
std::optional<ATBPaymentOption> const paymentOption = cfg->getPaymentOptionForKey(p.get());
if (paymentOption.has_value()) {
ATBPaymentOption option = paymentOption.value();
int const pop_daily_card_price = option.pop_daily_card_price;
qCritical() << "DAY_TICKET_CAMPER: daily ticket price" << pop_daily_card_price;
return pop_daily_card_price;
}
} break;
default:
break;
@ -246,6 +321,8 @@ int CALCULATE_LIBRARY_API get_maximal_parkingprice(Configuration *cfg,
int maxPrice = -1;
static const PaymentMethod paymentMethodId = Utilities::getPaymentMethodId(cfg);
paymentOptionIndex = cfg->getPaymentOptionIndex(permitType);
switch(permitType) {
case PERMIT_TYPE::SHORT_TERM_PARKING: { // e.g. szeged (customer_281)
if (paymentMethodId == PaymentMethod::Progressive || paymentMethodId == PaymentMethod::Steps) {
@ -269,6 +346,28 @@ int CALCULATE_LIBRARY_API get_maximal_parkingprice(Configuration *cfg,
break;
case PERMIT_TYPE::DAY_TICKET_CHILD:
break;
case PERMIT_TYPE::DAY_TICKET_BUS:
break;
case PERMIT_TYPE::DAY_TICKET_CAMPER:
break;
case PERMIT_TYPE::DAY_TICKET_PKW:
break;
case PERMIT_TYPE::SHORT_TERM_PARKING_BUS: {
std::optional<ATBPaymentOption> po = cfg->getPaymentOptionForKey(permitType);
if (po.has_value()) {
ATBPaymentOption option = po.value();
return option.pop_max_price;
}
} break;
case PERMIT_TYPE::SHORT_TERM_PARKING_PKW: {
std::optional<ATBPaymentOption> po = cfg->getPaymentOptionForKey(permitType);
if (po.has_value()) {
ATBPaymentOption option = po.value();
return option.pop_max_price;
}
} break;
case PERMIT_TYPE::SHORT_TERM_PARKING_CAMPER:
break;
default: ;
}
@ -338,11 +437,13 @@ CalcState CALCULATE_LIBRARY_API init_tariff(parking_tariff_t **tariff, char cons
if (! (*tariff)->ParseJson(*tariff, json.toStdString().c_str())) {
delete *tariff;
*tariff = nullptr;
qCritical() << " ... error parsing tariff";
return calcState.set(CalcState::State::ERROR_PARSING_TARIFF);
}
} else {
delete *tariff;
*tariff = nullptr;
qCritical() << " ... error loading tariff";
return calcState.set(CalcState::State::ERROR_LOADING_TARIFF);
}
@ -359,10 +460,27 @@ 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)
int CALCULATE_LIBRARY_API compute_next_timestep(parking_tariff_t *tariff, int currentTimeMinutes,
int UpDown, PermitType const &permitType)
{
qCritical() << " compute_next_timestep() currentTimeMinutes: " << currentTimeMinutes;
qCritical() << " compute_next_timestep() up/down (1=up, 0=down): " << UpDown;
qCritical() << __LINE__ << "compute_next_timestep() currentTimeMinutes: " << currentTimeMinutes;
qCritical() << __LINE__ << "compute_next_timestep() up/down (1=up, 0=down): " << UpDown;
// FIXME
//std::optional<ATBPaymentOption> paymentOption = tariff->getPaymentOptionForKey(permitType.get());
//if (!paymentOption.has_value()) {
// qCritical() << " compute_next_timestep() ERROR";
// return currentTimeMinutes;
//}
int const paymentOptionIndex = tariff->getPaymentOptionIndex(permitType);
int const &pop_plus_steps = tariff->getPaymentOptions(paymentOptionIndex).pop_plus_steps;
int const &pop_minus_steps = tariff->getPaymentOptions(paymentOptionIndex).pop_minus_steps;
qCritical() << __LINE__ << "compute_next_timestep() payment option index: " << paymentOptionIndex;
qCritical() << __LINE__ << "compute_next_timestep() plus steps: " << pop_plus_steps;
qCritical() << __LINE__ << "compute_next_timestep() minus steps: " << pop_minus_steps;
Configuration const *cfg = tariff;
@ -370,19 +488,19 @@ int CALCULATE_LIBRARY_API compute_next_timestep(parking_tariff_t *tariff, int cu
PaymentMethod const paymentMethodId = Utilities::getPaymentMethodId(cfg);
switch (paymentMethodId) {
case PaymentMethod::Progressive:
qCritical() << " compute_next_timestep() paymentMethodId: Progressive";
qCritical() << __LINE__ << "compute_next_timestep() paymentMethodId: Progressive";
break;
case PaymentMethod::Degressive:
qCritical() << " compute_next_timestep() paymentMethodId: Degressive";
qCritical() << __LINE__ << "compute_next_timestep() paymentMethodId: Degressive";
break;
case PaymentMethod::Linear:
qCritical() << " compute_next_timestep() paymentMethodId: Linear";
qCritical() << __LINE__ << "compute_next_timestep() paymentMethodId: Linear";
break;
case PaymentMethod::Steps:
qCritical() << " compute_next_timestep() paymentMethodId: Steps";
qCritical() << __LINE__ << "compute_next_timestep() paymentMethodId: Steps";
break;
case PaymentMethod::Undefined:
qCritical() << " compute_next_timestep() paymentMethodId: Undefined";
qCritical() << __LINE__ << "compute_next_timestep() paymentMethodId: Undefined";
break;
}
@ -390,59 +508,106 @@ int CALCULATE_LIBRARY_API compute_next_timestep(parking_tariff_t *tariff, int cu
// without given YearPeriod, SpecialDays and SpecialDaysWorktime
if ((paymentMethodId == PaymentMethod::Steps) ||
// progressive tariff: e.g. Neuhauser, Kirchdorf (743)
(paymentMethodId == PaymentMethod::Progressive))
(paymentMethodId == PaymentMethod::Progressive) ||
// degressive tariff: e.g. Fuchs Technik (500)
(paymentMethodId == PaymentMethod::Degressive))
{
QList<int> &stepList = Calculator::GetInstance().GetTimeSteps(tariff);
QList<int> &stepList = Calculator::GetInstance().GetTimeSteps(tariff, paymentOptionIndex);
int const size = stepList.size();
if (size == 0) {
qCritical() << "compute_next_timestep() *ERROR empty step-list*";
return currentTimeMinutes;
}
qCritical() << " compute_next_timestep() first time step:" << stepList[0];
qCritical() << " compute_next_timestep() timeSteps:" << stepList;
qCritical() << " compute_next_timestep() currentTimeInMinutes:" << currentTimeMinutes;
qCritical() << __LINE__ << "compute_next_timestep() first time step:" << stepList[0];
qCritical() << __LINE__ << "compute_next_timestep() timeSteps:" << stepList;
qCritical() << __LINE__ << "compute_next_timestep() currentTimeInMinutes:" << currentTimeMinutes;
// consider time shift: the step-list might have been computed at a
// slightly different time point
int currentStepIndex = stepList.indexOf(currentTimeMinutes);
if (currentStepIndex == -1) {
unsigned minimalDistance = ~0;
int j = -1;
for (int i = 0; i < stepList.size(); ++i) {
unsigned distance = std::abs(stepList[i] - currentTimeMinutes);
if (distance < minimalDistance) {
minimalDistance = distance;
j = i;
}
}
// max. tolerance set to 3 minutes
unsigned const tolerance = std::min(minimalDistance, (unsigned)(3));
if (j != -1) {
stepList[j] = currentTimeMinutes;
}
}
#if 0
int maxStep = -1;
if (size >= 2) {
maxStep = stepList[1] - stepList[0];
}
int tolerance = (maxStep == -1) ? 5 : std::min(maxStep, 5);
// max. tolerance set to 5 minutes
int const tolerance = (maxStep == -1) ? 5 : std::min(maxStep, 5);
for (int i=0; i < stepList.size(); ++i) {
if (std::abs(stepList[i] - currentTimeMinutes) <= tolerance) {
qCritical().noquote()
<< QString(" compute_next_timestep() correction stepList[%1]=%2 -> %3:")
<< __LINE__ << QString("compute_next_timestep() correction stepList[%1]=%2 -> %3:")
.arg(i).arg(stepList[0]).arg(currentTimeMinutes);
stepList[i] = currentTimeMinutes;
qCritical() << " compute_next_timestep() NEW timeSteps:" << stepList;
qCritical() << __LINE__ << "compute_next_timestep() NEW timeSteps:" << stepList;
}
}
int currentStepIndex = stepList.indexOf(currentTimeMinutes);
#endif
currentStepIndex = stepList.indexOf(currentTimeMinutes);
qCritical() << __LINE__ << "compute_next_timestep() currentStepIndex (" << currentStepIndex << ")";
if (currentStepIndex == -1) {
qCritical() << "compute_next_timestep() *NO STEP* for currentTimeMinutes (" << currentTimeMinutes << ")";
qCritical() << __LINE__ << "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 << ")";
qCritical() << __LINE__ << "compute_next_timestep() *NO NEXT STEP* for currentTimeMinutes (" << currentTimeMinutes << ")";
return currentTimeMinutes;
}
else {
return stepList[currentStepIndex + 1];
int const rest = currentStepIndex % pop_plus_steps;
if (rest) {
currentStepIndex -= rest;
}
qCritical() << __LINE__ << "compute_next_timestep() currentStepIndex (" << currentStepIndex << ")";
int const nextStepIndex = currentStepIndex + pop_plus_steps;
qCritical() << __LINE__ << "compute_next_timestep() next step index:" << nextStepIndex;
if (nextStepIndex >= 0 && nextStepIndex < stepList.size()) {
qCritical() << __LINE__ << "compute_next_timestep() return next time step:" << stepList[nextStepIndex];
return stepList[nextStepIndex];
}
}
}
if (UpDown == 0) { // DOWN
if (stepList[currentStepIndex] == stepList.first()) {
qCritical() << "compute_next_timestep() *NO PREVIOUS STEP* for currentTimeMinutes (" << currentTimeMinutes << ")";
qCritical() << __LINE__ << "compute_next_timestep() *NO PREVIOUS STEP* for currentTimeMinutes (" << currentTimeMinutes << ")";
return currentTimeMinutes;
}
else {
return stepList[currentStepIndex - 1];
int const nextStepIndex = currentStepIndex - pop_minus_steps;
qCritical() << __LINE__ << "compute_next_timestep() next step index:" << nextStepIndex;
if (nextStepIndex >= 0 && nextStepIndex < stepList.size()) {
qCritical() << __LINE__ << "compute_next_timestep() return next time step:" << stepList[nextStepIndex];
return stepList[nextStepIndex];
}
}
}
} else
@ -482,12 +647,17 @@ int CALCULATE_LIBRARY_API compute_next_timestep(parking_tariff_t *tariff, int cu
// this is currently not used
CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket(
parking_tariff_t *tariff,
time_t start_parking_time, // in minutes
time_t end_parking_time, // netto time in minutes
struct price_t *price) {
time_t start_parking_time, // in minutes
time_t end_parking_time, // netto time in minutes
struct price_t *price,
PermitType permitType) { // permitType maps to product
CalcState calcState;
double minMin = tariff->PaymentOption.find(tariff->getPaymentOptions().pop_payment_method_id)->second.pop_min_time;
double maxMin = tariff->PaymentOption.find(tariff->getPaymentOptions().pop_payment_method_id)->second.pop_max_time;
int const paymentOptionIndex = tariff->getPaymentOptionIndex(permitType.get());
double minMin = tariff->PaymentOption.find(tariff->getPaymentOptions(paymentOptionIndex).pop_payment_method_id)->second.pop_min_time;
double maxMin = tariff->PaymentOption.find(tariff->getPaymentOptions(paymentOptionIndex).pop_payment_method_id)->second.pop_max_time;
if (minMin < 0 || maxMin < 0 || maxMin < minMin) {
calcState.setDesc(QString("minMin=%1, maxMin=%2").arg(minMin).arg(maxMin));
@ -520,13 +690,13 @@ CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket(
if (start.isValid()) {
double cost = Calculator::GetInstance().GetCostFromDuration(
tariff,
tariff->getPaymentOptions().pop_payment_method_id,
tariff->getPaymentOptions(paymentOptionIndex).pop_payment_method_id,
start,
end,
duration, false, true);
double minCost = tariff->PaymentOption.find(tariff->getPaymentOptions().pop_payment_method_id)->second.pop_min_price;
double minCost = tariff->PaymentOption.find(tariff->getPaymentOptions(paymentOptionIndex).pop_payment_method_id)->second.pop_min_price;
if (cost < minCost) {
calcState.setDesc(QString("minCost=%1, cost=%2").arg(minCost).arg(cost));
calcState.setDesc(QString("line=%1 minCost=%2, cost=%3").arg(__LINE__).arg(minCost).arg(cost));
return calcState.set(CalcState::State::BELOW_MIN_PARKING_PRICE);
}
price->units = cost;
@ -540,15 +710,18 @@ CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket(
CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket(
parking_tariff_t *tariff,
QDateTime &start_parking_time,
QDateTime &start_parking_time_,
int netto_parking_time,
QDateTime &end_parking_time,
struct price_t *price,
PermitType permitType,
bool prepaid)
{
CalcState calcState;
int paymentOptionIndex = tariff->getPaymentOptionIndex(start_parking_time);
QDateTime start_parking_time(start_parking_time_);
int paymentOptionIndex = tariff->getPaymentOptionIndex(permitType);
double minMin = tariff->getPaymentOptions(paymentOptionIndex).pop_min_time;
double maxMin = tariff->getPaymentOptions(paymentOptionIndex).pop_max_time;
@ -560,8 +733,9 @@ CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket(
<< " netto_parking_time: " << netto_parking_time << endl
<< " start + netto: " << start_parking_time.addSecs(netto_parking_time * 60) << endl
<< " minMin: " << minMin << endl
<< " maxMin: " << maxMin;
<< " maxMin: " << maxMin
<< " prepaid: " << prepaid
<< " permitType: " << permitType.toString();
if (netto_parking_time < 0) {
calcState.setDesc(QString("end=%1, start=%2")
@ -583,20 +757,69 @@ CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket(
double cost = -1;
if (start_parking_time.isValid()) {
if (tariff->getPaymentOptions(paymentOptionIndex).pop_payment_method_id == PaymentMethod::Steps) {
if (tariff->getPaymentOptions(paymentOptionIndex).pop_payment_method_id == PaymentMethod::Steps ||
tariff->getPaymentOptions(paymentOptionIndex).pop_payment_method_id == PaymentMethod::Degressive) {
// hier muesste man unterscheiden: uebertrag oder nicht?
calcState = Calculator::GetInstance().isParkingAllowed(tariff, start_parking_time,
netto_parking_time, paymentOptionIndex);
if (calcState.getStatus() == CalcState::State::OUTSIDE_ALLOWED_PARKING_TIME) {
// qCritical() << "(" << __func__ << ":" << __LINE__ << ")"
// << calcState.toString();
qCritical() << "(" << __func__ << ":" << __LINE__ << ")"
<< calcState.toString();
return calcState;
}
cost = Calculator::GetInstance().GetCostFromDuration(tariff, start_parking_time, netto_parking_time, paymentOptionIndex);
end_parking_time = start_parking_time.addSecs(netto_parking_time*60);
// qCritical() << "(" << __func__ << ":" << __LINE__ << ")"
// << "end_parking_time" << end_parking_time.toString(Qt::ISODate);
QList<int> tlist = Calculator::GetInstance().GetTimeSteps(tariff);
Q_UNUSED(tlist);
// compute cost (price)
cost = Calculator::GetInstance().GetCostFromDuration(tariff, start_parking_time, netto_parking_time, paymentOptionIndex);
int weekDay = start_parking_time.date().dayOfWeek();
int pop_carry_over_option_id = tariff->getPaymentOptions(paymentOptionIndex).pop_carry_over_option_id;
qCritical() << __func__ << __LINE__ << "configured carry-over-id" << pop_carry_over_option_id;
std::optional<ATBPeriodYear> yperiod = Utilities::GetYearPeriodActive(tariff, start_parking_time);
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;
}
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;
// handle prepaid option
QDateTime effectiveStartTime(start_parking_time);
int const prepaid_option_id = tariff->getPaymentOptions(paymentOptionIndex).pop_prepaid_option_id;
std::optional<ATBPrepaid> prepaidOption = tariff->getPrepaidType(prepaid_option_id);
if (prepaidOption.has_value()) {
ATBPrepaid const &p = prepaidOption.value();
if (p.never) {
qCritical() << __func__ << __LINE__ << "prepaid: no";
} else {
if (start_parking_time.time() < p.static_end) { // static_end: e.g. 08:00:00
effectiveStartTime.setTime(p.static_end);
} else
if (start_parking_time.time() > p.static_start) { // static_start: e.g. 22:00:00
effectiveStartTime.setTime(p.static_start);
}
}
}
// handle carry over
int minutesUntilCarryOver = effectiveStartTime.time().secsTo(carryOverStart) / 60;
if (netto_parking_time > minutesUntilCarryOver) {
int const rest = netto_parking_time - minutesUntilCarryOver;
QDateTime s(effectiveStartTime);
s = s.addSecs(minutesUntilCarryOver * 60);
s = s.addSecs(carryOverDuration * 60);
end_parking_time = s.addSecs(rest * 60);
} else {
end_parking_time = effectiveStartTime.addSecs(netto_parking_time*60);
}
} else {
cost = Calculator::GetInstance().GetCostFromDuration(
@ -607,15 +830,16 @@ CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket(
netto_parking_time, // minutes, netto
false, prepaid);
}
// qCritical() << __func__ << __LINE__;
double minCost = tariff->getPaymentOptions(paymentOptionIndex).pop_min_price;
if (cost < minCost) {
calcState.setDesc(QString("minCost=%1, cost=%2").arg(minCost).arg(cost));
calcState.setDesc(QString("line=%1 minCost=%2, cost=%3").arg(__LINE__).arg(minCost).arg(cost));
return calcState.set(CalcState::State::BELOW_MIN_PARKING_PRICE);
}
// DEBUG
qCritical() << " end_parking_time: " << end_parking_time;
qCritical() << " -> calculated cost (netto): " << cost;
//qCritical() << __LINE__ << " end_parking_time: " << end_parking_time;
//qCritical() << __LINE__ << " -> calculated cost (netto): " << cost;
price->brutto = price->vat = price->vat_percentage = 0;
price->units = cost;
@ -625,6 +849,12 @@ CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket(
return calcState.set(CalcState::State::INVALID_START_DATE);
}
if (end_parking_time.time().hour() == 0 && end_parking_time.time().minute() == 0) {
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);
return calcState.set(CalcState::State::SUCCESS);
}
@ -632,7 +862,8 @@ CalcState CALCULATE_LIBRARY_API compute_duration_for_parking_ticket(
parking_tariff_t *tariff,
time_t start_parking_time,
double price,
QString &duration) {
QString &duration,
PermitType permitType) {
CalcState calcState;
QDate const d(1970, 1, 1);
QTime const t(0, 0, 0);
@ -641,15 +872,25 @@ CalcState CALCULATE_LIBRARY_API compute_duration_for_parking_ticket(
if (start.isValid()) {
QString cs = start.toString(Qt::ISODate);
bool prepaid = true;
int paymentOptionIndex = tariff->getPaymentOptionIndex(permitType);
int prepaid_option_id = tariff->getPaymentOptions(paymentOptionIndex).pop_prepaid_option_id;
if (prepaid_option_id == 2) { // see tariff03.json for 502: 2 means no prepaid-option
prepaid = false;
}
bool const nextDay = false;
// DEBUG
qCritical() << "compute_duration_for_parking_ticket(): ";
qCritical() << " start (cs): " << cs;
qCritical() << " price: " << price;
qCritical() << "compute_duration_for_parking_ticket(1): ";
qCritical() << " payment option index: " << paymentOptionIndex;
qCritical() << " prepaid: " << prepaid;
qCritical() << " start (cs): " << cs;
qCritical() << " price: " << price;
duration = Calculator::GetInstance().GetDurationFromCost(tariff,
tariff->getPaymentOptions().pop_payment_method_id,
tariff->getPaymentOptions(paymentOptionIndex).pop_payment_method_id,
cs.toLocal8Bit().constData(),
price, false, true).c_str();
price, permitType, nextDay, prepaid).c_str();
QDateTime d = QDateTime::fromString(duration, Qt::ISODate);
if (!d.isValid()) {
calcState.setDesc(QString("ticketEndTime=%1").arg(duration));
@ -666,16 +907,34 @@ CalcState CALCULATE_LIBRARY_API compute_duration_for_parking_ticket(
parking_tariff_t *tariff,
QDateTime const &start_parking_time,
double price,
QDateTime &ticketEndTime)
QDateTime &ticketEndTime,
PermitType permitType)
{
CalcState calcState;
bool prepaid = true;
int paymentOptionIndex = tariff->getPaymentOptionIndex(permitType);
int prepaid_option_id = tariff->getPaymentOptions(paymentOptionIndex).pop_prepaid_option_id;
if (prepaid_option_id == 2) {
prepaid = false;
}
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 (start_parking_time.isValid()) {
QString cs = start_parking_time.toString(Qt::ISODate);
QString endTime = Calculator::GetInstance().GetDurationFromCost(
tariff,
tariff->getPaymentOptions().pop_payment_method_id,
cs.toLocal8Bit().constData(),
price, false, true).c_str();
price, permitType, nextDay, prepaid).c_str();
if (endTime == CalcState::SUCCESS) {
calcState.setDesc(QString("SUCCESS"));
@ -754,7 +1013,10 @@ CalcState CALCULATE_LIBRARY_API compute_duration_for_parking_ticket(
return calcState.set(CalcState::State::SUCCESS);
}
CalcState CALCULATE_LIBRARY_API compute_duration_for_daily_ticket(parking_tariff_t *tariff, QDateTime const &start_parking_time, QDateTime &ticketEndTime)
CalcState CALCULATE_LIBRARY_API compute_duration_for_daily_ticket(parking_tariff_t *tariff,
QDateTime const &start_parking_time,
QDateTime &ticketEndTime,
PermitType PermitType)
{
CalcState calcState;
if (start_parking_time.isValid()) {

View File

@ -9,6 +9,7 @@
#include <sstream>
#include <algorithm>
#include <optional>
#include <QDateTime>
#include <QScopedArrayPointer>
#include <QDebug>
@ -121,6 +122,7 @@ std::string Calculator::GetDurationFromCost(Configuration* cfg,
uint8_t payment_option,
char const *startDatetimePassed, // given in local time
double cost,
PermitType permitType,
bool nextDay,
bool prepaid)
{
@ -128,14 +130,114 @@ std::string Calculator::GetDurationFromCost(Configuration* cfg,
Q_UNUSED(nextDay);
// Get input date
QDateTime inputDate = QDateTime::fromString(startDatetimePassed,Qt::ISODate);
QDateTime inputDate = QDateTime::fromString(startDatetimePassed, Qt::ISODate);
inputDate.setTime(QTime(inputDate.time().hour(), inputDate.time().minute(), 0));
static const PaymentMethod paymentMethodId = Utilities::getPaymentMethodId(cfg);
int const paymentOptionIndex = cfg->getPaymentOptionIndex(permitType.get());
//qCritical() << DBG_HEADER << " start" << inputDate.toString(Qt::ISODate);
//qCritical() << DBG_HEADER << "paymentMethodId" << static_cast<int>(paymentMethodId);
if (DBG_LEVEL >= DBG_DEBUG) {
qCritical() << DBG_HEADER << " start:" << inputDate.toString(Qt::ISODate);
qCritical() << DBG_HEADER << " option index:" << paymentOptionIndex;
qCritical() << DBG_HEADER << "paymentMethodId:" << static_cast<int>(paymentMethodId);
qCritical() << DBG_HEADER << " prepaid:" << prepaid;
qCritical() << DBG_HEADER << " cost (price):" << cost;
}
Calculator::GetInstance().GetTimeSteps(cfg, 0, inputDate);
QList<int> tsteps = Calculator::GetInstance().GetTimeSteps(cfg, paymentOptionIndex, inputDate);
if (DBG_LEVEL >= DBG_DEBUG) {
qCritical() << DBG_HEADER << " time steps:" << tsteps;
} else {
Q_UNUSED(tsteps);
}
if (paymentMethodId == PaymentMethod::Degressive) {
if (static_cast<int>(cost) < cfg->getPaymentOptions(paymentOptionIndex).pop_min_price) {
// minimal price is set by GetTimeSteps()
qCritical() << DBG_HEADER << " provided price (cost):" << cost;
qCritical() << DBG_HEADER << "configured minimal price:" << cfg->getPaymentOptions(paymentOptionIndex).pop_min_price;
return CalcState::BELOW_MIN_PARKING_PRICE.toStdString();
}
if (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;
// qCritical() << DBG_HEADER << " pop id:" << pop_id;
int price = 0;
int new_price = 0;
int durationInMinutes = 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;
int const durationId = itr->second.pra_payment_unit_id;
if (pop_accumulate_prices) {
price += pra_price;
} else {
price = pra_price;
}
//qCritical() << DBG_HEADER << " PRICE" << price << "COST" << cost;
//qCritical() << DBG_HEADER << " duration id" << durationId;
auto search = cfg->Duration.find(durationId);
if (search != cfg->Duration.end()) {
// found now the duration in minutes
// check if we are still inside the working-time-range
ATBDuration duration = search->second;
if (pop_accumulate_prices) {
uint32_t const durationUnit = cfg->Duration.find(durationId)->second.pun_duration;
new_price += pra_price;
// qCritical() << "(" << __func__ << ":" << __LINE__ << ") old price" << price << ", new_price:" << new_price;
if (new_price <= cost) {
duration_previous = durationUnit;
if (pop_accumulate_durations) {
durationInMinutes += durationUnit;
}
//qCritical() << "(" << __func__ << ":" << __LINE__ << ") duration_previous" << duration_previous;
//qCritical() << "(" << __func__ << ":" << __LINE__ << ") duration in minutes" << durationInMinutes;
//qCritical() << "(" << __func__ << ":" << __LINE__ << ") old price" << price << ", new_price:" << new_price;
} else {
//found = true;
//qCritical() << "(" << __func__ << ":" << __LINE__ << ") duration_previous" << duration_previous;
//qCritical() << "(" << __func__ << ":" << __LINE__ << ") duration in minutes" << durationInMinutes;
QDateTime d(inputDate.addSecs(duration_previous * 60));
qCritical() << DBG_HEADER << " provided price (cost):" << cost;
qCritical() << DBG_HEADER << " computed time for price (minutes):" << duration_previous;
qCritical() << DBG_HEADER << "configured minimal parking time (minutes):" << cfg->getPaymentOptions(paymentOptionIndex).pop_min_time;
if (duration_previous < cfg->getPaymentOptions(paymentOptionIndex).pop_min_time) {
return CalcState::BELOW_MIN_PARKING_TIME.toStdString(); // minimal parking time is set by GetTimeSteps()
}
return d.toString(Qt::ISODate).toStdString();
}
}
if ((double)price == cost) {
QDateTime d(inputDate.addSecs(durationInMinutes * 60));
QString const durationStr(d.toString(Qt::ISODate));
qCritical() << DBG_HEADER << " duration in minutes:" << durationInMinutes;
qCritical() << DBG_HEADER << " provided price (cost):" << cost;
qCritical() << DBG_HEADER << " duration for price:" << durationStr;
return durationStr.toStdString();
}
}
}
} else {
qCritical() << DBG_HEADER << " TODO";
}
} else
if (paymentMethodId == PaymentMethod::Steps) {
if (tariffIs24_7(cfg)) {
// use tariff with structure as for instance Schoenau, Koenigsee:
@ -152,15 +254,14 @@ std::string Calculator::GetDurationFromCost(Configuration* cfg,
}
}
// TODO: man braucht den richtigen Index
int paymentOptionIndex = 0;
int const pop_id = cfg->getPaymentOptions(paymentOptionIndex).pop_id;
int const pop_max_price = cfg->getPaymentOptions(paymentOptionIndex).pop_max_price;
int const pop_min_price = cfg->getPaymentOptions(paymentOptionIndex).pop_min_price;
if (cost > pop_max_price) {
cost = pop_max_price;
qCritical() << DBG_HEADER << "MAX-PARKING-PRICE" << pop_max_price << ", COST" << cost;
return CalcState::OVERPAID.toStdString();
//return CalcState::OVERPAID.toStdString();
}
if (cost < pop_min_price) {
@ -178,7 +279,7 @@ std::string Calculator::GetDurationFromCost(Configuration* cfg,
// in this case, adapt inputDate accordingly.
// #define DEBUG_GET_DURATION_FROM_COST 1
#define DEBUG_GET_DURATION_FROM_COST 0
#if DEBUG_GET_DURATION_FROM_COST==1
qCritical() << DBG_HEADER << "PRE-PAID-OPTION: ADAPT-INPUT-DATE" << inputDate.toString(Qt::ISODate);
#endif
@ -192,6 +293,9 @@ std::string Calculator::GetDurationFromCost(Configuration* cfg,
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);
//qCritical() << DBG_HEADER << "from" << pwd_time_from.toString(Qt::ISODate);
//qCritical() << DBG_HEADER << " to" << pwd_time_to.toString(Qt::ISODate);
if (inputDate.time() < pwd_time_from) {
inputDate.setTime(pwd_time_from);
useWeekDaysWorkTimeOfOtherDay = false;
@ -228,15 +332,21 @@ std::string Calculator::GetDurationFromCost(Configuration* cfg,
}
}
}
} else {
qCritical() << "(" << __func__ << ":" << __LINE__ << "no prepaid";
}
#if DEBUG_GET_DURATION_FROM_COST==1
qCritical() << DBG_HEADER << "(ADAPTED) INPUT-DATE" << inputDate.toString(Qt::ISODate);
#endif
//qCritical() << __func__ << __LINE__;
// inputDate is now located in a valid operational-working-range
// find this working-time-range
int pwd_period_day_in_week_id = inputDate.date().dayOfWeek();
//qCritical() << __func__ << __LINE__ << pwd_period_day_in_week_id;
//qCritical() << __func__ << __LINE__ << cfg->WeekDaysWorktime.count(pwd_period_day_in_week_id);
if (cfg->WeekDaysWorktime.count(pwd_period_day_in_week_id) == 0) {
qCritical() << DBG_HEADER
<< "ERROR" << inputDate.toString(Qt::ISODate)
@ -244,12 +354,17 @@ std::string Calculator::GetDurationFromCost(Configuration* cfg,
return "";
}
//qCritical() << __func__ << __LINE__;
QTime current_working_time_from;
QTime current_working_time_to;
for (auto[iter, rEnd] = cfg->WeekDaysWorktime.equal_range(pwd_period_day_in_week_id); iter != rEnd; ++iter) {
QTime pwd_time_from = QTime::fromString(QString::fromStdString(iter->second.pwd_time_from), Qt::ISODate);
QTime pwd_time_to = QTime::fromString(QString::fromStdString(iter->second.pwd_time_to), Qt::ISODate);
//qCritical() << __func__ << pwd_time_from.toString(Qt::ISODate);
//qCritical() << __func__ << pwd_time_to.toString(Qt::ISODate);
//qCritical() << __func__ << inputDate.toString(Qt::ISODate);
if (pwd_time_from <= inputDate.time() && inputDate.time() <= pwd_time_to) {
current_working_time_from = pwd_time_from;
current_working_time_to = pwd_time_to;
@ -269,11 +384,14 @@ std::string Calculator::GetDurationFromCost(Configuration* cfg,
qCritical() << DBG_HEADER << " CURRENT WORKING-TIME-TO" << current_working_time_to.toString(Qt::ISODate);
#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;
int const durationId = itr->second.pra_payment_unit_id;
@ -283,18 +401,37 @@ std::string Calculator::GetDurationFromCost(Configuration* cfg,
price = pra_price;
}
//qCritical() << DBG_HEADER << " PRICE" << price << "COST" << cost;
// qCritical() << DBG_HEADER << " PRICE" << price << "COST" << cost;
auto search = cfg->Duration.find(durationId);
if (search != cfg->Duration.end()) {
// found now the duration in minutes
// check if we are still inside the working-time-range
ATBDuration duration = search->second;
//if (pop_accumulate_durations) {
// durationInSecs += duration.pun_duration * 60;
//} else {
durationInSecs = duration.pun_duration * 60;
//}
if (pop_accumulate_prices) {
uint32_t const durationUnit = cfg->Duration.find(durationId)->second.pun_duration;
new_price += pra_price;
//qCritical() << "(" << __func__ << ":" << __LINE__ << ") XXXXXX price:" << price;
//qCritical() << "(" << __func__ << ":" << __LINE__ << ") YYYYYY new_price:" << new_price;
if (new_price <= cost) {
duration_previous = durationUnit;
//qCritical() << "(" << __func__ << ":" << __LINE__ << ") ZZZZZZ duration_previous" << duration_previous;
} else {
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;
}
if ((double)price == cost) {
QDateTime current_working_date_time_to = inputDate;
@ -341,17 +478,30 @@ 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 << "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;
QDateTime upper = inputDate.addDays(days);
upper.setTime(next_working_time_from);
//qCritical() << DBG_HEADER << "UPPER" << upper.toString(Qt::ISODate);
QDateTime lower = inputDate;
lower.setTime(current_working_time_to);
inputDate = inputDate.addSecs(lower.secsTo(upper) + durationInSecs);
//qCritical() << DBG_HEADER << "LOWER" << lower.toString(Qt::ISODate);
// inputDate = inputDate.addSecs(lower.secsTo(upper));
//qCritical() << DBG_HEADER << "NEW INPUT" << inputDate.toString(Qt::ISODate);
inputDate = inputDate.addSecs(durationInSecs);
#if DEBUG_GET_DURATION_FROM_COST==1
qCritical() << DBG_HEADER << "TICKET-END" << inputDate.toString(Qt::ISODate);
#endif
@ -388,6 +538,11 @@ std::string Calculator::GetDurationFromCost(Configuration* cfg,
return s.toStdString();
} // if ((double)price == cost) {
else {
//qCritical() << DBG_HEADER;
}
} else {
//qCritical() << __func__ << __LINE__;
}
}
@ -841,8 +996,11 @@ uint32_t Calculator::GetCostFromDuration(Configuration *cfg,
int paymentOptionIndex) const {
// for instance, a tariff as used in Schoenau, Koenigssee: only steps, no
// special days, nonstop.
//qCritical() << __func__ << __LINE__ << "paymentOptionIndex" << paymentOptionIndex;
static const PaymentMethod paymentMethodId = Utilities::getPaymentMethodId(cfg);
if (paymentMethodId == PaymentMethod::Steps) {
if (paymentMethodId == PaymentMethod::Steps ||
paymentMethodId == PaymentMethod::Degressive) {
QDateTime const end = start.addSecs(timeStepInMinutes*60);
return GetCostFromDuration(cfg, start, end, paymentOptionIndex);
}
@ -854,8 +1012,16 @@ uint32_t Calculator::GetCostFromDuration(Configuration * cfg,
QDateTime const &end,
int paymentOptionIndex) const {
static const PaymentMethod paymentMethodId = Utilities::getPaymentMethodId(cfg);
if (paymentMethodId == PaymentMethod::Steps) {
//qCritical() << __func__ << __LINE__ << "paymentOptionIndex" << paymentOptionIndex;
if (paymentMethodId == PaymentMethod::Steps ||
paymentMethodId == PaymentMethod::Degressive) {
int const timeStepInMinutes = start.secsTo(end) / 60;
QList<int> tlist = Calculator::GetInstance().GetTimeSteps(cfg, paymentOptionIndex, start);
qCritical() << DBG_HEADER << "timeStepList" << timeStepInMinutes << tlist;
qCritical() << DBG_HEADER << "timeStepInMinutes" << timeStepInMinutes << start.toString(Qt::ISODate);
return GetPriceForTimeStep(cfg, timeStepInMinutes, paymentOptionIndex);
}
return 0;
@ -866,8 +1032,8 @@ CalcState Calculator::isParkingAllowedForWeekDay(Configuration const *cfg,
int netto_parking_time,
int paymentOptionIndex) {
qCritical() << DBG_HEADER << "start" << start.toString(Qt::ISODate)
<< "paymentOptionIndex" << paymentOptionIndex;
//qCritical() << DBG_HEADER << "start" << start.toString(Qt::ISODate)
// << "paymentOptionIndex" << paymentOptionIndex;
// TODO: wieder entfernen
return CalcState(CalcState::State::SUCCESS, "PARKING_ALLOWED", QTime(), QTime());
@ -1239,23 +1405,25 @@ double Calculator::GetCostFromDuration(Configuration* cfg,
QDateTime &start_datetime,
QDateTime &end_datetime,
int durationMinutes,
PermitType permitType,
bool nextDay,
bool prepaid) {
Q_UNUSED(payment_option);
Q_UNUSED(nextDay);
int const paymentOptionIndex = cfg->getPaymentOptionIndex(permitType.get());
static const PaymentMethod paymentMethodId = Utilities::getPaymentMethodId(cfg);
if (paymentMethodId == PaymentMethod::Steps) {
if (tariffIs24_7(cfg)) {
end_datetime = start_datetime.addSecs(durationMinutes*60);
return GetCostFromDuration(cfg, start_datetime, end_datetime);
return GetCostFromDuration(cfg, start_datetime, end_datetime, paymentOptionIndex);
} else {
if (Utilities::IsYearPeriodActive(cfg, start_datetime)) {
if (!prepaid) {
CalcState cs = isParkingAllowed(cfg, start_datetime);
if (cs) {
end_datetime = start_datetime.addSecs(durationMinutes*60);
double cost = GetCostFromDuration(cfg, start_datetime, end_datetime);
double cost = GetCostFromDuration(cfg, start_datetime, end_datetime, paymentOptionIndex);
end_datetime = start_datetime;
end_datetime.setTime(cs.getAllowedTimeRange().getTimeUntil());
return cost;
@ -2130,9 +2298,6 @@ QList<int> Calculator::GetPriceSteps(Configuration * /*cfg*/) const {
QList<int> &Calculator::GetTimeSteps(Configuration *cfg, int paymentOptionIndex,
QDateTime const &s) const {
// TEST
// paymentOptionIndex = 1;
if (DBG_LEVEL >= DBG_DEBUG) {
qCritical() << "(" << __func__ << ":" << __LINE__ << ") paymentOptionIndex:" << paymentOptionIndex;
}
@ -2147,27 +2312,32 @@ QList<int> &Calculator::GetTimeSteps(Configuration *cfg, int paymentOptionIndex,
m_timeSteps[paymentOptionIndex].clear();
} else {
// int diff = paymentOp m_timeSteps.size()
m_timeSteps.push_back(QList<int>());
while (m_timeSteps.size() <= paymentOptionIndex) {
m_timeSteps.push_back(QList<int>());
}
}
QDateTime start = s;
start.setTime(QTime(s.time().hour(), s.time().minute(), 0));
if (DBG_LEVEL >= DBG_DEBUG) {
qCritical() << "(" << __func__ << ":" << __LINE__ << ") start:" << start.toString(Qt::ISODate);
}
int const pop_id = cfg->getPaymentOptions(paymentOptionIndex).pop_id;
int const pop_carry_over = cfg->getPaymentOptions(paymentOptionIndex).pop_carry_over;
int const pop_time_step_config = cfg->getPaymentOptions(paymentOptionIndex).pop_time_step_config;
int const pop_prepaid_option_id = cfg->getPaymentOptions(paymentOptionIndex).pop_prepaid_option_id;
static PaymentMethod const paymentMethodId = Utilities::getPaymentMethodId(cfg);
qCritical() << "(" << __func__ << ":" << __LINE__ << ") start parking time:" << start.toString(Qt::ISODate);
if (DBG_LEVEL >= DBG_DEBUG) {
qCritical() << "(" << __func__ << ":" << __LINE__ << ") start parking time:" << start.toString(Qt::ISODate);
qCritical() << "(" << __func__ << ":" << __LINE__ << ") payment option id:" << pop_id;
qCritical() << "(" << __func__ << ":" << __LINE__ << ") time step configuration:" << pop_time_step_config;
qCritical() << "(" << __func__ << ":" << __LINE__ << ") prepaid option id:" << pop_prepaid_option_id;
qCritical() << "(" << __func__ << ":" << __LINE__ << ") start parking time:" << start.toString(Qt::ISODate);
qCritical() << "(" << __func__ << ":" << __LINE__ << ") payment option id:" << pop_id;
qCritical() << "(" << __func__ << ":" << __LINE__ << ") payment method id:" << static_cast<int>(paymentMethodId);
qCritical() << "(" << __func__ << ":" << __LINE__ << ") time step config:" << pop_time_step_config;
qCritical() << "(" << __func__ << ":" << __LINE__ << ") prepaid option id:" << pop_prepaid_option_id;
}
if (pop_time_step_config == (int)ATBTimeStepConfig::TimeStepConfig::DYNAMIC) {
@ -2179,6 +2349,108 @@ QList<int> &Calculator::GetTimeSteps(Configuration *cfg, int paymentOptionIndex,
int const step = Utilities::getTimeRangeStep(cfg, id, paymentMethodId);
m_timeSteps[paymentOptionIndex].append(step);
}
} else
if (paymentMethodId == PaymentMethod::Degressive) { // e.g. fuchs, valser alm (fane) (502)
// with growing time, the price goes down
// for instance: until 13.59: price 8, from 14:00: price 5, then for the next day: 8
// for the following days: 8 euros
//qCritical() << "(" << __func__ << ":" << __LINE__ << ") degressive:";
//qCritical() << "(" << __func__ << ":" << __LINE__ << ") paymentOptionIndex:" << paymentOptionIndex;
m_timeSteps[paymentOptionIndex].clear();
// lookup pop_next_id in worktimes;
std::optional<QVector<ATBWeekDaysWorktime>> const &w = cfg->getAllWeekDayWorkTimes();
if (w.has_value()) {
QVector<ATBWeekDaysWorktime> const &vec = w.value();
//if (pop_carry_over == false) {
for (int i = 1; i <= vec.size(); ++i) {
QTime const &from = QTime::fromString(QString::fromStdString(vec[i-1].pwd_time_from), Qt::ISODate);
QString const &toStr = QString::fromStdString(vec[i-1].pwd_time_to);
QTime const &to = QTime::fromString(toStr, Qt::ISODate);
int weekDayId = vec[i-1].pwd_period_day_in_week_id;
if (start.date().dayOfWeek() == weekDayId) {
if (DBG_LEVEL >= DBG_DEBUG) {
qCritical() << "(" << __func__ << ":" << __LINE__ << ")" << weekDayId;
qCritical() << "(" << __func__ << ":" << __LINE__ << ") from" << from.toString(Qt::ISODate);
qCritical() << "(" << __func__ << ":" << __LINE__ << ") to" << to.toString(Qt::ISODate);
qCritical() << "(" << __func__ << ":" << __LINE__ << ") start" << start.toString(Qt::ISODate);
}
if (start.time() >= from && start.time() < to) {
int runtimeInMinutes = (start.time().secsTo(to) / 60);
if (to.hour() == 23 && to.minute() == 59) {
runtimeInMinutes += 1;
}
if (DBG_LEVEL >= DBG_DEBUG) {
qCritical() << "(" << __func__ << ":" << __LINE__ << ") runTimeInMinutes" << runtimeInMinutes;
qCritical() << "(" << __func__ << ":" << __LINE__ << ") index" << paymentOptionIndex;
}
// m_timeSteps[paymentOptionIndex] << runtimeInMinutes;
cfg->getPaymentOptions(paymentOptionIndex).pop_min_time = runtimeInMinutes;
int pop_id = vec[i-1].pwd_pop_id;
// int pwd_id = vec[i-1].pwd_id;
// int pwd_next_id = vec[i-1].pwd_next_id;
if (DBG_LEVEL >= DBG_DEBUG) {
qCritical() << "(" << __func__ << ":" << __LINE__ << ") pop_id" << pop_id;
}
int price = -1;
int durationId = -1;
for (auto[itr, rangeEnd] = cfg->PaymentRate.equal_range(pop_id); itr != rangeEnd; ++itr) {
durationId = itr->second.pra_payment_unit_id;
price = itr->second.pra_price;
auto search = cfg->Duration.find(durationId);
if (search != cfg->Duration.end()) {
ATBDuration duration = search->second;
duration.pun_duration = runtimeInMinutes;
search->second = duration;
break;
}
}
if (price >= 0 && durationId >= 0) {
if (DBG_LEVEL >= DBG_DEBUG) {
qCritical() << "(" << __func__ << ":" << __LINE__ << ") durationId" << durationId;
qCritical() << "(" << __func__ << ":" << __LINE__ << ") price" << price;
}
pop_id = cfg->getPaymentOptions(paymentOptionIndex).pop_id;
for (auto[itr, rangeEnd] = cfg->PaymentRate.equal_range(pop_id); itr != rangeEnd; ++itr) {
if (durationId == itr->second.pra_payment_unit_id) {
itr->second.pra_price = price;
cfg->getPaymentOptions(paymentOptionIndex).pop_min_price = price;
qCritical() << "(" << __func__ << ":" << __LINE__ << ") park min price" << price;
break;
}
}
}
break;
} // if (start.time() >= from && start.time() < to) {
} // if (start.date().dayOfWeek() == weekDayId) {
} // for (int i = 1; i <= vec.size(); ++i) {
m_timeSteps[paymentOptionIndex].clear();
int runtimeInMinutes = 0;
for (Configuration::TariffDurationType::const_iterator it = cfg->Duration.cbegin();
it != cfg->Duration.cend();
++it) {
runtimeInMinutes += it->second.pun_duration;
m_timeSteps[paymentOptionIndex] << runtimeInMinutes;
}
//} // if (pop_carry_over == false) {
} // if (w.has_value()) {
} else {
uint16_t timeStepCompensation = 0;
@ -2255,10 +2527,10 @@ QList<int> &Calculator::GetTimeSteps(Configuration *cfg, int paymentOptionIndex,
}
}
} else { // if (carryOverTimeRangeFrom == QTime(0, 0, 0)) {
if (DBG_LEVEL >= DBG_DEBUG) {
//if (DBG_LEVEL >= DBG_DEBUG) {
qCritical() << "(" << __func__ << ":" << __LINE__ << ") carry over time range from:" << carryOverTimeRangeFrom.toString(Qt::ISODate);
qCritical() << "(" << __func__ << ":" << __LINE__ << ") carry over time range to:" << carryOverTimeRangeTo.toString(Qt::ISODate);
}
//}
m_timeSteps[paymentOptionIndex].clear();
@ -2289,6 +2561,8 @@ QList<int> &Calculator::GetTimeSteps(Configuration *cfg, int paymentOptionIndex,
QDateTime nextTimeStep = start;
int runtimeInMinutes = 0;
// qCritical() << "(" << __func__ << ":" << __LINE__ << ") runtime in minutes (1):" << runtimeInMinutes;
int const pop_truncate_last_interpolation_step = cfg->getPaymentOptions(paymentOptionIndex).pop_truncate_last_interpolation_step;
// TODO: auslagern
@ -2303,8 +2577,12 @@ QList<int> &Calculator::GetTimeSteps(Configuration *cfg, int paymentOptionIndex,
}
}
//qCritical() << "(" << __func__ << ":" << __LINE__ << ") runtime in minutes:" << runtimeInMinutes;
for (auto[itr, rangeEnd] = cfg->PaymentRate.equal_range(pop_id); itr != rangeEnd; ++itr) {
int const durationId = itr->second.pra_payment_unit_id;
//qCritical() << "(" << __func__ << ":" << __LINE__ << ") durationId" << durationId;
// int const price = itr->second.pra_price;
auto search = cfg->Duration.find(durationId);
@ -2321,11 +2599,14 @@ QList<int> &Calculator::GetTimeSteps(Configuration *cfg, int paymentOptionIndex,
break;
}
//qCritical() << "(" << __func__ << ":" << __LINE__ << ") runtime in minutes:" << runtimeInMinutes;
std::optional<ATBInterpolation> ipolCheck = cfg->getInterpolationType(duration.pun_interpolation_id);
if (ipolCheck) {
ATBInterpolation interpolation = ipolCheck.value();
if (duration.pun_interpolation_id == (int)ATBInterpolation::DYNAMIC_ABSTRACT_TIMEPOINT_AND_STATIC_PRICE) {
qCritical() << "(" << __func__ << ":" << __LINE__ << ") HIER NICHT";
interpolation.dynamic_start = start.time();
interpolation.dynamic_start.setHMS(start.time().hour(), start.time().minute(), 0);
@ -2342,6 +2623,8 @@ QList<int> &Calculator::GetTimeSteps(Configuration *cfg, int paymentOptionIndex,
runtimeInMinutes += duration.pun_duration;
nextTimeStep = start.addSecs(runtimeInMinutes * 60);
//qCritical() << "(" << __func__ << ":" << __LINE__ << ") runtime in minutes (1):" << runtimeInMinutes;
if (nextTimeStep.time() > carryOverStart) {
int const backTime = carryOverStart.secsTo(nextTimeStep.time()) / 60;
runtimeInMinutes -= backTime;
@ -2376,15 +2659,45 @@ QList<int> &Calculator::GetTimeSteps(Configuration *cfg, int paymentOptionIndex,
search->second = duration;
} else
if (duration.pun_interpolation_id == (int)ATBInterpolation::NO_INTERPOLATION) {
#if 0
qCritical() << "(" << __func__ << ":" << __LINE__ << ") runtime in minutes (1):" << runtimeInMinutes;
//qCritical() << "(" << __func__ << ":" << __LINE__ << ") pun_id:" << duration.pun_id;
//qCritical() << "(" << __func__ << ":" << __LINE__ << ") pun duration:" << duration.pun_duration;
//qCritical() << "(" << __func__ << ":" << __LINE__ << ") next time step:" << nextTimeStep.toString(Qt::ISODate);
//qCritical() << "(" << __func__ << ":" << __LINE__ << ") runtime in minutes (2):" << runtimeInMinutes;
if (paymentOptionIndex == 1) { // testing TODO: muss in die payment options hinein
if (runtimeInMinutes == 0) {
if (start.time() < carryOverStart) {
runtimeInMinutes = start.time().secsTo(carryOverStart) / 60;
duration.pun_duration = runtimeInMinutes;
m_timeSteps[paymentOptionIndex] << duration.pun_duration;
search->second = duration;
cfg->getPaymentOptions(paymentOptionIndex).pop_min_time = runtimeInMinutes;
continue;
}
}
}
if (runtimeInMinutes == 0) {
if (start.time() < carryOverStart) {
runtimeInMinutes = start.time().secsTo(carryOverStart) / 60;
qCritical() << "(" << __func__ << ":" << __LINE__ << ") start:" << start.toString(Qt::ISODate);
qCritical() << "(" << __func__ << ":" << __LINE__ << ") carryOverStart:" << carryOverStart.toString(Qt::ISODate);
qCritical() << "(" << __func__ << ":" << __LINE__ << ") runtime in minutes:" << runtimeInMinutes;
qCritical() << "(" << __func__ << ":" << __LINE__ << ") pun_id:" << duration.pun_id;
duration.pun_duration = runtimeInMinutes;
m_timeSteps[paymentOptionIndex] << duration.pun_duration;
search->second = duration;
cfg->getPaymentOptions(paymentOptionIndex).pop_min_time = runtimeInMinutes;
}
continue;
}
//qCritical() << "(" << __func__ << ":" << __LINE__ << ") runtime in minutes:" << runtimeInMinutes;
QDateTime s = start.addSecs(runtimeInMinutes * 60);
int const minutes = s.time().secsTo(carryOverStart) / 60;
qCritical() << "(" << __func__ << ":" << __LINE__ << ") pun_id:" << duration.pun_id;
qCritical() << "(" << __func__ << ":" << __LINE__ << ") minutes:" << minutes;
qCritical() << "(" << __func__ << ":" << __LINE__ << ") start:" << start.toString(Qt::ISODate);
qCritical() << "(" << __func__ << ":" << __LINE__ << ") s:" << s.toString(Qt::ISODate);
#if 0
if (minutes > 0) {
runtimeInMinutes += minutes;
previous.pun_duration += minutes;
@ -2397,16 +2710,14 @@ QList<int> &Calculator::GetTimeSteps(Configuration *cfg, int paymentOptionIndex,
}
#endif
nextTimeStep = start.addSecs(runtimeInMinutes * 60);
//qCritical() << "(" << __func__ << ":" << __LINE__ << ") next time step:" << nextTimeStep.toString(Qt::ISODate);
//qCritical() << "(" << __func__ << ":" << __LINE__ << ") runtime in minutes (0):" << runtimeInMinutes;
nextTimeStep = start.addSecs(runtimeInMinutes * 60);
runtimeInMinutes += duration.pun_duration;
nextTimeStep = start.addSecs(runtimeInMinutes * 60);
//qCritical() << "(" << __func__ << ":" << __LINE__ << ") next time step:" << nextTimeStep.toString(Qt::ISODate);
//qCritical() << "(" << __func__ << ":" << __LINE__ << ") carry over start:" << carryOverStart.toString(Qt::ISODate);
//qCritical() << "(" << __func__ << ":" << __LINE__ << ") carryOverStart:" << carryOverStart.toString(Qt::ISODate);
//qCritical() << "(" << __func__ << ":" << __LINE__ << ") nextTimeStep.time():" << nextTimeStep.time().toString(Qt::ISODate);
// TOOO: truncate-flag == false
if (nextTimeStep.time() > carryOverStart) {
@ -2415,27 +2726,30 @@ QList<int> &Calculator::GetTimeSteps(Configuration *cfg, int paymentOptionIndex,
nextTimeStep.setTime(carryOverStart);
nextTimeStep = nextTimeStep.addSecs((backTime + carryOverDuration) * 60);
runtimeInMinutes += (backTime + carryOverDuration);
//qCritical() << "(" << __func__ << ":" << __LINE__ << ") runTimeInMinutes:" << runtimeInMinutes;
//qCritical() << "(" << __func__ << ":" << __LINE__ << ") nextTimeStep.time():" << nextTimeStep.time().toString(Qt::ISODate);
} else
if (nextTimeStep.time() < carryOverStart) {
int const forwardTime = nextTimeStep.time().secsTo(carryOverStart) / 60;
runtimeInMinutes += forwardTime;
nextTimeStep.setTime(carryOverStart);
//qCritical() << "(" << __func__ << ":" << __LINE__ << ") runTimeInMinutes:" << runtimeInMinutes;
//qCritical() << "(" << __func__ << ":" << __LINE__ << ") nextTimeStep.time():" << nextTimeStep.time().toString(Qt::ISODate);
}
if (DBG_LEVEL >= DBG_DEBUG) {
qCritical() << "(" << __func__ << ":" << __LINE__ << ") pun_id:" << duration.pun_id;
qCritical() << "(" << __func__ << ":" << __LINE__ << ") pun duration:" << duration.pun_duration;
qCritical() << "(" << __func__ << ":" << __LINE__ << ") next time step:" << nextTimeStep.toString(Qt::ISODate);
qCritical() << "(" << __func__ << ":" << __LINE__ << ") runtime in minutes (2):" << runtimeInMinutes;
}
duration.pun_duration = runtimeInMinutes;
//qCritical() << "(" << __func__ << ":" << __LINE__ << ") pun_id:" << duration.pun_id;
//qCritical() << "(" << __func__ << ":" << __LINE__ << ") pun_duration:" << duration.pun_duration;
// duration.pun_duration = runtimeInMinutes - carryOverDuration;
m_timeSteps[paymentOptionIndex] << duration.pun_duration;
search->second = duration;
} else {
qCritical() << "(" << __func__ << ":" << __LINE__ << ") HIER NICHT";
cfg->Duration.erase(search);
}
}
@ -2492,12 +2806,19 @@ QList<int> &Calculator::GetTimeSteps(Configuration *cfg, int paymentOptionIndex,
uint32_t Calculator::GetPriceForTimeStep(Configuration *cfg, int timeStep, int paymentOptionIndex) const {
// test
// paymentOptionIndex = 1;
int const pop_id = cfg->getPaymentOptions(paymentOptionIndex).pop_id;
int const pop_accumulate_durations = cfg->getPaymentOptions(paymentOptionIndex).pop_accumulate_durations;
int const pop_accumulate_prices = cfg->getPaymentOptions(paymentOptionIndex).pop_accumulate_prices;
uint32_t price = 0;
int pun_duration = 0;
qCritical() << "(" << __func__ << ":" << __LINE__ << ") paymentOptionIndex" << paymentOptionIndex;
//qCritical() << "(" << __func__ << ":" << __LINE__ << ") timeStep" << timeStep;
//qCritical() << "(" << __func__ << ":" << __LINE__ << ") pop_id" << pop_id;
for (auto[itr, rangeEnd] = cfg->PaymentRate.equal_range(pop_id); itr != rangeEnd; ++itr)
{
@ -2506,18 +2827,31 @@ uint32_t Calculator::GetPriceForTimeStep(Configuration *cfg, int timeStep, int p
Q_ASSERT(pun_id == payment_unit_id);
int const pun_duration = cfg->Duration.find(payment_unit_id)->second.pun_duration;
//qCritical() << "(" << __func__ << ":" << __LINE__ << ") pun_id" << pun_id;
//qCritical() << "(" << __func__ << ":" << __LINE__ << ") pun_unit_id" << payment_unit_id;
if (pop_accumulate_durations) {
pun_duration += cfg->Duration.find(payment_unit_id)->second.pun_duration;
} else {
pun_duration = cfg->Duration.find(payment_unit_id)->second.pun_duration;
}
if (pop_accumulate_prices) {
price += itr->second.pra_price;
} else {
price = (uint32_t)(itr->second.pra_price);
}
//qCritical() << "(" << __func__ << ":" << __LINE__ << ") price" << price;
//qCritical() << "(" << __func__ << ":" << __LINE__ << ") pun_id" << cfg->Duration.find(payment_unit_id)->second.pun_id;
//qCritical() << "(" << __func__ << ":" << __LINE__ << ") pun_duration" << pun_duration;
if (DBG_LEVEL >= DBG_DEBUG) {
qCritical() << "(" << __func__ << ":" << __LINE__ << ") price" << price;
qCritical() << "(" << __func__ << ":" << __LINE__ << ") pun_id" << pun_id;
qCritical() << "(" << __func__ << ":" << __LINE__ << ") pun_unit_id" << payment_unit_id;
qCritical() << "(" << __func__ << ":" << __LINE__ << ") pun_duration" << pun_duration;
qCritical() << "(" << __func__ << ":" << __LINE__ << ") timeStep" << timeStep;
}
if (timeStep == pun_duration) {
qCritical() << "(" << __func__ << ":" << __LINE__ << ") return price" << price;
return price;
}
}
@ -2527,8 +2861,13 @@ uint32_t Calculator::GetPriceForTimeStep(Configuration *cfg, int timeStep, int p
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;
int new_price = 0;
uint32_t duration = 0;
uint32_t duration_previous = 0;
for (auto[itr, rangeEnd] = cfg->PaymentRate.equal_range(pop_id); itr != rangeEnd; ++itr)
{
@ -2544,8 +2883,22 @@ uint32_t Calculator::GetDurationForPrice(Configuration *cfg, int price) const {
if (pra_price < price) {
duration = durationUnit;
}
if (pop_accumulate_prices) {
new_price += pra_price;
//qCritical() << "(" << __func__ << ":" << __LINE__ << ") pra_price:" << pra_price;
//qCritical() << "(" << __func__ << ":" << __LINE__ << ") new_price:" << new_price;
if (new_price <= price) {
duration_previous = durationUnit;
//qCritical() << "(" << __func__ << ":" << __LINE__ << ") duration_previous" << duration_previous;
} else {
//qCritical() << "(" << __func__ << ":" << __LINE__ << ") duration_previous" << duration_previous;
return duration_previous;
}
}
}
qCritical() << "(" << __func__ << ":" << __LINE__ << ") duration" << duration << "for price" << price;
return duration;
}
@ -2657,14 +3010,53 @@ Calculator::GetDailyTicketPrice(Configuration* cfg,
}
// [[fallthrough]];
case PERMIT_TYPE::DAY_TICKET: {
}
// [[fallthrough]];
case PERMIT_TYPE::SZEGED_START:
// [[fallthrough]];
case PERMIT_TYPE::SZEGED_STOP:
// [[fallthrough]];
case PERMIT_TYPE::INVALID:
break;
} break;
case PERMIT_TYPE::DAY_TICKET_PKW: {
PermitType const permitType(PERMIT_TYPE::DAY_TICKET_PKW);
std::optional<ATBPaymentOption> paymentOption = cfg->getPaymentOptionForKey(permitType.get());
if (paymentOption) {
ATBPaymentOption option = paymentOption.value();
int pop_id = option.pop_id;
int pop_daily_card_price = option.pop_daily_card_price;
qCritical() << "( GetDailyTicketPrice():" << __LINE__ << ")";
qCritical() << " PERMIT-TYPE:" << permitType.toString();
qCritical() << " option id:" << pop_id;
qCritical() << "daily_ticket_card_price:" << pop_daily_card_price;
price.netto = pop_daily_card_price;
value = value.value_or(price);
}
} break;
case PERMIT_TYPE::DAY_TICKET_BUS: {
} break;
case PERMIT_TYPE::DAY_TICKET_CAMPER: {
} break;
case PERMIT_TYPE::SHORT_TERM_PARKING_PKW: {
PermitType const permitType(PERMIT_TYPE::SHORT_TERM_PARKING_PKW);
std::optional<ATBPaymentOption> paymentOption = cfg->getPaymentOptionForKey(permitType.get());
if (paymentOption) {
ATBPaymentOption option = paymentOption.value();
int pop_id = option.pop_id;
int pop_daily_card_price = option.pop_daily_card_price;
qCritical() << "( GetDailyTicketPrice():" << __LINE__ << ")";
qCritical() << " PERMIT-TYPE:" << permitType.toString();
qCritical() << " option id:" << pop_id;
qCritical() << "daily_ticket_card_price:" << pop_daily_card_price;
price.netto = pop_daily_card_price;
value = value.value_or(price);
}
} break;
case PERMIT_TYPE::SHORT_TERM_PARKING_BUS: {
} break;
case PERMIT_TYPE::SHORT_TERM_PARKING_CAMPER: {
} break;
case PERMIT_TYPE::SZEGED_START: {
} break;
case PERMIT_TYPE::SZEGED_STOP: {
} break;
case PERMIT_TYPE::INVALID: {
} break;
}
} else {
// for projects which have not defined a daily ticket in their

View File

@ -582,6 +582,30 @@ bool Configuration::ParseJson(Configuration* cfg, const char* json)
this->currentPaymentOptions.last().pop_id = k->value.GetInt();
} else if (strcmp(inner_obj_name, "pop_label") == 0) {
this->currentPaymentOptions.last().pop_label = k->value.GetString();
} else if (strcmp(inner_obj_name, "pop_product_id") == 0) {
this->currentPaymentOptions.last().pop_product_id = k->value.GetInt();
} else if (strcmp(inner_obj_name, "pop_product_name") == 0) {
if (k->value.IsString()) {
QString const &s = QString::fromStdString(k->value.GetString());
this->currentPaymentOptions.last().pop_product_name = s;
}
} else if (strcmp(inner_obj_name, "pop_use_only_upto_datetime") == 0) {
if (k->value.IsString()) {
QString const &s = QString::fromStdString(k->value.GetString());
this->currentPaymentOptions.last().pop_use_only_upto_datetime = s;
}
} else if (strcmp(inner_obj_name, "pop_use_only_for_duration") == 0) {
if (k->value.IsInt()) {
this->currentPaymentOptions.last().pop_use_only_for_duration = k->value.GetInt();
}
} else if (strcmp(inner_obj_name, "pop_plus_steps") == 0) {
if (k->value.IsInt()) {
this->currentPaymentOptions.last().pop_plus_steps = k->value.GetInt();
}
} else if (strcmp(inner_obj_name, "pop_minus_steps") == 0) {
if (k->value.IsInt()) {
this->currentPaymentOptions.last().pop_minus_steps = k->value.GetInt();
}
} else if (strcmp(inner_obj_name, "pop_payment_method_id") == 0) {
this->currentPaymentOptions.last().pop_payment_method_id = k->value.GetInt();
} else if (strcmp(inner_obj_name, "pop_day_end_time") == 0) {
@ -712,6 +736,8 @@ bool Configuration::ParseJson(Configuration* cfg, const char* json)
break;*/
case MemberType::WeekDaysWorkTimeType:
if (strcmp(inner_obj_name, "pwd_id") == 0) WeekDaysWorktime.pwd_id = k->value.GetInt();
if (strcmp(inner_obj_name, "pwd_pop_id") == 0) WeekDaysWorktime.pwd_pop_id = k->value.GetInt();
if (strcmp(inner_obj_name, "pwd_next_id") == 0) WeekDaysWorktime.pwd_next_id = k->value.GetInt();
else if (strcmp(inner_obj_name, "pwd_period_week_day_id") == 0) WeekDaysWorktime.pwd_period_week_day_id = k->value.GetInt();
else if (strcmp(inner_obj_name, "pwd_period_day_in_week_id") == 0) WeekDaysWorktime.pwd_period_day_in_week_id = k->value.GetInt();
else if (strcmp(inner_obj_name, "pwd_time_from") == 0) WeekDaysWorktime.pwd_time_from = k->value.GetString();
@ -758,7 +784,7 @@ bool Configuration::ParseJson(Configuration* cfg, const char* json)
}
} break;
case MemberType::DurationType:
cfg->Duration.insert(pair<int, ATBDuration>(Duration.pun_id, Duration));
cfg->Duration.insert(pair<int, ATBDuration>(Duration.pun_id, Duration));
// qCritical() << Duration;
break;
case MemberType::SpecialDaysWorktimeType:
@ -864,7 +890,7 @@ std::optional<QDateTime> Configuration::getInterpolationEnd(QDateTime const &sta
ATBInterpolation interpolation = ipolCheck.value();
switch (duration.pun_interpolation_id) {
case static_cast<int>(ATBInterpolation::NO_INTERPOLATION):
//qCritical() << "(" << __func__ << ":" << __LINE__ << ") TODO";
//qCritical() << "(" << __func__ << ":" << __LINE__ << ") NO_INTERPOLATION";
break;
case static_cast<int>(ATBInterpolation::STATIC_WALLCLOCK_TIME_VALUES):
//qCritical() << "(" << __func__ << ":" << __LINE__ << ") TODO";
@ -969,6 +995,9 @@ int Configuration::getPaymentOptionIndex(QDateTime const &dt) const {
for (int opt=0; opt < numOptions; ++opt) {
uint64_t const pop_id = getPaymentOptions(opt).pop_id;
if (pop_id == (uint64_t)sd.ped_payment_option_id) {
qCritical() << __func__ << __LINE__ << opt;
return opt;
}
}
@ -978,6 +1007,9 @@ int Configuration::getPaymentOptionIndex(QDateTime const &dt) const {
for (int opt=0; opt < numOptions; ++opt) {
uint64_t const pop_business_hours = getPaymentOptions(opt).pop_business_hours;
if (pop_business_hours == 0) { // 0 == 24/7
return opt;
}
uint64_t p = 0;
int const dayOfWeek = dt.date().dayOfWeek();
@ -1008,6 +1040,9 @@ int Configuration::getPaymentOptionIndex(QDateTime const &dt) const {
}
if ((pop_business_hours & p) == p) {
qCritical() << __func__ << __LINE__ << opt;
return opt;
}
}
@ -1124,6 +1159,41 @@ Configuration::getTariffProductForProductTypeName(QString const &permitTypeName)
return value;
}
int Configuration::getPaymentOptionIndex(PERMIT_TYPE permitType) {
std::optional<QVector<ATBPaymentOption>> paymentOptions = getPaymentOptionsForAllKeys();
if (paymentOptions) {
QVector<ATBPaymentOption> const vec = paymentOptions.value();
PermitType const p(permitType);
for (int i = 0; i < vec.size(); ++i) {
if (vec[i].pop_product_name == p.toString()) {
return i;
}
}
}
return 0;
}
int Configuration::getPaymentOptionIndex(PERMIT_TYPE permitType) const {
std::optional<QVector<ATBPaymentOption>> paymentOptions = getPaymentOptionsForAllKeys();
if (paymentOptions) {
QVector<ATBPaymentOption> const vec = paymentOptions.value();
PermitType const p(permitType);
for (int i = 0; i < vec.size(); ++i) {
if (vec[i].pop_product_name == p.toString()) {
return i;
}
}
}
return 0;
}
std::optional<QVector<ATBTariffProduct>>
Configuration::getTariffProductForProductId(PermitType permitType) const {
QString permitTypeName(permitType);
@ -1233,6 +1303,65 @@ Configuration::getDailyTicketsForKey(int key) const {
return value;
}
std::optional<ATBPaymentOption>
Configuration::getPaymentOptionForId(int key) const {
ATBPaymentOption option;
std::optional<ATBPaymentOption> value;
for (auto[it, rangeEnd] = this->PaymentOption.equal_range(key); it != rangeEnd; ++it) {
value = value.value_or(it->second);
}
return value;
}
std::optional<QVector<ATBPaymentOption>>
Configuration::getPaymentOptionsForAllKeys() const {
QVector<ATBPaymentOption> paymentOptions;
std::optional<QVector<ATBPaymentOption>> value;
for (std::multimap<int, ATBPaymentOption>::const_iterator it = this->PaymentOption.cbegin();
it != this->PaymentOption.cend(); ++it) {
paymentOptions.append(it->second);
}
if (paymentOptions.size() > 0) {
value = value.value_or(paymentOptions);
}
return value;
}
// TODO: umbenennen: getPaymentOptionForPermitType
std::optional<ATBPaymentOption>
Configuration::getPaymentOptionForKey(PERMIT_TYPE permitType) const {
return getPaymentOptionForKey(static_cast<int>(permitType));
}
// TODO: umbenennen: getPaymentOptionForPermitType
std::optional<ATBPaymentOption>
Configuration::getPaymentOptionForKey(int permitType) const {
std::optional<ATBPaymentOption> value;
for (std::multimap<int, ATBPaymentOption>::const_iterator it = this->PaymentOption.cbegin();
it != this->PaymentOption.cend(); ++it) {
ATBPaymentOption const &paymentOption = it->second;
if (paymentOption.pop_product_id == permitType) {
value = value.value_or(paymentOption);
break;
}
}
return value;
}
// TODO: umbenennen: getPaymentOptionForPermitType
std::optional<ATBPaymentOption>
Configuration::getPaymentOptionForKey(QString const &permitTypeStr) const {
PERMIT_TYPE permitType = PermitType::toPermitType(permitTypeStr);
return getPaymentOptionForKey(static_cast<int>(permitType));
}
std::optional<QVector<ATBPaymentRate>>
Configuration::getPaymentRateForAllKeys() const {
QVector<ATBPaymentRate> paymentRates;
@ -1282,6 +1411,25 @@ Configuration::getCustomerForType(ATBCustomer::CustomerType customerType) {
return std::nullopt;
}
std::optional<QVector<ATBWeekDaysWorktime>>
Configuration::getAllWeekDayWorkTimes() {
QVector<ATBWeekDaysWorktime> worktimes;
std::optional<QVector<ATBWeekDaysWorktime>> value;
worktimes.clear();
for (std::multimap<int, ATBWeekDaysWorktime>::const_iterator it = this->WeekDaysWorktime.cbegin();
it != this->WeekDaysWorktime.cend(); ++it) {
worktimes.append(it->second);
}
if (worktimes.size() > 0) {
value = value.value_or(worktimes);
}
return value;
}
std::optional<ATBWeekDaysWorktime>
Configuration::getWeekDayWorkTime(QTime const &time, Qt::DayOfWeek dayOfWeek) {
ATBWeekDaysWorktime worktime;

View File

@ -215,6 +215,43 @@ bool Utilities::IsYearPeriodActive(Configuration const *cfg, QDateTime const &dt
return true;
}
std::optional<ATBPeriodYear>
Utilities::GetYearPeriodActive(Configuration const *cfg, QDateTime const &currentDateTime) {
ATBPeriodYear period;
std::optional<ATBPeriodYear> value;
for (multimap<int, ATBPeriodYear>::const_iterator it = cfg->YearPeriod.cbegin();
it != cfg->YearPeriod.cend();
++it) {
QDate const s(currentDateTime.date().year(), it->second.pye_start_month, it->second.pye_start_day);
QDate const e(currentDateTime.date().year(), it->second.pye_end_month, it->second.pye_end_day);
QDateTime start(currentDateTime);
QDateTime end(currentDateTime);
start.setDate(s);
end.setDate(e);
if (start.date().dayOfYear() < end.date().dayOfYear()) {
// start and end in the same year
if (currentDateTime.date().dayOfYear() >= start.date().dayOfYear() &&
currentDateTime.date().dayOfYear() <= end.date().dayOfYear()) {
value = value.value_or(it->second);
break;
}
} else {
if (currentDateTime.date().dayOfYear() >= start.date().dayOfYear() ||
currentDateTime.date().dayOfYear() <= end.date().dayOfYear()) {
value = value.value_or(it->second);
break;
}
}
}
return value;
}
/// <inheritdoc/>
bool Utilities::CheckSpecialDay(Configuration* cfg, const char* currentDateTimeStr, int* specialDayId, double* specialDayPrice)
{

View File

@ -49,9 +49,9 @@ extern "C" char* strptime(const char* s,
#define NEUHAUSER_STOCKERAU (0)
#define KLEIPEDA_LITAUEN (0)
#define SEXTEN (0)
#define SCHNALS_LEITER_KIRCHL (1)
#define SCHNALS_LEITER_KIRCHL (0)
#define SCHNALS_STAUMAUER (SCHNALS_LEITER_KIRCHL)
#define VALSER_ALM (0)
#define VALSER_ALM (1)
#if NEUHAUSER_KIRCHDORF==1
static bool test_neuhauser_kirchdorf(int step, double cost) {
@ -354,7 +354,7 @@ int main() {
QList<int> timeSteps = Calculator::GetInstance().GetTimeSteps(&cfg);
qCritical() << "TimeSteps" << timeSteps;
return 0;
// return 0;
CalcState cs;
double cost;
@ -363,7 +363,7 @@ int main() {
// for (int day = Qt::Monday; day <= Qt::Sunday; ++day) {
for (int day = Qt::Monday; day <= Qt::Monday; ++day) {
QDateTime s(QDate(2024, 5, 19 + day), QTime()); // 20: (whit) monday,..., 26: sunday
QDateTime s(QDate(2024, 7, 29 + day), QTime()); // 20: (whit) monday,..., 26: sunday
QDateTime end;
switch (day) {
@ -401,9 +401,11 @@ int main() {
bool prepaid = true);
*/
for (int minutes = 0; minutes < 1440; ++minutes) {
QDateTime start = s.addSecs(minutes * 60);
QDateTime effectiveStart = start;
//for (int minutes = 0; minutes < 1440; ++minutes) {
for (int minutes = 540; minutes <= 540; ++minutes) {
// QDateTime start = s.addSecs(minutes * 60);
QDateTime start(QDateTime::currentDateTime());
QDateTime effectiveStart(QDateTime::currentDateTime());
if (start.time() < QTime(8, 0, 0)) {
effectiveStart.setTime(QTime(8, 0, 0));
@ -415,55 +417,18 @@ int main() {
effectiveStart.setTime(QTime(8, 0, 0)); // next day
}
for (int i = 0; i <= 2100; i += 10) {
for (int i = 30; i <= 30; i += 10) {
//for (int i = 2100; i <= 2100; i += 10) {
cost = i;
if ((cs = compute_duration_for_parking_ticket(&cfg, start, cost, end))) { // return value
durationInMinutes = pop_min_time;
if (i > 0) {
durationInMinutes += (i/10) * 4;
}
offsetInMinutes = 0;
if (effectiveStart.time() >= QTime(8, 0, 0) && effectiveStart.time() <= QTime(22, 0, 0)) {
if (effectiveStart.time().secsTo(QTime(22, 0, 0)) < (durationInMinutes * 60)) {
offsetInMinutes = 600; // 22:00 -> 8:00
}
}
if (i == 0) {
i += 20;
}
if ((durationInMinutes + offsetInMinutes) == (effectiveStart.secsTo(end) / 60)) {
if (day == Qt::Monday && minutes >= 480 && minutes <= 1320) {
qCritical() << "| start ............................" << start.toString(Qt::ISODate);
qCritical() << "| cost ............................." << cost;
qCritical() << "| durationInMinutes ................" << durationInMinutes
<< "(" << (durationInMinutes - 60) << "+ 60 )";
qCritical() << "| offsetInMinutes .................." << offsetInMinutes;
qCritical() << "| end .............................." << end.toString(Qt::ISODate) << endl;
}
continue;
}
if ((cs = compute_duration_for_parking_ticket(&cfg, start, cost, end, PermitType(PERMIT_TYPE::SHORT_TERM_PARKING)))) { // return value
qCritical() << "start" << start.toString(Qt::ISODate) << "< cost" << cost
<< "> end" << end.toString(Qt::ISODate);
}
if (!cs) {
qCritical() << "ERROR CalcState" << cs.toString() << endl;
} else {
qCritical() << cs.toString();
}
qCritical() << __LINE__ << "start ............................" << start.toString(Qt::ISODate);
qCritical() << __LINE__ << "effectiveStart ..................." << effectiveStart.toString(Qt::ISODate);
qCritical() << __LINE__ << "cost ............................." << cost;
qCritical() << __LINE__ << "durationInMinutes ................" << durationInMinutes;
qCritical() << __LINE__ << "offsetInMinutes .................." << offsetInMinutes;
qCritical() << __LINE__ << "effectiveStart.secsTo(end) / 60 .." << effectiveStart.secsTo(end) / 60;
qCritical() << __LINE__ << "end .............................." << end.toString(Qt::ISODate) << endl;
exit(-1);
}
}
}
@ -552,7 +517,7 @@ int main() {
*/
//for (int minutes = 0; minutes < 1440; ++minutes) {
for (int minutes = 0; minutes < 1440; minutes += 1) {
for (int minutes = 480; minutes <= 480; minutes += 1) {
QDateTime start = s.addSecs(minutes * 60);
// qCritical() << "start" << start.toString(Qt::ISODate);
@ -569,66 +534,32 @@ int main() {
effectiveStart.setTime(QTime(8, 0, 0)); // next day
}
/*
for (int i = 10; i <= 400; i += 10) {
//for (int i = 2100; i <= 2100; i += 10) {
cost = i;
if ((cs = compute_duration_for_parking_ticket(&cfg, start, cost, end))) { // return value
if ((cs = compute_duration_for_parking_ticket(&cfg, start, cost, end, PermitType(PERMIT_TYPE::SHORT_TERM_PARKING)))) { // return value
qCritical() << "start" << start.toString(Qt::ISODate) << "< cost" << cost
<< "> end" << end.toString(Qt::ISODate);
durationInMinutes = pop_min_time;
if (i > 0) {
durationInMinutes += (i/10) * 4;
}
offsetInMinutes = 0;
if (effectiveStart.time() >= QTime(8, 0, 0) && effectiveStart.time() <= QTime(19, 0, 0)) {
if (effectiveStart.time().secsTo(QTime(19, 0, 0)) < (durationInMinutes * 60)) {
offsetInMinutes = 780; // 19:00 -> 8:00
}
}
if (i == 0) {
i += 20;
}
#if 0
if ((durationInMinutes + offsetInMinutes) == (effectiveStart.secsTo(end) / 60)) {
if (day == Qt::Monday && minutes >= 480 && minutes <= 1140) {
qCritical() << "| start ............................" << start.toString(Qt::ISODate);
qCritical() << "| cost ............................." << cost;
qCritical() << "| durationInMinutes ................" << durationInMinutes
<< "(" << (durationInMinutes - 60) << "+ 60 )";
qCritical() << "| offsetInMinutes .................." << offsetInMinutes;
qCritical() << "| end .............................." << end.toString(Qt::ISODate) << endl;
}
continue;
}
#endif
}
if (!cs) {
qCritical() << "ERROR CalcState" << cs.toString() << endl;
} else {
// qCritical() << cs.toString();
}
}
*/
int netto_parking_time = 60;
struct price_t price;
#if 0
qCritical() << __LINE__ << "start ............................" << start.toString(Qt::ISODate);
qCritical() << __LINE__ << "effectiveStart ..................." << effectiveStart.toString(Qt::ISODate);
qCritical() << __LINE__ << "cost ............................." << cost;
qCritical() << __LINE__ << "durationInMinutes ................" << durationInMinutes;
qCritical() << __LINE__ << "offsetInMinutes .................." << offsetInMinutes;
qCritical() << __LINE__ << "effectiveStart.secsTo(end) / 60 .." << effectiveStart.secsTo(end) / 60;
qCritical() << __LINE__ << "end .............................." << end.toString(Qt::ISODate) << endl;
exit(-1);
#endif
qCritical() << "start" << start.toString(Qt::ISODate);
QDateTime const s = start;
if ((cs = compute_price_for_parking_ticket(&cfg, start, netto_parking_time, end, &price, PermitType(PERMIT_TYPE::SHORT_TERM_PARKING)))) {
qCritical() << "start" << s.toString(Qt::ISODate)
<< "netto_parking_time" << netto_parking_time
<< "< price" << price.netto
<< "> end" << end.toString(Qt::ISODate);
}
}
}
@ -737,11 +668,12 @@ int main() {
effectiveStart.setTime(QTime(7, 0, 0)); // next day
}
#if 1
#if 0
PermitType permitType(PERMIT_TYPE::SHORT_TERM_PARKING);
for (int i = 200; i <= 200; i += 10) {
cost = i;
if ((cs = compute_duration_for_parking_ticket(&cfg, start, cost, end))) { // return value
if ((cs = compute_duration_for_parking_ticket(&cfg, start, cost, end, permitType))) { // return value
}
if (!cs) {
@ -759,7 +691,7 @@ int main() {
//for (int i = 2100; i <= 2100; i += 10) {
cost = i;
if ((cs = compute_duration_for_parking_ticket(&cfg, start, cost, end))) { // return value
if ((cs = compute_duration_for_parking_ticket(&cfg, start, cost, end, PermitType(PERMIT_TYPE::SHORT_TERM_PARKING_PKW)))) { // return value
}
if (!cs) {
@ -800,7 +732,7 @@ int main() {
int pop_max_price;
int pop_daily_card_price;
int zone = 2;
int zone = 3;
if (zone == 1) {
input.open("/opt/ptu5/opt/customer_502/etc/psa_tariff/tariff01.json");
@ -822,22 +754,85 @@ int main() {
cout << endl;
if (isParsed) {
pop_min_time = get_minimal_parkingtime(&cfg);
pop_max_time = get_maximal_parkingtime(&cfg);
pop_min_price = get_minimal_parkingprice(&cfg);
pop_max_price = get_maximal_parkingprice(&cfg);
pop_daily_card_price = cfg.getPaymentOptions().pop_daily_card_price;
qCritical() << " pop_min_time: " << pop_min_time;
qCritical() << " pop_max_time: " << pop_max_time;
qCritical() << " pop_min_price: " << pop_min_price;
qCritical() << " pop_max_price: " << pop_max_price;
if (zone == 1 || zone == 3) {
/*
pop_min_time = get_minimal_parkingtime(&cfg, PERMIT_TYPE::SHORT_TERM_PARKING_PKW);
pop_max_time = get_maximal_parkingtime(&cfg, PERMIT_TYPE::SHORT_TERM_PARKING_PKW);
pop_min_price = get_minimal_parkingprice(&cfg, PERMIT_TYPE::SHORT_TERM_PARKING_PKW);
pop_max_price = get_maximal_parkingprice(&cfg, PERMIT_TYPE::SHORT_TERM_PARKING_PKW);
pop_daily_card_price = cfg.getPaymentOptions().pop_daily_card_price;
qCritical() << " pop_min_time_pkw: " << pop_min_time;
qCritical() << " pop_max_time_pkw: " << pop_max_time;
qCritical() << " pop_min_price_pkw: " << pop_min_price;
qCritical() << " pop_max_price_pkw: " << pop_max_price;
pop_min_time = get_minimal_parkingtime(&cfg, PERMIT_TYPE::SHORT_TERM_PARKING_BUS);
pop_max_time = get_maximal_parkingtime(&cfg, PERMIT_TYPE::SHORT_TERM_PARKING_BUS);
pop_min_price = get_minimal_parkingprice(&cfg, PERMIT_TYPE::SHORT_TERM_PARKING_BUS);
pop_max_price = get_maximal_parkingprice(&cfg, PERMIT_TYPE::SHORT_TERM_PARKING_BUS);
pop_daily_card_price = cfg.getPaymentOptions().pop_daily_card_price;
qCritical() << " pop_min_time_bus: " << pop_min_time;
qCritical() << " pop_max_time_bus: " << pop_max_time;
qCritical() << " pop_min_price_bus: " << pop_min_price;
qCritical() << " pop_max_price_bus: " << pop_max_price;
*/
}
if (zone == 2) {
pop_min_time = get_minimal_parkingtime(&cfg);
pop_max_time = get_maximal_parkingtime(&cfg);
pop_min_price = get_minimal_parkingprice(&cfg);
pop_max_price = get_maximal_parkingprice(&cfg);
pop_daily_card_price = cfg.getPaymentOptions().pop_daily_card_price;
qCritical() << " pop_min_time: " << pop_min_time;
qCritical() << " pop_max_time: " << pop_max_time;
qCritical() << " pop_min_price: " << pop_min_price;
qCritical() << " pop_max_price: " << pop_max_price;
}
//QDateTime start = QDateTime::currentDateTime();
//start.setTime(QTime(12, 0, 0));
//QList<int> timeSteps = Calculator::GetInstance().GetTimeSteps(&cfg, 0, start);
//qCritical() << "TimeSteps" << timeSteps;
//return 0;
if (zone == 1) {
//int minParkingTime = get_minimal_parkingtime(&cfg);
QList<int> timeSteps = Calculator::GetInstance().GetTimeSteps(&cfg);
qCritical() << timeSteps;
int Down = 0;
int Up = 1;
QDateTime const start = QDateTime::currentDateTime();
int paymentOptionIndex = cfg.getPaymentOptionIndex(start);
if (paymentOptionIndex < 0) {
qCritical() << "ERROR paymentOptionIndex" << paymentOptionIndex
<< "< 0 for start" << start.toString(Qt::ISODate);
exit(-1);
}
QSet<uint32_t> const prices_pkw{600, 1200, 1800, 2400, 3000, 3600, 4200};
QSet<uint32_t> const prices_bus{3000, 6000, 9000, 12000, 15000, 18000, 21000};
QDateTime end;
CalcState calcState;
QDateTime s(QDateTime::currentDateTime());
s.setTime(QTime(12, 0, 0));
//calcState = compute_duration_for_parking_ticket(&cfg, s,
// (double)1200, end, PermitType(PERMIT_TYPE::SHORT_TERM_PARKING_PKW));
//qCritical() << end.toString(Qt::ISODate);
//qCritical() << calcState.toString();
calcState = compute_duration_for_parking_ticket(&cfg, s,
(double)50, end, PermitType(PERMIT_TYPE::SHORT_TERM_PARKING_BUS));
qCritical() << end.toString(Qt::ISODate);
qCritical() << calcState.toString();
}
if (zone == 2) {
//int minParkingTime = get_minimal_parkingtime(&cfg);
@ -857,6 +852,16 @@ int main() {
QSet<uint32_t> const prices{600, 1200, 1800, 2400, 3000, 3600, 4200};
QDateTime end;
CalcState calcState;
QDateTime s(QDateTime::currentDateTime());
s.setTime(QTime(18, 0, 0));
calcState = compute_duration_for_parking_ticket(&cfg, s,
(double)600, end, PermitType(PERMIT_TYPE::SHORT_TERM_PARKING));
qCritical() << end.toString(Qt::ISODate);
qCritical() << calcState.toString();
#if 0
for (int i=0; i<timeSteps.size(); ++i) {
int nextTimeStep = compute_next_timestep(&cfg, timeSteps.at(i), Up);
@ -881,89 +886,66 @@ int main() {
<< "(price so far:" << price << ")";
}
#endif
}
if (zone == 3) {
int price;
QDateTime productStart;
QDateTime productEnd;
QDateTime start = QDateTime::currentDateTime();
//QDateTime xx(QDateTime::fromString("2024-07-31T00:00:00", Qt::ISODate));
//xx = xx.addSecs(-60); // --> "2024-07-30T23:59:00"
//qCritical() << xx.toString(Qt::ISODate);
//QDateTime s(QDateTime::currentDateTime());
//s.setTime(QTime(12, 0, 0));
//QList<int> timeSteps = Calculator::GetInstance().GetTimeSteps(&cfg, 0, s);
//qCritical() << timeSteps;
int Down = 0;
int Up = 1;
QDateTime const start = QDateTime::currentDateTime();
int paymentOptionIndex = cfg.getPaymentOptionIndex(PERMIT_TYPE::SHORT_TERM_PARKING_PKW);
if (paymentOptionIndex != 0) {
qCritical() << "ERROR paymentOptionIndex" << paymentOptionIndex
<< "< 0 for start" << start.toString(Qt::ISODate);
exit(-1);
}
//QSet<uint32_t> const prices1{800, 1600, 2400, 3200, 4000, 4800, 5600};
//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);
#if 0
start.setTime(QTime(0, 0, 0));
price = compute_product_price(&cfg, PERMIT_TYPE::DAY_TICKET, start);
qCritical() << QString("line=%1 price (%2) :")
.arg(__LINE__)
.arg(start.time().toString(Qt::ISODate)) << price;
qCritical() << "minimal parking price" << minimal_parking_price;
price = get_minimal_parkingprice(&cfg, PERMIT_TYPE::DAY_TICKET, 0, start);
qCritical() << QString("line=%1 get_minimal_parkingprice:").arg(__LINE__) << price;
start.setTime(QTime(14, 0, 0));
productStart = productEnd = QDateTime();
price = compute_product_price(&cfg, PERMIT_TYPE::DAY_TICKET, start, &productStart, &productEnd);
qCritical() << QString("line=%1 price (%2-%3) :")
.arg(__LINE__)
.arg(productStart.time().toString(Qt::ISODate))
.arg(productEnd.time().toString(Qt::ISODate))
<< price;
price = get_minimal_parkingprice(&cfg, PERMIT_TYPE::DAY_TICKET, 0, start);
qCritical() << QString("line=%1 get_minimal_parkingprice:").arg(__LINE__)
<< price;
price = compute_product_price(&cfg, PERMIT_TYPE::DAY_TICKET, start);
qCritical() << QString("line=%1 price:").arg(__LINE__) << price;
start.setTime(QTime(15, 0, 0));
productStart = productEnd = QDateTime();
price = compute_product_price(&cfg, PERMIT_TYPE::DAY_TICKET, start, &productStart, &productEnd);
qCritical() << QString("line=%1 price (%2-%3) :")
.arg(__LINE__)
.arg(productStart.time().toString(Qt::ISODate))
.arg(productEnd.time().toString(Qt::ISODate))
<< price;
price = get_minimal_parkingprice(&cfg, PERMIT_TYPE::DAY_TICKET, 0, start);
qCritical() << QString("line=%1 get_minimal_parkingprice:").arg(__LINE__) << price;
start.setTime(QTime(16, 0, 0));
productStart = productEnd = QDateTime();
price = compute_product_price(&cfg, PERMIT_TYPE::DAY_TICKET, start, &productStart, &productEnd);
qCritical() << QString("line=%1 price (%2-%3) :")
.arg(__LINE__)
.arg(productStart.time().toString(Qt::ISODate))
.arg(productEnd.time().toString(Qt::ISODate))
<< price;
price = get_minimal_parkingprice(&cfg, PERMIT_TYPE::DAY_TICKET, 0, start);
qCritical() << QString("line=%1 get_minimal_parkingprice:").arg(__LINE__) << price;
start.setTime(QTime(17, 0, 0));
productStart = productEnd = QDateTime();
price = compute_product_price(&cfg, PERMIT_TYPE::DAY_TICKET, start, &productStart, &productEnd);
qCritical() << QString("line=%1 price (%2-%3) :")
.arg(__LINE__)
.arg(productStart.time().toString(Qt::ISODate))
.arg(productEnd.time().toString(Qt::ISODate))
<< price;
//price = get_minimal_parkingprice(&cfg, PERMIT_TYPE::DAY_TICKET, 0, start);
//qCritical() << QString("line=%1 get_minimal_parkingprice:").arg(__LINE__) << price;
//price = get_minimal_parkingprice(&cfg, PERMIT_TYPE::DAY_TICKET);
//qCritical() << QString("line=%1 get_minimal_parkingprice:").arg(__LINE__) << price;
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));
qCritical() << "RUN" << i << end.toString(Qt::ISODate) << calcState.toString();
}
#else
for (int h = 0; h < 24; ++h) {
start.setTime(QTime(h, 0, 0));
productStart = productEnd = QDateTime();
price = compute_product_price(&cfg, PERMIT_TYPE::DAY_TICKET, start, &productStart, &productEnd);
qCritical() << QString("line=%1 %2 price (%3-%4) :")
.arg(__LINE__)
.arg(start.time().toString(Qt::ISODate))
.arg(productStart.time().toString(Qt::ISODate))
.arg(productEnd.time().toString(Qt::ISODate))
<< price;
s.setTime(QTime(15, 0, 0));
minimal_parking_price = get_minimal_parkingprice(&cfg,
PermitType(PERMIT_TYPE::SHORT_TERM_PARKING_PKW),
paymentOptionIndex, s);
qCritical() << "minimal parking price" << minimal_parking_price;
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));
qCritical() << "RUN" << i << end.toString(Qt::ISODate) << calcState.toString();
}
#endif
}
@ -1484,7 +1466,7 @@ int main() {
for (int i = 0, j=timeSteps.size() ; i < timeSteps.size(); --j, ++i) {
QDateTime end = start.addSecs(timeSteps.at(i)*60);
cs = compute_price_for_parking_ticket(&cfg, start, timeSteps.at(i), end, &costs);
cs = compute_price_for_parking_ticket(&cfg, start, timeSteps.at(i), end, &costs, PermitType(PERMIT_TYPE::SHORT_TERM_PARKING));
if (cs.getStatus() != CalcState::State::SUCCESS) {
if (start.time().hour() >= 8 && start.time().hour() < 18) {
qCritical() << "ERROR CALC-STATE-1=" << QString(cs);
@ -1507,7 +1489,7 @@ int main() {
}
qCritical() << "compute_price_for_parking_ticket()/GetCostFromDuration() TIME: "
<< timeSteps.at(i) << "PRICE=" << price1;
<< timeSteps.at(i) << "PRICE=" << price1 << "end=" << end.toString(Qt::ISODate);
//std::string duration = Calculator::GetInstance().GetDurationFromCost(&cfg, 4,
@ -1591,7 +1573,7 @@ int main() {
double cost = 0;
CalcState cs;
if ((cs = compute_price_for_parking_ticket(&cfg, start, *step, end, &price))) {
if ((cs = compute_price_for_parking_ticket(&cfg, start, *step, end, &price, PermitType(PERMIT_TYPE::SHORT_TERM_PARKING)))) {
cost = price.netto;
qCritical() << "step" << *step << ": cost" << cost;
} else {
@ -1675,7 +1657,7 @@ int main() {
double cost = 0;
CalcState cs;
if ((cs = compute_price_for_parking_ticket(&cfg, start, *step, end, &price))) {
if ((cs = compute_price_for_parking_ticket(&cfg, start, *step, end, &price, PermitType(PERMIT_TYPE::SHORT_TERM_PARKING)))) {
cost = price.netto;
qCritical() << "step" << *step << ": cost" << cost;
} else {
@ -1760,7 +1742,7 @@ int main() {
double cost = 0;
CalcState cs;
if ((cs = compute_price_for_parking_ticket(&cfg, start, *step, end, &price))) {
if ((cs = compute_price_for_parking_ticket(&cfg, start, *step, end, &price, PermitType(PERMIT_TYPE::SHORT_TERM_PARKING)))) {
cost = price.netto;
qCritical() << "step" << *step << ": cost" << cost;
} else {
@ -1818,7 +1800,7 @@ int main() {
double cost = 0;
CalcState cs;
if ((cs = compute_price_for_parking_ticket(&cfg, start, *step, end, &price))) {
if ((cs = compute_price_for_parking_ticket(&cfg, start, *step, end, &price, PermitType(PERMIT_TYPE::SHORT_TERM_PARKING)))) {
cost = price.netto;
qCritical() << "step" << *step << ": cost" << cost;
} else {
@ -1921,7 +1903,7 @@ int main() {
CalcState cs;
for (int i = 13, j=timeSteps.size() ; i < timeSteps.size(); --j, ++i) {
QDateTime end = start.addSecs(timeSteps.at(i)*60);
cs = compute_price_for_parking_ticket(&cfg, start, timeSteps.at(i), end, &costs);
cs = compute_price_for_parking_ticket(&cfg, start, timeSteps.at(i), end, &costs, PermitType(PERMIT_TYPE::SHORT_TERM_PARKING));
qCritical() << endl;
}
@ -1946,7 +1928,7 @@ int main() {
for (int i = 0, j=timeSteps.size() ; i < timeSteps.size(); --j, ++i) {
QDateTime end = start.addSecs(timeSteps.at(i)*60);
cs = compute_price_for_parking_ticket(&cfg, start, timeSteps.at(i), end, &costs);
cs = compute_price_for_parking_ticket(&cfg, start, timeSteps.at(i), end, &costs, PermitType(PERMIT_TYPE::SHORT_TERM_PARKING));
if (cs.getStatus() != CalcState::State::SUCCESS) {
if (start.time().hour() >= 8 && start.time().hour() < 18) {
qCritical() << "ERROR CALC-STATE-1=" << QString(cs);

View File

@ -30,7 +30,9 @@ SOURCES += main.cpp
# HEADERS +=
OTHER_FILES += \
/home/linux/customer_505/etc/psa_tariff/tariff01.json
/opt/ptu5/opt/customer_502/etc/psa_tariff/tariff01.json \
/opt/ptu5/opt/customer_502/etc/psa_tariff/tariff02.json \
/opt/ptu5/opt/customer_502/etc/psa_tariff/tariff03.json