Compare commits
	
		
			12 Commits
		
	
	
		
			schoenau
			...
			schoenau_2
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 0217bb8918 | |||
| 4b35b1ffb7 | |||
| 80e228b498 | |||
| 574161ff76 | |||
| b80cd5e6ef | |||
| 
						
						
							
						
						3a2e521345
	
				 | 
					
					
						|||
| 
						
						
							
						
						cd77e380ef
	
				 | 
					
					
						|||
| 
						
						
							
						
						aaa4348a9a
	
				 | 
					
					
						|||
| 
						
						
							
						
						17c4aac452
	
				 | 
					
					
						|||
| 
						
						
							
						
						68c438bfe0
	
				 | 
					
					
						|||
| 
						
						
							
						
						509bc29d7e
	
				 | 
					
					
						|||
| 
						
						
							
						
						f7e462188f
	
				 | 
					
					
						
							
								
								
									
										13
									
								
								library/include/mobilisis/atb_project.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										13
									
								
								library/include/mobilisis/atb_project.h
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,13 @@
 | 
				
			|||||||
 | 
					#ifndef ATB_PROJECT_H_INCLUDED
 | 
				
			||||||
 | 
					#define ATB_PROJECT_H_INCLUDED
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <QString>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class ATBProject {
 | 
				
			||||||
 | 
					  public:
 | 
				
			||||||
 | 
					    QString project;
 | 
				
			||||||
 | 
					    QString version;
 | 
				
			||||||
 | 
					    QString info;
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#endif // ATB_PROJECT_H_INCLUDED
 | 
				
			||||||
@@ -1,6 +1,7 @@
 | 
				
			|||||||
#pragma once
 | 
					#pragma once
 | 
				
			||||||
#include <iostream>
 | 
					#include <iostream>
 | 
				
			||||||
#include "configuration.h"
 | 
					#include "configuration.h"
 | 
				
			||||||
 | 
					#include "payment_method.h"
 | 
				
			||||||
#include <QDateTime>
 | 
					#include <QDateTime>
 | 
				
			||||||
using namespace std;
 | 
					using namespace std;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -30,4 +31,21 @@ public:
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    // Daily ticket
 | 
					    // Daily ticket
 | 
				
			||||||
    QDateTime GetDailyTicketDuration(Configuration* cfg, const QDateTime start_datetime, uint8_t payment_option, bool carry_over);
 | 
					    QDateTime GetDailyTicketDuration(Configuration* cfg, const QDateTime start_datetime, uint8_t payment_option, bool carry_over);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    //
 | 
				
			||||||
 | 
					    // helper function to find time steps for a tariff with PaymentMethod::Steps
 | 
				
			||||||
 | 
					    // (e.g. Schoenau/Koenigsee)
 | 
				
			||||||
 | 
					    //
 | 
				
			||||||
 | 
					    QList<int> GetTimeSteps(Configuration *cfg) const;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					private:
 | 
				
			||||||
 | 
					    // Introduced for PaymentMethod::Steps (e.g. Schoenau)
 | 
				
			||||||
 | 
					    // 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;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -20,6 +20,7 @@
 | 
				
			|||||||
#include "member_type.h"
 | 
					#include "member_type.h"
 | 
				
			||||||
#include "period_year.h"
 | 
					#include "period_year.h"
 | 
				
			||||||
#include "payment_rate.h"
 | 
					#include "payment_rate.h"
 | 
				
			||||||
 | 
					#include "atb_project.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
using namespace std;
 | 
					using namespace std;
 | 
				
			||||||
using namespace rapidjson;
 | 
					using namespace rapidjson;
 | 
				
			||||||
@@ -27,8 +28,8 @@ using namespace rapidjson;
 | 
				
			|||||||
class Configuration
 | 
					class Configuration
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
public:
 | 
					public:
 | 
				
			||||||
 | 
					    ATBProject project;
 | 
				
			||||||
	ATBCurrency Currency;
 | 
					    ATBCurrency Currency;
 | 
				
			||||||
	ATBDuration duration;
 | 
						ATBDuration duration;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	multimap<int, ATBDuration> Duration;
 | 
						multimap<int, ATBDuration> Duration;
 | 
				
			||||||
@@ -48,6 +49,8 @@ public:
 | 
				
			|||||||
	/// <returns>Returns operation status bool (OK | FAIL) </returns>
 | 
						/// <returns>Returns operation status bool (OK | FAIL) </returns>
 | 
				
			||||||
	bool ParseJson(Configuration* cfg, const char* json);
 | 
						bool ParseJson(Configuration* cfg, const char* json);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    ATBPaymentOption const & getPaymentOptions();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
private:
 | 
					private:
 | 
				
			||||||
	/// <summary>
 | 
						/// <summary>
 | 
				
			||||||
	/// Identify type of JSON member
 | 
						/// Identify type of JSON member
 | 
				
			||||||
@@ -55,4 +58,6 @@ private:
 | 
				
			|||||||
	/// <param name="member_name"></param>
 | 
						/// <param name="member_name"></param>
 | 
				
			||||||
	/// <returns></returns>
 | 
						/// <returns></returns>
 | 
				
			||||||
	MemberType IdentifyJsonMember(const char* member_name);
 | 
						MemberType IdentifyJsonMember(const char* member_name);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    ATBPaymentOption currentPaymentOptions;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -65,7 +65,8 @@ HEADERS += \
 | 
				
			|||||||
    include/mobilisis/tariff_period_year.h \
 | 
					    include/mobilisis/tariff_period_year.h \
 | 
				
			||||||
    include/mobilisis/tariff_payment_rate.h \
 | 
					    include/mobilisis/tariff_payment_rate.h \
 | 
				
			||||||
    include/mobilisis/tariff_log.h \
 | 
					    include/mobilisis/tariff_log.h \
 | 
				
			||||||
    include/mobilisis/calculate_price.h
 | 
					    include/mobilisis/calculate_price.h \
 | 
				
			||||||
 | 
					    include/mobilisis/atb_project.h
 | 
				
			||||||
 | 
					
 | 
				
			||||||
OTHER_FILES += src/main.cpp
 | 
					OTHER_FILES += src/main.cpp
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -100,8 +100,8 @@ CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket(
 | 
				
			|||||||
        time_t end_parking_time,   // netto time in minutes
 | 
					        time_t end_parking_time,   // netto time in minutes
 | 
				
			||||||
        struct price_t *price) {
 | 
					        struct price_t *price) {
 | 
				
			||||||
    CalcState calcState;
 | 
					    CalcState calcState;
 | 
				
			||||||
    double minMin = tariff->PaymentOption.find(PaymentOption::Option1)->second.pop_min_time;
 | 
					    double minMin = tariff->PaymentOption.find(tariff->getPaymentOptions().pop_payment_method_id)->second.pop_min_time;
 | 
				
			||||||
    double maxMin = tariff->PaymentOption.find(PaymentOption::Option1)->second.pop_max_time;
 | 
					    double maxMin = tariff->PaymentOption.find(tariff->getPaymentOptions().pop_payment_method_id)->second.pop_max_time;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (minMin < 0 || maxMin < 0 || maxMin < minMin) {
 | 
					    if (minMin < 0 || maxMin < 0 || maxMin < minMin) {
 | 
				
			||||||
        calcState.setDesc(QString("minMin=%1, maxMin=%2").arg(minMin).arg(maxMin));
 | 
					        calcState.setDesc(QString("minMin=%1, maxMin=%2").arg(minMin).arg(maxMin));
 | 
				
			||||||
@@ -134,11 +134,12 @@ CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket(
 | 
				
			|||||||
    QDateTime end(start);
 | 
					    QDateTime end(start);
 | 
				
			||||||
    if (start.isValid()) {
 | 
					    if (start.isValid()) {
 | 
				
			||||||
        double cost = calculator.GetCostFromDuration(
 | 
					        double cost = calculator.GetCostFromDuration(
 | 
				
			||||||
                    tariff, PaymentOption::Option1,
 | 
					                    tariff,
 | 
				
			||||||
 | 
					                    tariff->getPaymentOptions().pop_payment_method_id,
 | 
				
			||||||
                    start,
 | 
					                    start,
 | 
				
			||||||
                    end,
 | 
					                    end,
 | 
				
			||||||
                    duration, false, true);
 | 
					                    duration, false, true);
 | 
				
			||||||
        double minCost = tariff->PaymentOption.find(PaymentOption::Option1)->second.pop_min_price;
 | 
					        double minCost = tariff->PaymentOption.find(tariff->getPaymentOptions().pop_payment_method_id)->second.pop_min_price;
 | 
				
			||||||
        if (cost < minCost) {
 | 
					        if (cost < minCost) {
 | 
				
			||||||
            calcState.setDesc(QString("minCost=%1, cost=%2").arg(minCost).arg(cost));
 | 
					            calcState.setDesc(QString("minCost=%1, cost=%2").arg(minCost).arg(cost));
 | 
				
			||||||
            return calcState.set(CalcState::State::BELOW_MIN_PARKING_PRICE);
 | 
					            return calcState.set(CalcState::State::BELOW_MIN_PARKING_PRICE);
 | 
				
			||||||
@@ -160,8 +161,8 @@ CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket(
 | 
				
			|||||||
        struct price_t *price)
 | 
					        struct price_t *price)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    CalcState calcState;
 | 
					    CalcState calcState;
 | 
				
			||||||
    double minMin = tariff->PaymentOption.find(PaymentOption::Option1)->second.pop_min_time;
 | 
					    double minMin = tariff->getPaymentOptions().pop_min_time;
 | 
				
			||||||
    double maxMin = tariff->PaymentOption.find(PaymentOption::Option1)->second.pop_max_time;
 | 
					    double maxMin = tariff->getPaymentOptions().pop_max_time;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // DEBUG
 | 
					    // DEBUG
 | 
				
			||||||
    qCritical() << "compute_price_for_parking_ticket() " << endl
 | 
					    qCritical() << "compute_price_for_parking_ticket() " << endl
 | 
				
			||||||
@@ -192,12 +193,13 @@ CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket(
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    if (start_parking_time.isValid()) {
 | 
					    if (start_parking_time.isValid()) {
 | 
				
			||||||
        double cost = calculator.GetCostFromDuration(
 | 
					        double cost = calculator.GetCostFromDuration(
 | 
				
			||||||
                        tariff, PaymentOption::Option1,
 | 
					                        tariff,
 | 
				
			||||||
 | 
					                        tariff->getPaymentOptions().pop_payment_method_id,
 | 
				
			||||||
                        start_parking_time,         // starting time
 | 
					                        start_parking_time,         // starting time
 | 
				
			||||||
                        end_parking_time,           // return value: end time
 | 
					                        end_parking_time,           // return value: end time
 | 
				
			||||||
                        netto_parking_time,         // minutes, netto
 | 
					                        netto_parking_time,         // minutes, netto
 | 
				
			||||||
                        false, true);
 | 
					                        false, true);
 | 
				
			||||||
        double minCost = tariff->PaymentOption.find(PaymentOption::Option1)->second.pop_min_price;
 | 
					        double minCost = tariff->getPaymentOptions().pop_min_price;
 | 
				
			||||||
        if (cost < minCost) {
 | 
					        if (cost < minCost) {
 | 
				
			||||||
            calcState.setDesc(QString("minCost=%1, cost=%2").arg(minCost, cost));
 | 
					            calcState.setDesc(QString("minCost=%1, cost=%2").arg(minCost, cost));
 | 
				
			||||||
            return calcState.set(CalcState::State::BELOW_MIN_PARKING_PRICE);
 | 
					            return calcState.set(CalcState::State::BELOW_MIN_PARKING_PRICE);
 | 
				
			||||||
@@ -233,7 +235,8 @@ CalcState CALCULATE_LIBRARY_API compute_duration_for_parking_ticket(
 | 
				
			|||||||
        qCritical() << "      start (cs): " << cs;
 | 
					        qCritical() << "      start (cs): " << cs;
 | 
				
			||||||
        qCritical() << "           price: " << price;
 | 
					        qCritical() << "           price: " << price;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        duration = calculator.GetDurationFromCost(tariff, PaymentOption::Option1,
 | 
					        duration = calculator.GetDurationFromCost(tariff,
 | 
				
			||||||
 | 
					                                                  tariff->getPaymentOptions().pop_payment_method_id,
 | 
				
			||||||
                                                  cs.toLocal8Bit().constData(),
 | 
					                                                  cs.toLocal8Bit().constData(),
 | 
				
			||||||
                                                  price, false, true).c_str();
 | 
					                                                  price, false, true).c_str();
 | 
				
			||||||
        QDateTime d = QDateTime::fromString(duration, Qt::ISODate);
 | 
					        QDateTime d = QDateTime::fromString(duration, Qt::ISODate);
 | 
				
			||||||
@@ -258,7 +261,8 @@ CalcState CALCULATE_LIBRARY_API compute_duration_for_parking_ticket(
 | 
				
			|||||||
    if (start_parking_time.isValid()) {
 | 
					    if (start_parking_time.isValid()) {
 | 
				
			||||||
        QString cs = start_parking_time.toString(Qt::ISODate);
 | 
					        QString cs = start_parking_time.toString(Qt::ISODate);
 | 
				
			||||||
        QString endTime = calculator.GetDurationFromCost(
 | 
					        QString endTime = calculator.GetDurationFromCost(
 | 
				
			||||||
                    tariff, PaymentOption::Option1,
 | 
					                    tariff,
 | 
				
			||||||
 | 
					                    tariff->getPaymentOptions().pop_payment_method_id,
 | 
				
			||||||
                    cs.toLocal8Bit().constData(),
 | 
					                    cs.toLocal8Bit().constData(),
 | 
				
			||||||
                    price, false, true).c_str();
 | 
					                    price, false, true).c_str();
 | 
				
			||||||
        ticketEndTime = QDateTime::fromString(endTime,Qt::ISODate);
 | 
					        ticketEndTime = QDateTime::fromString(endTime,Qt::ISODate);
 | 
				
			||||||
@@ -286,7 +290,7 @@ CalcState CALCULATE_LIBRARY_API compute_duration_for_daily_ticket(parking_tariff
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        ticketEndTime = calculator.GetDailyTicketDuration(tariff,
 | 
					        ticketEndTime = calculator.GetDailyTicketDuration(tariff,
 | 
				
			||||||
                                                            start_parking_time,
 | 
					                                                            start_parking_time,
 | 
				
			||||||
                                                            PaymentOption::Option1,
 | 
					                                                            tariff->getPaymentOptions().pop_payment_method_id,
 | 
				
			||||||
                                                            false);    // carry over
 | 
					                                                            false);    // carry over
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // DEBUG
 | 
					        // DEBUG
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,5 +1,5 @@
 | 
				
			|||||||
#include "calculator_functions.h"
 | 
					#include "calculator_functions.h"
 | 
				
			||||||
#include "payment_method.h"
 | 
					#include "payment_option.h"
 | 
				
			||||||
#include "utilities.h"
 | 
					#include "utilities.h"
 | 
				
			||||||
#include "tariff_log.h"
 | 
					#include "tariff_log.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -118,6 +118,15 @@ std::string Calculator::GetDurationFromCost(Configuration* cfg,
 | 
				
			|||||||
                                            bool nextDay,
 | 
					                                            bool nextDay,
 | 
				
			||||||
                                            bool prepaid)
 | 
					                                            bool prepaid)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 | 
					    // 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)
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        return QString().setNum(GetDurationForPrice(cfg, price)).toStdString();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Get input date
 | 
					    // Get input date
 | 
				
			||||||
    QDateTime inputDate = QDateTime::fromString(start_datetime,Qt::ISODate);
 | 
					    QDateTime inputDate = QDateTime::fromString(start_datetime,Qt::ISODate);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -336,11 +345,53 @@ std::string Calculator::GetDurationFromCost(Configuration* cfg,
 | 
				
			|||||||
    return inputDate.toString(Qt::ISODate).toStdString();
 | 
					    return inputDate.toString(Qt::ISODate).toStdString();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					///////////////////////////////////////
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/// <inheritdoc/>
 | 
				
			||||||
 | 
					///
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					uint32_t Calculator::GetCostFromDuration(Configuration *cfg,
 | 
				
			||||||
 | 
					                                         QDateTime const &start,
 | 
				
			||||||
 | 
					                                         quint64 timeStepInMinutes) const {
 | 
				
			||||||
 | 
					    // for instance, a tariff as used in Schoenau, Koenigssee: only steps, no
 | 
				
			||||||
 | 
					    // special days, nonstop.
 | 
				
			||||||
 | 
					    if (cfg->YearPeriod.size() == 0
 | 
				
			||||||
 | 
					     && cfg->SpecialDays.size() == 0
 | 
				
			||||||
 | 
					     && cfg->SpecialDaysWorktime.size() == 0) {
 | 
				
			||||||
 | 
					        QDateTime const end = start.addSecs(timeStepInMinutes*60);
 | 
				
			||||||
 | 
					        return GetCostFromDuration(cfg, start, end);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    return 0;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					uint32_t Calculator::GetCostFromDuration(Configuration * cfg,
 | 
				
			||||||
 | 
					                                         QDateTime const &start,
 | 
				
			||||||
 | 
					                                         QDateTime const &end) const {
 | 
				
			||||||
 | 
					    if (cfg->YearPeriod.size() == 0
 | 
				
			||||||
 | 
					     && cfg->SpecialDays.size() == 0
 | 
				
			||||||
 | 
					     && cfg->SpecialDaysWorktime.size() == 0) {
 | 
				
			||||||
 | 
					        int const timeStepInMinutes = start.secsTo(end) / 60;
 | 
				
			||||||
 | 
					        return GetPriceForTimeStep(cfg, timeStepInMinutes);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    return 0;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
///////////////////////////////////////
 | 
					///////////////////////////////////////
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/// <inheritdoc/>
 | 
					/// <inheritdoc/>
 | 
				
			||||||
double Calculator::GetCostFromDuration(Configuration* cfg, uint8_t payment_option, const QDateTime start_datetime, QDateTime & end_datetime,  double durationMin, bool nextDay, bool prepaid)
 | 
					double Calculator::GetCostFromDuration(Configuration* cfg, uint8_t payment_option, const QDateTime start_datetime, QDateTime & end_datetime,  double durationMin, bool nextDay, bool prepaid)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 | 
					    if (cfg->YearPeriod.size() == 0
 | 
				
			||||||
 | 
					        && cfg->SpecialDays.size() == 0
 | 
				
			||||||
 | 
					        && cfg->SpecialDaysWorktime.size() == 0)
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        end_datetime = start_datetime.addSecs(durationMin*60);
 | 
				
			||||||
 | 
					        return GetCostFromDuration(cfg, start_datetime, end_datetime);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Get input date
 | 
					    // Get input date
 | 
				
			||||||
    QDateTime inputDate = start_datetime;
 | 
					    QDateTime inputDate = start_datetime;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -541,3 +592,58 @@ 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 *cfg) const {
 | 
				
			||||||
 | 
					    QList<int> timeSteps;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    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 durationUnit = cfg->Duration.find(durationId)->second.pun_duration;
 | 
				
			||||||
 | 
					        timeSteps << durationUnit;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return timeSteps;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					uint32_t Calculator::GetPriceForTimeStep(Configuration *cfg, int timeStep) 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 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 (uint32_t)(itr->second.pra_price);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    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;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -59,8 +59,9 @@ bool Configuration::ParseJson(Configuration* cfg, const char* json)
 | 
				
			|||||||
			|| !document.HasMember("PaymentRate")
 | 
								|| !document.HasMember("PaymentRate")
 | 
				
			||||||
			|| !document.HasMember("Duration")
 | 
								|| !document.HasMember("Duration")
 | 
				
			||||||
			//|| !document.HasMember("WeekDays")
 | 
								//|| !document.HasMember("WeekDays")
 | 
				
			||||||
			|| !document.HasMember("SpecialDaysWorktime")
 | 
					            //|| !document.HasMember("SpecialDaysWorktime")
 | 
				
			||||||
			|| !document.HasMember("SpecialDays"))
 | 
					            //|| !document.HasMember("SpecialDays")
 | 
				
			||||||
 | 
					            )
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			printf("%s", "Error: not a valid configuration JSON\n");
 | 
								printf("%s", "Error: not a valid configuration JSON\n");
 | 
				
			||||||
			return false;
 | 
								return false;
 | 
				
			||||||
@@ -87,13 +88,26 @@ bool Configuration::ParseJson(Configuration* cfg, const char* json)
 | 
				
			|||||||
			const char* mb_name = i->name.GetString();
 | 
								const char* mb_name = i->name.GetString();
 | 
				
			||||||
            if (mb_name == NULL) continue;
 | 
					            if (mb_name == NULL) continue;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            // if (!document[mb_name].IsArray()) {
 | 
					            if (document[mb_name].IsString()) {
 | 
				
			||||||
                std::string const _mb_name(mb_name);
 | 
					                QString const _mb_name(mb_name);
 | 
				
			||||||
                if (_mb_name == "version" || _mb_name == "project" ||
 | 
					                if (_mb_name.startsWith("Project", Qt::CaseInsensitive)) {
 | 
				
			||||||
                    _mb_name == "zone" || _mb_name == "info") {
 | 
					                    cfg->project.project = document[mb_name].GetString();
 | 
				
			||||||
 | 
					                    continue;
 | 
				
			||||||
 | 
					                 }
 | 
				
			||||||
 | 
					                if (_mb_name.startsWith("Version", Qt::CaseInsensitive)) {
 | 
				
			||||||
 | 
					                    cfg->project.version = document[mb_name].GetString();
 | 
				
			||||||
                    continue;
 | 
					                    continue;
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
            // }
 | 
					                if (_mb_name.startsWith("Info", Qt::CaseInsensitive)) {
 | 
				
			||||||
 | 
					                    cfg->project.info = document[mb_name].GetString();
 | 
				
			||||||
 | 
					                    continue;
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            // ... everything else should be an array
 | 
				
			||||||
 | 
					            if (!document[mb_name].IsArray()) {
 | 
				
			||||||
 | 
					                continue;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			//printf(" -%s\n", mb_name);
 | 
								//printf(" -%s\n", mb_name);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -155,7 +169,8 @@ bool Configuration::ParseJson(Configuration* cfg, const char* json)
 | 
				
			|||||||
						else if (strcmp(inner_obj_name, "pop_min_price") == 0) PaymentOption.pop_min_price = k->value.GetDouble();
 | 
											else if (strcmp(inner_obj_name, "pop_min_price") == 0) PaymentOption.pop_min_price = k->value.GetDouble();
 | 
				
			||||||
						else if (strcmp(inner_obj_name, "pop_carry_over") == 0) PaymentOption.pop_carry_over = k->value.GetInt();
 | 
											else if (strcmp(inner_obj_name, "pop_carry_over") == 0) PaymentOption.pop_carry_over = k->value.GetInt();
 | 
				
			||||||
                        else if (strcmp(inner_obj_name, "pop_daily_card_price") == 0) PaymentOption.pop_daily_card_price = k->value.GetInt();
 | 
					                        else if (strcmp(inner_obj_name, "pop_daily_card_price") == 0) PaymentOption.pop_daily_card_price = k->value.GetInt();
 | 
				
			||||||
						break;
 | 
					                        this->currentPaymentOptions = PaymentOption;
 | 
				
			||||||
 | 
					                        break;
 | 
				
			||||||
					case MemberType::DurationType:
 | 
										case MemberType::DurationType:
 | 
				
			||||||
						if (strcmp(inner_obj_name, "pun_id") == 0) Duration.pun_id = k->value.GetInt();
 | 
											if (strcmp(inner_obj_name, "pun_id") == 0) Duration.pun_id = k->value.GetInt();
 | 
				
			||||||
						else if (strcmp(inner_obj_name, "pun_label") == 0) Duration.pun_label = k->value.GetString();
 | 
											else if (strcmp(inner_obj_name, "pun_label") == 0) Duration.pun_label = k->value.GetString();
 | 
				
			||||||
@@ -245,3 +260,10 @@ bool Configuration::ParseJson(Configuration* cfg, const char* json)
 | 
				
			|||||||
		return false;
 | 
							return false;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const ATBPaymentOption & Configuration::getPaymentOptions()
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    return this->currentPaymentOptions;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user