Compare commits
13 Commits
73b1c1459e
...
neuhauser_
Author | SHA1 | Date | |
---|---|---|---|
88e92dddb9 | |||
0f05a1a784 | |||
2d696941a5 | |||
5598b02816 | |||
548447af1f | |||
b9a7c04db9 | |||
5b8d9c62cc | |||
56e2843ddb | |||
6b76c4c2dd | |||
54e9a0f86d | |||
d7beb3b41b | |||
9d220df52e | |||
de7a63bc2a |
@@ -109,6 +109,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);
|
||||
|
||||
CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket( // deprecated
|
||||
parking_tariff_t *tariff,
|
||||
time_t start_parking_time,
|
||||
|
@@ -82,4 +82,9 @@ namespace Utilities {
|
||||
bool isCarryOverSet(Configuration const *cfg, PaymentMethod paymentMethodId);
|
||||
bool isCarryOverNotSet(Configuration const *cfg, PaymentMethod paymentMethodId);
|
||||
PaymentMethod getPaymentMethodId(Configuration const *cfg);
|
||||
|
||||
int getMinimalParkingTime(Configuration const *cfg, PaymentMethod methodId);
|
||||
int getMaximalParkingTime(Configuration const *cfg, PaymentMethod methodId);
|
||||
uint32_t getMinimalParkingPrice(Configuration const *cfg, PaymentMethod methodId);
|
||||
uint32_t getFirstDurationStep(Configuration const *cfg, PaymentMethod methodId);
|
||||
}
|
||||
|
@@ -2,7 +2,7 @@ TEMPLATE = lib
|
||||
TARGET = mobilisis_calc
|
||||
#CONFIG += staticlib
|
||||
|
||||
QMAKE_CXXFLAGS += -std=c++17 -g -O0
|
||||
QMAKE_CXXFLAGS += -std=c++17 -g -O
|
||||
|
||||
INCLUDEPATH += $$_PRO_FILE_PWD_/include
|
||||
INCLUDEPATH += $$_PRO_FILE_PWD_/include/mobilisis
|
||||
|
@@ -2,6 +2,7 @@
|
||||
#include "configuration.h"
|
||||
#include "calculator_functions.h"
|
||||
#include "payment_option.h"
|
||||
#include "utilities.h"
|
||||
|
||||
#include <QFile>
|
||||
#include <QFileInfo>
|
||||
@@ -92,6 +93,97 @@ void CALCULATE_LIBRARY_API free_tariff(parking_tariff_t *tariff) {
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// UpDown 1 -> up; 0 -> down
|
||||
int CALCULATE_LIBRARY_API compute_next_timestep(parking_tariff_t *tariff, int currentTimeMinutes, int UpDown)
|
||||
{
|
||||
qCritical() << " compute_next_timestep() currentTimeMinutes: " << currentTimeMinutes;
|
||||
Configuration const *cfg = tariff;
|
||||
|
||||
// compute payment method id (e.g. Linear=3, Steps=4)
|
||||
PaymentMethod const paymentMethodId = Utilities::getPaymentMethodId(cfg);
|
||||
switch (paymentMethodId) {
|
||||
case PaymentMethod::Progressive:
|
||||
qCritical() << " compute_next_timestep() paymentMethodId: Progressive";
|
||||
break;
|
||||
case PaymentMethod::Degressive:
|
||||
qCritical() << " compute_next_timestep() paymentMethodId: Degressive";
|
||||
break;
|
||||
case PaymentMethod::Linear:
|
||||
qCritical() << " compute_next_timestep() paymentMethodId: Linear";
|
||||
break;
|
||||
case PaymentMethod::Steps:
|
||||
qCritical() << " compute_next_timestep() paymentMethodId: Steps";
|
||||
break;
|
||||
case PaymentMethod::Undefined:
|
||||
qCritical() << " compute_next_timestep() paymentMethodId: Undefined";
|
||||
break;
|
||||
}
|
||||
|
||||
// use tariff with structure as for instance Schnau, Koenigsee:
|
||||
// without given YearPeriod, SpecialDays and SpecialDaysWorktime
|
||||
if (paymentMethodId == PaymentMethod::Steps)
|
||||
{
|
||||
static const QList<int> stepList = calculator.GetTimeSteps(tariff);
|
||||
|
||||
int currentStepIndex = stepList.indexOf(currentTimeMinutes);
|
||||
|
||||
if (currentStepIndex == -1) {
|
||||
qCritical() << "compute_next_timestep() *NO STEP* for currentTimeMinutes (" << currentTimeMinutes << ")";
|
||||
return currentTimeMinutes;
|
||||
}
|
||||
|
||||
if (UpDown == 1) { // UP
|
||||
if (stepList[currentStepIndex] == stepList.last()) {
|
||||
qCritical() << "compute_next_timestep() *NO NEXT STEP* for currentTimeMinutes (" << currentTimeMinutes << ")";
|
||||
return currentTimeMinutes;
|
||||
}
|
||||
else {
|
||||
return stepList[currentStepIndex + 1];
|
||||
}
|
||||
}
|
||||
if (UpDown == 0) { // DOWN
|
||||
if (stepList[currentStepIndex] == stepList.first()) {
|
||||
qCritical() << "compute_next_timestep() *NO PREVIOUS STEP* for currentTimeMinutes (" << currentTimeMinutes << ")";
|
||||
return currentTimeMinutes;
|
||||
}
|
||||
else {
|
||||
return stepList[currentStepIndex - 1];
|
||||
}
|
||||
}
|
||||
} else
|
||||
if (paymentMethodId == PaymentMethod::Linear) {
|
||||
|
||||
// currentTimeMinutes is the number of minutes actually used. This
|
||||
// value is an offset from the start time and cannot be used as a
|
||||
// QDateTime.
|
||||
|
||||
qCritical() << "compute_next_timestep() up/down (1=up, 0=down):" << UpDown;
|
||||
|
||||
// get minimal and maximal parking times
|
||||
int const minParkingTime = Utilities::getMinimalParkingTime(cfg, paymentMethodId);
|
||||
int const maxParkingTime = Utilities::getMaximalParkingTime(cfg, paymentMethodId);
|
||||
|
||||
qCritical() << " compute_next_timestep() maxParkingTime:" << maxParkingTime;
|
||||
qCritical() << " compute_next_timestep() minParkingTime:" << minParkingTime;
|
||||
|
||||
// use the first (i.e. main duration step contained in the tariff json-file)
|
||||
int firstDurationStep = Utilities::getFirstDurationStep(cfg, paymentMethodId);
|
||||
firstDurationStep = ((UpDown == 1) ? firstDurationStep : -firstDurationStep);
|
||||
|
||||
qCritical() << " compute_next_timestep() firstDurationStep:" << firstDurationStep;
|
||||
|
||||
int const nextTimeStep = currentTimeMinutes + firstDurationStep;
|
||||
|
||||
if (nextTimeStep >= minParkingTime && nextTimeStep <= maxParkingTime) {
|
||||
qCritical() << " compute_next_timestep() nextTimeStep:" << nextTimeStep;
|
||||
return nextTimeStep;
|
||||
}
|
||||
}
|
||||
|
||||
qCritical() << "compute_next_timestep() *CAN NOT COMPUTE* for currentTimeMinutes (" << currentTimeMinutes << ")";
|
||||
return currentTimeMinutes;
|
||||
}
|
||||
|
||||
// this is currently not used
|
||||
CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket(
|
||||
|
@@ -140,7 +140,7 @@ std::string Calculator::GetDurationFromCost(Configuration* cfg,
|
||||
|
||||
Ticket t = private_GetDurationFromCost(cfg, inputDate, price, prepaid);
|
||||
|
||||
qCritical().noquote() << t;
|
||||
// qCritical().noquote() << t;
|
||||
|
||||
// TODO: im fehlerfall
|
||||
return t.getValidUntil().toString(Qt::ISODate).toStdString();
|
||||
@@ -207,7 +207,7 @@ double Calculator::GetCostFromDuration(Configuration* cfg,
|
||||
durationMinutes,
|
||||
prepaid);
|
||||
if (t) {
|
||||
qCritical().noquote() << t;
|
||||
// qCritical().noquote() << t;
|
||||
}
|
||||
|
||||
end_datetime = t.getValidUntil();
|
||||
@@ -265,7 +265,7 @@ int Calculator::findNextWorkTimeRange(QDateTime const &dt,
|
||||
|
||||
if (dt.time() < worktime_from) {
|
||||
nextWorkTimeRange = w;
|
||||
continue;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return nextWorkTimeRange;
|
||||
@@ -324,8 +324,6 @@ Ticket Calculator::private_GetCostFromDuration(Configuration const* cfg,
|
||||
for (current = start; durationMinutes > 0; current = current.addDays(1)) {
|
||||
int const weekdayId = current.date().dayOfWeek();
|
||||
|
||||
qCritical() << "current" << current.toString(Qt::ISODate) << weekdayId;
|
||||
|
||||
specialDayId = -1;
|
||||
|
||||
// find worktime ranges for the current day
|
||||
@@ -366,28 +364,32 @@ Ticket Calculator::private_GetCostFromDuration(Configuration const* cfg,
|
||||
|
||||
QTime const &lastWorktimeTo = worktime[ranges-1].getTimeUntil();
|
||||
|
||||
// find worktime range to start with
|
||||
// qCritical() << "start" << start.toString(Qt::ISODate)
|
||||
// << "current" << current.toString(Qt::ISODate) << lastWorktimeTo;
|
||||
|
||||
// find worktime range to start with
|
||||
int currentRange = 0;
|
||||
if (!isSpecialDay) {
|
||||
if (start != current) { // on next day
|
||||
current.setTime(worktime[currentRange].getTimeFrom());
|
||||
} else {
|
||||
// check if inputDate is located inside a valid worktime-range...
|
||||
currentRange = findWorkTimeRange(current, worktime, ranges);
|
||||
if (currentRange == -1) { // no...
|
||||
if (!prepaid) { // parking is not allowed
|
||||
if ((currentRange = findWorkTimeRange(current, worktime, ranges)) == -1) {
|
||||
if (!prepaid && carryOverNotSet) { // parking is not allowed
|
||||
return Ticket(start, QDateTime(), durationMinutesNetto, 0,
|
||||
0, Ticket::s[INVALID_FROM_DATETIME]);
|
||||
}
|
||||
// find the next worktime-range (on the same day), and start from there
|
||||
currentRange = findNextWorkTimeRange(current, worktime, ranges);
|
||||
if ((currentRange = findNextWorkTimeRange(current, worktime, ranges)) == -1) {
|
||||
end = current;
|
||||
continue;
|
||||
}
|
||||
current.setTime(worktime[currentRange].getTimeFrom());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
qCritical() << "current" << current.toString(Qt::ISODate) << currentRange;
|
||||
// qCritical() << "current" << current.toString(Qt::ISODate);
|
||||
|
||||
for (int w = currentRange; w < ranges; ++w, ++totalTimeRanges) {
|
||||
if (durationMinutes > 0) {
|
||||
@@ -400,13 +402,7 @@ Ticket Calculator::private_GetCostFromDuration(Configuration const* cfg,
|
||||
current.setTime(worktime_from);
|
||||
}
|
||||
|
||||
qCritical() << "worktime_from" << worktime_from;
|
||||
qCritical() << "worktime_to" << worktime_to;
|
||||
qCritical() << "current" << current.toString(Qt::ISODate);
|
||||
|
||||
if (price == 0) {
|
||||
// inputDate = inputDate.addDays(1);
|
||||
// inputDate.setTime(worktime_from);
|
||||
end = current;
|
||||
current.setTime(QTime());
|
||||
continue;
|
||||
@@ -425,12 +421,13 @@ Ticket Calculator::private_GetCostFromDuration(Configuration const* cfg,
|
||||
return Ticket();
|
||||
}
|
||||
} else {
|
||||
qDebug() << "* PREPAID MODE ACTIVE *";
|
||||
//qDebug() << "* PREPAID MODE ACTIVE *";
|
||||
//qCritical() << "current" << current.toString(Qt::ISODate) << worktime_from << lastWorktimeTo;
|
||||
if (current.time() < worktime_from) {
|
||||
current.setTime(worktime_from);
|
||||
end = current;
|
||||
} else if(current.time() > lastWorktimeTo) {
|
||||
qDebug() << " *** PREPAID *** Current time is past the time range end, searching for next available day";
|
||||
//qDebug() << " *** PREPAID *** Current time is past the time range end, searching for next available day";
|
||||
end = current;
|
||||
current.setTime(QTime());
|
||||
continue;
|
||||
@@ -451,6 +448,7 @@ Ticket Calculator::private_GetCostFromDuration(Configuration const* cfg,
|
||||
current.setTime(QTime());
|
||||
break; // stop while, and continue in outer loop
|
||||
} else {
|
||||
//qCritical() << "current" << current.toString(Qt::ISODate) << worktime_to;
|
||||
if(current.time() < worktime_to) {
|
||||
// Increment input date minutes for each monetary unit
|
||||
current = current.addSecs(60);
|
||||
@@ -458,7 +456,7 @@ Ticket Calculator::private_GetCostFromDuration(Configuration const* cfg,
|
||||
durationMinutes -= 1;
|
||||
//costFromDuration += price_per_unit;
|
||||
costFromDuration += price;
|
||||
qCritical() << "current" << current.toString(Qt::ISODate) << durationMinutes << costFromDuration;
|
||||
//qCritical() << "current" << current.toString(Qt::ISODate);
|
||||
} else break;
|
||||
}
|
||||
} // while(durationMinutes > 0) {
|
||||
@@ -468,12 +466,9 @@ Ticket Calculator::private_GetCostFromDuration(Configuration const* cfg,
|
||||
|
||||
int durationMinutesBrutto = start.secsTo(end) / 60;
|
||||
|
||||
qCritical() << "start" << start.toString(Qt::ISODate) << "end" << end
|
||||
<< llround(Utilities::CalculatePricePerUnit(costFromDuration, durationUnit));
|
||||
|
||||
return
|
||||
Ticket(start, end, durationMinutesNetto, durationMinutesBrutto,
|
||||
llround(Utilities::CalculatePricePerUnit(costFromDuration, durationUnit)),
|
||||
ceil(Utilities::CalculatePricePerUnit(costFromDuration, durationUnit)),
|
||||
Ticket::s[VALID]);
|
||||
}
|
||||
|
||||
@@ -485,8 +480,6 @@ Ticket Calculator::private_GetDurationFromCost(Configuration *cfg,
|
||||
// Get input date
|
||||
QDateTime current = start;
|
||||
|
||||
qCritical() << "current" << current.toString(Qt::ISODate);
|
||||
|
||||
// use tariff with structure as for instance Schnau, Koenigsee:
|
||||
// without given YearPeriod, SpecialDays and SpecialDaysWorktime
|
||||
if (cfg->YearPeriod.size() == 0
|
||||
@@ -526,22 +519,18 @@ Ticket Calculator::private_GetDurationFromCost(Configuration *cfg,
|
||||
return Ticket();
|
||||
}
|
||||
|
||||
qCritical() << "current" << current.toString(Qt::ISODate);
|
||||
|
||||
uint32_t durationMinutesNetto = 0;
|
||||
int moneyLeft = cost;
|
||||
uint32_t durationUnit = 1;
|
||||
double moneyLeft = cost;
|
||||
double durationUnit = 1;
|
||||
int specialDayId = -1;
|
||||
bool isSpecialDay = false;
|
||||
QDateTime end = start;
|
||||
int totalTimeRanges = 0;
|
||||
uint32_t price = 0;
|
||||
double price = 0;
|
||||
|
||||
for (current = start; moneyLeft > 0; current = current.addDays(1), moneyLeft /= durationUnit) {
|
||||
for (current = start; moneyLeft > 0 && moneyLeft >= price; current = current.addDays(1)) {
|
||||
int const weekdayId = current.date().dayOfWeek();
|
||||
|
||||
qCritical() << "current" << current.toString(Qt::ISODate) << weekdayId;
|
||||
|
||||
specialDayId = -1;
|
||||
|
||||
// find worktime ranges for the current day
|
||||
@@ -549,9 +538,12 @@ Ticket Calculator::private_GetDurationFromCost(Configuration *cfg,
|
||||
QScopedArrayPointer<TariffTimeRange> worktime(new TariffTimeRange[timeRanges]);
|
||||
int ranges = 0;
|
||||
|
||||
if((isSpecialDay = Utilities::CheckSpecialDay(cfg, current, &specialDayId, &price))) {
|
||||
uint32_t p = 0;
|
||||
if((isSpecialDay = Utilities::CheckSpecialDay(cfg, current, &specialDayId, &p))) {
|
||||
// Set special day price:
|
||||
durationUnit = specialDaysDurationUnit;
|
||||
price = p / durationUnit;
|
||||
price = std::round(price * 1000.0) / 1000.0;
|
||||
worktime[ranges].setTimeRange(SpecialDaysWorkTimeFrom(cfg, specialDayId),
|
||||
SpecialDaysWorkTimeUntil(cfg, specialDayId));
|
||||
ranges = 1;
|
||||
@@ -561,10 +553,12 @@ Ticket Calculator::private_GetDurationFromCost(Configuration *cfg,
|
||||
// the computation the price is divided by durationUnit.
|
||||
price = weekDaysPrice;
|
||||
durationUnit = weekDaysDurationUnit;
|
||||
price /= durationUnit;
|
||||
price = std::round(price * 1000.0) / 1000.0; // round to 3 decimals
|
||||
|
||||
// If no working day found, skip it (epsecially Sundays!)
|
||||
if (cfg->WeekDaysWorktime.count(weekdayId) <= 0) {
|
||||
qDebug() << "No workday found, trying to find next available day";
|
||||
// qDebug() << "No workday found, trying to find next available day";
|
||||
end = current;
|
||||
current.setTime(QTime()); // start at midnight on the next day
|
||||
continue;
|
||||
@@ -580,33 +574,30 @@ Ticket Calculator::private_GetDurationFromCost(Configuration *cfg,
|
||||
}
|
||||
}
|
||||
|
||||
moneyLeft *= durationUnit;
|
||||
|
||||
QTime const &lastWorktimeTo = worktime[ranges-1].getTimeUntil();
|
||||
|
||||
// find worktime range to start with
|
||||
|
||||
int currentRange = 0;
|
||||
if (!isSpecialDay) {
|
||||
if (start != current) { // on next day
|
||||
current.setTime(worktime[currentRange].getTimeFrom());
|
||||
} else {
|
||||
// check if inputDate is located inside a valid worktime-range...
|
||||
currentRange = findWorkTimeRange(current, worktime, ranges);
|
||||
if (currentRange == -1) { // no...
|
||||
if (!prepaid) { // parking is not allowed
|
||||
if ((currentRange = findWorkTimeRange(current, worktime, ranges)) == -1) {
|
||||
if (!prepaid && carryOverNotSet) { // parking is not allowed
|
||||
return Ticket(start, QDateTime(), durationMinutesNetto, 0,
|
||||
0, Ticket::s[INVALID_FROM_DATETIME]);
|
||||
}
|
||||
// find the next worktime-range (on the same day), and start from there
|
||||
currentRange = findNextWorkTimeRange(current, worktime, ranges);
|
||||
if ((currentRange = findNextWorkTimeRange(current, worktime, ranges)) == -1) {
|
||||
end = current;
|
||||
continue;
|
||||
}
|
||||
current.setTime(worktime[currentRange].getTimeFrom());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
qCritical() << "current" << current.toString(Qt::ISODate) << currentRange;
|
||||
|
||||
for (int w = currentRange; w < ranges; ++w, ++totalTimeRanges) {
|
||||
if (moneyLeft > 0) {
|
||||
QTime const &worktime_from = worktime[w].getTimeFrom();
|
||||
@@ -618,10 +609,6 @@ Ticket Calculator::private_GetDurationFromCost(Configuration *cfg,
|
||||
current.setTime(worktime_from);
|
||||
}
|
||||
|
||||
qCritical() << "worktime_from" << worktime_from;
|
||||
qCritical() << "worktime_to" << worktime_to;
|
||||
qCritical() << "current" << current.toString(Qt::ISODate);
|
||||
|
||||
if (price == 0) {
|
||||
// inputDate = inputDate.addDays(1);
|
||||
// inputDate.setTime(worktime_from);
|
||||
@@ -655,7 +642,7 @@ Ticket Calculator::private_GetDurationFromCost(Configuration *cfg,
|
||||
}
|
||||
}
|
||||
|
||||
while(moneyLeft > 0) {
|
||||
while(moneyLeft >= price) {
|
||||
// Check for active year period
|
||||
if (!IsYearPeriodActive(cfg, current)) {
|
||||
return Ticket();
|
||||
@@ -675,13 +662,11 @@ Ticket Calculator::private_GetDurationFromCost(Configuration *cfg,
|
||||
} else {
|
||||
if(current.time() < worktime_to) {
|
||||
// Increment input date minutes for each monetary unit
|
||||
durationMinutesNetto +=1;
|
||||
moneyLeft -= price;
|
||||
moneyLeft = std::round(moneyLeft * 1000.0) / 1000.0;
|
||||
current = current.addSecs(60);
|
||||
end = current;
|
||||
if(price > 0) {
|
||||
durationMinutesNetto +=1;
|
||||
}
|
||||
moneyLeft -= price;
|
||||
qCritical() << "current" << current.toString(Qt::ISODate) << "moneyLeft" << moneyLeft;
|
||||
} else break;
|
||||
}
|
||||
} // while(durationMinutes > 0) {
|
||||
@@ -691,8 +676,8 @@ Ticket Calculator::private_GetDurationFromCost(Configuration *cfg,
|
||||
|
||||
int durationMinutesBrutto = start.secsTo(end) / 60;
|
||||
|
||||
qCritical() << "start" << start.toString(Qt::ISODate) << "end"
|
||||
<< end.toString(Qt::ISODate) << durationMinutesBrutto;
|
||||
//qCritical() << "start" << start.toString(Qt::ISODate) << "end"
|
||||
// << end.toString(Qt::ISODate) << durationMinutesBrutto;
|
||||
|
||||
return
|
||||
Ticket(start, end, durationMinutesNetto, durationMinutesBrutto,
|
||||
|
@@ -373,3 +373,29 @@ PaymentMethod Utilities::getPaymentMethodId(Configuration const *cfg) {
|
||||
|
||||
return PaymentMethod::Undefined;
|
||||
}
|
||||
|
||||
int Utilities::getMinimalParkingTime(Configuration const *cfg, PaymentMethod methodId) {
|
||||
return std::max((int)cfg->PaymentOption.find(methodId)->second.pop_min_time, 0);
|
||||
}
|
||||
|
||||
int Utilities::getMaximalParkingTime(Configuration const *cfg, PaymentMethod methodId) {
|
||||
return std::max((int)cfg->PaymentOption.find(methodId)->second.pop_max_time, 0);
|
||||
}
|
||||
|
||||
uint32_t Utilities::getMinimalParkingPrice(Configuration const *cfg, PaymentMethod methodId) {
|
||||
return std::max((int)cfg->PaymentOption.find(methodId)->second.pop_min_price, 0);
|
||||
}
|
||||
|
||||
uint32_t Utilities::getFirstDurationStep(Configuration const *cfg, PaymentMethod methodId) {
|
||||
|
||||
int const popId = cfg->PaymentOption.find(methodId)->second.pop_id;
|
||||
int const punId = cfg->PaymentRate.find(popId)->second.pra_payment_unit_id;
|
||||
uint32_t const firstDurationStep= cfg->Duration.find(punId)->second.pun_duration;
|
||||
|
||||
qCritical() << "getFirstDurationStep() payment-method-id:" << (int)methodId;
|
||||
qCritical() << "getFirstDurationStep() pop-id:" << popId;
|
||||
qCritical() << "getFirstDurationStep() pun-id:" << punId;
|
||||
qCritical() << "getFirstDurationStep() first-step:" << firstDurationStep;
|
||||
|
||||
return firstDurationStep;
|
||||
}
|
||||
|
235
main/main.cpp
235
main/main.cpp
@@ -33,10 +33,16 @@ extern "C" char* strptime(const char* s,
|
||||
#include "calculator_functions.h"
|
||||
#include <calculate_price.h>
|
||||
|
||||
#define SZEGED (1)
|
||||
#define NEUHAUSER_KORNEUBURG (0)
|
||||
|
||||
|
||||
int main() {
|
||||
|
||||
#if NEUHAUSER_KORNEUBURG==1
|
||||
std::ifstream input("/tmp/tariff_korneuburg.json");
|
||||
int pop_max_time;
|
||||
|
||||
std::stringstream sstr;
|
||||
while(input >> sstr.rdbuf());
|
||||
std::string json(sstr.str());
|
||||
@@ -47,129 +53,130 @@ int main() {
|
||||
bool isParsed = cfg.ParseJson(&cfg, json.c_str());
|
||||
cout << endl;
|
||||
|
||||
|
||||
if (isParsed)
|
||||
if (isParsed) {
|
||||
{
|
||||
QDateTime start = QDateTime::fromString("2023-12-08T17:50:00",Qt::ISODate);
|
||||
//QDateTime start = QDateTime::currentDateTime();
|
||||
QDateTime end = start.addSecs(120);
|
||||
uint32_t cost = calculator.GetCostFromDuration(&cfg, 3, start, end, 30);
|
||||
pop_max_time = 3*60;
|
||||
bool nextDay = false;
|
||||
bool prePaid = true;
|
||||
// zone 1 (lila)
|
||||
QDateTime s(QDate(2023, 11, 30), QTime());
|
||||
QDateTime end;
|
||||
for (int duration = 30; duration <= pop_max_time; duration += 5) {
|
||||
for (int offset = 420; offset < 1140; ++offset) {
|
||||
if (offset > 720 && offset < 840) {
|
||||
continue;
|
||||
}
|
||||
QDateTime start = s.addSecs(offset * 60);
|
||||
//qCritical() << "start" << start.toString(Qt::ISODate);
|
||||
|
||||
qCritical() << "cost=" << cost;
|
||||
qCritical() << "end=" << end;
|
||||
double cost = calculator.GetCostFromDuration(&cfg, 3, start, end, duration, nextDay, prePaid);
|
||||
//Q_ASSERT(cost == duration*2.5);
|
||||
//qCritical() << "";
|
||||
//qCritical() << "start" << start.toString(Qt::ISODate)
|
||||
// << "end" << end.toString(Qt::ISODate)
|
||||
// << "duration" << duration
|
||||
// << "cost" << cost;
|
||||
|
||||
std::string duration = calculator.GetDurationFromCost(&cfg, 3,
|
||||
start.toString(Qt::ISODate).toStdString().c_str(),
|
||||
60);
|
||||
std::string duration = calculator.GetDurationFromCost(&cfg, 3, start.toString(Qt::ISODate).toStdString().c_str(), cost);
|
||||
//Q_ASSERT(cost == duration*2.5);
|
||||
qCritical() << "start" << start.toString(Qt::ISODate)
|
||||
<< "cost" << cost
|
||||
<< "until" << duration.c_str() << start.secsTo(QDateTime::fromString(duration.c_str(), Qt::ISODate)) / 60;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
|
||||
qCritical() << "duration=" << duration.c_str();
|
||||
#elif SZEGED==1
|
||||
std::ifstream input;
|
||||
int pop_max_time;
|
||||
|
||||
for (int t=6; t < 7; t+=20) {
|
||||
switch (t) {
|
||||
case 1: {
|
||||
input.open("/opt/ptu5/opt/customer_281/etc/psa_tariff/tariff01.json");
|
||||
pop_max_time = 6*60;
|
||||
} break;
|
||||
case 2: {
|
||||
input.open("/opt/ptu5/opt/customer_281/etc/psa_tariff/tariff02.json");
|
||||
pop_max_time = 5*60;
|
||||
} break;
|
||||
case 3: {
|
||||
input.open("/opt/ptu5/opt/customer_281/etc/psa_tariff/tariff03.json");
|
||||
pop_max_time = 6*60;
|
||||
} break;
|
||||
case 4: {
|
||||
input.open("/opt/ptu5/opt/customer_281/etc/psa_tariff/tariff04.json");
|
||||
pop_max_time = 4*60;
|
||||
} break;
|
||||
case 5: {
|
||||
input.open("/opt/ptu5/opt/customer_281/etc/psa_tariff/tariff05.json");
|
||||
pop_max_time = 6*60;
|
||||
} break;
|
||||
case 6: {
|
||||
input.open("/opt/ptu5/opt/customer_281/etc/psa_tariff/tariff06.json");
|
||||
pop_max_time = 4*60;
|
||||
} break;
|
||||
default:
|
||||
continue;
|
||||
}
|
||||
std::stringstream sstr;
|
||||
while(input >> sstr.rdbuf());
|
||||
std::string json(sstr.str());
|
||||
|
||||
Calculator calculator;
|
||||
Configuration cfg;
|
||||
|
||||
bool isParsed = cfg.ParseJson(&cfg, json.c_str());
|
||||
cout << endl;
|
||||
|
||||
if (isParsed) {
|
||||
{
|
||||
// zone 1 (lila)
|
||||
QDateTime s(QDate(2023, 11, 30), QTime());
|
||||
QDateTime end;
|
||||
for (int duration = 15; duration <= pop_max_time; duration += 5) {
|
||||
for (int offset = 480; offset < 1080; ++offset) {
|
||||
QDateTime start = s.addSecs(offset * 60);
|
||||
//qCritical() << "start" << start.toString(Qt::ISODate);
|
||||
|
||||
double cost = calculator.GetCostFromDuration(&cfg, 3, start, end, duration);
|
||||
//Q_ASSERT(cost == duration*2.5);
|
||||
//qCritical() << "";
|
||||
//qCritical() << "start" << start.toString(Qt::ISODate)
|
||||
// << "end" << end.toString(Qt::ISODate)
|
||||
// << "duration" << duration
|
||||
// << "cost" << cost;
|
||||
|
||||
std::string duration = calculator.GetDurationFromCost(&cfg, 3, start.toString(Qt::ISODate).toStdString().c_str(), cost);
|
||||
//Q_ASSERT(cost == duration*2.5);
|
||||
qCritical() << "start" << start.toString(Qt::ISODate)
|
||||
<< "cost" << cost
|
||||
<< "until" << duration.c_str() << start.secsTo(QDateTime::fromString(duration.c_str(), Qt::ISODate)) / 60;
|
||||
}
|
||||
}
|
||||
}
|
||||
{
|
||||
QDateTime start(QDate(2023, 12, 1), QTime(18, 0));
|
||||
QDateTime end;
|
||||
double cost = calculator.GetCostFromDuration(&cfg, 3, start, end, 60);
|
||||
// Q_ASSERT(cost == 150);
|
||||
qCritical() << "end" << end.toString(Qt::ISODate) << "cost" << cost;
|
||||
}
|
||||
{
|
||||
QDateTime start(QDate(2023, 10, 31), QTime(18, 0));
|
||||
QDateTime end;
|
||||
double cost = calculator.GetCostFromDuration(&cfg, 3, start, end, 60);
|
||||
//Q_ASSERT(cost == 150);
|
||||
qCritical() << "end" << end.toString(Qt::ISODate) << "cost" << cost;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
parking_tariff_t *tariff = 0;
|
||||
if (init_tariff(&tariff, "/etc/psa_tariff/")) {
|
||||
struct price_t price;
|
||||
memset(&price, 0x00, sizeof(price));
|
||||
|
||||
QDateTime start = QDateTime::fromString("2023-05-11T07:50:00",Qt::ISODate); //QDateTime::currentDateTime();
|
||||
time_t start_parking_time = start.toSecsSinceEpoch() / 60;
|
||||
time_t end_parking_time = start_parking_time + 615;
|
||||
|
||||
if (compute_price_for_parking_ticket(tariff,
|
||||
start_parking_time,
|
||||
end_parking_time,
|
||||
&price))
|
||||
{
|
||||
qDebug() << "GetCostFromDuration() => price=" << price.netto;
|
||||
}
|
||||
|
||||
QString duration;
|
||||
if(compute_duration_for_parking_ticket(tariff,start_parking_time,3090,duration))
|
||||
{
|
||||
qDebug() << "GetDurationFromCost() => duration=" << duration;
|
||||
}
|
||||
|
||||
// Daily ticket
|
||||
//compute_duration_for_daily_ticket(tariff,start.toString(Qt::ISODate),3);
|
||||
|
||||
//Configuration* cfg, QString start_datetime, uint8_t payment_option, bool carry_over
|
||||
// // 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);
|
||||
}
|
||||
|
||||
return 0;
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
|
||||
|
Reference in New Issue
Block a user