Compare commits
2 Commits
bad-neuena
...
2.0.0
Author | SHA1 | Date | |
---|---|---|---|
9bfea0f46d
|
|||
7ee90a9e8a
|
@@ -109,6 +109,8 @@ 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,
|
||||||
|
@@ -43,9 +43,6 @@ private:
|
|||||||
// For tariff of following structure: only steps, no special days, nonstop.
|
// 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, quint64 durationMinutes) const;
|
||||||
uint32_t GetCostFromDuration(Configuration *cfg, QDateTime const &start, QDateTime const &end) const;
|
uint32_t GetCostFromDuration(Configuration *cfg, QDateTime const &start, QDateTime const &end) const;
|
||||||
|
|
||||||
|
|
||||||
//
|
|
||||||
uint32_t GetPriceForTimeStep(Configuration *cfg, int timeStep) const;
|
uint32_t GetPriceForTimeStep(Configuration *cfg, int timeStep) const;
|
||||||
uint32_t GetDurationForPrice(Configuration *cfg, int price) const;
|
uint32_t GetDurationForPrice(Configuration *cfg, int price) const;
|
||||||
};
|
};
|
||||||
|
@@ -93,6 +93,44 @@ 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)
|
||||||
|
{
|
||||||
|
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];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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(
|
||||||
parking_tariff_t *tariff,
|
parking_tariff_t *tariff,
|
||||||
|
@@ -634,22 +634,29 @@ uint32_t Calculator::GetPriceForTimeStep(Configuration *cfg, int timeStep) const
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* private: read price directly from config file (used with PaymentMethod::Steps)
|
||||||
|
*
|
||||||
|
* return duration in minutes for greatest pra_price < price
|
||||||
|
*/
|
||||||
|
|
||||||
uint32_t Calculator::GetDurationForPrice(Configuration *cfg, int price) const {
|
uint32_t Calculator::GetDurationForPrice(Configuration *cfg, int price) const {
|
||||||
int const pop_id = cfg->getPaymentOptions().pop_id;
|
int const pop_id = cfg->getPaymentOptions().pop_id;
|
||||||
|
uint32_t duration = 0;
|
||||||
|
|
||||||
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 payment_unit_id = itr->second.pra_payment_unit_id;
|
int const durationId = itr->second.pra_payment_unit_id;
|
||||||
int const pra_price = itr->second.pra_price;
|
int const pra_price = itr->second.pra_price;
|
||||||
|
uint32_t const durationUnit = cfg->Duration.find(durationId)->second.pun_duration;
|
||||||
|
|
||||||
if (price == pra_price) {
|
if (price == pra_price) {
|
||||||
int const durationId = itr->second.pra_payment_unit_id;
|
|
||||||
int const durationUnit = cfg->Duration.find(durationId)->second.pun_duration;
|
|
||||||
|
|
||||||
return durationUnit;
|
return durationUnit;
|
||||||
}
|
}
|
||||||
|
if (pra_price < price) {
|
||||||
|
duration = durationUnit;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return duration;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user