2023-11-27 16:15:18 +01:00
|
|
|
#ifndef CALCULATOR_FUNCTIONS_H_INCLUDED
|
|
|
|
#define CALCULATOR_FUNCTIONS_H_INCLUDED
|
|
|
|
|
2023-04-24 15:31:46 +02:00
|
|
|
#include <iostream>
|
2023-11-27 16:15:18 +01:00
|
|
|
#include <optional>
|
|
|
|
|
2023-04-24 15:31:46 +02:00
|
|
|
#include "configuration.h"
|
2024-01-30 10:35:07 +01:00
|
|
|
#include "calculate_price.h"
|
2023-11-22 08:55:00 +01:00
|
|
|
#include "payment_method.h"
|
2023-11-27 16:15:18 +01:00
|
|
|
#include "ticket.h"
|
|
|
|
#include "tariff_time_range.h"
|
|
|
|
|
2023-05-15 14:05:55 +02:00
|
|
|
#include <QDateTime>
|
2023-04-24 15:31:46 +02:00
|
|
|
using namespace std;
|
|
|
|
|
2024-01-18 14:49:56 +01:00
|
|
|
class Calculator {
|
2024-04-12 14:20:05 +02:00
|
|
|
mutable QVector<QList<int>> m_timeSteps;
|
2024-01-30 10:35:07 +01:00
|
|
|
mutable QList<int> m_priceSteps;
|
2024-01-23 10:51:25 +01:00
|
|
|
|
2024-04-19 13:06:37 +02:00
|
|
|
CalcState isParkingAllowedForWeekDay(Configuration const *cfg,
|
|
|
|
QDateTime const &start,
|
|
|
|
int netto_parking_time,
|
|
|
|
int paymentOptionIndex);
|
|
|
|
|
|
|
|
CalcState isParkingAllowedForSpecialDay(Configuration const *cfg,
|
|
|
|
QDateTime const &start,
|
|
|
|
int netto_parking_time,
|
|
|
|
int paymentOptionIndex);
|
|
|
|
|
2024-01-23 10:51:25 +01:00
|
|
|
protected:
|
2024-01-18 14:49:56 +01:00
|
|
|
explicit Calculator() = default;
|
2023-11-26 19:53:29 +01:00
|
|
|
|
2024-01-23 10:51:25 +01:00
|
|
|
public:
|
|
|
|
Calculator(Calculator const &other) = delete;
|
|
|
|
void operator=(Calculator const &) = delete;
|
|
|
|
|
|
|
|
static Calculator &GetInstance() {
|
|
|
|
static Calculator c;
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
2024-04-12 14:20:05 +02:00
|
|
|
void ResetTimeSteps(int paymentOptionIndex) {
|
|
|
|
if (m_timeSteps.size() > 0) {
|
|
|
|
m_timeSteps[paymentOptionIndex].clear();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
QList<int> timeSteps(int paymentOptionIndex=0) const {
|
|
|
|
if (m_timeSteps.size() > 0) {
|
|
|
|
return m_timeSteps[paymentOptionIndex];
|
|
|
|
}
|
|
|
|
return QList<int>();
|
|
|
|
}
|
2024-01-23 10:51:25 +01:00
|
|
|
|
2024-01-30 10:35:07 +01:00
|
|
|
void ResetPriceSteps() { m_priceSteps.clear(); }
|
|
|
|
QList<int> priceSteps() const { return m_priceSteps; }
|
|
|
|
|
2024-04-19 13:06:37 +02:00
|
|
|
CalcState isParkingAllowed(Configuration const *cfg,
|
|
|
|
QDateTime const &start);
|
|
|
|
|
|
|
|
CalcState isParkingAllowed(Configuration const *cfg,
|
|
|
|
QDateTime const &start,
|
|
|
|
int netto_parking_time,
|
|
|
|
int paymentOptionIndex);
|
2024-01-31 15:14:44 +01:00
|
|
|
|
2023-04-24 15:31:46 +02:00
|
|
|
/// <summary>
|
|
|
|
/// Gets duration in seconds from cost
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="tariff_cfg">Pointer to configuration</param>
|
|
|
|
/// <param name="vehicle_type">Type of vehicle</param>
|
|
|
|
/// <param name="start_datetime">Date/time of payment to be conducted in ISO8601 format (e.g. 2022-12-25T08:00:00Z)</param>
|
|
|
|
/// <param name="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);
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Gets cost from duration in seconds
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="tariff_cfg">Pointer to configuration</param>
|
|
|
|
/// <param name="vehicle_type">Type of vehicle</param>
|
|
|
|
/// <param name="start_datetime">Date/time of payment to be conducted in ISO8601 format (e.g. 2022-12-25T08:00:00Z) </param>
|
2023-05-16 15:31:53 +02:00
|
|
|
/// <param name="end_datetime">Date/time of park end to be conducted in ISO8601 format (e.g. 2022-12-25T08:00:00Z) </param>
|
2023-04-24 15:31:46 +02:00
|
|
|
/// <param name="durationMin">Duration of parking in minutes</param>
|
|
|
|
/// <returns>Returns cost (data type: double)</returns>
|
2024-02-15 16:05:49 +01:00
|
|
|
double GetCostFromDuration(Configuration* cfg, uint8_t vehicle_type, QDateTime &start_datetime, QDateTime & end_datetime, int durationMin, bool nextDay = false, bool prepaid = false);
|
2023-05-15 14:05:55 +02:00
|
|
|
|
|
|
|
// Daily ticket
|
2023-05-16 16:43:45 +02:00
|
|
|
QDateTime GetDailyTicketDuration(Configuration* cfg, const QDateTime start_datetime, uint8_t payment_option, bool carry_over);
|
2024-01-30 10:37:30 +01:00
|
|
|
std::optional<struct price_t> GetDailyTicketPrice(Configuration* cfg, QDateTime const &startDatetime, QDateTime &endTime, PERMIT_TYPE permitType);
|
2023-11-22 08:55:00 +01:00
|
|
|
|
2023-11-23 09:36:50 +01:00
|
|
|
//
|
|
|
|
// helper function to find time steps for a tariff with PaymentMethod::Steps
|
|
|
|
// (e.g. Schoenau/Koenigsee)
|
|
|
|
//
|
2024-04-12 14:20:05 +02:00
|
|
|
QList<int> GetTimeSteps(Configuration *cfg, int paymentOptionIndex=0) const;
|
|
|
|
QList<int> GetSteps(Configuration *cfg, int paymentOptionIndex=0) const { return GetTimeSteps(cfg, paymentOptionIndex); }
|
2023-12-12 10:36:22 +01:00
|
|
|
|
2024-01-30 10:37:30 +01:00
|
|
|
QList<int> GetPriceSteps(Configuration *cfg) const;
|
|
|
|
|
2023-12-12 10:36:22 +01:00
|
|
|
// additional helper functions
|
|
|
|
bool noSpecialDays(Configuration const *cfg) const {
|
|
|
|
return (cfg->SpecialDays.size() == 0) && (cfg->SpecialDaysWorktime.size() == 0);
|
|
|
|
}
|
|
|
|
bool specialDays(Configuration const *cfg) const {
|
|
|
|
return !noSpecialDays(cfg);
|
|
|
|
}
|
|
|
|
bool tariffIs24_7(Configuration const *cfg) const {
|
|
|
|
return (cfg->YearPeriod.size() == 0 &&
|
|
|
|
cfg->SpecialDays.size() == 0 &&
|
|
|
|
cfg->SpecialDaysWorktime.size() == 0);
|
|
|
|
}
|
2023-11-22 08:55:00 +01:00
|
|
|
|
2024-01-18 14:49:56 +01:00
|
|
|
// testing public:
|
2023-11-22 08:55:00 +01:00
|
|
|
// Introduced for PaymentMethod::Steps (e.g. Schoenau)
|
|
|
|
// For tariff of following structure: only steps, no special days, nonstop.
|
2024-04-19 13:06:37 +02:00
|
|
|
uint32_t GetCostFromDuration(Configuration *cfg, QDateTime const &start, quint64 durationMinutes, int paymentOptionIndex=0) const;
|
|
|
|
uint32_t GetCostFromDuration(Configuration *cfg, QDateTime const &start, QDateTime const &end, int paymentOptionIndex=0) const;
|
2023-11-22 08:55:00 +01:00
|
|
|
|
2024-01-24 16:35:58 +01:00
|
|
|
private:
|
2023-11-27 16:15:18 +01:00
|
|
|
Ticket private_GetCostFromDuration(Configuration const* cfg,
|
|
|
|
QDateTime const &start,
|
2023-11-28 15:17:27 +01:00
|
|
|
int durationMinutes,
|
|
|
|
bool prepaid = false);
|
2023-11-28 16:42:29 +01:00
|
|
|
Ticket private_GetDurationFromCost(Configuration *cfg,
|
|
|
|
QDateTime const &start,
|
|
|
|
uint32_t price,
|
|
|
|
bool prepaid = false);
|
2023-11-26 19:53:29 +01:00
|
|
|
|
2023-11-28 15:17:27 +01:00
|
|
|
bool checkDurationMinutes(int minParkingTime, int maxParkingTime,
|
2023-11-26 19:53:29 +01:00
|
|
|
int durationMinutes);
|
2023-11-22 08:55:00 +01:00
|
|
|
|
|
|
|
//
|
2024-04-19 13:06:37 +02:00
|
|
|
uint32_t GetPriceForTimeStep(Configuration *cfg, int timeStep, int paymentOptionIndex=0) const;
|
2023-12-12 10:40:20 +01:00
|
|
|
uint32_t GetPriceForStep(Configuration *cfg, int step) const {
|
|
|
|
return GetPriceForTimeStep(cfg, step);
|
|
|
|
}
|
2023-11-23 09:36:50 +01:00
|
|
|
uint32_t GetDurationForPrice(Configuration *cfg, int price) const;
|
2023-12-12 10:40:20 +01:00
|
|
|
uint32_t GetStepForPrice(Configuration *cfg, int price) const {
|
|
|
|
return GetDurationForPrice(cfg, price);
|
|
|
|
}
|
2023-11-27 16:15:18 +01:00
|
|
|
|
|
|
|
int findWorkTimeRange(QDateTime const &dt,
|
|
|
|
QScopedArrayPointer<TariffTimeRange> const &worktime,
|
|
|
|
size_t size);
|
|
|
|
int findNextWorkTimeRange(QDateTime const &dt,
|
|
|
|
QScopedArrayPointer<TariffTimeRange> const &worktime,
|
|
|
|
size_t size);
|
2023-05-15 14:05:55 +02:00
|
|
|
};
|
2023-11-27 16:15:18 +01:00
|
|
|
|
|
|
|
#endif // CALCULATOR_FUNCTIONS_H_INCLUDED
|