Compare commits
6 Commits
0.0.2
...
moransBran
Author | SHA1 | Date | |
---|---|---|---|
6ea58be34d | |||
8a7828c1e6 | |||
7bd7f66666 | |||
617eee39ed | |||
6b3c1cbf0c | |||
1142efaec2 |
@@ -132,6 +132,16 @@ CalcState CALCULATE_LIBRARY_API compute_duration_for_parking_ticket(
|
|||||||
QDateTime const &start_parking_time,
|
QDateTime const &start_parking_time,
|
||||||
double cost,
|
double cost,
|
||||||
QDateTime &ticketEndTime);
|
QDateTime &ticketEndTime);
|
||||||
|
|
||||||
|
CalcState CALCULATE_LIBRARY_API compute_duration_for_daily_ticket(
|
||||||
|
parking_tariff_t *tariff,
|
||||||
|
QString const &start_parking_time,
|
||||||
|
uint8_t paymentMethod);
|
||||||
|
|
||||||
|
CalcState CALCULATE_LIBRARY_API compute_duration_for_24hour_daily_ticket(
|
||||||
|
parking_tariff_t *tariff,
|
||||||
|
QString const &start_parking_time,
|
||||||
|
uint8_t paymentMethod);
|
||||||
//#ifdef __cplusplus
|
//#ifdef __cplusplus
|
||||||
//} // extern "C"
|
//} // extern "C"
|
||||||
//#endif
|
//#endif
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include "configuration.h"
|
#include "configuration.h"
|
||||||
|
#include <QDateTime>
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
class Calculator
|
class Calculator
|
||||||
@@ -26,4 +26,10 @@ public:
|
|||||||
/// <param name="durationMin">Duration of parking in minutes</param>
|
/// <param name="durationMin">Duration of parking in minutes</param>
|
||||||
/// <returns>Returns cost (data type: double)</returns>
|
/// <returns>Returns cost (data type: double)</returns>
|
||||||
double GetCostFromDuration(Configuration* cfg, uint8_t vehicle_type, char const* start_datetime, double durationMin, bool nextDay = false, bool prepaid = false);
|
double GetCostFromDuration(Configuration* cfg, uint8_t vehicle_type, char const* start_datetime, double durationMin, bool nextDay = false, bool prepaid = false);
|
||||||
|
|
||||||
|
// Daily ticket
|
||||||
|
QString GetDailyTicketDuration(Configuration* cfg, QString start_datetime, uint8_t payment_option, bool carry_over);
|
||||||
|
|
||||||
|
// 24-hour daily ticket
|
||||||
|
QString Get24HourTicketDuration(Configuration* cfg, QString start_datetime, uint8_t payment_option);
|
||||||
};
|
};
|
@@ -14,4 +14,6 @@ public:
|
|||||||
double pop_max_time;
|
double pop_max_time;
|
||||||
double pop_min_price;
|
double pop_min_price;
|
||||||
int pop_carry_over;
|
int pop_carry_over;
|
||||||
|
int pop_daily_card_price;
|
||||||
|
int pop_multi_hour_price;
|
||||||
};
|
};
|
@@ -68,5 +68,6 @@ public:
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="pra_price"></param>
|
/// <param name="pra_price"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
static double CalculatePricePerUnit(double pra_price);
|
static double CalculatePricePerUnit(double pra_price, double durationUnit = -1);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
@@ -233,7 +233,7 @@ CalcState CALCULATE_LIBRARY_API compute_duration_for_parking_ticket(
|
|||||||
duration = calculator.GetDurationFromCost(tariff, PaymentOption::Option1,
|
duration = calculator.GetDurationFromCost(tariff, PaymentOption::Option1,
|
||||||
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);
|
||||||
if (!d.isValid()) {
|
if (!d.isValid()) {
|
||||||
calcState.setDesc(QString("ticketEndTime=%1").arg(duration));
|
calcState.setDesc(QString("ticketEndTime=%1").arg(duration));
|
||||||
return calcState.set(CalcState::State::WRONG_ISO_TIME_FORMAT);
|
return calcState.set(CalcState::State::WRONG_ISO_TIME_FORMAT);
|
||||||
@@ -274,3 +274,22 @@ CalcState CALCULATE_LIBRARY_API compute_duration_for_parking_ticket(
|
|||||||
|
|
||||||
return calcState.set(CalcState::State::SUCCESS);
|
return calcState.set(CalcState::State::SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CalcState CALCULATE_LIBRARY_API compute_duration_for_daily_ticket(parking_tariff_t *tariff, QString const &start_parking_time,uint8_t paymentMethod)
|
||||||
|
{
|
||||||
|
CalcState calcState;
|
||||||
|
QString result = calculator.GetDailyTicketDuration(tariff, start_parking_time, PaymentOption::Option1,false);
|
||||||
|
qDebug() << "DailyTicket() => " + result;
|
||||||
|
|
||||||
|
return calcState.set(CalcState::State::SUCCESS);
|
||||||
|
}
|
||||||
|
|
||||||
|
CalcState CALCULATE_LIBRARY_API compute_duration_for_24hour_daily_ticket(parking_tariff_t *tariff, QString const &start_parking_time,uint8_t paymentMethod)
|
||||||
|
{
|
||||||
|
CalcState calcState;
|
||||||
|
QString result = calculator.Get24HourTicketDuration(tariff, start_parking_time, PaymentOption::Option1,false);
|
||||||
|
qDebug() << "24HourDailyTicket() => " + result;
|
||||||
|
|
||||||
|
return calcState.set(CalcState::State::SUCCESS);
|
||||||
|
}
|
||||||
|
|
||||||
|
@@ -10,6 +10,7 @@
|
|||||||
double total_duration_min = 0.0f;
|
double total_duration_min = 0.0f;
|
||||||
double total_cost = 0.0f;
|
double total_cost = 0.0f;
|
||||||
bool overtime = false;
|
bool overtime = false;
|
||||||
|
int protection_counter = 0;
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
inline struct tm* localtime_r(const time_t *clock, struct tm* result){
|
inline struct tm* localtime_r(const time_t *clock, struct tm* result){
|
||||||
@@ -19,6 +20,127 @@ inline struct tm* localtime_r(const time_t *clock, struct tm* result){
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
QString Calculator::Get24HourTicketDuration(Configuration *cfg, QString start_datetime, uint8_t payment_option)
|
||||||
|
{
|
||||||
|
if(start_datetime.isNull() || start_datetime.isEmpty()) return "Invalid date-time";
|
||||||
|
protection_counter = 0;
|
||||||
|
|
||||||
|
double day_price = 0.0f;
|
||||||
|
int current_special_day_id = -1;
|
||||||
|
|
||||||
|
QDateTime inputDateTime = QDateTime::fromString(start_datetime, Qt::ISODate);
|
||||||
|
QTime worktime_from;
|
||||||
|
QTime worktime_to;
|
||||||
|
|
||||||
|
int daily_24hour_card_price = cfg->PaymentOption.find(payment_option)->second.pop_multi_hour_price;
|
||||||
|
if(daily_24hour_card_price <= 0) return "24-hour daily ticket: price zero or less";
|
||||||
|
|
||||||
|
bool is_special_day = Utilities::CheckSpecialDay(cfg, start_datetime.toStdString().c_str(), ¤t_special_day_id, &day_price);
|
||||||
|
|
||||||
|
if(is_special_day)
|
||||||
|
{
|
||||||
|
worktime_from = QTime::fromString(cfg->SpecialDaysWorktime.find(current_special_day_id)->second.pedwt_time_from.c_str(), Qt::ISODate);
|
||||||
|
worktime_to = QTime::fromString(cfg->SpecialDaysWorktime.find(current_special_day_id)->second.pedwt_time_to.c_str(),Qt::ISODate);
|
||||||
|
return "24-hour ticket cannot be bought on special day";
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check next special day
|
||||||
|
inputDateTime = inputDateTime.addSecs(86400);
|
||||||
|
while(Utilities::CheckSpecialDay(cfg, inputDateTime.toString(Qt::ISODate).toLocal8Bit(), ¤t_special_day_id, &day_price))
|
||||||
|
{
|
||||||
|
protection_counter++;
|
||||||
|
if(protection_counter >=7) return NULL;
|
||||||
|
inputDateTime = inputDateTime.addSecs(86400);
|
||||||
|
}
|
||||||
|
return inputDateTime.toString(Qt::ISODate) + ", price = " + to_string(daily_24hour_card_price).c_str();
|
||||||
|
}
|
||||||
|
|
||||||
|
QString Calculator::GetDailyTicketDuration(Configuration* cfg, QString start_datetime, uint8_t payment_option, bool carry_over)
|
||||||
|
{
|
||||||
|
if(start_datetime.isNull() || start_datetime.isEmpty()) return NULL;
|
||||||
|
|
||||||
|
double day_price = 0.0f;
|
||||||
|
int current_special_day_id = -1;
|
||||||
|
bool is_special_day = Utilities::CheckSpecialDay(cfg, start_datetime.toStdString().c_str(), ¤t_special_day_id, &day_price);
|
||||||
|
|
||||||
|
QDateTime inputDateTime = QDateTime::fromString(start_datetime, Qt::ISODate);
|
||||||
|
QTime worktime_from;
|
||||||
|
QTime worktime_to;
|
||||||
|
|
||||||
|
int daily_card_price = cfg->PaymentOption.find(payment_option)->second.pop_daily_card_price;
|
||||||
|
if(daily_card_price <= 0) return "Daily ticket price zero or less";
|
||||||
|
|
||||||
|
if(is_special_day)
|
||||||
|
{
|
||||||
|
worktime_from = QTime::fromString(cfg->SpecialDaysWorktime.find(current_special_day_id)->second.pedwt_time_from.c_str(), Qt::ISODate);
|
||||||
|
worktime_to = QTime::fromString(cfg->SpecialDaysWorktime.find(current_special_day_id)->second.pedwt_time_to.c_str(),Qt::ISODate);
|
||||||
|
|
||||||
|
if(inputDateTime.time() < worktime_from) inputDateTime.setTime(worktime_from);
|
||||||
|
if(carry_over) inputDateTime.setTime(worktime_from);
|
||||||
|
|
||||||
|
if(inputDateTime.time() >= worktime_to)
|
||||||
|
{
|
||||||
|
// Go to next day if outside worktime
|
||||||
|
inputDateTime = inputDateTime.addSecs(86400);
|
||||||
|
return GetDailyTicketDuration(cfg,inputDateTime.toString(Qt::ISODate), payment_option,true);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(day_price <=0)
|
||||||
|
{
|
||||||
|
// Go to next day if special day price is 0
|
||||||
|
inputDateTime = inputDateTime.addSecs(86400);
|
||||||
|
return GetDailyTicketDuration(cfg,inputDateTime.toString(Qt::ISODate), payment_option,true);
|
||||||
|
}
|
||||||
|
|
||||||
|
int diff = abs(inputDateTime.time().secsTo(worktime_to));
|
||||||
|
inputDateTime = inputDateTime.addSecs(diff);
|
||||||
|
|
||||||
|
//qDebug() << "Ticket is valid until: " << inputDateTime.toString(Qt::ISODate) << "price = " << daily_card_price << ", duration = " << diff / 60;
|
||||||
|
return inputDateTime.toString(Qt::ISODate) + ", price = " + to_string(daily_card_price).c_str() + ", duration = " + to_string((diff/60)).c_str();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Get day of week
|
||||||
|
int weekdayId = 0;
|
||||||
|
weekdayId = Utilities::ZellersAlgorithm(inputDateTime.date().day(),inputDateTime.date().month(),inputDateTime.date().year());
|
||||||
|
|
||||||
|
// If no working day found, skip it (recursively call method again)
|
||||||
|
size_t found = 0;
|
||||||
|
found = cfg->WeekDaysWorktime.count(weekdayId);
|
||||||
|
|
||||||
|
// When no workday found, go to next available day
|
||||||
|
if(found <=0)
|
||||||
|
{
|
||||||
|
inputDateTime = inputDateTime.addSecs(86400);
|
||||||
|
return GetDailyTicketDuration(cfg,inputDateTime.toString(Qt::ISODate), payment_option,true);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
worktime_from = QTime::fromString(cfg->WeekDaysWorktime.find(weekdayId)->second.pwd_time_from.c_str(),Qt::ISODate);
|
||||||
|
worktime_to = QTime::fromString(cfg->WeekDaysWorktime.find(weekdayId)->second.pwd_time_to.c_str(),Qt::ISODate);
|
||||||
|
if(inputDateTime.time() < worktime_from)
|
||||||
|
inputDateTime.setTime(worktime_from);
|
||||||
|
|
||||||
|
if(carry_over)
|
||||||
|
inputDateTime.setTime(worktime_from);
|
||||||
|
|
||||||
|
if(inputDateTime.time() >= worktime_to)
|
||||||
|
{
|
||||||
|
// Go to next day if outside worktime
|
||||||
|
inputDateTime = inputDateTime.addSecs(86400);
|
||||||
|
return GetDailyTicketDuration(cfg,inputDateTime.toString(Qt::ISODate), payment_option,true);
|
||||||
|
}
|
||||||
|
|
||||||
|
int diff = abs(inputDateTime.time().secsTo(worktime_to));
|
||||||
|
inputDateTime = inputDateTime.addSecs(diff);
|
||||||
|
|
||||||
|
//qDebug() << "Ticket is valid until: " << inputDateTime.toString(Qt::ISODate) << "price = " << daily_card_price << ", duration = " << diff / 60;
|
||||||
|
return inputDateTime.toString(Qt::ISODate) + ", price = " + to_string(daily_card_price).c_str() + ", duration = " + to_string((diff/60)).c_str();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
std::string Calculator::GetDurationFromCost(Configuration* cfg,
|
std::string Calculator::GetDurationFromCost(Configuration* cfg,
|
||||||
uint8_t payment_option,
|
uint8_t payment_option,
|
||||||
@@ -27,6 +149,7 @@ std::string Calculator::GetDurationFromCost(Configuration* cfg,
|
|||||||
bool nextDay,
|
bool nextDay,
|
||||||
bool prepaid)
|
bool prepaid)
|
||||||
{
|
{
|
||||||
|
|
||||||
// Get input date
|
// Get input date
|
||||||
QDateTime inputDate = QDateTime::fromString(start_datetime,Qt::ISODate);
|
QDateTime inputDate = QDateTime::fromString(start_datetime,Qt::ISODate);
|
||||||
|
|
||||||
@@ -43,6 +166,7 @@ std::string Calculator::GetDurationFromCost(Configuration* cfg,
|
|||||||
|
|
||||||
double min_price = 0;
|
double min_price = 0;
|
||||||
min_price = cfg->PaymentOption.find(payment_option)->second.pop_min_price;
|
min_price = cfg->PaymentOption.find(payment_option)->second.pop_min_price;
|
||||||
|
|
||||||
if(price < min_price)
|
if(price < min_price)
|
||||||
{
|
{
|
||||||
return "PARKING NOT ALLOWED";
|
return "PARKING NOT ALLOWED";
|
||||||
@@ -90,8 +214,12 @@ std::string Calculator::GetDurationFromCost(Configuration* cfg,
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Set new price for the normal day
|
// Set new price for the normal day
|
||||||
day_price = cfg->PaymentRate.find(payment_option)->second.pra_price;
|
int pop_id = cfg->PaymentOption.find(payment_option)->second.pop_id;
|
||||||
price_per_unit = Utilities::CalculatePricePerUnit(day_price);
|
day_price = cfg->PaymentRate.find(pop_id)->second.pra_price;
|
||||||
|
|
||||||
|
int durationId = cfg->PaymentRate.find(pop_id)->second.pra_payment_unit_id;
|
||||||
|
double durationUnit = cfg->Duration.find(durationId)->second.pun_duration;
|
||||||
|
price_per_unit = Utilities::CalculatePricePerUnit(day_price,durationUnit);
|
||||||
|
|
||||||
// If no working day found, skip it (recursively call method again)
|
// If no working day found, skip it (recursively call method again)
|
||||||
size_t found = 0;
|
size_t found = 0;
|
||||||
@@ -109,6 +237,11 @@ std::string Calculator::GetDurationFromCost(Configuration* cfg,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (price_per_unit < 0) price_per_unit = 1.0f;
|
if (price_per_unit < 0) price_per_unit = 1.0f;
|
||||||
|
|
||||||
|
// Commented on 07.06.2023
|
||||||
|
//if((price/price_per_unit) < minMin)
|
||||||
|
// return "PARKING NOT ALLOWED";
|
||||||
|
|
||||||
LOG_DEBUG("Calculated price per minute: ", price_per_unit);
|
LOG_DEBUG("Calculated price per minute: ", price_per_unit);
|
||||||
|
|
||||||
if (price_per_unit < 0)
|
if (price_per_unit < 0)
|
||||||
@@ -151,7 +284,7 @@ std::string Calculator::GetDurationFromCost(Configuration* cfg,
|
|||||||
|
|
||||||
while(true)
|
while(true)
|
||||||
{
|
{
|
||||||
if(money_left <= 0) break;
|
if((int)money_left <= 0) break;
|
||||||
|
|
||||||
// Check year period
|
// Check year period
|
||||||
bool isYearPeriodActive = false;
|
bool isYearPeriodActive = false;
|
||||||
@@ -225,7 +358,7 @@ std::string Calculator::GetDurationFromCost(Configuration* cfg,
|
|||||||
|
|
||||||
if (calc_price > 0 && total_duration_min > 0)
|
if (calc_price > 0 && total_duration_min > 0)
|
||||||
{
|
{
|
||||||
inputDate = inputDate.addSecs(-(int)ceil(calc_price) * 60);
|
inputDate.addSecs(-(int)ceil(calc_price) * 60);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(price >= min_price && total_duration_min >= minMin)
|
if(price >= min_price && total_duration_min >= minMin)
|
||||||
@@ -321,8 +454,13 @@ double Calculator::GetCostFromDuration(Configuration* cfg, uint8_t payment_optio
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Set new price for the normal day
|
// Set new price for the normal day
|
||||||
day_price = cfg->PaymentRate.find(payment_option)->second.pra_price;
|
|
||||||
price_per_unit = Utilities::CalculatePricePerUnit(day_price);
|
int pop_id = cfg->PaymentOption.find(payment_option)->second.pop_id;
|
||||||
|
day_price = cfg->PaymentRate.find(pop_id)->second.pra_price;
|
||||||
|
|
||||||
|
int durationId = cfg->PaymentRate.find(pop_id)->second.pra_payment_unit_id;
|
||||||
|
double durationUnit = cfg->Duration.find(durationId)->second.pun_duration;
|
||||||
|
price_per_unit = Utilities::CalculatePricePerUnit(day_price,durationUnit);
|
||||||
|
|
||||||
// If no working day found, skip it (recursively call method again)
|
// If no working day found, skip it (recursively call method again)
|
||||||
size_t found = 0;
|
size_t found = 0;
|
||||||
@@ -417,11 +555,12 @@ double Calculator::GetCostFromDuration(Configuration* cfg, uint8_t payment_optio
|
|||||||
return 0.0f;
|
return 0.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int carry_over_status = 0;
|
||||||
|
carry_over_status = cfg->PaymentOption.find(payment_option)->second.pop_carry_over;
|
||||||
|
|
||||||
// Go to next day if minutes not spent
|
// Go to next day if minutes not spent
|
||||||
if(inputDate.time() >= worktime_to)
|
if(inputDate.time() >= worktime_to)
|
||||||
{
|
{
|
||||||
int carry_over_status = 0;
|
|
||||||
carry_over_status = cfg->PaymentOption.find(payment_option)->second.pop_carry_over;
|
|
||||||
if (carry_over_status < 1) break;
|
if (carry_over_status < 1) break;
|
||||||
|
|
||||||
LOG_DEBUG("Reached end of worktime, searching for the next working day");
|
LOG_DEBUG("Reached end of worktime, searching for the next working day");
|
||||||
|
@@ -154,6 +154,8 @@ bool Configuration::ParseJson(Configuration* cfg, const char* json)
|
|||||||
else if (strcmp(inner_obj_name, "pop_max_time") == 0) PaymentOption.pop_max_time = k->value.GetDouble();
|
else if (strcmp(inner_obj_name, "pop_max_time") == 0) PaymentOption.pop_max_time = 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_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_multi_hour_price") == 0) PaymentOption.pop_multi_hour_price = k->value.GetInt();
|
||||||
break;
|
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();
|
||||||
@@ -209,7 +211,7 @@ bool Configuration::ParseJson(Configuration* cfg, const char* json)
|
|||||||
cfg->PaymentMethod.insert(pair<int, ATBPaymentMethod>(PaymentMethod.pme_id, PaymentMethod));
|
cfg->PaymentMethod.insert(pair<int, ATBPaymentMethod>(PaymentMethod.pme_id, PaymentMethod));
|
||||||
break;
|
break;
|
||||||
case MemberType::PaymentRateType:
|
case MemberType::PaymentRateType:
|
||||||
cfg->PaymentRate.insert(pair<int, ATBPaymentRate>(PaymentRate.pra_payment_unit_id, PaymentRate));
|
cfg->PaymentRate.insert(pair<int, ATBPaymentRate>(PaymentRate.pra_payment_option_id, PaymentRate));
|
||||||
break;
|
break;
|
||||||
case MemberType::PaymentOptionType:
|
case MemberType::PaymentOptionType:
|
||||||
cfg->PaymentOption.insert(pair<int, ATBPaymentOption>(PaymentOption.pop_payment_method_id, PaymentOption));
|
cfg->PaymentOption.insert(pair<int, ATBPaymentOption>(PaymentOption.pop_payment_method_id, PaymentOption));
|
||||||
|
@@ -8,12 +8,15 @@ static int protection_counter = 0;
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="pra_price"></param>
|
/// <param name="pra_price"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
double Utilities::CalculatePricePerUnit(double pra_price)
|
double Utilities::CalculatePricePerUnit(double pra_price, double durationUnit)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
double price_per_unit = pra_price;
|
double price_per_unit = pra_price;
|
||||||
price_per_unit /= 60.0f; // Divided by 60 because price per unit is set per hour and we are using minutes
|
double unit = durationUnit;
|
||||||
|
|
||||||
|
if(unit < 0 || unit > 65535 ) unit = 60.0f;
|
||||||
|
price_per_unit /= unit; // Divided by 60 because price per unit is set per hour and we are using minutes
|
||||||
//printf("Price per unit (min) is: %lf\n", price_per_unit);
|
//printf("Price per unit (min) is: %lf\n", price_per_unit);
|
||||||
return price_per_unit;
|
return price_per_unit;
|
||||||
}
|
}
|
||||||
|
@@ -1,10 +1,9 @@
|
|||||||
#include <calculate_price.h>
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
#include <calculate_price.h>
|
||||||
|
|
||||||
|
|
||||||
extern "C" char* strptime(const char* s,
|
extern "C" char* strptime(const char* s,
|
||||||
const char* f,
|
const char* f,
|
||||||
@@ -27,64 +26,37 @@ extern "C" char* strptime(const char* s,
|
|||||||
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QDateTime>
|
#include <QDateTime>
|
||||||
#include <QDir>
|
|
||||||
|
|
||||||
#include <fstream>
|
|
||||||
#include <sstream>
|
|
||||||
#include "calculator_functions.h"
|
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
|
|
||||||
std::ifstream input(QDir::homePath().append("/tariff01.json").toStdString());
|
|
||||||
std::stringstream sstr;
|
|
||||||
while(input >> sstr.rdbuf());
|
|
||||||
std::string json(sstr.str());
|
|
||||||
|
|
||||||
Calculator calculator;
|
|
||||||
Configuration cfg;
|
|
||||||
|
|
||||||
bool isParsed = cfg.ParseJson(&cfg, json.c_str());
|
|
||||||
cout << endl;
|
|
||||||
|
|
||||||
char const *startDate = "";
|
|
||||||
|
|
||||||
if (isParsed)
|
|
||||||
{
|
|
||||||
startDate = "2023-05-10T13:52:18.665Z";
|
|
||||||
std::string duration = calculator.GetDurationFromCost(&cfg, 3, (char *)startDate, 33, false, true);
|
|
||||||
cout << "---> startDate " << startDate << " _price_ = " << 33
|
|
||||||
<< " Total duration is: " << duration << endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
parking_tariff_t *tariff = 0;
|
parking_tariff_t *tariff = 0;
|
||||||
if (init_tariff(&tariff, "/etc/psa_tariff/")) {
|
if (init_tariff(&tariff, "C:\\Users\\MROD\\Documents\\QtCreator\\Old\\build-MOBILISIS-Calculator-Desktop_Qt_5_12_12_MSVC2017_32bit-Debug\\main\\etc\\psa_tariff\\tariff01.json"))
|
||||||
|
{
|
||||||
struct price_t price;
|
struct price_t price;
|
||||||
memset(&price, 0x00, sizeof(price));
|
memset(&price, 0x00, sizeof(price));
|
||||||
QDateTime start = QDateTime::fromString("2023-05-11T07:50:00",Qt::ISODate); //QDateTime::currentDateTime();
|
QDateTime start = QDateTime::fromString("2023-06-01T07:50:00.000Z",Qt::ISODate); //QDateTime::currentDateTime();
|
||||||
time_t start_parking_time = start.toSecsSinceEpoch() / 60;
|
time_t start_parking_time = start.toSecsSinceEpoch() / 60;
|
||||||
time_t end_parking_time = start_parking_time + 610;
|
time_t end_parking_time = start_parking_time + 1230;
|
||||||
|
|
||||||
if (compute_price_for_parking_ticket(tariff,
|
// if (compute_price_for_parking_ticket(tariff,
|
||||||
start_parking_time,
|
// start_parking_time,
|
||||||
end_parking_time,
|
// end_parking_time,
|
||||||
&price)) {
|
// &price))
|
||||||
qDebug() << "GetCostFromDuration() => price=" << price.netto;
|
// {
|
||||||
}
|
// qDebug() << "GetCostFromDuration() => price=" << price.netto;
|
||||||
|
// }
|
||||||
|
|
||||||
QString duration;
|
// QString duration;
|
||||||
if(compute_duration_for_parking_ticket(tariff,start_parking_time,1525,duration))
|
// if(compute_duration_for_parking_ticket(tariff,start_parking_time,1650,duration))
|
||||||
{
|
// {
|
||||||
qDebug() << "GetDurationFromCost() => duration=" << duration;
|
// qDebug() << "GetDurationFromCost() => duration=" << duration;
|
||||||
}
|
// }
|
||||||
|
|
||||||
|
// Daily ticket
|
||||||
|
// compute_duration_for_daily_ticket(tariff,start.toString(Qt::ISODate),3);
|
||||||
|
|
||||||
|
compute_duration_for_24hour_daily_ticket(tariff,start.toString(Qt::ISODate),3);
|
||||||
|
|
||||||
|
//Configuration* cfg, QString start_datetime, uint8_t payment_option, bool carry_over
|
||||||
// // tests
|
// // tests
|
||||||
// struct tm now;
|
// struct tm now;
|
||||||
// memset(&now, 0, sizeof(now));
|
// memset(&now, 0, sizeof(now));
|
||||||
|
@@ -7,8 +7,6 @@ QMAKE_CFLAGS = -c -pipe -std=c11 -g -O0 -Wall -Wno-attributes -W -DDEBUG -D_REEN
|
|||||||
QMAKE_CXX_FLAGS += -std=c11
|
QMAKE_CXX_FLAGS += -std=c11
|
||||||
|
|
||||||
INCLUDEPATH += $$_PRO_FILE_PWD_/../../MOBILISIS-Calculator/library/include/mobilisis/
|
INCLUDEPATH += $$_PRO_FILE_PWD_/../../MOBILISIS-Calculator/library/include/mobilisis/
|
||||||
INCLUDEPATH += $$_PRO_FILE_PWD_/../../MOBILISIS-Calculator/library/include/rapidjson/
|
|
||||||
INCLUDEPATH += $$_PRO_FILE_PWD_/../../MOBILISIS-Calculator/library/include/
|
|
||||||
INCLUDEPATH += .
|
INCLUDEPATH += .
|
||||||
|
|
||||||
unix {
|
unix {
|
||||||
|
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user