Compare commits
No commits in common. "b9a7c04db9ed77365e3a3a1e45c19dbf5f17e60a" and "9d220df52efd39528c8613637f4d5c4b182dbc6b" have entirely different histories.
b9a7c04db9
...
9d220df52e
@ -109,8 +109,6 @@ CalcState CALCULATE_LIBRARY_API init_tariff(parking_tariff_t **tariff,
|
|||||||
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 zone = -1);
|
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
|
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,
|
||||||
|
@ -82,9 +82,4 @@ namespace Utilities {
|
|||||||
bool isCarryOverSet(Configuration const *cfg, PaymentMethod paymentMethodId);
|
bool isCarryOverSet(Configuration const *cfg, PaymentMethod paymentMethodId);
|
||||||
bool isCarryOverNotSet(Configuration const *cfg, PaymentMethod paymentMethodId);
|
bool isCarryOverNotSet(Configuration const *cfg, PaymentMethod paymentMethodId);
|
||||||
PaymentMethod getPaymentMethodId(Configuration const *cfg);
|
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,6 @@
|
|||||||
#include "configuration.h"
|
#include "configuration.h"
|
||||||
#include "calculator_functions.h"
|
#include "calculator_functions.h"
|
||||||
#include "payment_option.h"
|
#include "payment_option.h"
|
||||||
#include "utilities.h"
|
|
||||||
|
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
#include <QFileInfo>
|
#include <QFileInfo>
|
||||||
@ -93,77 +92,6 @@ 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)
|
|
||||||
{
|
|
||||||
// use tariff with structure as for instance Schnau, Koenigsee:
|
|
||||||
// without given YearPeriod, SpecialDays and SpecialDaysWorktime
|
|
||||||
if (tariff->YearPeriod.size() == 0
|
|
||||||
&& tariff->SpecialDays.size() == 0
|
|
||||||
&& tariff->SpecialDaysWorktime.size() == 0)
|
|
||||||
{
|
|
||||||
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 {
|
|
||||||
Configuration const *cfg = tariff;
|
|
||||||
|
|
||||||
// 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() currentTimeMinutes:" << currentTimeMinutes;
|
|
||||||
|
|
||||||
// compute payment method id (e.g. Linear=3, Steps=4)
|
|
||||||
PaymentMethod paymentMethodId = Utilities::getPaymentMethodId(cfg);
|
|
||||||
qCritical() << " compute_next_timestep() paymentMethodId:" << paymentMethodId;
|
|
||||||
|
|
||||||
// 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:" << paymentMethodId;
|
|
||||||
qCritical() << " compute_next_timestep() minParkingTime:" << paymentMethodId;
|
|
||||||
|
|
||||||
// use the first (i.e. main duration step contained in the tariff json-file)
|
|
||||||
int firstDurationStep = Utilities::getFirstDurationStep(cfg, paymentMethodId);
|
|
||||||
qCritical() << " compute_next_timestep() firstDurationStep:" << paymentMethodId;
|
|
||||||
|
|
||||||
int nextTimeStep = currentTimeMinutes + firstDurationStep;
|
|
||||||
if (currentTimeMinutes >= 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
|
// this is currently not used
|
||||||
CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket(
|
CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket(
|
||||||
|
@ -265,7 +265,7 @@ int Calculator::findNextWorkTimeRange(QDateTime const &dt,
|
|||||||
|
|
||||||
if (dt.time() < worktime_from) {
|
if (dt.time() < worktime_from) {
|
||||||
nextWorkTimeRange = w;
|
nextWorkTimeRange = w;
|
||||||
break;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nextWorkTimeRange;
|
return nextWorkTimeRange;
|
||||||
@ -364,9 +364,6 @@ Ticket Calculator::private_GetCostFromDuration(Configuration const* cfg,
|
|||||||
|
|
||||||
QTime const &lastWorktimeTo = worktime[ranges-1].getTimeUntil();
|
QTime const &lastWorktimeTo = worktime[ranges-1].getTimeUntil();
|
||||||
|
|
||||||
// qCritical() << "start" << start.toString(Qt::ISODate)
|
|
||||||
// << "current" << current.toString(Qt::ISODate) << lastWorktimeTo;
|
|
||||||
|
|
||||||
// find worktime range to start with
|
// find worktime range to start with
|
||||||
int currentRange = 0;
|
int currentRange = 0;
|
||||||
if (!isSpecialDay) {
|
if (!isSpecialDay) {
|
||||||
@ -389,8 +386,6 @@ Ticket Calculator::private_GetCostFromDuration(Configuration const* cfg,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// qCritical() << "current" << current.toString(Qt::ISODate);
|
|
||||||
|
|
||||||
for (int w = currentRange; w < ranges; ++w, ++totalTimeRanges) {
|
for (int w = currentRange; w < ranges; ++w, ++totalTimeRanges) {
|
||||||
if (durationMinutes > 0) {
|
if (durationMinutes > 0) {
|
||||||
QTime const &worktime_from = worktime[w].getTimeFrom();
|
QTime const &worktime_from = worktime[w].getTimeFrom();
|
||||||
@ -421,13 +416,12 @@ Ticket Calculator::private_GetCostFromDuration(Configuration const* cfg,
|
|||||||
return Ticket();
|
return Ticket();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
//qDebug() << "* PREPAID MODE ACTIVE *";
|
qDebug() << "* PREPAID MODE ACTIVE *";
|
||||||
//qCritical() << "current" << current.toString(Qt::ISODate) << worktime_from << lastWorktimeTo;
|
|
||||||
if (current.time() < worktime_from) {
|
if (current.time() < worktime_from) {
|
||||||
current.setTime(worktime_from);
|
current.setTime(worktime_from);
|
||||||
end = current;
|
end = current;
|
||||||
} else if(current.time() > lastWorktimeTo) {
|
} 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;
|
end = current;
|
||||||
current.setTime(QTime());
|
current.setTime(QTime());
|
||||||
continue;
|
continue;
|
||||||
@ -448,7 +442,6 @@ Ticket Calculator::private_GetCostFromDuration(Configuration const* cfg,
|
|||||||
current.setTime(QTime());
|
current.setTime(QTime());
|
||||||
break; // stop while, and continue in outer loop
|
break; // stop while, and continue in outer loop
|
||||||
} else {
|
} else {
|
||||||
//qCritical() << "current" << current.toString(Qt::ISODate) << worktime_to;
|
|
||||||
if(current.time() < worktime_to) {
|
if(current.time() < worktime_to) {
|
||||||
// Increment input date minutes for each monetary unit
|
// Increment input date minutes for each monetary unit
|
||||||
current = current.addSecs(60);
|
current = current.addSecs(60);
|
||||||
@ -456,7 +449,6 @@ Ticket Calculator::private_GetCostFromDuration(Configuration const* cfg,
|
|||||||
durationMinutes -= 1;
|
durationMinutes -= 1;
|
||||||
//costFromDuration += price_per_unit;
|
//costFromDuration += price_per_unit;
|
||||||
costFromDuration += price;
|
costFromDuration += price;
|
||||||
//qCritical() << "current" << current.toString(Qt::ISODate);
|
|
||||||
} else break;
|
} else break;
|
||||||
}
|
}
|
||||||
} // while(durationMinutes > 0) {
|
} // while(durationMinutes > 0) {
|
||||||
|
@ -373,21 +373,3 @@ PaymentMethod Utilities::getPaymentMethodId(Configuration const *cfg) {
|
|||||||
|
|
||||||
return PaymentMethod::Undefined;
|
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 popId = cfg->PaymentOption.find(methodId)->second.pop_id;
|
|
||||||
int punId = cfg->PaymentRate.find(popId)->second.pra_payment_unit_id;
|
|
||||||
return cfg->Duration.find(punId)->second.pun_id;
|
|
||||||
}
|
|
||||||
|
@ -33,66 +33,13 @@ extern "C" char* strptime(const char* s,
|
|||||||
#include "calculator_functions.h"
|
#include "calculator_functions.h"
|
||||||
#include <calculate_price.h>
|
#include <calculate_price.h>
|
||||||
|
|
||||||
#define SZEGED (1)
|
|
||||||
#define NEUHAUSER_KORNEUBURG (0)
|
|
||||||
|
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
|
|
||||||
#if NEUHAUSER_KORNEUBURG==1
|
//std::ifstream input("/tmp/tariff_korneuburg.json");
|
||||||
std::ifstream input("/tmp/tariff_korneuburg.json");
|
|
||||||
int pop_max_time;
|
int pop_max_time;
|
||||||
|
|
||||||
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) {
|
|
||||||
{
|
|
||||||
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);
|
|
||||||
|
|
||||||
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(), 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;
|
|
||||||
|
|
||||||
#elif SZEGED==1
|
|
||||||
std::ifstream input;
|
std::ifstream input;
|
||||||
int pop_max_time;
|
for (int t=1; t < 7; t+=20) {
|
||||||
|
|
||||||
for (int t=6; t < 7; t+=20) {
|
|
||||||
switch (t) {
|
switch (t) {
|
||||||
case 1: {
|
case 1: {
|
||||||
input.open("/opt/ptu5/opt/customer_281/etc/psa_tariff/tariff01.json");
|
input.open("/opt/ptu5/opt/customer_281/etc/psa_tariff/tariff01.json");
|
||||||
@ -176,7 +123,6 @@ int main() {
|
|||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user