Compare commits
4 Commits
89b7589600
...
1b933c05a6
Author | SHA1 | Date | |
---|---|---|---|
1b933c05a6 | |||
ac45ebb926 | |||
9af39fa83f | |||
17ae11212a |
@ -13,9 +13,23 @@
|
|||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
class Calculator {
|
class Calculator {
|
||||||
public:
|
mutable QList<int> m_timeSteps;
|
||||||
|
|
||||||
|
protected:
|
||||||
explicit Calculator() = default;
|
explicit Calculator() = default;
|
||||||
|
|
||||||
|
public:
|
||||||
|
Calculator(Calculator const &other) = delete;
|
||||||
|
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
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -10,16 +10,15 @@
|
|||||||
#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.GetTimeSteps(cfg);
|
return Calculator::GetInstance().GetTimeSteps(cfg);
|
||||||
}
|
}
|
||||||
|
|
||||||
int CALCULATE_LIBRARY_API get_minimal_parkingtime(Configuration *cfg) {
|
int CALCULATE_LIBRARY_API get_minimal_parkingtime(Configuration *cfg) {
|
||||||
// get_time_steps() possibly re-computes pop_min_time: see
|
// for each new sell-procedure, recomute the timesteps. implicitly, set
|
||||||
// calculator.GetTimeSteps()
|
// the minimal parking time.
|
||||||
get_time_steps(cfg);
|
Calculator::GetInstance().ResetTimeSteps();
|
||||||
|
Calculator::GetInstance().GetTimeSteps(cfg);
|
||||||
return qRound(cfg->getPaymentOptions().pop_min_time);
|
return qRound(cfg->getPaymentOptions().pop_min_time);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -109,7 +108,9 @@ void CALCULATE_LIBRARY_API free_tariff(parking_tariff_t *tariff) {
|
|||||||
// UpDown 1 -> up; 0 -> down
|
// UpDown 1 -> up; 0 -> down
|
||||||
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)
|
||||||
@ -136,7 +137,8 @@ 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)
|
||||||
{
|
{
|
||||||
static const QList<int> stepList = calculator.GetTimeSteps(tariff);
|
const QList<int> stepList = Calculator::GetInstance().GetTimeSteps(tariff);
|
||||||
|
qCritical() << " compute_next_timestep() timeSteps:" << stepList;
|
||||||
|
|
||||||
int currentStepIndex = stepList.indexOf(currentTimeMinutes);
|
int currentStepIndex = stepList.indexOf(currentTimeMinutes);
|
||||||
|
|
||||||
@ -237,7 +239,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.GetCostFromDuration(
|
double cost = Calculator::GetInstance().GetCostFromDuration(
|
||||||
tariff,
|
tariff,
|
||||||
tariff->getPaymentOptions().pop_payment_method_id,
|
tariff->getPaymentOptions().pop_payment_method_id,
|
||||||
start,
|
start,
|
||||||
@ -296,7 +298,7 @@ CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (start_parking_time.isValid()) {
|
if (start_parking_time.isValid()) {
|
||||||
double cost = calculator.GetCostFromDuration(
|
double cost = Calculator::GetInstance().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
|
||||||
@ -339,7 +341,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.GetDurationFromCost(tariff,
|
duration = Calculator::GetInstance().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();
|
||||||
@ -364,7 +366,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.GetDurationFromCost(
|
QString endTime = Calculator::GetInstance().GetDurationFromCost(
|
||||||
tariff,
|
tariff,
|
||||||
tariff->getPaymentOptions().pop_payment_method_id,
|
tariff->getPaymentOptions().pop_payment_method_id,
|
||||||
cs.toLocal8Bit().constData(),
|
cs.toLocal8Bit().constData(),
|
||||||
@ -392,7 +394,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.GetDailyTicketDuration(tariff,
|
ticketEndTime = Calculator::GetInstance().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,7 +696,10 @@ Ticket Calculator::private_GetDurationFromCost(Configuration *cfg,
|
|||||||
}
|
}
|
||||||
|
|
||||||
QList<int> Calculator::GetTimeSteps(Configuration *cfg) const {
|
QList<int> Calculator::GetTimeSteps(Configuration *cfg) const {
|
||||||
QList<int> timeSteps;
|
if (m_timeSteps.size() > 0) {
|
||||||
|
//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));
|
||||||
@ -705,12 +708,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() << " start parking time:" << start.toString(Qt::ISODate);
|
qCritical() << __PRETTY_FUNCTION__ << " start parking time:" << start.toString(Qt::ISODate);
|
||||||
qCritical() << " payment option id:" << pop_id;
|
qCritical() << __PRETTY_FUNCTION__ << " payment option id:" << pop_id;
|
||||||
qCritical() << " payment option carry over:" << pop_carry_over;
|
qCritical() << __PRETTY_FUNCTION__ << " 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() << "payment option time step config:" << "TimeStepConfig::DYNAMIC";
|
//qCritical() << __PRETTY_FUNCTION__ << "payment option time step config:" << "TimeStepConfig::DYNAMIC";
|
||||||
|
|
||||||
uint16_t timeStepCompensation = 0;
|
uint16_t timeStepCompensation = 0;
|
||||||
|
|
||||||
@ -739,19 +742,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() << "configured minimal parking time:" << cfg->getPaymentOptions().pop_min_time;
|
qCritical() << __PRETTY_FUNCTION__ << "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() << " computed minimal parking time:" << cfg->getPaymentOptions().pop_min_time;
|
qCritical() << __PRETTY_FUNCTION__ << " 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;
|
||||||
timeSteps << duration.pun_duration;
|
m_timeSteps << duration.pun_duration;
|
||||||
} else {
|
} else {
|
||||||
duration.pun_duration = duration.pun_duration_max - timeStepCompensation;
|
duration.pun_duration = duration.pun_duration_max - timeStepCompensation;
|
||||||
timeSteps << duration.pun_duration;;
|
m_timeSteps << duration.pun_duration;;
|
||||||
}
|
}
|
||||||
|
|
||||||
cfg->Duration.erase(search);
|
cfg->Duration.erase(search);
|
||||||
@ -771,17 +774,19 @@ QList<int> Calculator::GetTimeSteps(Configuration *cfg) const {
|
|||||||
// TODO
|
// TODO
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
qCritical() << "payment option time step config:" << "TimeStepConfig::STATIC";
|
qCritical() << __PRETTY_FUNCTION__ << "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;
|
||||||
timeSteps << durationUnit;
|
m_timeSteps << durationUnit;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return timeSteps;
|
Critical() << __PRETTY_FUNCTION__ << "NEW timeSteps:" << m_timeSteps;
|
||||||
|
|
||||||
|
return m_timeSteps;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t Calculator::GetPriceForTimeStep(Configuration *cfg, int timeStep) const {
|
uint32_t Calculator::GetPriceForTimeStep(Configuration *cfg, int timeStep) const {
|
||||||
|
@ -54,18 +54,22 @@ int main() {
|
|||||||
cout << endl;
|
cout << endl;
|
||||||
|
|
||||||
if (isParsed) {
|
if (isParsed) {
|
||||||
QDateTime start = QDateTime::currentDateTime();
|
int minParkingTime = get_minimal_parkingtime(&cfg);
|
||||||
start.setTime(QTime(start.time().hour(), start.time().minute(), 0));
|
QList<int> timeSteps = Calculator::GetInstance().GetTimeSteps(&cfg);
|
||||||
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) {
|
||||||
uint32_t price = calculator.GetPriceForTimeStep(&cfg, timeSteps.at(i));
|
int nextTimeStep = compute_next_timestep(&cfg, timeSteps.at(i), Up);
|
||||||
uint32_t duration = calculator.GetDurationForPrice(&cfg, price);
|
qCritical() << "nextTimeStep" << nextTimeStep;
|
||||||
qCritical() << "nextTimeStep relative to start:"
|
|
||||||
<< duration << start.addSecs(duration * 60)
|
// uint32_t price = calculator.GetPriceForTimeStep(&cfg, timeSteps.at(i));
|
||||||
<< "(price so far:" << price << ")";
|
// uint32_t duration = calculator.GetDurationForPrice(&cfg, 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