Compare commits
No commits in common. "master" and "schoenau_23112023" have entirely different histories.
master
...
schoenau_2
@ -109,8 +109,6 @@ 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,
|
||||
|
@ -43,6 +43,9 @@ private:
|
||||
// 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, QDateTime const &end) const;
|
||||
|
||||
|
||||
//
|
||||
uint32_t GetPriceForTimeStep(Configuration *cfg, int timeStep) const;
|
||||
uint32_t GetDurationForPrice(Configuration *cfg, int price) const;
|
||||
};
|
||||
|
@ -93,44 +93,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)
|
||||
{
|
||||
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
|
||||
CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket(
|
||||
parking_tariff_t *tariff,
|
||||
|
@ -118,21 +118,17 @@ std::string Calculator::GetDurationFromCost(Configuration* cfg,
|
||||
bool nextDay,
|
||||
bool prepaid)
|
||||
{
|
||||
|
||||
// Get input date
|
||||
QDateTime inputDate = QDateTime::fromString(start_datetime,Qt::ISODate);
|
||||
|
||||
// use tariff with structure as for instance Schnau, Koenigsee:
|
||||
// without given YearPeriod, SpecialDays and SpecialDaysWorktime
|
||||
if (cfg->YearPeriod.size() == 0
|
||||
&& cfg->SpecialDays.size() == 0
|
||||
&& cfg->SpecialDaysWorktime.size() == 0)
|
||||
{
|
||||
inputDate = inputDate.addSecs(GetDurationForPrice(cfg, price) * 60);
|
||||
|
||||
return inputDate.toString(Qt::ISODate).toStdString();
|
||||
return QString().setNum(GetDurationForPrice(cfg, price)).toStdString();
|
||||
}
|
||||
|
||||
// Get input date
|
||||
QDateTime inputDate = QDateTime::fromString(start_datetime,Qt::ISODate);
|
||||
|
||||
// Get day of week
|
||||
int weekdayId = 0;
|
||||
@ -140,13 +136,13 @@ std::string Calculator::GetDurationFromCost(Configuration* cfg,
|
||||
|
||||
//Get min and max time defined in JSON
|
||||
double minMin = 0;
|
||||
minMin = cfg->getPaymentOptions().pop_min_time;
|
||||
minMin = cfg->PaymentOption.find(payment_option)->second.pop_min_time;
|
||||
|
||||
double maxMin = 0;
|
||||
maxMin = cfg->getPaymentOptions().pop_max_time;
|
||||
maxMin = cfg->PaymentOption.find(payment_option)->second.pop_max_time;
|
||||
|
||||
double min_price = 0;
|
||||
min_price = cfg->getPaymentOptions().pop_min_price;
|
||||
min_price = cfg->PaymentOption.find(payment_option)->second.pop_min_price;
|
||||
|
||||
if(price < min_price)
|
||||
{
|
||||
@ -456,13 +452,11 @@ double Calculator::GetCostFromDuration(Configuration* cfg, uint8_t payment_optio
|
||||
double price_per_unit = 0.0f;
|
||||
QTime worktime_from;
|
||||
QTime worktime_to;
|
||||
double durationUnit = 60.0;
|
||||
|
||||
if(is_special_day)
|
||||
{
|
||||
// Set price_per_unit to special day price: at the end of the calculation
|
||||
// divide by durationUnit to get correct price.
|
||||
price_per_unit = day_price;
|
||||
// Set special day price
|
||||
price_per_unit = Utilities::CalculatePricePerUnit(day_price);
|
||||
worktime_from = QTime::fromString(cfg->SpecialDaysWorktime.find(current_special_day_id)->second.pedwt_time_from.c_str());
|
||||
worktime_to = QTime::fromString(cfg->SpecialDaysWorktime.find(current_special_day_id)->second.pedwt_time_to.c_str());
|
||||
}
|
||||
@ -474,13 +468,8 @@ double Calculator::GetCostFromDuration(Configuration* cfg, uint8_t payment_optio
|
||||
day_price = cfg->PaymentRate.find(pop_id)->second.pra_price;
|
||||
|
||||
int durationId = cfg->PaymentRate.find(pop_id)->second.pra_payment_unit_id;
|
||||
durationUnit = cfg->Duration.find(durationId)->second.pun_duration;
|
||||
if (durationUnit == 0) {
|
||||
durationUnit = 60.0;
|
||||
}
|
||||
// Set price_per_unit to day price: at the end of the calculation
|
||||
// divide by durationUnit to get correct price.
|
||||
price_per_unit = day_price;
|
||||
double durationUnit = cfg->Duration.find(durationId)->second.pun_duration;
|
||||
price_per_unit = Utilities::CalculatePricePerUnit(day_price,durationUnit);
|
||||
|
||||
// If no working day found, skip it (recursively call method again)
|
||||
size_t found = 0;
|
||||
@ -491,7 +480,7 @@ double Calculator::GetCostFromDuration(Configuration* cfg, uint8_t payment_optio
|
||||
{
|
||||
LOG_DEBUG("- No workday found, trying to find next available day");
|
||||
inputDate = inputDate.addDays(1);
|
||||
return GetCostFromDuration(cfg, payment_option, inputDate, end_datetime, durationMin, true, prepaid);
|
||||
return floor(GetCostFromDuration(cfg, payment_option, inputDate, end_datetime, durationMin, true, prepaid));
|
||||
}
|
||||
worktime_from = QTime::fromString(cfg->WeekDaysWorktime.find(weekdayId)->second.pwd_time_from.c_str());
|
||||
worktime_to = QTime::fromString(cfg->WeekDaysWorktime.find(weekdayId)->second.pwd_time_to.c_str());
|
||||
@ -601,7 +590,7 @@ double Calculator::GetCostFromDuration(Configuration* cfg, uint8_t payment_optio
|
||||
|
||||
double ret_val = total_cost;
|
||||
total_cost = 0.0f;
|
||||
return round(ret_val / durationUnit);
|
||||
return ceil(ret_val);
|
||||
}
|
||||
|
||||
|
||||
@ -641,29 +630,20 @@ uint32_t Calculator::GetPriceForTimeStep(Configuration *cfg, int timeStep) const
|
||||
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 {
|
||||
int const pop_id = cfg->getPaymentOptions().pop_id;
|
||||
uint32_t duration = 0;
|
||||
int const pop_id = cfg->getPaymentOptions().pop_id;
|
||||
|
||||
for (auto[itr, rangeEnd] = cfg->PaymentRate.equal_range(pop_id); itr != rangeEnd; ++itr)
|
||||
{
|
||||
int const durationId = itr->second.pra_payment_unit_id;
|
||||
int const pra_price = itr->second.pra_price;
|
||||
uint32_t const durationUnit = cfg->Duration.find(durationId)->second.pun_duration;
|
||||
int const payment_unit_id = itr->second.pra_payment_unit_id;
|
||||
int const pra_price = cfg->PaymentRate.find(payment_unit_id)->second.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;
|
||||
}
|
||||
if (pra_price < price) {
|
||||
duration = durationUnit;
|
||||
}
|
||||
}
|
||||
|
||||
return duration;
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user