Mainly removed debug output. Regression tests with szeged looking good.
This commit is contained in:
		@@ -140,7 +140,7 @@ std::string Calculator::GetDurationFromCost(Configuration* cfg,
 | 
			
		||||
 | 
			
		||||
    Ticket t = private_GetDurationFromCost(cfg, inputDate, price, prepaid);
 | 
			
		||||
 | 
			
		||||
    qCritical().noquote() << t;
 | 
			
		||||
    // qCritical().noquote() << t;
 | 
			
		||||
 | 
			
		||||
    // TODO: im fehlerfall
 | 
			
		||||
    return t.getValidUntil().toString(Qt::ISODate).toStdString();
 | 
			
		||||
@@ -207,7 +207,7 @@ double Calculator::GetCostFromDuration(Configuration* cfg,
 | 
			
		||||
                                           durationMinutes,
 | 
			
		||||
                                           prepaid);
 | 
			
		||||
    if (t) {
 | 
			
		||||
        qCritical().noquote() << t;
 | 
			
		||||
        // qCritical().noquote() << t;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    end_datetime = t.getValidUntil();
 | 
			
		||||
@@ -324,8 +324,6 @@ Ticket Calculator::private_GetCostFromDuration(Configuration const* cfg,
 | 
			
		||||
    for (current = start; durationMinutes > 0; current = current.addDays(1)) {
 | 
			
		||||
        int const weekdayId = current.date().dayOfWeek();
 | 
			
		||||
 | 
			
		||||
        qCritical() << "current" << current.toString(Qt::ISODate) << weekdayId;
 | 
			
		||||
 | 
			
		||||
        specialDayId = -1;
 | 
			
		||||
 | 
			
		||||
        // find worktime ranges for the current day
 | 
			
		||||
@@ -367,28 +365,27 @@ Ticket Calculator::private_GetCostFromDuration(Configuration const* cfg,
 | 
			
		||||
        QTime const &lastWorktimeTo = worktime[ranges-1].getTimeUntil();
 | 
			
		||||
 | 
			
		||||
        // find worktime range to start with
 | 
			
		||||
 | 
			
		||||
        int currentRange = 0;
 | 
			
		||||
        if (!isSpecialDay) {
 | 
			
		||||
            if (start != current) { // on next day
 | 
			
		||||
                current.setTime(worktime[currentRange].getTimeFrom());
 | 
			
		||||
            } else {
 | 
			
		||||
                // check if inputDate is located inside a valid worktime-range...
 | 
			
		||||
                currentRange = findWorkTimeRange(current, worktime, ranges);
 | 
			
		||||
                if (currentRange == -1) { // no...
 | 
			
		||||
                    if (!prepaid) {       // parking is not allowed
 | 
			
		||||
                if ((currentRange = findWorkTimeRange(current, worktime, ranges)) == -1) {
 | 
			
		||||
                    if (!prepaid && carryOverNotSet) {       // parking is not allowed
 | 
			
		||||
                        return Ticket(start, QDateTime(), durationMinutesNetto, 0,
 | 
			
		||||
                                      0, Ticket::s[INVALID_FROM_DATETIME]);
 | 
			
		||||
                    }
 | 
			
		||||
                    // find the next worktime-range (on the same day), and start from there
 | 
			
		||||
                    currentRange = findNextWorkTimeRange(current, worktime, ranges);
 | 
			
		||||
                    if ((currentRange = findNextWorkTimeRange(current, worktime, ranges)) == -1) {
 | 
			
		||||
                        end = current;
 | 
			
		||||
                        continue;
 | 
			
		||||
                    }
 | 
			
		||||
                    current.setTime(worktime[currentRange].getTimeFrom());
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        qCritical() << "current" << current.toString(Qt::ISODate) << currentRange;
 | 
			
		||||
 | 
			
		||||
        for (int w = currentRange; w < ranges; ++w, ++totalTimeRanges) {
 | 
			
		||||
            if (durationMinutes > 0) {
 | 
			
		||||
                QTime const &worktime_from = worktime[w].getTimeFrom();
 | 
			
		||||
@@ -400,13 +397,7 @@ Ticket Calculator::private_GetCostFromDuration(Configuration const* cfg,
 | 
			
		||||
                    current.setTime(worktime_from);
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                qCritical() << "worktime_from" << worktime_from;
 | 
			
		||||
                qCritical() << "worktime_to" << worktime_to;
 | 
			
		||||
                qCritical() << "current" << current.toString(Qt::ISODate);
 | 
			
		||||
 | 
			
		||||
                if (price == 0) {
 | 
			
		||||
                    // inputDate = inputDate.addDays(1);
 | 
			
		||||
                    // inputDate.setTime(worktime_from);
 | 
			
		||||
                    end = current;
 | 
			
		||||
                    current.setTime(QTime());
 | 
			
		||||
                    continue;
 | 
			
		||||
@@ -458,7 +449,6 @@ Ticket Calculator::private_GetCostFromDuration(Configuration const* cfg,
 | 
			
		||||
                            durationMinutes -= 1;
 | 
			
		||||
                            //costFromDuration += price_per_unit;
 | 
			
		||||
                            costFromDuration += price;
 | 
			
		||||
        qCritical() << "current" << current.toString(Qt::ISODate) << durationMinutes << costFromDuration;
 | 
			
		||||
                        } else break;
 | 
			
		||||
                    }
 | 
			
		||||
                } // while(durationMinutes > 0) {
 | 
			
		||||
@@ -468,12 +458,9 @@ Ticket Calculator::private_GetCostFromDuration(Configuration const* cfg,
 | 
			
		||||
 | 
			
		||||
    int durationMinutesBrutto =  start.secsTo(end) / 60;
 | 
			
		||||
 | 
			
		||||
    qCritical() << "start" << start.toString(Qt::ISODate) << "end" << end
 | 
			
		||||
                <<  llround(Utilities::CalculatePricePerUnit(costFromDuration, durationUnit));
 | 
			
		||||
 | 
			
		||||
    return
 | 
			
		||||
        Ticket(start, end, durationMinutesNetto, durationMinutesBrutto,
 | 
			
		||||
               llround(Utilities::CalculatePricePerUnit(costFromDuration, durationUnit)),
 | 
			
		||||
               ceil(Utilities::CalculatePricePerUnit(costFromDuration, durationUnit)),
 | 
			
		||||
               Ticket::s[VALID]);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -485,8 +472,6 @@ Ticket Calculator::private_GetDurationFromCost(Configuration *cfg,
 | 
			
		||||
    // Get input date
 | 
			
		||||
    QDateTime current = start;
 | 
			
		||||
 | 
			
		||||
    qCritical() << "current" << current.toString(Qt::ISODate);
 | 
			
		||||
 | 
			
		||||
    // use tariff with structure as for instance Schnau, Koenigsee:
 | 
			
		||||
    // without given YearPeriod, SpecialDays and SpecialDaysWorktime
 | 
			
		||||
    if (cfg->YearPeriod.size() == 0
 | 
			
		||||
@@ -526,22 +511,18 @@ Ticket Calculator::private_GetDurationFromCost(Configuration *cfg,
 | 
			
		||||
        return Ticket();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    qCritical() << "current" << current.toString(Qt::ISODate);
 | 
			
		||||
 | 
			
		||||
    uint32_t durationMinutesNetto = 0;
 | 
			
		||||
    int moneyLeft = cost;
 | 
			
		||||
    uint32_t durationUnit = 1;
 | 
			
		||||
    double moneyLeft = cost;
 | 
			
		||||
    double durationUnit = 1;
 | 
			
		||||
    int specialDayId = -1;
 | 
			
		||||
    bool isSpecialDay = false;
 | 
			
		||||
    QDateTime end = start;
 | 
			
		||||
    int totalTimeRanges = 0;
 | 
			
		||||
    uint32_t price = 0;
 | 
			
		||||
    double price = 0;
 | 
			
		||||
 | 
			
		||||
    for (current = start; moneyLeft > 0; current = current.addDays(1), moneyLeft /= durationUnit) {
 | 
			
		||||
    for (current = start; moneyLeft > 0 && moneyLeft >= price; current = current.addDays(1)) {
 | 
			
		||||
        int const weekdayId = current.date().dayOfWeek();
 | 
			
		||||
 | 
			
		||||
        qCritical() << "current" << current.toString(Qt::ISODate) << weekdayId;
 | 
			
		||||
 | 
			
		||||
        specialDayId = -1;
 | 
			
		||||
 | 
			
		||||
        // find worktime ranges for the current day
 | 
			
		||||
@@ -549,9 +530,12 @@ Ticket Calculator::private_GetDurationFromCost(Configuration *cfg,
 | 
			
		||||
        QScopedArrayPointer<TariffTimeRange> worktime(new TariffTimeRange[timeRanges]);
 | 
			
		||||
        int ranges = 0;
 | 
			
		||||
 | 
			
		||||
        if((isSpecialDay = Utilities::CheckSpecialDay(cfg, current, &specialDayId, &price))) {
 | 
			
		||||
        uint32_t p = 0;
 | 
			
		||||
        if((isSpecialDay = Utilities::CheckSpecialDay(cfg, current, &specialDayId, &p))) {
 | 
			
		||||
            // Set special day price:
 | 
			
		||||
            durationUnit = specialDaysDurationUnit;
 | 
			
		||||
            price = p / durationUnit;
 | 
			
		||||
            price = std::round(price * 1000.0) / 1000.0;
 | 
			
		||||
            worktime[ranges].setTimeRange(SpecialDaysWorkTimeFrom(cfg, specialDayId),
 | 
			
		||||
                                          SpecialDaysWorkTimeUntil(cfg, specialDayId));
 | 
			
		||||
            ranges = 1;
 | 
			
		||||
@@ -561,10 +545,12 @@ Ticket Calculator::private_GetDurationFromCost(Configuration *cfg,
 | 
			
		||||
            // the computation the price is divided by durationUnit.
 | 
			
		||||
            price = weekDaysPrice;
 | 
			
		||||
            durationUnit = weekDaysDurationUnit;
 | 
			
		||||
            price /= durationUnit;
 | 
			
		||||
            price = std::round(price * 1000.0) / 1000.0; // round to 3 decimals
 | 
			
		||||
 | 
			
		||||
            // If no working day found, skip it (epsecially Sundays!)
 | 
			
		||||
            if (cfg->WeekDaysWorktime.count(weekdayId) <= 0) {
 | 
			
		||||
                qDebug() << "No workday found, trying to find next available day";
 | 
			
		||||
         //     qDebug() << "No workday found, trying to find next available day";
 | 
			
		||||
                end = current;
 | 
			
		||||
                current.setTime(QTime()); // start at midnight on the next day
 | 
			
		||||
                continue;
 | 
			
		||||
@@ -580,33 +566,30 @@ Ticket Calculator::private_GetDurationFromCost(Configuration *cfg,
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        moneyLeft *= durationUnit;
 | 
			
		||||
 | 
			
		||||
        QTime const &lastWorktimeTo = worktime[ranges-1].getTimeUntil();
 | 
			
		||||
 | 
			
		||||
        // find worktime range to start with
 | 
			
		||||
 | 
			
		||||
        int currentRange = 0;
 | 
			
		||||
        if (!isSpecialDay) {
 | 
			
		||||
            if (start != current) { // on next day
 | 
			
		||||
                current.setTime(worktime[currentRange].getTimeFrom());
 | 
			
		||||
            } else {
 | 
			
		||||
                // check if inputDate is located inside a valid worktime-range...
 | 
			
		||||
                currentRange = findWorkTimeRange(current, worktime, ranges);
 | 
			
		||||
                if (currentRange == -1) { // no...
 | 
			
		||||
                    if (!prepaid) {       // parking is not allowed
 | 
			
		||||
                if ((currentRange = findWorkTimeRange(current, worktime, ranges)) == -1) {
 | 
			
		||||
                    if (!prepaid && carryOverNotSet) {       // parking is not allowed
 | 
			
		||||
                        return Ticket(start, QDateTime(), durationMinutesNetto, 0,
 | 
			
		||||
                                      0, Ticket::s[INVALID_FROM_DATETIME]);
 | 
			
		||||
                    }
 | 
			
		||||
                    // find the next worktime-range (on the same day), and start from there
 | 
			
		||||
                    currentRange = findNextWorkTimeRange(current, worktime, ranges);
 | 
			
		||||
                    if ((currentRange = findNextWorkTimeRange(current, worktime, ranges)) == -1) {
 | 
			
		||||
                        end = current;
 | 
			
		||||
                        continue;
 | 
			
		||||
                    }
 | 
			
		||||
                    current.setTime(worktime[currentRange].getTimeFrom());
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        qCritical() << "current" << current.toString(Qt::ISODate) << currentRange;
 | 
			
		||||
 | 
			
		||||
        for (int w = currentRange; w < ranges; ++w, ++totalTimeRanges) {
 | 
			
		||||
            if (moneyLeft > 0) {
 | 
			
		||||
                QTime const &worktime_from = worktime[w].getTimeFrom();
 | 
			
		||||
@@ -618,10 +601,6 @@ Ticket Calculator::private_GetDurationFromCost(Configuration *cfg,
 | 
			
		||||
                    current.setTime(worktime_from);
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                qCritical() << "worktime_from" << worktime_from;
 | 
			
		||||
                qCritical() << "worktime_to" << worktime_to;
 | 
			
		||||
                qCritical() << "current" << current.toString(Qt::ISODate);
 | 
			
		||||
 | 
			
		||||
                if (price == 0) {
 | 
			
		||||
                    // inputDate = inputDate.addDays(1);
 | 
			
		||||
                    // inputDate.setTime(worktime_from);
 | 
			
		||||
@@ -655,7 +634,7 @@ Ticket Calculator::private_GetDurationFromCost(Configuration *cfg,
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                while(moneyLeft > 0) {
 | 
			
		||||
                while(moneyLeft >= price) {
 | 
			
		||||
                    // Check for active year period
 | 
			
		||||
                    if (!IsYearPeriodActive(cfg, current)) {
 | 
			
		||||
                        return Ticket();
 | 
			
		||||
@@ -675,13 +654,11 @@ Ticket Calculator::private_GetDurationFromCost(Configuration *cfg,
 | 
			
		||||
                    } else {
 | 
			
		||||
                        if(current.time() < worktime_to) {
 | 
			
		||||
                            // Increment input date minutes for each monetary unit
 | 
			
		||||
                            durationMinutesNetto +=1;
 | 
			
		||||
                            moneyLeft -= price;
 | 
			
		||||
                            moneyLeft = std::round(moneyLeft * 1000.0) / 1000.0;
 | 
			
		||||
                            current = current.addSecs(60);
 | 
			
		||||
                            end = current;
 | 
			
		||||
                            if(price > 0) {
 | 
			
		||||
                                durationMinutesNetto +=1;
 | 
			
		||||
                            }
 | 
			
		||||
                            moneyLeft -= price;
 | 
			
		||||
        qCritical() << "current" << current.toString(Qt::ISODate) << "moneyLeft" << moneyLeft;
 | 
			
		||||
                        } else break;
 | 
			
		||||
                    }
 | 
			
		||||
                } // while(durationMinutes > 0) {
 | 
			
		||||
@@ -691,8 +668,8 @@ Ticket Calculator::private_GetDurationFromCost(Configuration *cfg,
 | 
			
		||||
 | 
			
		||||
    int durationMinutesBrutto =  start.secsTo(end) / 60;
 | 
			
		||||
 | 
			
		||||
    qCritical() << "start" << start.toString(Qt::ISODate) << "end"
 | 
			
		||||
                << end.toString(Qt::ISODate) << durationMinutesBrutto;
 | 
			
		||||
    //qCritical() << "start" << start.toString(Qt::ISODate) << "end"
 | 
			
		||||
    //            << end.toString(Qt::ISODate) << durationMinutesBrutto;
 | 
			
		||||
 | 
			
		||||
    return
 | 
			
		||||
        Ticket(start, end, durationMinutesNetto, durationMinutesBrutto,
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user