Compare commits
60 Commits
5c0bbf1502
...
schoenau_2
Author | SHA1 | Date | |
---|---|---|---|
0217bb8918 | |||
4b35b1ffb7 | |||
80e228b498 | |||
574161ff76 | |||
b80cd5e6ef | |||
3a2e521345
|
|||
cd77e380ef
|
|||
aaa4348a9a
|
|||
17c4aac452
|
|||
68c438bfe0
|
|||
509bc29d7e
|
|||
f7e462188f
|
|||
d15c9dad29
|
|||
cb8cd5dead
|
|||
9d64350e4f
|
|||
1a71edc274 | |||
51d8beda2a | |||
7bab9d6ba2 | |||
8b4d64bd0c | |||
eefdde4693 | |||
6157861d62 | |||
23748966de
|
|||
7bd7f66666 | |||
268d43cdea
|
|||
a453886f0a
|
|||
eef94a3fb3
|
|||
88a0b6ebe2
|
|||
3097819c01
|
|||
acf799da7e
|
|||
3bf71f84d5
|
|||
73f5eca656
|
|||
b8753cc2ed
|
|||
29986e0451
|
|||
1146db743c
|
|||
c6302edec5
|
|||
617eee39ed | |||
6b3c1cbf0c | |||
1142efaec2 | |||
90eae152bf
|
|||
6d001f1501
|
|||
de32022b89
|
|||
1e2f1589ac
|
|||
2f8c8cab4c | |||
ee1f7eca44
|
|||
1069c5ad90
|
|||
46bffc250d
|
|||
2599513ef9 | |||
ef66c1f0c0 | |||
219d820104 | |||
ed9166c226 | |||
818c67ad63 | |||
4a076e1dad
|
|||
62426e60d5
|
|||
c28351b1bf
|
|||
69c469c918
|
|||
e7606b6568 | |||
fe0ebb409a
|
|||
3d88c8e67e
|
|||
eebb6d926e | |||
69c48e3acc |
13
library/include/mobilisis/atb_project.h
Normal file
13
library/include/mobilisis/atb_project.h
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
#ifndef ATB_PROJECT_H_INCLUDED
|
||||||
|
#define ATB_PROJECT_H_INCLUDED
|
||||||
|
|
||||||
|
#include <QString>
|
||||||
|
|
||||||
|
class ATBProject {
|
||||||
|
public:
|
||||||
|
QString project;
|
||||||
|
QString version;
|
||||||
|
QString info;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // ATB_PROJECT_H_INCLUDED
|
@@ -5,6 +5,7 @@
|
|||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
|
|
||||||
#include <QString>
|
#include <QString>
|
||||||
|
#include <QDateTime>
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
#ifdef CALCULATE_LIBRARY_EXPORTS
|
#ifdef CALCULATE_LIBRARY_EXPORTS
|
||||||
@@ -20,9 +21,9 @@ class Configuration;
|
|||||||
|
|
||||||
typedef Configuration parking_tariff_t;
|
typedef Configuration parking_tariff_t;
|
||||||
|
|
||||||
#ifdef __cplusplus
|
//#ifdef __cplusplus
|
||||||
extern "C" {
|
//extern "C" {
|
||||||
#endif
|
//#endif
|
||||||
|
|
||||||
struct CALCULATE_LIBRARY_API price_t {
|
struct CALCULATE_LIBRARY_API price_t {
|
||||||
uint32_t units;
|
uint32_t units;
|
||||||
@@ -41,6 +42,7 @@ struct CALCULATE_LIBRARY_API CalcState {
|
|||||||
NEGATIVE_PARING_TIME,
|
NEGATIVE_PARING_TIME,
|
||||||
INVALID_START_DATE,
|
INVALID_START_DATE,
|
||||||
WRONG_PARAM_VALUES,
|
WRONG_PARAM_VALUES,
|
||||||
|
WRONG_ISO_TIME_FORMAT,
|
||||||
ABOVE_MAX_PARKING_TIME,
|
ABOVE_MAX_PARKING_TIME,
|
||||||
BELOW_MIN_PARKING_TIME,
|
BELOW_MIN_PARKING_TIME,
|
||||||
BELOW_MIN_PARKING_PRICE,
|
BELOW_MIN_PARKING_PRICE,
|
||||||
@@ -92,6 +94,8 @@ struct CALCULATE_LIBRARY_API CalcState {
|
|||||||
case State::INVALID_START_DATE:
|
case State::INVALID_START_DATE:
|
||||||
s = "INVALID_START_DATE";
|
s = "INVALID_START_DATE";
|
||||||
break;
|
break;
|
||||||
|
case State::WRONG_ISO_TIME_FORMAT:
|
||||||
|
s = "WRONG_ISO_TIME_FORMAT";
|
||||||
}
|
}
|
||||||
return s + ":" + m_desc;
|
return s + ":" + m_desc;
|
||||||
}
|
}
|
||||||
@@ -103,21 +107,39 @@ struct CALCULATE_LIBRARY_API CalcState {
|
|||||||
CalcState CALCULATE_LIBRARY_API init_tariff(parking_tariff_t **tariff,
|
CalcState CALCULATE_LIBRARY_API init_tariff(parking_tariff_t **tariff,
|
||||||
char const *config_file);
|
char const *config_file);
|
||||||
void CALCULATE_LIBRARY_API free_tariff(parking_tariff_t *tariff);
|
void CALCULATE_LIBRARY_API free_tariff(parking_tariff_t *tariff);
|
||||||
int CALCULATE_LIBRARY_API get_zone_nr();
|
int CALCULATE_LIBRARY_API get_zone_nr(int zone = -1);
|
||||||
|
|
||||||
CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket(
|
CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket( // deprecated
|
||||||
parking_tariff_t *tariff,
|
parking_tariff_t *tariff,
|
||||||
time_t start_parking_time,
|
time_t start_parking_time,
|
||||||
time_t end_parking_time,
|
time_t end_parking_time,
|
||||||
struct price_t *price);
|
struct price_t *price);
|
||||||
|
|
||||||
CalcState CALCULATE_LIBRARY_API compute_duration_for_parking_ticket(
|
CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket(
|
||||||
|
parking_tariff_t *tariff,
|
||||||
|
QDateTime const &start_parking_time,
|
||||||
|
int netto_parking_time,
|
||||||
|
QDateTime &end_parking_time, // return value
|
||||||
|
struct price_t *price); // return value
|
||||||
|
|
||||||
|
CalcState CALCULATE_LIBRARY_API compute_duration_for_parking_ticket( // deprecated
|
||||||
parking_tariff_t *tariff,
|
parking_tariff_t *tariff,
|
||||||
time_t start_parking_time,
|
time_t start_parking_time,
|
||||||
double cost,
|
double cost,
|
||||||
QString &duration);
|
QString &duration);
|
||||||
#ifdef __cplusplus
|
|
||||||
} // extern "C"
|
CalcState CALCULATE_LIBRARY_API compute_duration_for_parking_ticket(
|
||||||
#endif
|
parking_tariff_t *tariff,
|
||||||
|
QDateTime const &start_parking_time,
|
||||||
|
double cost,
|
||||||
|
QDateTime &ticketEndTime); // return value
|
||||||
|
|
||||||
|
CalcState CALCULATE_LIBRARY_API compute_duration_for_daily_ticket(
|
||||||
|
parking_tariff_t *tariff,
|
||||||
|
QDateTime const &start_parking_time,
|
||||||
|
QDateTime &ticketEndTime);
|
||||||
|
//#ifdef __cplusplus
|
||||||
|
//} // extern "C"
|
||||||
|
//#endif
|
||||||
|
|
||||||
#endif // CALCULATE_PRICE_H
|
#endif // CALCULATE_PRICE_H
|
||||||
|
@@ -1,7 +1,8 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include "configuration.h"
|
#include "configuration.h"
|
||||||
|
#include "payment_method.h"
|
||||||
|
#include <QDateTime>
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
class Calculator
|
class Calculator
|
||||||
@@ -23,7 +24,28 @@ public:
|
|||||||
/// <param name="tariff_cfg">Pointer to configuration</param>
|
/// <param name="tariff_cfg">Pointer to configuration</param>
|
||||||
/// <param name="vehicle_type">Type of vehicle</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="start_datetime">Date/time of payment to be conducted in ISO8601 format (e.g. 2022-12-25T08:00:00Z) </param>
|
||||||
|
/// <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>
|
/// <param name="durationMin">Duration of parking in minutes</param>
|
||||||
/// <returns>Returns cost (data type: double)</returns>
|
/// <returns>Returns cost (data type: double)</returns>
|
||||||
double GetCostFromDuration(Configuration* cfg, uint8_t vehicle_type, char const* start_datetime, double durationMin, bool nextDay = false, bool prepaid = false);
|
double GetCostFromDuration(Configuration* cfg, uint8_t vehicle_type, const QDateTime start_datetime, QDateTime & end_datetime, double durationMin, bool nextDay = false, bool prepaid = false);
|
||||||
|
|
||||||
|
// Daily ticket
|
||||||
|
QDateTime GetDailyTicketDuration(Configuration* cfg, const QDateTime start_datetime, uint8_t payment_option, bool carry_over);
|
||||||
|
|
||||||
|
//
|
||||||
|
// helper function to find time steps for a tariff with PaymentMethod::Steps
|
||||||
|
// (e.g. Schoenau/Koenigsee)
|
||||||
|
//
|
||||||
|
QList<int> GetTimeSteps(Configuration *cfg) const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
// Introduced for PaymentMethod::Steps (e.g. Schoenau)
|
||||||
|
// For tariff of following structure: only steps, no special days, nonstop.
|
||||||
|
uint32_t GetCostFromDuration(Configuration *cfg, QDateTime const &start, quint64 durationMinutes) const;
|
||||||
|
uint32_t GetCostFromDuration(Configuration *cfg, QDateTime const &start, QDateTime const &end) const;
|
||||||
|
|
||||||
|
|
||||||
|
//
|
||||||
|
uint32_t GetPriceForTimeStep(Configuration *cfg, int timeStep) const;
|
||||||
|
uint32_t GetDurationForPrice(Configuration *cfg, int price) const;
|
||||||
};
|
};
|
@@ -20,6 +20,7 @@
|
|||||||
#include "member_type.h"
|
#include "member_type.h"
|
||||||
#include "period_year.h"
|
#include "period_year.h"
|
||||||
#include "payment_rate.h"
|
#include "payment_rate.h"
|
||||||
|
#include "atb_project.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace rapidjson;
|
using namespace rapidjson;
|
||||||
@@ -27,8 +28,8 @@ using namespace rapidjson;
|
|||||||
class Configuration
|
class Configuration
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
ATBProject project;
|
||||||
ATBCurrency Currency;
|
ATBCurrency Currency;
|
||||||
ATBDuration duration;
|
ATBDuration duration;
|
||||||
|
|
||||||
multimap<int, ATBDuration> Duration;
|
multimap<int, ATBDuration> Duration;
|
||||||
@@ -48,6 +49,8 @@ public:
|
|||||||
/// <returns>Returns operation status bool (OK | FAIL) </returns>
|
/// <returns>Returns operation status bool (OK | FAIL) </returns>
|
||||||
bool ParseJson(Configuration* cfg, const char* json);
|
bool ParseJson(Configuration* cfg, const char* json);
|
||||||
|
|
||||||
|
ATBPaymentOption const & getPaymentOptions();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Identify type of JSON member
|
/// Identify type of JSON member
|
||||||
@@ -55,4 +58,6 @@ private:
|
|||||||
/// <param name="member_name"></param>
|
/// <param name="member_name"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
MemberType IdentifyJsonMember(const char* member_name);
|
MemberType IdentifyJsonMember(const char* member_name);
|
||||||
|
|
||||||
|
ATBPaymentOption currentPaymentOptions;
|
||||||
};
|
};
|
@@ -2,12 +2,12 @@
|
|||||||
|
|
||||||
enum DayOfWeek
|
enum DayOfWeek
|
||||||
{
|
{
|
||||||
Saturday = 0x06,
|
Monday = 0x01,
|
||||||
Sunday = 0x01,
|
Tuesday = 0x02,
|
||||||
Monday = 0x02,
|
Wednesday = 0x03,
|
||||||
Tuesday = 0x02,
|
Thursday = 0x04,
|
||||||
Wednesday = 0x03,
|
Friday = 0x05,
|
||||||
Thursday = 0x04,
|
Saturday = 0x06,
|
||||||
Friday = 0x05,
|
Sunday = 0x07,
|
||||||
UndefinedDay = 0xFF
|
UndefinedDay = 0xFF
|
||||||
};
|
};
|
@@ -14,4 +14,5 @@ public:
|
|||||||
double pop_max_time;
|
double pop_max_time;
|
||||||
double pop_min_price;
|
double pop_min_price;
|
||||||
int pop_carry_over;
|
int pop_carry_over;
|
||||||
|
int pop_daily_card_price;
|
||||||
};
|
};
|
@@ -68,5 +68,6 @@ public:
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="pra_price"></param>
|
/// <param name="pra_price"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
static double CalculatePricePerUnit(double pra_price);
|
static double CalculatePricePerUnit(double pra_price, double durationUnit = -1);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
TEMPLATE = lib
|
TEMPLATE = lib
|
||||||
TARGET = mobilisis_calc
|
TARGET = mobilisis_calc
|
||||||
# CONFIG += staticlib
|
#CONFIG += staticlib
|
||||||
|
|
||||||
QMAKE_CXXFLAGS += -std=c++17 -g -O0
|
QMAKE_CXXFLAGS += -std=c++17 -g -O0
|
||||||
|
|
||||||
@@ -65,7 +65,8 @@ HEADERS += \
|
|||||||
include/mobilisis/tariff_period_year.h \
|
include/mobilisis/tariff_period_year.h \
|
||||||
include/mobilisis/tariff_payment_rate.h \
|
include/mobilisis/tariff_payment_rate.h \
|
||||||
include/mobilisis/tariff_log.h \
|
include/mobilisis/tariff_log.h \
|
||||||
include/mobilisis/calculate_price.h
|
include/mobilisis/calculate_price.h \
|
||||||
|
include/mobilisis/atb_project.h
|
||||||
|
|
||||||
OTHER_FILES += src/main.cpp
|
OTHER_FILES += src/main.cpp
|
||||||
|
|
||||||
|
@@ -10,24 +10,31 @@
|
|||||||
|
|
||||||
static Calculator calculator;
|
static Calculator calculator;
|
||||||
|
|
||||||
int CALCULATE_LIBRARY_API get_zone_nr() {
|
int CALCULATE_LIBRARY_API get_zone_nr(int zone)
|
||||||
QFile zone("/etc/zone_nr");
|
{
|
||||||
if (zone.exists()) {
|
if(zone > -1) return zone;
|
||||||
QFileInfo finfo(zone);
|
else
|
||||||
if (finfo.size() <= 4) { // decimal 000\n
|
{
|
||||||
if (zone.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
QFile zone("/etc/zone_nr");
|
||||||
QTextStream in(&zone);
|
if (zone.exists()) {
|
||||||
return in.readLine(100).toInt();
|
QFileInfo finfo(zone);
|
||||||
|
if (finfo.size() <= 4) { // decimal 000\n
|
||||||
|
if (zone.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
||||||
|
QTextStream in(&zone);
|
||||||
|
return in.readLine(100).toInt();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CalcState CALCULATE_LIBRARY_API init_tariff(parking_tariff_t **tariff, char const *config_file) {
|
CalcState CALCULATE_LIBRARY_API init_tariff(parking_tariff_t **tariff, char const *config_file) {
|
||||||
*tariff = new Configuration();
|
*tariff = new Configuration();
|
||||||
|
|
||||||
CalcState calcState;
|
CalcState calcState;
|
||||||
|
#if __linux__
|
||||||
|
|
||||||
int const zone = get_zone_nr();
|
int const zone = get_zone_nr();
|
||||||
|
|
||||||
// DEBUG
|
// DEBUG
|
||||||
@@ -49,13 +56,16 @@ CalcState CALCULATE_LIBRARY_API init_tariff(parking_tariff_t **tariff, char cons
|
|||||||
memset(buffer, 0x00, sizeof(buffer));
|
memset(buffer, 0x00, sizeof(buffer));
|
||||||
snprintf(buffer, sizeof(buffer)-1, "tariff%02d.json", zone);
|
snprintf(buffer, sizeof(buffer)-1, "tariff%02d.json", zone);
|
||||||
confFile += buffer;
|
confFile += buffer;
|
||||||
|
#else // windows
|
||||||
|
QString confFile(config_file);
|
||||||
|
#endif
|
||||||
|
|
||||||
// DEBUG
|
// DEBUG
|
||||||
qCritical() << " ... confFile = " << confFile;
|
qCritical() << " ... confFile = " << confFile;
|
||||||
|
|
||||||
QFile fname(confFile);
|
QFile fname(confFile);
|
||||||
if (fname.exists() &&
|
if (fname.exists() &&
|
||||||
fname.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
fname.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
||||||
// DEBUG
|
// DEBUG
|
||||||
qCritical() << " ... confFile is open";
|
qCritical() << " ... confFile is open";
|
||||||
|
|
||||||
@@ -82,32 +92,34 @@ void CALCULATE_LIBRARY_API free_tariff(parking_tariff_t *tariff) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// this is currently not used
|
||||||
CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket(
|
CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket(
|
||||||
parking_tariff_t *tariff,
|
parking_tariff_t *tariff,
|
||||||
time_t start_parking_time, // in minutes
|
time_t start_parking_time, // in minutes
|
||||||
time_t end_parking_time, // in minutes
|
time_t end_parking_time, // netto time in minutes
|
||||||
struct price_t *price) {
|
struct price_t *price) {
|
||||||
CalcState calcState;
|
CalcState calcState;
|
||||||
double minMin = tariff->PaymentOption.find(PaymentOption::Option1)->second.pop_min_time;
|
double minMin = tariff->PaymentOption.find(tariff->getPaymentOptions().pop_payment_method_id)->second.pop_min_time;
|
||||||
double maxMin = tariff->PaymentOption.find(PaymentOption::Option1)->second.pop_max_time;
|
double maxMin = tariff->PaymentOption.find(tariff->getPaymentOptions().pop_payment_method_id)->second.pop_max_time;
|
||||||
|
|
||||||
if (minMin < 0 || maxMin < 0 || maxMin < minMin) {
|
if (minMin < 0 || maxMin < 0 || maxMin < minMin) {
|
||||||
calcState.setDesc(QString("minMin=%1, maxMin=%2").arg(minMin, maxMin));
|
calcState.setDesc(QString("minMin=%1, maxMin=%2").arg(minMin).arg(maxMin));
|
||||||
return calcState.set(CalcState::State::WRONG_PARAM_VALUES);
|
return calcState.set(CalcState::State::WRONG_PARAM_VALUES);
|
||||||
}
|
}
|
||||||
|
|
||||||
int const duration = end_parking_time - start_parking_time;
|
int const duration = end_parking_time - start_parking_time;
|
||||||
if (duration < 0) {
|
if (duration < 0) {
|
||||||
calcState.setDesc(QString("end=%1, start=%2")
|
calcState.setDesc(QString("end=%1, start=%2")
|
||||||
.arg(end_parking_time, start_parking_time));
|
.arg(end_parking_time, start_parking_time));
|
||||||
return calcState.set(CalcState::State::NEGATIVE_PARING_TIME);
|
return calcState.set(CalcState::State::NEGATIVE_PARING_TIME);
|
||||||
}
|
}
|
||||||
if (duration > maxMin) {
|
if (duration > maxMin) {
|
||||||
calcState.setDesc(QString("duration=%1, maxMin=%2").arg(duration, maxMin));
|
calcState.setDesc(QString("duration=%1, maxMin=%2").arg(duration).arg(maxMin));
|
||||||
return calcState.set(CalcState::State::ABOVE_MAX_PARKING_TIME);
|
return calcState.set(CalcState::State::ABOVE_MAX_PARKING_TIME);
|
||||||
}
|
}
|
||||||
if (duration < minMin) {
|
if (duration < minMin) {
|
||||||
calcState.setDesc(QString("duration=%1, minMin=%2").arg(duration, minMin));
|
calcState.setDesc(QString("duration=%1, minMin=%2").arg(duration).arg(minMin));
|
||||||
return calcState.set(CalcState::State::BELOW_MIN_PARKING_TIME);
|
return calcState.set(CalcState::State::BELOW_MIN_PARKING_TIME);
|
||||||
}
|
}
|
||||||
if (duration == 0) {
|
if (duration == 0) {
|
||||||
@@ -119,15 +131,17 @@ CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket(
|
|||||||
QTime const t(0, 0, 0);
|
QTime const t(0, 0, 0);
|
||||||
QDateTime start(d, t, Qt::UTC);
|
QDateTime start(d, t, Qt::UTC);
|
||||||
start = start.toLocalTime().addSecs(start_parking_time * 60);
|
start = start.toLocalTime().addSecs(start_parking_time * 60);
|
||||||
|
QDateTime end(start);
|
||||||
if (start.isValid()) {
|
if (start.isValid()) {
|
||||||
QString cs = start.toString(Qt::ISODate);
|
|
||||||
double cost = calculator.GetCostFromDuration(
|
double cost = calculator.GetCostFromDuration(
|
||||||
tariff, PaymentOption::Option1,
|
tariff,
|
||||||
cs.toLocal8Bit().constData(),
|
tariff->getPaymentOptions().pop_payment_method_id,
|
||||||
duration, false, true);
|
start,
|
||||||
double minCost = tariff->PaymentOption.find(PaymentOption::Option1)->second.pop_min_price;
|
end,
|
||||||
|
duration, false, true);
|
||||||
|
double minCost = tariff->PaymentOption.find(tariff->getPaymentOptions().pop_payment_method_id)->second.pop_min_price;
|
||||||
if (cost < minCost) {
|
if (cost < minCost) {
|
||||||
calcState.setDesc(QString("minCost=%1, cost=%2").arg(minCost, cost));
|
calcState.setDesc(QString("minCost=%1, cost=%2").arg(minCost).arg(cost));
|
||||||
return calcState.set(CalcState::State::BELOW_MIN_PARKING_PRICE);
|
return calcState.set(CalcState::State::BELOW_MIN_PARKING_PRICE);
|
||||||
}
|
}
|
||||||
price->units = cost;
|
price->units = cost;
|
||||||
@@ -139,11 +153,75 @@ CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket(
|
|||||||
return calcState.set(CalcState::State::SUCCESS);
|
return calcState.set(CalcState::State::SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket(
|
||||||
|
parking_tariff_t *tariff,
|
||||||
|
QDateTime const &start_parking_time,
|
||||||
|
int netto_parking_time,
|
||||||
|
QDateTime &end_parking_time,
|
||||||
|
struct price_t *price)
|
||||||
|
{
|
||||||
|
CalcState calcState;
|
||||||
|
double minMin = tariff->getPaymentOptions().pop_min_time;
|
||||||
|
double maxMin = tariff->getPaymentOptions().pop_max_time;
|
||||||
|
|
||||||
|
// DEBUG
|
||||||
|
qCritical() << "compute_price_for_parking_ticket() " << endl
|
||||||
|
<< " start_parking_time: " << start_parking_time << endl
|
||||||
|
<< " netto_parking_time: " << netto_parking_time << endl
|
||||||
|
<< " minMin: " << minMin << endl
|
||||||
|
<< " maxMin: " << maxMin;
|
||||||
|
|
||||||
|
|
||||||
|
if (netto_parking_time < 0) {
|
||||||
|
calcState.setDesc(QString("end=%1, start=%2")
|
||||||
|
.arg(end_parking_time.toString(Qt::ISODate),
|
||||||
|
start_parking_time.toString(Qt::ISODate)));
|
||||||
|
return calcState.set(CalcState::State::NEGATIVE_PARING_TIME);
|
||||||
|
}
|
||||||
|
if (netto_parking_time > maxMin) {
|
||||||
|
calcState.setDesc(QString("duration=%1, maxMin=%2").arg(netto_parking_time).arg(maxMin));
|
||||||
|
return calcState.set(CalcState::State::ABOVE_MAX_PARKING_TIME);
|
||||||
|
}
|
||||||
|
if (netto_parking_time < minMin) {
|
||||||
|
calcState.setDesc(QString("duration=%1, minMin=%2").arg(netto_parking_time).arg(minMin));
|
||||||
|
return calcState.set(CalcState::State::BELOW_MIN_PARKING_TIME);
|
||||||
|
}
|
||||||
|
if (netto_parking_time == 0) {
|
||||||
|
memset(price, 0x00, sizeof(*price));
|
||||||
|
return calcState.set(CalcState::State::SUCCESS);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (start_parking_time.isValid()) {
|
||||||
|
double cost = calculator.GetCostFromDuration(
|
||||||
|
tariff,
|
||||||
|
tariff->getPaymentOptions().pop_payment_method_id,
|
||||||
|
start_parking_time, // starting time
|
||||||
|
end_parking_time, // return value: end time
|
||||||
|
netto_parking_time, // minutes, netto
|
||||||
|
false, true);
|
||||||
|
double minCost = tariff->getPaymentOptions().pop_min_price;
|
||||||
|
if (cost < minCost) {
|
||||||
|
calcState.setDesc(QString("minCost=%1, cost=%2").arg(minCost, cost));
|
||||||
|
return calcState.set(CalcState::State::BELOW_MIN_PARKING_PRICE);
|
||||||
|
}
|
||||||
|
|
||||||
|
// DEBUG
|
||||||
|
qCritical() << " -> calculated cost (price->netto) = " << cost;
|
||||||
|
|
||||||
|
price->units = cost;
|
||||||
|
price->netto = cost;
|
||||||
|
} else {
|
||||||
|
return calcState.set(CalcState::State::INVALID_START_DATE);
|
||||||
|
}
|
||||||
|
|
||||||
|
return calcState.set(CalcState::State::SUCCESS);
|
||||||
|
}
|
||||||
|
|
||||||
CalcState CALCULATE_LIBRARY_API compute_duration_for_parking_ticket(
|
CalcState CALCULATE_LIBRARY_API compute_duration_for_parking_ticket(
|
||||||
parking_tariff_t *tariff,
|
parking_tariff_t *tariff,
|
||||||
time_t start_parking_time,
|
time_t start_parking_time,
|
||||||
double price,
|
double price,
|
||||||
QString &duration) {
|
QString &duration) {
|
||||||
CalcState calcState;
|
CalcState calcState;
|
||||||
QDate const d(1970, 1, 1);
|
QDate const d(1970, 1, 1);
|
||||||
QTime const t(0, 0, 0);
|
QTime const t(0, 0, 0);
|
||||||
@@ -151,12 +229,83 @@ CalcState CALCULATE_LIBRARY_API compute_duration_for_parking_ticket(
|
|||||||
start = start.toLocalTime().addSecs(start_parking_time * 60);
|
start = start.toLocalTime().addSecs(start_parking_time * 60);
|
||||||
if (start.isValid()) {
|
if (start.isValid()) {
|
||||||
QString cs = start.toString(Qt::ISODate);
|
QString cs = start.toString(Qt::ISODate);
|
||||||
duration = calculator.GetDurationFromCost(tariff, PaymentOption::Option1,
|
|
||||||
|
// DEBUG
|
||||||
|
qCritical() << "compute_duration_for_parking_ticket(): ";
|
||||||
|
qCritical() << " start (cs): " << cs;
|
||||||
|
qCritical() << " price: " << price;
|
||||||
|
|
||||||
|
duration = calculator.GetDurationFromCost(tariff,
|
||||||
|
tariff->getPaymentOptions().pop_payment_method_id,
|
||||||
cs.toLocal8Bit().constData(),
|
cs.toLocal8Bit().constData(),
|
||||||
price, false, true).c_str();
|
price, false, true).c_str();
|
||||||
|
QDateTime d = QDateTime::fromString(duration, Qt::ISODate);
|
||||||
|
if (!d.isValid()) {
|
||||||
|
calcState.setDesc(QString("ticketEndTime=%1").arg(duration));
|
||||||
|
return calcState.set(CalcState::State::WRONG_ISO_TIME_FORMAT);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
return calcState.set(CalcState::State::INVALID_START_DATE);
|
return calcState.set(CalcState::State::INVALID_START_DATE);
|
||||||
}
|
}
|
||||||
|
|
||||||
return calcState.set(CalcState::State::SUCCESS);
|
return calcState.set(CalcState::State::SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CalcState CALCULATE_LIBRARY_API compute_duration_for_parking_ticket(
|
||||||
|
parking_tariff_t *tariff,
|
||||||
|
QDateTime const &start_parking_time,
|
||||||
|
double price,
|
||||||
|
QDateTime &ticketEndTime)
|
||||||
|
{
|
||||||
|
CalcState calcState;
|
||||||
|
if (start_parking_time.isValid()) {
|
||||||
|
QString cs = start_parking_time.toString(Qt::ISODate);
|
||||||
|
QString endTime = calculator.GetDurationFromCost(
|
||||||
|
tariff,
|
||||||
|
tariff->getPaymentOptions().pop_payment_method_id,
|
||||||
|
cs.toLocal8Bit().constData(),
|
||||||
|
price, false, true).c_str();
|
||||||
|
ticketEndTime = QDateTime::fromString(endTime,Qt::ISODate);
|
||||||
|
|
||||||
|
// DEBUG
|
||||||
|
qCritical() << "compute_duration_for_parking_ticket(): ";
|
||||||
|
qCritical() << " endTime: " << endTime;
|
||||||
|
qCritical() << " ticketEndTime: " << ticketEndTime;
|
||||||
|
|
||||||
|
if (!ticketEndTime.isValid()) {
|
||||||
|
calcState.setDesc(QString("ticketEndTime=%1").arg(endTime));
|
||||||
|
return calcState.set(CalcState::State::WRONG_ISO_TIME_FORMAT);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return calcState.set(CalcState::State::INVALID_START_DATE);
|
||||||
|
}
|
||||||
|
|
||||||
|
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 calcState;
|
||||||
|
if (start_parking_time.isValid()) {
|
||||||
|
|
||||||
|
ticketEndTime = calculator.GetDailyTicketDuration(tariff,
|
||||||
|
start_parking_time,
|
||||||
|
tariff->getPaymentOptions().pop_payment_method_id,
|
||||||
|
false); // carry over
|
||||||
|
|
||||||
|
// DEBUG
|
||||||
|
qCritical() << "compute_duration_for_daily_ticket(): ";
|
||||||
|
qCritical() << " ticketEndTime: " << ticketEndTime;
|
||||||
|
|
||||||
|
if (!ticketEndTime.isValid()) {
|
||||||
|
calcState.setDesc(QString("ticketEndTime=%1").arg(ticketEndTime.toString(Qt::ISODate)));
|
||||||
|
return calcState.set(CalcState::State::WRONG_ISO_TIME_FORMAT);
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
return calcState.set(CalcState::State::INVALID_START_DATE);
|
||||||
|
}
|
||||||
|
|
||||||
|
return calcState.set(CalcState::State::SUCCESS);
|
||||||
|
}
|
||||||
|
|
||||||
|
File diff suppressed because it is too large
Load Diff
@@ -59,8 +59,9 @@ bool Configuration::ParseJson(Configuration* cfg, const char* json)
|
|||||||
|| !document.HasMember("PaymentRate")
|
|| !document.HasMember("PaymentRate")
|
||||||
|| !document.HasMember("Duration")
|
|| !document.HasMember("Duration")
|
||||||
//|| !document.HasMember("WeekDays")
|
//|| !document.HasMember("WeekDays")
|
||||||
|| !document.HasMember("SpecialDaysWorktime")
|
//|| !document.HasMember("SpecialDaysWorktime")
|
||||||
|| !document.HasMember("SpecialDays"))
|
//|| !document.HasMember("SpecialDays")
|
||||||
|
)
|
||||||
{
|
{
|
||||||
printf("%s", "Error: not a valid configuration JSON\n");
|
printf("%s", "Error: not a valid configuration JSON\n");
|
||||||
return false;
|
return false;
|
||||||
@@ -87,13 +88,26 @@ bool Configuration::ParseJson(Configuration* cfg, const char* json)
|
|||||||
const char* mb_name = i->name.GetString();
|
const char* mb_name = i->name.GetString();
|
||||||
if (mb_name == NULL) continue;
|
if (mb_name == NULL) continue;
|
||||||
|
|
||||||
// if (!document[mb_name].IsArray()) {
|
if (document[mb_name].IsString()) {
|
||||||
std::string const _mb_name(mb_name);
|
QString const _mb_name(mb_name);
|
||||||
if (_mb_name == "version" || _mb_name == "project" ||
|
if (_mb_name.startsWith("Project", Qt::CaseInsensitive)) {
|
||||||
_mb_name == "zone" || _mb_name == "info") {
|
cfg->project.project = document[mb_name].GetString();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (_mb_name.startsWith("Version", Qt::CaseInsensitive)) {
|
||||||
|
cfg->project.version = document[mb_name].GetString();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
// }
|
if (_mb_name.startsWith("Info", Qt::CaseInsensitive)) {
|
||||||
|
cfg->project.info = document[mb_name].GetString();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ... everything else should be an array
|
||||||
|
if (!document[mb_name].IsArray()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
//printf(" -%s\n", mb_name);
|
//printf(" -%s\n", mb_name);
|
||||||
|
|
||||||
@@ -154,7 +168,9 @@ bool Configuration::ParseJson(Configuration* cfg, const char* json)
|
|||||||
else if (strcmp(inner_obj_name, "pop_max_time") == 0) PaymentOption.pop_max_time = k->value.GetDouble();
|
else if (strcmp(inner_obj_name, "pop_max_time") == 0) PaymentOption.pop_max_time = k->value.GetDouble();
|
||||||
else if (strcmp(inner_obj_name, "pop_min_price") == 0) PaymentOption.pop_min_price = k->value.GetDouble();
|
else if (strcmp(inner_obj_name, "pop_min_price") == 0) PaymentOption.pop_min_price = k->value.GetDouble();
|
||||||
else if (strcmp(inner_obj_name, "pop_carry_over") == 0) PaymentOption.pop_carry_over = k->value.GetInt();
|
else if (strcmp(inner_obj_name, "pop_carry_over") == 0) PaymentOption.pop_carry_over = k->value.GetInt();
|
||||||
break;
|
else if (strcmp(inner_obj_name, "pop_daily_card_price") == 0) PaymentOption.pop_daily_card_price = k->value.GetInt();
|
||||||
|
this->currentPaymentOptions = PaymentOption;
|
||||||
|
break;
|
||||||
case MemberType::DurationType:
|
case MemberType::DurationType:
|
||||||
if (strcmp(inner_obj_name, "pun_id") == 0) Duration.pun_id = k->value.GetInt();
|
if (strcmp(inner_obj_name, "pun_id") == 0) Duration.pun_id = k->value.GetInt();
|
||||||
else if (strcmp(inner_obj_name, "pun_label") == 0) Duration.pun_label = k->value.GetString();
|
else if (strcmp(inner_obj_name, "pun_label") == 0) Duration.pun_label = k->value.GetString();
|
||||||
@@ -209,7 +225,7 @@ bool Configuration::ParseJson(Configuration* cfg, const char* json)
|
|||||||
cfg->PaymentMethod.insert(pair<int, ATBPaymentMethod>(PaymentMethod.pme_id, PaymentMethod));
|
cfg->PaymentMethod.insert(pair<int, ATBPaymentMethod>(PaymentMethod.pme_id, PaymentMethod));
|
||||||
break;
|
break;
|
||||||
case MemberType::PaymentRateType:
|
case MemberType::PaymentRateType:
|
||||||
cfg->PaymentRate.insert(pair<int, ATBPaymentRate>(PaymentRate.pra_payment_unit_id, PaymentRate));
|
cfg->PaymentRate.insert(pair<int, ATBPaymentRate>(PaymentRate.pra_payment_option_id, PaymentRate));
|
||||||
break;
|
break;
|
||||||
case MemberType::PaymentOptionType:
|
case MemberType::PaymentOptionType:
|
||||||
cfg->PaymentOption.insert(pair<int, ATBPaymentOption>(PaymentOption.pop_payment_method_id, PaymentOption));
|
cfg->PaymentOption.insert(pair<int, ATBPaymentOption>(PaymentOption.pop_payment_method_id, PaymentOption));
|
||||||
@@ -244,3 +260,10 @@ bool Configuration::ParseJson(Configuration* cfg, const char* json)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
const ATBPaymentOption & Configuration::getPaymentOptions()
|
||||||
|
{
|
||||||
|
return this->currentPaymentOptions;
|
||||||
|
}
|
||||||
|
@@ -8,12 +8,15 @@ static int protection_counter = 0;
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="pra_price"></param>
|
/// <param name="pra_price"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
double Utilities::CalculatePricePerUnit(double pra_price)
|
double Utilities::CalculatePricePerUnit(double pra_price, double durationUnit)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
double price_per_unit = pra_price;
|
double price_per_unit = pra_price;
|
||||||
price_per_unit /= 60.0f; // Divided by 60 because price per unit is set per hour and we are using minutes
|
double unit = durationUnit;
|
||||||
|
|
||||||
|
if(unit < 0 || unit > 65535 ) unit = 60.0f;
|
||||||
|
price_per_unit /= unit; // Divided by 60 because price per unit is set per hour and we are using minutes
|
||||||
//printf("Price per unit (min) is: %lf\n", price_per_unit);
|
//printf("Price per unit (min) is: %lf\n", price_per_unit);
|
||||||
return price_per_unit;
|
return price_per_unit;
|
||||||
}
|
}
|
||||||
@@ -33,7 +36,7 @@ time_t Utilities::GetCurrentLocalTime()
|
|||||||
memset(&tm_curr_time, '\0', sizeof(struct tm));
|
memset(&tm_curr_time, '\0', sizeof(struct tm));
|
||||||
|
|
||||||
tm_curr_time = *localtime(&curr_time);
|
tm_curr_time = *localtime(&curr_time);
|
||||||
curr_time = mktime(&tm_curr_time) - timezone;
|
curr_time = mktime(&tm_curr_time); //- timezone;
|
||||||
return curr_time;
|
return curr_time;
|
||||||
}
|
}
|
||||||
catch (...)
|
catch (...)
|
||||||
|
196
main/main.cpp
196
main/main.cpp
@@ -1,10 +1,9 @@
|
|||||||
#include <calculate_price.h>
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
#include <calculate_price.h>
|
||||||
|
|
||||||
|
|
||||||
extern "C" char* strptime(const char* s,
|
extern "C" char* strptime(const char* s,
|
||||||
const char* f,
|
const char* f,
|
||||||
@@ -27,88 +26,135 @@ extern "C" char* strptime(const char* s,
|
|||||||
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QDateTime>
|
#include <QDateTime>
|
||||||
|
#include <QDir>
|
||||||
|
|
||||||
|
#include <fstream>
|
||||||
|
#include <sstream>
|
||||||
|
#include "calculator_functions.h"
|
||||||
|
#include <calculate_price.h>
|
||||||
|
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
|
|
||||||
|
std::ifstream input(QDir::homePath().append("/tariff01.json").toStdString());
|
||||||
|
std::stringstream sstr;
|
||||||
|
while(input >> sstr.rdbuf());
|
||||||
|
std::string json(sstr.str());
|
||||||
|
|
||||||
|
Calculator calculator;
|
||||||
|
Configuration cfg;
|
||||||
|
|
||||||
|
bool isParsed = cfg.ParseJson(&cfg, json.c_str());
|
||||||
|
cout << endl;
|
||||||
|
|
||||||
|
char const *startDate = "";
|
||||||
|
|
||||||
|
if (isParsed)
|
||||||
|
{
|
||||||
|
startDate = "2023-05-10T13:52:18.665Z";
|
||||||
|
std::string duration = calculator.GetDurationFromCost(&cfg, 3, (char *)startDate, 33, false, true);
|
||||||
|
cout << "---> startDate " << startDate << " _price_ = " << 33
|
||||||
|
<< " Total duration is: " << duration << endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
parking_tariff_t *tariff = 0;
|
parking_tariff_t *tariff = 0;
|
||||||
if (init_tariff(&tariff, "/etc/psa_tariff/")) {
|
if (init_tariff(&tariff, "/etc/psa_tariff/")) {
|
||||||
struct price_t price;
|
struct price_t price;
|
||||||
memset(&price, 0x00, sizeof(price));
|
memset(&price, 0x00, sizeof(price));
|
||||||
QDateTime start = QDateTime::currentDateTime();
|
QDateTime start = QDateTime::fromString("2023-05-11T07:50:00",Qt::ISODate); //QDateTime::currentDateTime();
|
||||||
time_t start_parking_time = start.toSecsSinceEpoch() / 60;
|
time_t start_parking_time = start.toSecsSinceEpoch() / 60;
|
||||||
time_t end_parking_time = start_parking_time + 60;
|
time_t end_parking_time = start_parking_time + 615;
|
||||||
|
|
||||||
if (compute_price_for_parking_ticket(tariff,
|
if (compute_price_for_parking_ticket(tariff,
|
||||||
start_parking_time,
|
start_parking_time,
|
||||||
end_parking_time,
|
end_parking_time,
|
||||||
&price)) {
|
&price))
|
||||||
qDebug() << "price=" << price.netto;
|
{
|
||||||
|
qDebug() << "GetCostFromDuration() => price=" << price.netto;
|
||||||
}
|
}
|
||||||
|
|
||||||
// tests
|
QString duration;
|
||||||
struct tm now;
|
if(compute_duration_for_parking_ticket(tariff,start_parking_time,3090,duration))
|
||||||
memset(&now, 0, sizeof(now));
|
{
|
||||||
|
qDebug() << "GetDurationFromCost() => duration=" << duration;
|
||||||
// 3.Jan 2023 -> Tuesday
|
|
||||||
strptime("2023-01-03T14:00:00", "%Y-%m-%dT%H:%M:%S", &now);
|
|
||||||
for (int i = 0; i < 600; ++i) {
|
|
||||||
start_parking_time = mktime(&now);
|
|
||||||
end_parking_time = start_parking_time + 240; // duration == 240
|
|
||||||
|
|
||||||
if (compute_price_for_parking_ticket(tariff,
|
|
||||||
start_parking_time,
|
|
||||||
end_parking_time,
|
|
||||||
&price)) {
|
|
||||||
int const zone = get_zone_nr();
|
|
||||||
switch (zone) {
|
|
||||||
case 1:
|
|
||||||
assert(price.netto == 879); // expected value: 880
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
/* fall through */
|
|
||||||
case 3:
|
|
||||||
assert(price.netto == 1920);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
time_t t = start_parking_time + 60;
|
|
||||||
now = *localtime(&t);
|
|
||||||
}
|
}
|
||||||
//
|
|
||||||
// test May 1st 2023
|
|
||||||
//
|
|
||||||
memset(&now, 0, sizeof(now));
|
|
||||||
strptime("2023-04-30T06:00:00", "%Y-%m-%dT%H:%M:%S", &now);
|
|
||||||
now.tm_hour -= 1; // for ctime
|
|
||||||
// for (int i=0; i<6*24; ++i) {
|
|
||||||
for (int i=0; i<1; ++i) {
|
|
||||||
int const duration = 120;
|
|
||||||
time_t t = mktime(&now);
|
|
||||||
start_parking_time = t / 60;
|
|
||||||
end_parking_time = start_parking_time + duration;
|
|
||||||
|
|
||||||
if (compute_price_for_parking_ticket(tariff,
|
// Daily ticket
|
||||||
start_parking_time,
|
//compute_duration_for_daily_ticket(tariff,start.toString(Qt::ISODate),3);
|
||||||
end_parking_time,
|
|
||||||
&price)) {
|
|
||||||
int const zone = get_zone_nr();
|
|
||||||
switch (zone) {
|
|
||||||
case 1:
|
|
||||||
qDebug() << i << zone << ctime(&t) << price.netto << " FT";
|
|
||||||
assert(price.netto == 440);
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
/* fall through */
|
|
||||||
case 3:
|
|
||||||
qDebug() << i << zone << ctime(&t) << price.netto << " FT";
|
|
||||||
assert(price.netto == 960);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
t = (start_parking_time + 60)*60;
|
//Configuration* cfg, QString start_datetime, uint8_t payment_option, bool carry_over
|
||||||
now = *localtime(&t);
|
// // tests
|
||||||
}
|
// struct tm now;
|
||||||
|
// memset(&now, 0, sizeof(now));
|
||||||
|
|
||||||
|
// // 3.Jan 2023 -> Tuesday
|
||||||
|
// strptime("2023-01-03T14:00:00", "%Y-%m-%dT%H:%M:%S", &now);
|
||||||
|
// for (int i = 0; i < 600; ++i) {
|
||||||
|
// start_parking_time = mktime(&now);
|
||||||
|
// end_parking_time = start_parking_time + 240; // duration == 240
|
||||||
|
|
||||||
|
// if (compute_price_for_parking_ticket(tariff,
|
||||||
|
// start_parking_time,
|
||||||
|
// end_parking_time,
|
||||||
|
// &price)) {
|
||||||
|
// int const zone = get_zone_nr(1);
|
||||||
|
// switch (zone) {
|
||||||
|
// case 1:
|
||||||
|
// assert(price.netto == 879); // expected value: 880
|
||||||
|
// break;
|
||||||
|
// case 2:
|
||||||
|
// /* fall through */
|
||||||
|
// case 3:
|
||||||
|
// assert(price.netto == 1920);
|
||||||
|
// break;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// time_t t = start_parking_time + 60;
|
||||||
|
// now = *localtime(&t);
|
||||||
|
// }
|
||||||
|
// //
|
||||||
|
// // test May 1st 2023
|
||||||
|
// //
|
||||||
|
// memset(&now, 0, sizeof(now));
|
||||||
|
// strptime("2023-04-30T06:00:00", "%Y-%m-%dT%H:%M:%S", &now);
|
||||||
|
// now.tm_hour -= 1; // for ctime
|
||||||
|
// // for (int i=0; i<6*24; ++i) {
|
||||||
|
// for (int i=0; i<1; ++i) {
|
||||||
|
// int const duration = 120;
|
||||||
|
// time_t t = mktime(&now);
|
||||||
|
// start_parking_time = t / 60;
|
||||||
|
// end_parking_time = start_parking_time + duration;
|
||||||
|
|
||||||
|
// if (compute_price_for_parking_ticket(tariff,
|
||||||
|
// start_parking_time,
|
||||||
|
// end_parking_time,
|
||||||
|
// &price)) {
|
||||||
|
// int const zone = get_zone_nr();
|
||||||
|
// switch (zone) {
|
||||||
|
// case 1:
|
||||||
|
// qDebug() << i << zone << ctime(&t) << price.netto << " FT";
|
||||||
|
// assert(price.netto == 440);
|
||||||
|
// break;
|
||||||
|
// case 2:
|
||||||
|
// /* fall through */
|
||||||
|
// case 3:
|
||||||
|
// qDebug() << i << zone << ctime(&t) << price.netto << " FT";
|
||||||
|
// assert(price.netto == 960);
|
||||||
|
// break;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
// t = (start_parking_time + 60)*60;
|
||||||
|
// now = *localtime(&t);
|
||||||
|
// }
|
||||||
|
|
||||||
free_tariff(tariff);
|
free_tariff(tariff);
|
||||||
}
|
}
|
||||||
@@ -145,7 +191,7 @@ int main() {
|
|||||||
struct tm now; // = Utilities::DateTimeToStructTm("2023-03-01T16:00:00");
|
struct tm now; // = Utilities::DateTimeToStructTm("2023-03-01T16:00:00");
|
||||||
memset(&now, 0, sizeof(now));
|
memset(&now, 0, sizeof(now));
|
||||||
char buffer[64];
|
char buffer[64];
|
||||||
//#if 0
|
//#if 0
|
||||||
// 3.Jan 2023 -> Tuesday
|
// 3.Jan 2023 -> Tuesday
|
||||||
strptime("2023-01-03T14:00:00", "%Y-%m-%dT%H:%M:%S", &now);
|
strptime("2023-01-03T14:00:00", "%Y-%m-%dT%H:%M:%S", &now);
|
||||||
for (int i = 0; i < 600; ++i) {
|
for (int i = 0; i < 600; ++i) {
|
||||||
@@ -220,8 +266,8 @@ int main() {
|
|||||||
|
|
||||||
int const duration = 120;
|
int const duration = 120;
|
||||||
double cost = calculator.GetCostFromDuration(&cfg,
|
double cost = calculator.GetCostFromDuration(&cfg,
|
||||||
PaymentOption::Option1, buffer, duration,
|
PaymentOption::Option1, buffer, duration,
|
||||||
false, true);
|
false, true);
|
||||||
|
|
||||||
switch (zone) {
|
switch (zone) {
|
||||||
case 1:
|
case 1:
|
||||||
@@ -259,8 +305,8 @@ int main() {
|
|||||||
|
|
||||||
int const duration = 120;
|
int const duration = 120;
|
||||||
double cost = calculator.GetCostFromDuration(&cfg,
|
double cost = calculator.GetCostFromDuration(&cfg,
|
||||||
PaymentOption::Option1, buffer, duration,
|
PaymentOption::Option1, buffer, duration,
|
||||||
false, true);
|
false, true);
|
||||||
|
|
||||||
switch (zone) {
|
switch (zone) {
|
||||||
case 1:
|
case 1:
|
||||||
@@ -293,8 +339,8 @@ int main() {
|
|||||||
|
|
||||||
double const compCost = (duration < 15) ? 0 : duration * ((zone == 1) ? 3.6666 : 8.0);
|
double const compCost = (duration < 15) ? 0 : duration * ((zone == 1) ? 3.6666 : 8.0);
|
||||||
double cost = calculator.GetCostFromDuration(&cfg,
|
double cost = calculator.GetCostFromDuration(&cfg,
|
||||||
PaymentOption::Option1, buffer, duration,
|
PaymentOption::Option1, buffer, duration,
|
||||||
false, true);
|
false, true);
|
||||||
if (fabs(cost - compCost) > 1.0) { // zone 1 has rounding errors
|
if (fabs(cost - compCost) > 1.0) { // zone 1 has rounding errors
|
||||||
cout << "ERROR ===> [" << i << "] " << asctime(&now)
|
cout << "ERROR ===> [" << i << "] " << asctime(&now)
|
||||||
<< " - Total cost is: " << cost << " FT (computed="
|
<< " - Total cost is: " << cost << " FT (computed="
|
||||||
|
@@ -7,6 +7,8 @@ QMAKE_CFLAGS = -c -pipe -std=c11 -g -O0 -Wall -Wno-attributes -W -DDEBUG -D_REEN
|
|||||||
QMAKE_CXX_FLAGS += -std=c11
|
QMAKE_CXX_FLAGS += -std=c11
|
||||||
|
|
||||||
INCLUDEPATH += $$_PRO_FILE_PWD_/../../MOBILISIS-Calculator/library/include/mobilisis/
|
INCLUDEPATH += $$_PRO_FILE_PWD_/../../MOBILISIS-Calculator/library/include/mobilisis/
|
||||||
|
INCLUDEPATH += $$_PRO_FILE_PWD_/../../MOBILISIS-Calculator/library/include/rapidjson/
|
||||||
|
INCLUDEPATH += $$_PRO_FILE_PWD_/../../MOBILISIS-Calculator/library/include/
|
||||||
INCLUDEPATH += .
|
INCLUDEPATH += .
|
||||||
|
|
||||||
unix {
|
unix {
|
||||||
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user