Add helper functions GetTimeSteps() and GetPriceForTimeSteps().

This commit is contained in:
Gerhard Hoffmann 2023-10-11 15:40:13 +02:00
parent 4925870227
commit 7508cb6c45

View File

@ -541,3 +541,38 @@ double Calculator::GetCostFromDuration(Configuration* cfg, uint8_t payment_optio
total_cost = 0.0f; total_cost = 0.0f;
return ceil(ret_val); return ceil(ret_val);
} }
QList<int> Calculator::GetTimeSteps(Configuration const *cfg, int paymentOption) {
QList<int> timeSteps;
int const pop_id = cfg->PaymentOption.find(paymentOption)->second.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 durationUnit = cfg->Duration.find(durationId)->second.pun_duration;
timeSteps << durationUnit;
}
return timeSteps;
}
double Calculator::GetPriceForTimeStep(Configuration const *cfg, int paymentOption, int timeStep) {
int const pop_id = cfg->PaymentOption.find(paymentOption)->second.pop_id;
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 pun_id = cfg->Duration.find(payment_unit_id)->second.pun_id;
Q_ASSERT(pun_id == payment_unit_id);
int const pun_duration = cfg->Duration.find(payment_unit_id)->second.pun_duration;
if (timeStep == pun_duration) {
return itr->second.pra_price;
}
}
return 0.0;
}