Implement GetDurationForPrice().

This commit is contained in:
Gerhard Hoffmann 2023-11-23 09:41:02 +01:00
parent 80e228b498
commit 4b35b1ffb7

View File

@ -629,3 +629,21 @@ uint32_t Calculator::GetPriceForTimeStep(Configuration const *cfg, uint8_t payme
return 0; return 0;
} }
uint32_t Calculator::GetDurationForPrice(Configuration *cfg, int price) const {
int const pop_id = cfg->getPaymentOptions().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 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;
}
}
return 0;
}