Extend computation of time steps in GetTimeSteps() for the case

of dynamic time steps (e.g. for Neuhauser, Galtuer (745)).
This commit is contained in:
Gerhard Hoffmann 2024-01-18 14:57:04 +01:00
parent 89e0f2137b
commit 80fa2fe0e2

View File

@ -699,12 +699,69 @@ QList<int> Calculator::GetTimeSteps(Configuration *cfg) const {
QList<int> timeSteps;
int const pop_id = cfg->getPaymentOptions().pop_id;
int const pop_carry_over = cfg->getPaymentOptions().pop_carry_over;
int const pop_time_step_config = cfg->getPaymentOptions().pop_time_step_config;
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;
if (pop_time_step_config == (int)ATBTimeStepConfig::TimeStepConfig::DYNAMIC) {
if (pop_carry_over) {
int const pop_carry_over_time_range_id = cfg->getPaymentOptions().pop_carry_over_time_range_id;
QTime const carryOverTimeRangeFrom = cfg->TimeRange.find(pop_carry_over_time_range_id)->second.time_range_from;
QTime const carryOverTimeRangeTo = cfg->TimeRange.find(pop_carry_over_time_range_id)->second.time_range_to;
if (carryOverTimeRangeFrom.secsTo(carryOverTimeRangeTo) <= 60) { // carry over time point, usually 00:00:00
if (carryOverTimeRangeFrom == QTime(0, 0, 0)) {
for (auto[itr, rangeEnd] = cfg->PaymentRate.equal_range(pop_id); itr != rangeEnd; ++itr) {
int const durationId = itr->second.pra_payment_unit_id;
auto search = cfg->Duration.find(durationId);
if (search != cfg->Duration.end()) {
ATBDuration duration = search->second;
if (durationId == 1) {
//duration.pun_duration_min = search->second.pun_duration_min;
//duration.pun_duration_max = search->second.pun_duration_max;
QDateTime carryOver = m_start;
carryOver = carryOver.addDays(1);
carryOver.setTime(QTime(0, 0, 0));
int const timeStep = std::ceil(m_start.secsTo(carryOver) / 60.0);
if (timeStep < duration.pun_duration_min || timeStep > duration.pun_duration_max) {
qCritical()
<< QString("ERROR timeStep (%1) < durationMin (%2) || timeStep (%3)) > durationMax (%4)")
.arg(timeStep).arg(duration.pun_duration_min)
.arg(timeStep).arg(duration.pun_duration_max);
break;
}
duration.pun_duration = timeStep;
m_timeStepCompensation = duration.pun_duration_max - duration.pun_duration;
timeSteps << duration.pun_duration;
} else {
duration.pun_duration = duration.pun_duration_max - m_timeStepCompensation;
timeSteps << duration.pun_duration;;
}
cfg->Duration.erase(search);
cfg->Duration.insert(pair<int, ATBDuration>(duration.pun_id, duration));
} else { // if (search != cfg->Duration.end()) {
// TODO
}
}
} else { // if (carryOverTimeRangeFrom == QTime(0, 0, 0)) {
// TODO
}
} else { // if (carryOverTimeRangeFrom == carryOverTimeRangeTo) {
// TODO
}
} else { // if (pop_carry_over) {
// TODO
}
} else {
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;