Compare commits
6 Commits
cb78e27d37
...
00bf13af86
Author | SHA1 | Date | |
---|---|---|---|
00bf13af86 | |||
062d936042 | |||
86c27986cc | |||
10b018a338 | |||
1c13a705c8 | |||
fd5b41364a |
@ -6,4 +6,8 @@ main.depends = library
|
||||
|
||||
contains( CONFIG, PTU5_YOCTO ) {
|
||||
SUBDIRS = library
|
||||
}
|
||||
}
|
||||
|
||||
OTHER_FILES += \
|
||||
tariffs/tariff01.json \
|
||||
tariffs/tariff02.json
|
||||
|
@ -1,6 +1,8 @@
|
||||
#pragma once
|
||||
#include <iostream>
|
||||
#include "configuration.h"
|
||||
#include "payment_method.h"
|
||||
|
||||
#include <QDateTime>
|
||||
using namespace std;
|
||||
|
||||
@ -28,6 +30,11 @@ public:
|
||||
/// <returns>Returns cost (data type: double)</returns>
|
||||
double GetCostFromDuration(Configuration* cfg, uint8_t vehicle_type, const QDateTime start_datetime, QDateTime & end_datetime, double durationMin, bool nextDay = false, bool prepaid = false);
|
||||
|
||||
// Introduced for Schoenau, Koenigsee.
|
||||
// For tariff of following structure: only steps, no special days, nonstop.
|
||||
uint32_t GetCostFromDuration(Configuration const* cfg, QDateTime const &start, quint64 durationMinutes, uint8_t paymentMethod = PaymentMethod::Steps);
|
||||
uint32_t GetCostFromDuration(Configuration const* cfg, QDateTime const &start, QDateTime const &end, uint8_t paymentMethod = PaymentMethod::Steps);
|
||||
|
||||
// Daily ticket
|
||||
QDateTime GetDailyTicketDuration(Configuration* cfg, const QDateTime start_datetime, uint8_t payment_option, bool carry_over);
|
||||
|
||||
@ -35,7 +42,7 @@ public:
|
||||
//
|
||||
// helper functions for Schoenau
|
||||
//
|
||||
QList<int> GetTimeSteps(Configuration const *cfg, int paymentOption);
|
||||
QList<int> GetTimeSteps(Configuration const *cfg, int paymentMethod);
|
||||
//
|
||||
double GetPriceForTimeStep(Configuration const *cfg, int paymentOption, int timeStep);
|
||||
uint32_t GetPriceForTimeStep(Configuration const *cfg, uint8_t paymentMethod, int timeStep);
|
||||
};
|
||||
|
@ -339,17 +339,38 @@ std::string Calculator::GetDurationFromCost(Configuration* cfg,
|
||||
///////////////////////////////////////
|
||||
|
||||
/// <inheritdoc/>
|
||||
///
|
||||
|
||||
uint32_t Calculator::GetCostFromDuration(Configuration const* cfg,
|
||||
QDateTime const &start,
|
||||
quint64 timeStepInMinutes,
|
||||
uint8_t paymentMethod) {
|
||||
// for instance, a tariff as used in Schoenau, Koenigssee: only steps, no
|
||||
// special days, nonstop.
|
||||
if (paymentMethod == PaymentMethod::Steps
|
||||
&& cfg->SpecialDays.size() == 0
|
||||
&& cfg->SpecialDaysWorktime.size() == 0) {
|
||||
QDateTime const end = start.addSecs(timeStepInMinutes*60);
|
||||
return GetCostFromDuration(cfg, start, end, paymentMethod);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint32_t Calculator::GetCostFromDuration(Configuration const* cfg,
|
||||
QDateTime const &start,
|
||||
QDateTime const &end,
|
||||
uint8_t paymentMethod) {
|
||||
if (paymentMethod == PaymentMethod::Steps
|
||||
&& cfg->SpecialDays.size() == 0
|
||||
&& cfg->SpecialDaysWorktime.size() == 0) {
|
||||
int const timeStepInMinutes = start.secsTo(end) / 60;
|
||||
return GetPriceForTimeStep(cfg, paymentMethod, timeStepInMinutes);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
double Calculator::GetCostFromDuration(Configuration* cfg, uint8_t payment_option, const QDateTime start_datetime, QDateTime & end_datetime, double durationMin, bool nextDay, bool prepaid)
|
||||
{
|
||||
if (cfg->project.project == "Schoenau" || cfg->project.project == "schoenau") {
|
||||
static QList<int> const timeSteps = GetTimeSteps(cfg, payment_option);
|
||||
if (!timeSteps.contains(durationMin)) {
|
||||
return 0.0f; // error: timestep not valid
|
||||
}
|
||||
|
||||
return GetPriceForTimeStep(cfg, payment_option, durationMin);
|
||||
}
|
||||
|
||||
// Get input date
|
||||
QDateTime inputDate = start_datetime;
|
||||
|
||||
@ -566,7 +587,7 @@ QList<int> Calculator::GetTimeSteps(Configuration const *cfg, int paymentOption)
|
||||
return timeSteps;
|
||||
}
|
||||
|
||||
double Calculator::GetPriceForTimeStep(Configuration const *cfg, int paymentOption, int timeStep) {
|
||||
uint32_t Calculator::GetPriceForTimeStep(Configuration const *cfg, uint8_t paymentOption, int timeStep) {
|
||||
|
||||
int const pop_id = cfg->PaymentOption.find(paymentOption)->second.pop_id;
|
||||
|
||||
@ -579,9 +600,9 @@ double Calculator::GetPriceForTimeStep(Configuration const *cfg, int paymentOpti
|
||||
|
||||
int const pun_duration = cfg->Duration.find(payment_unit_id)->second.pun_duration;
|
||||
if (timeStep == pun_duration) {
|
||||
return itr->second.pra_price;
|
||||
return (uint32_t)(itr->second.pra_price);
|
||||
}
|
||||
}
|
||||
|
||||
return 0.0;
|
||||
return 0;
|
||||
}
|
||||
|
@ -34,8 +34,8 @@ bool Configuration::ParseJson(Configuration* cfg, const char* json)
|
||||
}
|
||||
|
||||
// Parse JSON to document
|
||||
Document document;
|
||||
document.Parse(json);
|
||||
Document document;
|
||||
document.Parse(json);
|
||||
|
||||
// Return if parse error has been found
|
||||
ParseErrorCode err = document.GetParseError();
|
||||
@ -55,13 +55,13 @@ bool Configuration::ParseJson(Configuration* cfg, const char* json)
|
||||
|
||||
// Validate JSON, check configuration members
|
||||
if (!document.HasMember("Currency")
|
||||
|| !document.HasMember("PaymentMethod")
|
||||
|| !document.HasMember("PaymentOption")
|
||||
|| !document.HasMember("PaymentRate")
|
||||
|| !document.HasMember("Duration")
|
||||
//|| !document.HasMember("WeekDays")
|
||||
|| !document.HasMember("SpecialDaysWorktime")
|
||||
|| !document.HasMember("SpecialDays"))
|
||||
|| !document.HasMember("PaymentMethod")
|
||||
|| !document.HasMember("PaymentOption")
|
||||
|| !document.HasMember("PaymentRate")
|
||||
|| !document.HasMember("Duration"))
|
||||
//|| !document.HasMember("WeekDays")
|
||||
//|| !document.HasMember("SpecialDaysWorktime")
|
||||
//|| !document.HasMember("SpecialDays"))
|
||||
{
|
||||
printf("%s", "Error: not a valid configuration JSON\n");
|
||||
return false;
|
||||
|
@ -24,10 +24,16 @@ extern "C" char* strptime(const char* s,
|
||||
#endif
|
||||
|
||||
#include "calculate_price.h"
|
||||
#include "calculator_functions.h"
|
||||
#include "payment_method.h"
|
||||
|
||||
|
||||
#include <QDebug>
|
||||
#include <QDateTime>
|
||||
|
||||
|
||||
static Calculator calculator;
|
||||
|
||||
int main() {
|
||||
|
||||
parking_tariff_t *tariff = 0;
|
||||
@ -37,24 +43,27 @@ int main() {
|
||||
memset(&price, 0x00, sizeof(price));
|
||||
// QDateTime start = QDateTime::fromString("2023-06-01T07:50:00.000Z",Qt::ISODate); //QDateTime::currentDateTime();
|
||||
QDateTime start = QDateTime::currentDateTime();
|
||||
time_t start_parking_time = start.toSecsSinceEpoch() / 60;
|
||||
// time_t start_parking_time = start.toSecsSinceEpoch() / 60;
|
||||
|
||||
// zone 1
|
||||
int timeSteps[9] = {60, 180, 1440, 2880, 4320, 5670, 7200, 8640, 10080};
|
||||
//int timeSteps[9] = {60, 180, 1440, 2880, 4320, 5670, 7200, 8640, 10080};
|
||||
|
||||
// zone 2
|
||||
//int timeSteps[3] = {60, 180, 1440};
|
||||
|
||||
for (int i = 0 ; i < sizeof(timeSteps)/sizeof(int); ++i) {
|
||||
time_t end_parking_time = start_parking_time + timeSteps[i];
|
||||
static QList<int> const timeSteps = calculator.GetTimeSteps(tariff, PaymentMethod::Steps);
|
||||
|
||||
if (compute_price_for_parking_ticket(tariff,
|
||||
start_parking_time,
|
||||
end_parking_time,
|
||||
&price))
|
||||
{
|
||||
qDebug() << "GetCostFromDuration() time: " << timeSteps[i] << "price=" << price.netto;
|
||||
}
|
||||
qCritical() << timeSteps;
|
||||
|
||||
for (int i = 0 ; i < timeSteps.size(); ++i) {
|
||||
// time_t end_parking_time = start_parking_time + timeSteps[i];
|
||||
QDateTime end = start.addSecs(timeSteps.at(i)*60);
|
||||
|
||||
double price = calculator.GetCostFromDuration(tariff,
|
||||
start,
|
||||
timeSteps.at(i),
|
||||
PaymentMethod::Steps);
|
||||
qDebug() << "GetCostFromDuration() time: " << timeSteps.at(i) << "price=" << price;
|
||||
}
|
||||
|
||||
free_tariff(tariff);
|
||||
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
117
tariffs/tariff03.json
Normal file
117
tariffs/tariff03.json
Normal file
@ -0,0 +1,117 @@
|
||||
{
|
||||
"Project" : "Schoenau",
|
||||
"Version" : "1.0.0",
|
||||
"Info" : "",
|
||||
"Currency": [
|
||||
{
|
||||
"pcu_id": 1,
|
||||
"pcu_sign": "€",
|
||||
"pcu_major": "Euro",
|
||||
"pcu_minor": "Cent",
|
||||
"pcu_active": true
|
||||
}
|
||||
],
|
||||
"PaymentMethod": [
|
||||
{
|
||||
"pme_id": 1,
|
||||
"pme_label": "progressive"
|
||||
},
|
||||
{
|
||||
"pme_id": 2,
|
||||
"pme_label": "degressive"
|
||||
},
|
||||
{
|
||||
"pme_id": 3,
|
||||
"pme_label": "linear"
|
||||
},
|
||||
{
|
||||
"pme_id": 4,
|
||||
"pme_label": "steps"
|
||||
}
|
||||
],
|
||||
"PaymentOption": [
|
||||
{
|
||||
"pop_id": 1100,
|
||||
"pop_label": "Zone 2",
|
||||
"pop_payment_method_id": 4,
|
||||
"pop_day_end_time": "15:07:00",
|
||||
"pop_day_night_end_time": "15:07:00",
|
||||
"pop_price_night": 0,
|
||||
"pop_min_time": 60,
|
||||
"pop_max_time": 1440,
|
||||
"pop_min_price": 2,
|
||||
"pop_carry_over": 1,
|
||||
"pop_daily_card_price": 0,
|
||||
"pop_multi_hour_price": 5
|
||||
}
|
||||
],
|
||||
"PaymentRate": [
|
||||
{
|
||||
"pra_payment_option_id": 1100,
|
||||
"pra_payment_unit_id": 1,
|
||||
"pra_price": 2
|
||||
},
|
||||
{
|
||||
"pra_payment_option_id": 1100,
|
||||
"pra_payment_unit_id": 6,
|
||||
"pra_price": 4
|
||||
},
|
||||
{
|
||||
"pra_payment_option_id": 1100,
|
||||
"pra_payment_unit_id": 5,
|
||||
"pra_price": 5
|
||||
}
|
||||
],
|
||||
"Duration": [
|
||||
{
|
||||
"pun_id": 1,
|
||||
"pun_label": "1h",
|
||||
"pun_duration": 60
|
||||
},
|
||||
{
|
||||
"pun_id": 3,
|
||||
"pun_label": "15 min",
|
||||
"pun_duration": 15
|
||||
},
|
||||
{
|
||||
"pun_id": 5,
|
||||
"pun_label": "24h",
|
||||
"pun_duration": 1440
|
||||
},
|
||||
{
|
||||
"pun_id": 6,
|
||||
"pun_label": "3h",
|
||||
"pun_duration": 180
|
||||
},
|
||||
{
|
||||
"pun_id": 7,
|
||||
"pun_label": "48h",
|
||||
"pun_duration": 2880
|
||||
},
|
||||
{
|
||||
"pun_id": 8,
|
||||
"pun_label": "72h",
|
||||
"pun_duration": 4320
|
||||
},
|
||||
{
|
||||
"pun_id": 9,
|
||||
"pun_label": "96h",
|
||||
"pun_duration": 5670
|
||||
},
|
||||
{
|
||||
"pun_id": 10,
|
||||
"pun_label": "120h",
|
||||
"pun_duration": 7200
|
||||
},
|
||||
{
|
||||
"pun_id": 11,
|
||||
"pun_label": "144h",
|
||||
"pun_duration": 8640
|
||||
},
|
||||
{
|
||||
"pun_id": 12,
|
||||
"pun_label": "168h",
|
||||
"pun_duration": 10080
|
||||
}
|
||||
]
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user