Compare commits
No commits in common. "1b933c05a63d4b89d201b23dab4fd836723912ae" and "89b7589600ff06ba3da8694bbea96c0d80328347" have entirely different histories.
1b933c05a6
...
89b7589600
@ -13,22 +13,8 @@
|
|||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
class Calculator {
|
class Calculator {
|
||||||
mutable QList<int> m_timeSteps;
|
|
||||||
|
|
||||||
protected:
|
|
||||||
explicit Calculator() = default;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Calculator(Calculator const &other) = delete;
|
explicit Calculator() = default;
|
||||||
void operator=(Calculator const &) = delete;
|
|
||||||
|
|
||||||
static Calculator &GetInstance() {
|
|
||||||
static Calculator c;
|
|
||||||
return c;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ResetTimeSteps() { m_timeSteps.clear(); }
|
|
||||||
QList<int> timeSteps() const { return m_timeSteps; }
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets duration in seconds from cost
|
/// Gets duration in seconds from cost
|
||||||
|
@ -10,15 +10,16 @@
|
|||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QList>
|
#include <QList>
|
||||||
|
|
||||||
|
static Calculator calculator;
|
||||||
|
|
||||||
QList<int> CALCULATE_LIBRARY_API get_time_steps(Configuration *cfg) {
|
QList<int> CALCULATE_LIBRARY_API get_time_steps(Configuration *cfg) {
|
||||||
return Calculator::GetInstance().GetTimeSteps(cfg);
|
return calculator.GetTimeSteps(cfg);
|
||||||
}
|
}
|
||||||
|
|
||||||
int CALCULATE_LIBRARY_API get_minimal_parkingtime(Configuration *cfg) {
|
int CALCULATE_LIBRARY_API get_minimal_parkingtime(Configuration *cfg) {
|
||||||
// for each new sell-procedure, recomute the timesteps. implicitly, set
|
// get_time_steps() possibly re-computes pop_min_time: see
|
||||||
// the minimal parking time.
|
// calculator.GetTimeSteps()
|
||||||
Calculator::GetInstance().ResetTimeSteps();
|
get_time_steps(cfg);
|
||||||
Calculator::GetInstance().GetTimeSteps(cfg);
|
|
||||||
return qRound(cfg->getPaymentOptions().pop_min_time);
|
return qRound(cfg->getPaymentOptions().pop_min_time);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -109,8 +110,6 @@ void CALCULATE_LIBRARY_API free_tariff(parking_tariff_t *tariff) {
|
|||||||
int CALCULATE_LIBRARY_API compute_next_timestep(parking_tariff_t *tariff, int currentTimeMinutes, int UpDown)
|
int CALCULATE_LIBRARY_API compute_next_timestep(parking_tariff_t *tariff, int currentTimeMinutes, int UpDown)
|
||||||
{
|
{
|
||||||
qCritical() << " compute_next_timestep() currentTimeMinutes: " << currentTimeMinutes;
|
qCritical() << " compute_next_timestep() currentTimeMinutes: " << currentTimeMinutes;
|
||||||
qCritical() << " compute_next_timestep() up/down (1=up, 0=down): " << UpDown;
|
|
||||||
|
|
||||||
Configuration const *cfg = tariff;
|
Configuration const *cfg = tariff;
|
||||||
|
|
||||||
// compute payment method id (e.g. Linear=3, Steps=4)
|
// compute payment method id (e.g. Linear=3, Steps=4)
|
||||||
@ -137,8 +136,7 @@ int CALCULATE_LIBRARY_API compute_next_timestep(parking_tariff_t *tariff, int cu
|
|||||||
// without given YearPeriod, SpecialDays and SpecialDaysWorktime
|
// without given YearPeriod, SpecialDays and SpecialDaysWorktime
|
||||||
if (paymentMethodId == PaymentMethod::Steps)
|
if (paymentMethodId == PaymentMethod::Steps)
|
||||||
{
|
{
|
||||||
const QList<int> stepList = Calculator::GetInstance().GetTimeSteps(tariff);
|
static const QList<int> stepList = calculator.GetTimeSteps(tariff);
|
||||||
qCritical() << " compute_next_timestep() timeSteps:" << stepList;
|
|
||||||
|
|
||||||
int currentStepIndex = stepList.indexOf(currentTimeMinutes);
|
int currentStepIndex = stepList.indexOf(currentTimeMinutes);
|
||||||
|
|
||||||
@ -239,7 +237,7 @@ CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket(
|
|||||||
start = start.toLocalTime().addSecs(start_parking_time * 60);
|
start = start.toLocalTime().addSecs(start_parking_time * 60);
|
||||||
QDateTime end(start);
|
QDateTime end(start);
|
||||||
if (start.isValid()) {
|
if (start.isValid()) {
|
||||||
double cost = Calculator::GetInstance().GetCostFromDuration(
|
double cost = calculator.GetCostFromDuration(
|
||||||
tariff,
|
tariff,
|
||||||
tariff->getPaymentOptions().pop_payment_method_id,
|
tariff->getPaymentOptions().pop_payment_method_id,
|
||||||
start,
|
start,
|
||||||
@ -298,7 +296,7 @@ CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (start_parking_time.isValid()) {
|
if (start_parking_time.isValid()) {
|
||||||
double cost = Calculator::GetInstance().GetCostFromDuration(
|
double cost = calculator.GetCostFromDuration(
|
||||||
tariff,
|
tariff,
|
||||||
tariff->getPaymentOptions().pop_payment_method_id,
|
tariff->getPaymentOptions().pop_payment_method_id,
|
||||||
start_parking_time, // starting time
|
start_parking_time, // starting time
|
||||||
@ -341,7 +339,7 @@ CalcState CALCULATE_LIBRARY_API compute_duration_for_parking_ticket(
|
|||||||
qCritical() << " start (cs): " << cs;
|
qCritical() << " start (cs): " << cs;
|
||||||
qCritical() << " price: " << price;
|
qCritical() << " price: " << price;
|
||||||
|
|
||||||
duration = Calculator::GetInstance().GetDurationFromCost(tariff,
|
duration = calculator.GetDurationFromCost(tariff,
|
||||||
tariff->getPaymentOptions().pop_payment_method_id,
|
tariff->getPaymentOptions().pop_payment_method_id,
|
||||||
cs.toLocal8Bit().constData(),
|
cs.toLocal8Bit().constData(),
|
||||||
price, false, true).c_str();
|
price, false, true).c_str();
|
||||||
@ -366,7 +364,7 @@ CalcState CALCULATE_LIBRARY_API compute_duration_for_parking_ticket(
|
|||||||
CalcState calcState;
|
CalcState calcState;
|
||||||
if (start_parking_time.isValid()) {
|
if (start_parking_time.isValid()) {
|
||||||
QString cs = start_parking_time.toString(Qt::ISODate);
|
QString cs = start_parking_time.toString(Qt::ISODate);
|
||||||
QString endTime = Calculator::GetInstance().GetDurationFromCost(
|
QString endTime = calculator.GetDurationFromCost(
|
||||||
tariff,
|
tariff,
|
||||||
tariff->getPaymentOptions().pop_payment_method_id,
|
tariff->getPaymentOptions().pop_payment_method_id,
|
||||||
cs.toLocal8Bit().constData(),
|
cs.toLocal8Bit().constData(),
|
||||||
@ -394,7 +392,7 @@ CalcState CALCULATE_LIBRARY_API compute_duration_for_daily_ticket(parking_tariff
|
|||||||
CalcState calcState;
|
CalcState calcState;
|
||||||
if (start_parking_time.isValid()) {
|
if (start_parking_time.isValid()) {
|
||||||
|
|
||||||
ticketEndTime = Calculator::GetInstance().GetDailyTicketDuration(tariff,
|
ticketEndTime = calculator.GetDailyTicketDuration(tariff,
|
||||||
start_parking_time,
|
start_parking_time,
|
||||||
tariff->getPaymentOptions().pop_payment_method_id,
|
tariff->getPaymentOptions().pop_payment_method_id,
|
||||||
false); // carry over
|
false); // carry over
|
||||||
|
@ -696,10 +696,7 @@ Ticket Calculator::private_GetDurationFromCost(Configuration *cfg,
|
|||||||
}
|
}
|
||||||
|
|
||||||
QList<int> Calculator::GetTimeSteps(Configuration *cfg) const {
|
QList<int> Calculator::GetTimeSteps(Configuration *cfg) const {
|
||||||
if (m_timeSteps.size() > 0) {
|
QList<int> timeSteps;
|
||||||
//qCritical() << __PRETTY_FUNCTION__ << "timeSteps:" << m_timeSteps;
|
|
||||||
return m_timeSteps;
|
|
||||||
}
|
|
||||||
|
|
||||||
QDateTime start = QDateTime::currentDateTime();
|
QDateTime start = QDateTime::currentDateTime();
|
||||||
start.setTime(QTime(start.time().hour(), start.time().minute(), 0));
|
start.setTime(QTime(start.time().hour(), start.time().minute(), 0));
|
||||||
@ -708,12 +705,12 @@ QList<int> Calculator::GetTimeSteps(Configuration *cfg) const {
|
|||||||
int const pop_carry_over = cfg->getPaymentOptions().pop_carry_over;
|
int const pop_carry_over = cfg->getPaymentOptions().pop_carry_over;
|
||||||
int const pop_time_step_config = cfg->getPaymentOptions().pop_time_step_config;
|
int const pop_time_step_config = cfg->getPaymentOptions().pop_time_step_config;
|
||||||
|
|
||||||
qCritical() << __PRETTY_FUNCTION__ << " start parking time:" << start.toString(Qt::ISODate);
|
qCritical() << " start parking time:" << start.toString(Qt::ISODate);
|
||||||
qCritical() << __PRETTY_FUNCTION__ << " payment option id:" << pop_id;
|
qCritical() << " payment option id:" << pop_id;
|
||||||
qCritical() << __PRETTY_FUNCTION__ << " payment option carry over:" << pop_carry_over;
|
qCritical() << " payment option carry over:" << pop_carry_over;
|
||||||
|
|
||||||
if (pop_time_step_config == (int)ATBTimeStepConfig::TimeStepConfig::DYNAMIC) {
|
if (pop_time_step_config == (int)ATBTimeStepConfig::TimeStepConfig::DYNAMIC) {
|
||||||
//qCritical() << __PRETTY_FUNCTION__ << "payment option time step config:" << "TimeStepConfig::DYNAMIC";
|
qCritical() << "payment option time step config:" << "TimeStepConfig::DYNAMIC";
|
||||||
|
|
||||||
uint16_t timeStepCompensation = 0;
|
uint16_t timeStepCompensation = 0;
|
||||||
|
|
||||||
@ -742,19 +739,19 @@ QList<int> Calculator::GetTimeSteps(Configuration *cfg) const {
|
|||||||
.arg(timeStep).arg(duration.pun_duration_max);
|
.arg(timeStep).arg(duration.pun_duration_max);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
qCritical() << __PRETTY_FUNCTION__ << "configured minimal parking time:" << cfg->getPaymentOptions().pop_min_time;
|
qCritical() << "configured minimal parking time:" << cfg->getPaymentOptions().pop_min_time;
|
||||||
|
|
||||||
// set dynamic minimal parking time
|
// set dynamic minimal parking time
|
||||||
cfg->getPaymentOptions().pop_min_time = timeStep;
|
cfg->getPaymentOptions().pop_min_time = timeStep;
|
||||||
|
|
||||||
qCritical() << __PRETTY_FUNCTION__ << " computed minimal parking time:" << cfg->getPaymentOptions().pop_min_time;
|
qCritical() << " computed minimal parking time:" << cfg->getPaymentOptions().pop_min_time;
|
||||||
|
|
||||||
duration.pun_duration = timeStep;
|
duration.pun_duration = timeStep;
|
||||||
timeStepCompensation = duration.pun_duration_max - duration.pun_duration;
|
timeStepCompensation = duration.pun_duration_max - duration.pun_duration;
|
||||||
m_timeSteps << duration.pun_duration;
|
timeSteps << duration.pun_duration;
|
||||||
} else {
|
} else {
|
||||||
duration.pun_duration = duration.pun_duration_max - timeStepCompensation;
|
duration.pun_duration = duration.pun_duration_max - timeStepCompensation;
|
||||||
m_timeSteps << duration.pun_duration;;
|
timeSteps << duration.pun_duration;;
|
||||||
}
|
}
|
||||||
|
|
||||||
cfg->Duration.erase(search);
|
cfg->Duration.erase(search);
|
||||||
@ -774,19 +771,17 @@ QList<int> Calculator::GetTimeSteps(Configuration *cfg) const {
|
|||||||
// TODO
|
// TODO
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
qCritical() << __PRETTY_FUNCTION__ << "payment option time step config:" << "TimeStepConfig::STATIC";
|
qCritical() << "payment option time step config:" << "TimeStepConfig::STATIC";
|
||||||
|
|
||||||
for (auto[itr, rangeEnd] = cfg->PaymentRate.equal_range(pop_id); itr != rangeEnd; ++itr)
|
for (auto[itr, rangeEnd] = cfg->PaymentRate.equal_range(pop_id); itr != rangeEnd; ++itr)
|
||||||
{
|
{
|
||||||
int const durationId = itr->second.pra_payment_unit_id;
|
int const durationId = itr->second.pra_payment_unit_id;
|
||||||
int const durationUnit = cfg->Duration.find(durationId)->second.pun_duration;
|
int const durationUnit = cfg->Duration.find(durationId)->second.pun_duration;
|
||||||
m_timeSteps << durationUnit;
|
timeSteps << durationUnit;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Critical() << __PRETTY_FUNCTION__ << "NEW timeSteps:" << m_timeSteps;
|
return timeSteps;
|
||||||
|
|
||||||
return m_timeSteps;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t Calculator::GetPriceForTimeStep(Configuration *cfg, int timeStep) const {
|
uint32_t Calculator::GetPriceForTimeStep(Configuration *cfg, int timeStep) const {
|
||||||
|
@ -54,22 +54,18 @@ int main() {
|
|||||||
cout << endl;
|
cout << endl;
|
||||||
|
|
||||||
if (isParsed) {
|
if (isParsed) {
|
||||||
int minParkingTime = get_minimal_parkingtime(&cfg);
|
QDateTime start = QDateTime::currentDateTime();
|
||||||
QList<int> timeSteps = Calculator::GetInstance().GetTimeSteps(&cfg);
|
start.setTime(QTime(start.time().hour(), start.time().minute(), 0));
|
||||||
|
Calculator calculator(start);
|
||||||
|
QList<int> timeSteps = calculator.GetTimeSteps(&cfg);
|
||||||
qCritical() << timeSteps;
|
qCritical() << timeSteps;
|
||||||
int Down = 0;
|
|
||||||
int Up = 1;
|
|
||||||
//compute_next_timestep(&cfg, )
|
|
||||||
|
|
||||||
for (int i=0; i<timeSteps.size(); ++i) {
|
for (int i=0; i<timeSteps.size(); ++i) {
|
||||||
int nextTimeStep = compute_next_timestep(&cfg, timeSteps.at(i), Up);
|
uint32_t price = calculator.GetPriceForTimeStep(&cfg, timeSteps.at(i));
|
||||||
qCritical() << "nextTimeStep" << nextTimeStep;
|
uint32_t duration = calculator.GetDurationForPrice(&cfg, price);
|
||||||
|
qCritical() << "nextTimeStep relative to start:"
|
||||||
// uint32_t price = calculator.GetPriceForTimeStep(&cfg, timeSteps.at(i));
|
<< duration << start.addSecs(duration * 60)
|
||||||
// uint32_t duration = calculator.GetDurationForPrice(&cfg, price);
|
<< "(price so far:" << price << ")";
|
||||||
// qCritical() << "nextTimeStep relative to start:"
|
|
||||||
// << duration << start.addSecs(duration * 60)
|
|
||||||
// << "(price so far:" << price << ")";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user