Compare commits
29 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
d15c9dad29
|
|||
|
cb8cd5dead
|
|||
|
9d64350e4f
|
|||
| 1a71edc274 | |||
| 51d8beda2a | |||
| 7bab9d6ba2 | |||
| 8b4d64bd0c | |||
| eefdde4693 | |||
| 6157861d62 | |||
|
23748966de
|
|||
|
268d43cdea
|
|||
|
a453886f0a
|
|||
|
eef94a3fb3
|
|||
|
88a0b6ebe2
|
|||
|
3097819c01
|
|||
|
acf799da7e
|
|||
|
3bf71f84d5
|
|||
|
73f5eca656
|
|||
|
b8753cc2ed
|
|||
|
29986e0451
|
|||
|
1146db743c
|
|||
|
c6302edec5
|
|||
|
90eae152bf
|
|||
|
6d001f1501
|
|||
|
de32022b89
|
|||
|
1e2f1589ac
|
|||
|
ee1f7eca44
|
|||
|
1069c5ad90
|
|||
|
46bffc250d
|
@@ -109,7 +109,7 @@ CalcState CALCULATE_LIBRARY_API init_tariff(parking_tariff_t **tariff,
|
|||||||
void CALCULATE_LIBRARY_API free_tariff(parking_tariff_t *tariff);
|
void CALCULATE_LIBRARY_API free_tariff(parking_tariff_t *tariff);
|
||||||
int CALCULATE_LIBRARY_API get_zone_nr(int zone = -1);
|
int CALCULATE_LIBRARY_API get_zone_nr(int zone = -1);
|
||||||
|
|
||||||
CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket(
|
CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket( // deprecated
|
||||||
parking_tariff_t *tariff,
|
parking_tariff_t *tariff,
|
||||||
time_t start_parking_time,
|
time_t start_parking_time,
|
||||||
time_t end_parking_time,
|
time_t end_parking_time,
|
||||||
@@ -118,10 +118,11 @@ CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket(
|
|||||||
CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket(
|
CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket(
|
||||||
parking_tariff_t *tariff,
|
parking_tariff_t *tariff,
|
||||||
QDateTime const &start_parking_time,
|
QDateTime const &start_parking_time,
|
||||||
QDateTime const &end_parking_time,
|
int netto_parking_time,
|
||||||
struct price_t *price);
|
QDateTime &end_parking_time, // return value
|
||||||
|
struct price_t *price); // return value
|
||||||
|
|
||||||
CalcState CALCULATE_LIBRARY_API compute_duration_for_parking_ticket(
|
CalcState CALCULATE_LIBRARY_API compute_duration_for_parking_ticket( // deprecated
|
||||||
parking_tariff_t *tariff,
|
parking_tariff_t *tariff,
|
||||||
time_t start_parking_time,
|
time_t start_parking_time,
|
||||||
double cost,
|
double cost,
|
||||||
@@ -131,12 +132,12 @@ CalcState CALCULATE_LIBRARY_API compute_duration_for_parking_ticket(
|
|||||||
parking_tariff_t *tariff,
|
parking_tariff_t *tariff,
|
||||||
QDateTime const &start_parking_time,
|
QDateTime const &start_parking_time,
|
||||||
double cost,
|
double cost,
|
||||||
QDateTime &ticketEndTime);
|
QDateTime &ticketEndTime); // return value
|
||||||
|
|
||||||
CalcState CALCULATE_LIBRARY_API compute_duration_for_daily_ticket(
|
CalcState CALCULATE_LIBRARY_API compute_duration_for_daily_ticket(
|
||||||
parking_tariff_t *tariff,
|
parking_tariff_t *tariff,
|
||||||
QString const &start_parking_time,
|
QDateTime const &start_parking_time,
|
||||||
uint8_t paymentMethod);
|
QDateTime &ticketEndTime);
|
||||||
//#ifdef __cplusplus
|
//#ifdef __cplusplus
|
||||||
//} // extern "C"
|
//} // extern "C"
|
||||||
//#endif
|
//#endif
|
||||||
|
|||||||
@@ -23,10 +23,11 @@ public:
|
|||||||
/// <param name="tariff_cfg">Pointer to configuration</param>
|
/// <param name="tariff_cfg">Pointer to configuration</param>
|
||||||
/// <param name="vehicle_type">Type of vehicle</param>
|
/// <param name="vehicle_type">Type of vehicle</param>
|
||||||
/// <param name="start_datetime">Date/time of payment to be conducted in ISO8601 format (e.g. 2022-12-25T08:00:00Z) </param>
|
/// <param name="start_datetime">Date/time of payment to be conducted in ISO8601 format (e.g. 2022-12-25T08:00:00Z) </param>
|
||||||
|
/// <param name="end_datetime">Date/time of park end to be conducted in ISO8601 format (e.g. 2022-12-25T08:00:00Z) </param>
|
||||||
/// <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, const QDateTime start_datetime, QDateTime & end_datetime, double durationMin, bool nextDay = false, bool prepaid = false);
|
||||||
|
|
||||||
// Daily ticket
|
// Daily ticket
|
||||||
QString GetDailyTicketDuration(Configuration* cfg, QString start_datetime, uint8_t payment_option, bool carry_over);
|
QDateTime GetDailyTicketDuration(Configuration* cfg, const QDateTime start_datetime, uint8_t payment_option, bool carry_over);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -2,12 +2,12 @@
|
|||||||
|
|
||||||
enum DayOfWeek
|
enum DayOfWeek
|
||||||
{
|
{
|
||||||
Saturday = 0x06,
|
Monday = 0x01,
|
||||||
Sunday = 0x01,
|
Tuesday = 0x02,
|
||||||
Monday = 0x02,
|
Wednesday = 0x03,
|
||||||
Tuesday = 0x02,
|
Thursday = 0x04,
|
||||||
Wednesday = 0x03,
|
Friday = 0x05,
|
||||||
Thursday = 0x04,
|
Saturday = 0x06,
|
||||||
Friday = 0x05,
|
Sunday = 0x07,
|
||||||
UndefinedDay = 0xFF
|
UndefinedDay = 0xFF
|
||||||
};
|
};
|
||||||
@@ -92,10 +92,12 @@ void CALCULATE_LIBRARY_API free_tariff(parking_tariff_t *tariff) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// this is currently not used
|
||||||
CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket(
|
CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket(
|
||||||
parking_tariff_t *tariff,
|
parking_tariff_t *tariff,
|
||||||
time_t start_parking_time, // in minutes
|
time_t start_parking_time, // in minutes
|
||||||
time_t end_parking_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(PaymentOption::Option1)->second.pop_min_time;
|
||||||
@@ -129,11 +131,12 @@ CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket(
|
|||||||
QTime const t(0, 0, 0);
|
QTime const t(0, 0, 0);
|
||||||
QDateTime start(d, t, Qt::UTC);
|
QDateTime start(d, t, Qt::UTC);
|
||||||
start = start.toLocalTime().addSecs(start_parking_time * 60);
|
start = start.toLocalTime().addSecs(start_parking_time * 60);
|
||||||
|
QDateTime end(start);
|
||||||
if (start.isValid()) {
|
if (start.isValid()) {
|
||||||
QString cs = start.toString(Qt::ISODate);
|
|
||||||
double cost = calculator.GetCostFromDuration(
|
double cost = calculator.GetCostFromDuration(
|
||||||
tariff, PaymentOption::Option1,
|
tariff, PaymentOption::Option1,
|
||||||
cs.toLocal8Bit().constData(),
|
start,
|
||||||
|
end,
|
||||||
duration, false, true);
|
duration, false, true);
|
||||||
double minCost = tariff->PaymentOption.find(PaymentOption::Option1)->second.pop_min_price;
|
double minCost = tariff->PaymentOption.find(PaymentOption::Option1)->second.pop_min_price;
|
||||||
if (cost < minCost) {
|
if (cost < minCost) {
|
||||||
@@ -152,8 +155,10 @@ CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket(
|
|||||||
CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket(
|
CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket(
|
||||||
parking_tariff_t *tariff,
|
parking_tariff_t *tariff,
|
||||||
QDateTime const &start_parking_time,
|
QDateTime const &start_parking_time,
|
||||||
QDateTime const &end_parking_time,
|
int netto_parking_time,
|
||||||
struct price_t *price) {
|
QDateTime &end_parking_time,
|
||||||
|
struct price_t *price)
|
||||||
|
{
|
||||||
CalcState calcState;
|
CalcState calcState;
|
||||||
double minMin = tariff->PaymentOption.find(PaymentOption::Option1)->second.pop_min_time;
|
double minMin = tariff->PaymentOption.find(PaymentOption::Option1)->second.pop_min_time;
|
||||||
double maxMin = tariff->PaymentOption.find(PaymentOption::Option1)->second.pop_max_time;
|
double maxMin = tariff->PaymentOption.find(PaymentOption::Option1)->second.pop_max_time;
|
||||||
@@ -161,39 +166,37 @@ CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket(
|
|||||||
// DEBUG
|
// DEBUG
|
||||||
qCritical() << "compute_price_for_parking_ticket() " << endl
|
qCritical() << "compute_price_for_parking_ticket() " << endl
|
||||||
<< " start_parking_time: " << start_parking_time << endl
|
<< " start_parking_time: " << start_parking_time << endl
|
||||||
<< " end_parking_time: " << end_parking_time << endl
|
<< " netto_parking_time: " << netto_parking_time << endl
|
||||||
<< " minMin: " << minMin << endl
|
<< " minMin: " << minMin << endl
|
||||||
<< " maxMin: " << maxMin;
|
<< " maxMin: " << maxMin;
|
||||||
|
|
||||||
|
|
||||||
int const duration = (end_parking_time.toSecsSinceEpoch() -
|
if (netto_parking_time < 0) {
|
||||||
start_parking_time.toSecsSinceEpoch()) / 60;
|
|
||||||
|
|
||||||
if (duration < 0) {
|
|
||||||
calcState.setDesc(QString("end=%1, start=%2")
|
calcState.setDesc(QString("end=%1, start=%2")
|
||||||
.arg(end_parking_time.toString(Qt::ISODate),
|
.arg(end_parking_time.toString(Qt::ISODate),
|
||||||
start_parking_time.toString(Qt::ISODate)));
|
start_parking_time.toString(Qt::ISODate)));
|
||||||
return calcState.set(CalcState::State::NEGATIVE_PARING_TIME);
|
return calcState.set(CalcState::State::NEGATIVE_PARING_TIME);
|
||||||
}
|
}
|
||||||
if (duration > maxMin) {
|
if (netto_parking_time > maxMin) {
|
||||||
calcState.setDesc(QString("duration=%1, maxMin=%2").arg(duration, maxMin));
|
calcState.setDesc(QString("duration=%1, maxMin=%2").arg(netto_parking_time).arg(maxMin));
|
||||||
return calcState.set(CalcState::State::ABOVE_MAX_PARKING_TIME);
|
return calcState.set(CalcState::State::ABOVE_MAX_PARKING_TIME);
|
||||||
}
|
}
|
||||||
if (duration < minMin) {
|
if (netto_parking_time < minMin) {
|
||||||
calcState.setDesc(QString("duration=%1, minMin=%2").arg(duration, minMin));
|
calcState.setDesc(QString("duration=%1, minMin=%2").arg(netto_parking_time).arg(minMin));
|
||||||
return calcState.set(CalcState::State::BELOW_MIN_PARKING_TIME);
|
return calcState.set(CalcState::State::BELOW_MIN_PARKING_TIME);
|
||||||
}
|
}
|
||||||
if (duration == 0) {
|
if (netto_parking_time == 0) {
|
||||||
memset(price, 0x00, sizeof(*price));
|
memset(price, 0x00, sizeof(*price));
|
||||||
return calcState.set(CalcState::State::SUCCESS);
|
return calcState.set(CalcState::State::SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (start_parking_time.isValid()) {
|
if (start_parking_time.isValid()) {
|
||||||
QString cs = start_parking_time.toString(Qt::ISODate);
|
|
||||||
double cost = calculator.GetCostFromDuration(
|
double cost = calculator.GetCostFromDuration(
|
||||||
tariff, PaymentOption::Option1,
|
tariff, PaymentOption::Option1,
|
||||||
cs.toLocal8Bit().constData(),
|
start_parking_time, // starting time
|
||||||
duration, false, true);
|
end_parking_time, // return value: end time
|
||||||
|
netto_parking_time, // minutes, netto
|
||||||
|
false, true);
|
||||||
double minCost = tariff->PaymentOption.find(PaymentOption::Option1)->second.pop_min_price;
|
double minCost = tariff->PaymentOption.find(PaymentOption::Option1)->second.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));
|
||||||
@@ -233,7 +236,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);
|
QDateTime d = QDateTime::fromString(duration, Qt::ISODate);
|
||||||
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);
|
||||||
@@ -249,7 +252,8 @@ CalcState CALCULATE_LIBRARY_API compute_duration_for_parking_ticket(
|
|||||||
parking_tariff_t *tariff,
|
parking_tariff_t *tariff,
|
||||||
QDateTime const &start_parking_time,
|
QDateTime const &start_parking_time,
|
||||||
double price,
|
double price,
|
||||||
QDateTime &ticketEndTime) {
|
QDateTime &ticketEndTime)
|
||||||
|
{
|
||||||
CalcState calcState;
|
CalcState calcState;
|
||||||
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);
|
||||||
@@ -275,11 +279,28 @@ 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 CALCULATE_LIBRARY_API compute_duration_for_daily_ticket(parking_tariff_t *tariff, QDateTime const &start_parking_time, QDateTime &ticketEndTime)
|
||||||
{
|
{
|
||||||
CalcState calcState;
|
CalcState calcState;
|
||||||
QString result = calculator.GetDailyTicketDuration(tariff, start_parking_time, PaymentOption::Option1,false);
|
if (start_parking_time.isValid()) {
|
||||||
qDebug() << "DailyTicket() => " + result;
|
|
||||||
|
ticketEndTime = calculator.GetDailyTicketDuration(tariff,
|
||||||
|
start_parking_time,
|
||||||
|
PaymentOption::Option1,
|
||||||
|
false); // carry over
|
||||||
|
|
||||||
|
// DEBUG
|
||||||
|
qCritical() << "compute_duration_for_daily_ticket(): ";
|
||||||
|
qCritical() << " ticketEndTime: " << ticketEndTime;
|
||||||
|
|
||||||
|
if (!ticketEndTime.isValid()) {
|
||||||
|
calcState.setDesc(QString("ticketEndTime=%1").arg(ticketEndTime.toString(Qt::ISODate)));
|
||||||
|
return calcState.set(CalcState::State::WRONG_ISO_TIME_FORMAT);
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
return calcState.set(CalcState::State::INVALID_START_DATE);
|
||||||
|
}
|
||||||
|
|
||||||
return calcState.set(CalcState::State::SUCCESS);
|
return calcState.set(CalcState::State::SUCCESS);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,20 +19,25 @@ inline struct tm* localtime_r(const time_t *clock, struct tm* result){
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
QString Calculator::GetDailyTicketDuration(Configuration* cfg, QString start_datetime, uint8_t payment_option, bool carry_over)
|
QDateTime Calculator::GetDailyTicketDuration(Configuration* cfg, const QDateTime start_datetime, uint8_t payment_option, bool carry_over)
|
||||||
{
|
{
|
||||||
if(start_datetime.isNull() || start_datetime.isEmpty()) return NULL;
|
if(!start_datetime.isValid()) {
|
||||||
|
return QDateTime();
|
||||||
|
}
|
||||||
|
|
||||||
double day_price = 0.0f;
|
double day_price = 0.0f;
|
||||||
int current_special_day_id = -1;
|
int current_special_day_id = -1;
|
||||||
bool is_special_day = Utilities::CheckSpecialDay(cfg, start_datetime.toStdString().c_str(), ¤t_special_day_id, &day_price);
|
bool is_special_day = Utilities::CheckSpecialDay(cfg, start_datetime.toString(Qt::ISODate).toStdString().c_str(), ¤t_special_day_id, &day_price);
|
||||||
|
|
||||||
QDateTime inputDateTime = QDateTime::fromString(start_datetime, Qt::ISODate);
|
QDateTime inputDateTime = start_datetime;
|
||||||
QTime worktime_from;
|
QTime worktime_from;
|
||||||
QTime worktime_to;
|
QTime worktime_to;
|
||||||
|
|
||||||
int daily_card_price = cfg->PaymentOption.find(payment_option)->second.pop_daily_card_price;
|
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(daily_card_price <= 0) {
|
||||||
|
LOG_ERROR("Calculator::GetDailyTicketDuration(): Daily ticket price zero or less");
|
||||||
|
return QDateTime();
|
||||||
|
}
|
||||||
|
|
||||||
if(is_special_day)
|
if(is_special_day)
|
||||||
{
|
{
|
||||||
@@ -46,21 +51,21 @@ QString Calculator::GetDailyTicketDuration(Configuration* cfg, QString start_dat
|
|||||||
{
|
{
|
||||||
// Go to next day if outside worktime
|
// Go to next day if outside worktime
|
||||||
inputDateTime = inputDateTime.addSecs(86400);
|
inputDateTime = inputDateTime.addSecs(86400);
|
||||||
return GetDailyTicketDuration(cfg,inputDateTime.toString(Qt::ISODate), payment_option,true);
|
return GetDailyTicketDuration(cfg,inputDateTime, payment_option,true);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(day_price <=0)
|
if(day_price <=0)
|
||||||
{
|
{
|
||||||
// Go to next day if special day price is 0
|
// Go to next day if special day price is 0
|
||||||
inputDateTime = inputDateTime.addSecs(86400);
|
inputDateTime = inputDateTime.addSecs(86400);
|
||||||
return GetDailyTicketDuration(cfg,inputDateTime.toString(Qt::ISODate), payment_option,true);
|
return GetDailyTicketDuration(cfg,inputDateTime, payment_option,true);
|
||||||
}
|
}
|
||||||
|
|
||||||
int diff = abs(inputDateTime.time().secsTo(worktime_to));
|
int diff = abs(inputDateTime.time().secsTo(worktime_to));
|
||||||
inputDateTime = inputDateTime.addSecs(diff);
|
inputDateTime = inputDateTime.addSecs(diff);
|
||||||
|
|
||||||
//qDebug() << "Ticket is valid until: " << inputDateTime.toString(Qt::ISODate) << "price = " << daily_card_price << ", duration = " << diff / 60;
|
//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 inputDateTime;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -76,7 +81,7 @@ QString Calculator::GetDailyTicketDuration(Configuration* cfg, QString start_dat
|
|||||||
if(found <=0)
|
if(found <=0)
|
||||||
{
|
{
|
||||||
inputDateTime = inputDateTime.addSecs(86400);
|
inputDateTime = inputDateTime.addSecs(86400);
|
||||||
return GetDailyTicketDuration(cfg,inputDateTime.toString(Qt::ISODate), payment_option,true);
|
return GetDailyTicketDuration(cfg,inputDateTime, payment_option,true);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -92,18 +97,18 @@ QString Calculator::GetDailyTicketDuration(Configuration* cfg, QString start_dat
|
|||||||
{
|
{
|
||||||
// Go to next day if outside worktime
|
// Go to next day if outside worktime
|
||||||
inputDateTime = inputDateTime.addSecs(86400);
|
inputDateTime = inputDateTime.addSecs(86400);
|
||||||
return GetDailyTicketDuration(cfg,inputDateTime.toString(Qt::ISODate), payment_option,true);
|
return GetDailyTicketDuration(cfg,inputDateTime, payment_option,true);
|
||||||
}
|
}
|
||||||
|
|
||||||
int diff = abs(inputDateTime.time().secsTo(worktime_to));
|
int diff = abs(inputDateTime.time().secsTo(worktime_to));
|
||||||
inputDateTime = inputDateTime.addSecs(diff);
|
inputDateTime = inputDateTime.addSecs(diff);
|
||||||
|
|
||||||
//qDebug() << "Ticket is valid until: " << inputDateTime.toString(Qt::ISODate) << "price = " << daily_card_price << ", duration = " << diff / 60;
|
//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 inputDateTime;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return NULL;
|
return QDateTime();
|
||||||
}
|
}
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
std::string Calculator::GetDurationFromCost(Configuration* cfg,
|
std::string Calculator::GetDurationFromCost(Configuration* cfg,
|
||||||
@@ -201,16 +206,9 @@ 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;
|
||||||
|
|
||||||
if((price/price_per_unit) < minMin) return "PARKING NOT ALLOWED";
|
// 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)
|
|
||||||
{
|
|
||||||
inputDate = inputDate.addDays(1);
|
|
||||||
inputDate.setTime(worktime_from);
|
|
||||||
return GetDurationFromCost(cfg, payment_option, inputDate.toString(Qt::ISODate).toStdString().c_str(), money_left, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
// If overtime flag is set
|
// If overtime flag is set
|
||||||
if (overtime || nextDay)
|
if (overtime || nextDay)
|
||||||
{
|
{
|
||||||
@@ -314,15 +312,15 @@ std::string Calculator::GetDurationFromCost(Configuration* cfg,
|
|||||||
// }
|
// }
|
||||||
|
|
||||||
double ret_val = 0;
|
double ret_val = 0;
|
||||||
double calc_price = (int)total_duration_min - (int)price / price_per_unit;
|
// double calc_price = (int)total_duration_min - (int)price / price_per_unit;
|
||||||
|
|
||||||
if (calc_price > 0 && total_duration_min > 0)
|
//if (calc_price > 0 && total_duration_min > 0)
|
||||||
{
|
//{
|
||||||
inputDate.addSecs(-(int)ceil(calc_price) * 60);
|
// inputDate = inputDate.addSecs(-(int)ceil(calc_price) * 60);
|
||||||
}
|
//}
|
||||||
|
|
||||||
if(price >= min_price && total_duration_min >= minMin)
|
if(price >= min_price && total_duration_min >= minMin)
|
||||||
qDebug() << "Valid until: " << inputDate.toString(Qt::ISODate);
|
qDebug() << "GetDurationFromCost(): Valid until: " << inputDate.toString(Qt::ISODate);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
qDebug() << "Parking not allowed";
|
qDebug() << "Parking not allowed";
|
||||||
@@ -341,10 +339,10 @@ std::string Calculator::GetDurationFromCost(Configuration* cfg,
|
|||||||
///////////////////////////////////////
|
///////////////////////////////////////
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
double Calculator::GetCostFromDuration(Configuration* cfg, uint8_t payment_option, const char* start_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)
|
||||||
{
|
{
|
||||||
// Get input date
|
// Get input date
|
||||||
QDateTime inputDate = QDateTime::fromString(start_datetime,Qt::ISODate);
|
QDateTime inputDate = start_datetime;
|
||||||
|
|
||||||
// Get day of week
|
// Get day of week
|
||||||
int weekdayId = 0;
|
int weekdayId = 0;
|
||||||
@@ -431,7 +429,7 @@ double Calculator::GetCostFromDuration(Configuration* cfg, uint8_t payment_optio
|
|||||||
{
|
{
|
||||||
LOG_DEBUG("- No workday found, trying to find next available day");
|
LOG_DEBUG("- No workday found, trying to find next available day");
|
||||||
inputDate = inputDate.addDays(1);
|
inputDate = inputDate.addDays(1);
|
||||||
return floor(GetCostFromDuration(cfg, payment_option, inputDate.toString(Qt::ISODate).toStdString().c_str(), durationMin, true, prepaid));
|
return floor(GetCostFromDuration(cfg, payment_option, inputDate, end_datetime, durationMin, true, prepaid));
|
||||||
}
|
}
|
||||||
worktime_from = QTime::fromString(cfg->WeekDaysWorktime.find(weekdayId)->second.pwd_time_from.c_str());
|
worktime_from = QTime::fromString(cfg->WeekDaysWorktime.find(weekdayId)->second.pwd_time_from.c_str());
|
||||||
worktime_to = QTime::fromString(cfg->WeekDaysWorktime.find(weekdayId)->second.pwd_time_to.c_str());
|
worktime_to = QTime::fromString(cfg->WeekDaysWorktime.find(weekdayId)->second.pwd_time_to.c_str());
|
||||||
@@ -444,7 +442,7 @@ double Calculator::GetCostFromDuration(Configuration* cfg, uint8_t payment_optio
|
|||||||
{
|
{
|
||||||
inputDate = inputDate.addDays(1);
|
inputDate = inputDate.addDays(1);
|
||||||
inputDate.setTime(worktime_from);
|
inputDate.setTime(worktime_from);
|
||||||
return GetCostFromDuration(cfg, payment_option, inputDate.toString(Qt::ISODate).toStdString().c_str(), durationMin, true, prepaid);
|
return GetCostFromDuration(cfg, payment_option, inputDate, end_datetime, durationMin, true, prepaid);
|
||||||
}
|
}
|
||||||
|
|
||||||
// If overtime flag is set
|
// If overtime flag is set
|
||||||
@@ -474,7 +472,7 @@ double Calculator::GetCostFromDuration(Configuration* cfg, uint8_t payment_optio
|
|||||||
{
|
{
|
||||||
LOG_DEBUG(" *** PREPAID *** Current time is past the time range end, searching for next available day");
|
LOG_DEBUG(" *** PREPAID *** Current time is past the time range end, searching for next available day");
|
||||||
inputDate = inputDate.addDays(1);
|
inputDate = inputDate.addDays(1);
|
||||||
return GetCostFromDuration(cfg, payment_option, inputDate.toString(Qt::ISODate).toStdString().c_str(), durationMin, true, prepaid);
|
return GetCostFromDuration(cfg, payment_option, inputDate, end_datetime, durationMin, true, prepaid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -526,7 +524,7 @@ double Calculator::GetCostFromDuration(Configuration* cfg, uint8_t payment_optio
|
|||||||
LOG_DEBUG("Reached end of worktime, searching for the next working day");
|
LOG_DEBUG("Reached end of worktime, searching for the next working day");
|
||||||
inputDate = inputDate.addDays(1);
|
inputDate = inputDate.addDays(1);
|
||||||
overtime = true;
|
overtime = true;
|
||||||
return GetCostFromDuration(cfg, payment_option, inputDate.toString(Qt::ISODate).toStdString().c_str(), total_duration_min);
|
return GetCostFromDuration(cfg, payment_option, inputDate, end_datetime, total_duration_min);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Increment input date minutes for each monetary unit
|
// Increment input date minutes for each monetary unit
|
||||||
@@ -535,7 +533,10 @@ double Calculator::GetCostFromDuration(Configuration* cfg, uint8_t payment_optio
|
|||||||
total_cost += price_per_unit;
|
total_cost += price_per_unit;
|
||||||
|
|
||||||
}
|
}
|
||||||
qDebug() << "Valid until:" << inputDate.toString(Qt::ISODate).toStdString().c_str();
|
qDebug() << "GetCostFromDuration(): Valid until:" << inputDate.toString(Qt::ISODate).toStdString().c_str();
|
||||||
|
|
||||||
|
end_datetime = inputDate;
|
||||||
|
|
||||||
double ret_val = total_cost;
|
double ret_val = total_cost;
|
||||||
total_cost = 0.0f;
|
total_cost = 0.0f;
|
||||||
return ceil(ret_val);
|
return ceil(ret_val);
|
||||||
|
|||||||
+39
-3
@@ -26,11 +26,47 @@ 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"
|
||||||
|
#include <calculate_price.h>
|
||||||
|
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
|
|
||||||
parking_tariff_t *tariff = 0;
|
std::ifstream input(QDir::homePath().append("/tariff01.json").toStdString());
|
||||||
if (init_tariff(&tariff, "C:\\Users\\MROD\\Documents\\QtCreator\\build-MOBILISIS-Calculator-Desktop_Qt_5_12_12_MSVC2017_32bit-Debug\\main\\etc\\psa_tariff\\zone1.json"))
|
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;
|
||||||
|
if (init_tariff(&tariff, "/etc/psa_tariff/")) {
|
||||||
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-05-11T07:50:00",Qt::ISODate); //QDateTime::currentDateTime();
|
||||||
@@ -52,7 +88,7 @@ int main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Daily ticket
|
// Daily ticket
|
||||||
compute_duration_for_daily_ticket(tariff,start.toString(Qt::ISODate),3);
|
//compute_duration_for_daily_ticket(tariff,start.toString(Qt::ISODate),3);
|
||||||
|
|
||||||
//Configuration* cfg, QString start_datetime, uint8_t payment_option, bool carry_over
|
//Configuration* cfg, QString start_datetime, uint8_t payment_option, bool carry_over
|
||||||
// // tests
|
// // tests
|
||||||
|
|||||||
@@ -7,6 +7,8 @@ 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 {
|
||||||
|
|||||||
+805
-1
File diff suppressed because one or more lines are too long
+805
-1
File diff suppressed because one or more lines are too long
+812
-1
File diff suppressed because one or more lines are too long
+805
-1
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user