Added computeEffectiveStartMinute(). Added calculation when we have a max_price which will be reset at midnight
This commit is contained in:
parent
da762b0441
commit
76cc30a7a3
@ -59,6 +59,23 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
static minute_t computeEffectiveStartMinute(parking_tariff_t const *tariff,
|
||||
minute_t startMinute) {
|
||||
QDateTime const start = TUtils::fromMinutes(startMinute);
|
||||
minute_t free_of_charge = 0;
|
||||
minute_t startMinuteDay = start.time().hour()*60 +start.time().minute();
|
||||
if (startMinuteDay >= tariff->day_tariff_start &&
|
||||
startMinuteDay < tariff->day_tariff_end) {
|
||||
free_of_charge = tariff->free_of_charge_day_tariff;
|
||||
} else
|
||||
if ((startMinuteDay >= tariff->night_tariff_start && startMinuteDay < MINUTES_PER_DAY) ||
|
||||
(startMinuteDay >= 0 && startMinuteDay < tariff->night_tariff_end)) {
|
||||
free_of_charge = tariff->free_of_charge_night_tariff;
|
||||
}
|
||||
|
||||
return (startMinute + free_of_charge);
|
||||
}
|
||||
|
||||
static bool checkCalculatePreConditions(parking_tariff_t const* tariff,
|
||||
minute_t startMinute, // CET
|
||||
minute_t endMinute, // CET
|
||||
@ -85,16 +102,26 @@ static bool checkCalculatePreConditions(parking_tariff_t const* tariff,
|
||||
}
|
||||
}
|
||||
|
||||
minute_t const effectiveStartMinute = startMinute + tariff->free_of_charge;
|
||||
QDateTime const start = TUtils::fromMinutes(startMinute);
|
||||
//QDateTime const effStart = TUtils::fromMinutes(effectiveStartMinute);
|
||||
//minute_t free_of_charge = 0;
|
||||
//minute_t startMinuteDay = start.time().hour()*60 +start.time().minute();
|
||||
//if (startMinuteDay >= tariff->day_tariff_start &&
|
||||
// startMinuteDay < tariff->day_tariff_end) {
|
||||
// free_of_charge = tariff->free_of_charge_day_tariff;
|
||||
//} else
|
||||
//if ((startMinuteDay >= tariff->night_tariff_start && startMinuteDay < MINUTES_PER_DAY) ||
|
||||
// (startMinuteDay >= 0 && startMinuteDay < tariff->night_tariff_end)) {
|
||||
// free_of_charge = tariff->free_of_charge_night_tariff;
|
||||
//}
|
||||
|
||||
minute_t const effectiveStartMinute = computeEffectiveStartMinute(tariff, startMinute);
|
||||
QDateTime const end = TUtils::fromMinutes(endMinute);
|
||||
|
||||
if (effectiveStartMinute > endMinute) {
|
||||
fprintf(stderr,
|
||||
"[start:%02d:%02d, ende:%02d:%02d]: %ld free minutes. no charge.\n",
|
||||
start.time().hour(), start.time().minute(),
|
||||
end.time().hour(), end.time().minute(), tariff->free_of_charge);
|
||||
end.time().hour(), end.time().minute(), tariff->free_of_charge_day_tariff);
|
||||
memset(price, 0x00, sizeof(*price));
|
||||
return false;
|
||||
}
|
||||
@ -103,7 +130,7 @@ static bool checkCalculatePreConditions(parking_tariff_t const* tariff,
|
||||
return true;
|
||||
}
|
||||
|
||||
#define DEBUG_INTERNAL 1
|
||||
#define DEBUG_INTERNAL 0
|
||||
|
||||
TariffStep const *
|
||||
compute_price_for_parking_ticket_internal(parking_tariff_t const *tariff,
|
||||
@ -117,7 +144,7 @@ compute_price_for_parking_ticket_internal(parking_tariff_t const *tariff,
|
||||
|
||||
int const minute = start.time().minute();
|
||||
int const hour = start.time().hour();
|
||||
int const day = start.date().dayOfWeek()-Qt::Monday;
|
||||
int const day = start.date().dayOfWeek()-1;
|
||||
int const week = 0;
|
||||
|
||||
// printf("%d%d%04d\n", week, day, hour*60+minute);
|
||||
@ -129,12 +156,14 @@ compute_price_for_parking_ticket_internal(parking_tariff_t const *tariff,
|
||||
|
||||
|
||||
uint32_t price_units = 0;
|
||||
if (tariff->max_price_for_24_hours == (uint32_t)(-1)) {
|
||||
//if (tariff->max_price_for_24_hours == (uint32_t)(-1)) {
|
||||
if (tariff->basic_tariff) {
|
||||
while (step->dateTime() < end) {
|
||||
price_units += step->price();
|
||||
step = step->next();
|
||||
}
|
||||
} else {
|
||||
}
|
||||
if (tariff->max_price_24h_after_arrival){
|
||||
QDateTime stepDateTime = step->dateTime();
|
||||
QDateTime nextStepDateTime;
|
||||
// QDateTime prevStepDateTime;
|
||||
@ -196,6 +225,63 @@ compute_price_for_parking_ticket_internal(parking_tariff_t const *tariff,
|
||||
}
|
||||
price_units += _24h_price_units;
|
||||
}
|
||||
if (tariff->max_price_at_midnight) {
|
||||
// restart pricing at midnight if current price is max_price_at_midnight
|
||||
QDateTime stepDateTime = step->dateTime();
|
||||
QDateTime nextStepDateTime;
|
||||
QDateTime midnight(stepDateTime.date().addDays(1), QTime(0,0));
|
||||
uint32_t day_price_units = 0;
|
||||
bool dbg = true;
|
||||
while (stepDateTime < end) {
|
||||
uint32_t const price_units_tmp = step->price();
|
||||
step = step->next();
|
||||
nextStepDateTime = step->dateTime();
|
||||
if (stepDateTime < midnight) {
|
||||
day_price_units += price_units_tmp;
|
||||
if (day_price_units > tariff->max_price_at_midnight) {
|
||||
day_price_units = tariff->max_price_at_midnight;
|
||||
if (dbg) {
|
||||
#if DEBUG_INTERNAL
|
||||
fprintf(stderr,
|
||||
"[%s:%02d:%02d price_so_far=%d day_price=%d]\n",
|
||||
stepDateTime.date().toString().toStdString().c_str(),
|
||||
stepDateTime.time().hour(), stepDateTime.time().minute(),
|
||||
price_units, day_price_units);
|
||||
//dbg = false;
|
||||
#endif
|
||||
}
|
||||
} else {
|
||||
#if DEBUG_INTERNAL
|
||||
dbg = true;
|
||||
fprintf(stderr,
|
||||
"[%s:%02d:%02d price_so_far=%d day_price=%d]\n",
|
||||
stepDateTime.date().toString().toStdString().c_str(),
|
||||
stepDateTime.time().hour(), stepDateTime.time().minute(),
|
||||
price_units, day_price_units);
|
||||
#endif
|
||||
}
|
||||
} else {
|
||||
if (day_price_units == tariff->max_price_at_midnight) {
|
||||
price_units += day_price_units;
|
||||
day_price_units = 0;
|
||||
} else {
|
||||
day_price_units += price_units_tmp;
|
||||
}
|
||||
#if DEBUG_INTERNAL
|
||||
fprintf(stderr,
|
||||
"[%s:%02d:%02d 24h max. price_so_far=%d day_price=%d]\n",
|
||||
stepDateTime.date().toString().toStdString().c_str(),
|
||||
stepDateTime.time().hour(), stepDateTime.time().minute(),
|
||||
price_units, day_price_units);
|
||||
#endif
|
||||
midnight = stepDateTime;
|
||||
midnight.setDate(midnight.date().addDays(1));
|
||||
midnight.setTime(QTime(0, 0));
|
||||
}
|
||||
stepDateTime = nextStepDateTime;
|
||||
}
|
||||
price_units += day_price_units;
|
||||
}
|
||||
|
||||
price->units = price_units;
|
||||
price->netto = roundf((price->units * tariff->unit_scale_factor) / tariff->unit_definition);
|
||||
@ -218,10 +304,10 @@ bool compute_price_for_parking_ticket(parking_tariff_t const *tariff,
|
||||
// minute_t const parkingTime = endMinute - startMinute;
|
||||
memset(price, 0x00, sizeof(*price));
|
||||
|
||||
minute_t const effectiveStartMinute = startMinute + tariff->free_of_charge;
|
||||
QDateTime const start = TUtils::fromMinutes(startMinute);
|
||||
QDateTime const effStart = TUtils::fromMinutes(effectiveStartMinute);
|
||||
QDateTime const end = TUtils::fromMinutes(endMinute);
|
||||
minute_t const effectiveStartMinute = computeEffectiveStartMinute(tariff, startMinute);
|
||||
// QDateTime const start = TUtils::fromMinutes(startMinute);
|
||||
// QDateTime const effStart = TUtils::fromMinutes(effectiveStartMinute);
|
||||
// QDateTime const end = TUtils::fromMinutes(endMinute);
|
||||
|
||||
//qDebug() << effStart;
|
||||
//qDebug() << end;
|
||||
|
Loading…
Reference in New Issue
Block a user