Compare commits

...

5 Commits

5 changed files with 111 additions and 36 deletions

View File

@ -77,10 +77,10 @@ static bool checkCalculatePreConditions(parking_tariff_t const* tariff,
return false;
}
if (tariff->max_parking_time != -1) {
if (parkingTime > tariff->max_parking_time) {
if (tariff->parking_time_max != -1) {
if (parkingTime > tariff->parking_time_max) {
qCritical() << "parkingTime" << parkingTime
<< ">" << tariff->max_parking_time;
<< ">" << tariff->parking_time_max;
return false;
}
}
@ -286,7 +286,7 @@ bool compute_duration_for_parking_ticket(parking_tariff_t const *tariff,
minute_t *end_parking_time,
struct price_t const *price) {
price_t p;
for (int i = 0; i < tariff->max_parking_time; ++i) {
for (int i = 0; i < tariff->parking_time_max; ++i) {
minute_t end_time = start_parking_time + i;
if (compute_price_for_parking_ticket(tariff, start_parking_time,
end_time, &p)) {

View File

@ -42,18 +42,5 @@ static constexpr uint16_t const DAYS = 7;
static constexpr uint32_t const MAX_OFFSET = (uint32_t)sizeof(TariffMinute[3][7][1440]);
static constexpr uint32_t const UNDEFINED_NEXT_MINUTE = MAX_OFFSET;
struct TariffDay {
TariffMinute m[1];
//TariffMinute m[MINUTES_PER_DAY];
};
struct TariffWeek {
TariffDay mon = {{}};
};
struct TariffSteps {
};
#endif // CALCULATE_PARKING_TICKETS_GLOBAL_H

View File

@ -2,6 +2,7 @@
#include <cstdio>
#include <string>
#include <algorithm>
#include <QDebug>
#include <QDateTime>
@ -23,6 +24,11 @@ using namespace rapidjson;
#define MAX_PARKING_PRICE "max_parking_price"
#define MAX_PRICE_FOR_24_HOURS "max_price_for_24_hours"
#define MAX_PARKING_TIME "max_parking_time"
#define TARIFF_VERSION "version"
#define TARIFF_FEATURES "tariff_features"
#define WAITING_PERIOD "waiting_period"
#define PARKING_TIME_MIN "parking_time_min"
#define PARKING_TIME_MAX "parking_time_max"
static const char *weekStr[] {
"week1", "week2", "week3"
@ -59,6 +65,37 @@ parking_tariff_t *parking_tariff_t::parseTariff(const char *confFile) {
tariff = new parking_tariff_t();
if (d.HasMember(TARIFF_VERSION)) {
Value::MemberIterator o = d.FindMember(TARIFF_VERSION);
assert(o != d.MemberEnd());
assert(o->value.IsString());
std::string version = o->value.GetString();
strncpy(tariff->tariff_version, version.c_str(),
std::min((int)version.size(),
(int)sizeof(tariff->tariff_version)-1));
tariff->tariff_version[sizeof(tariff->tariff_version)-1] = '\0';
}
if (d.HasMember(TARIFF_FEATURES)) {
Value::MemberIterator o = d.FindMember(TARIFF_FEATURES);
assert(o != d.MemberEnd());
assert(o->value.IsArray());
int const s = o->value.Size();
if (s > 0) {
// TODO
} else {
tariff->tariff_features = 0;
memset(tariff->_tariff_features, 0x00,
sizeof(tariff->_tariff_features));
}
}
if (d.HasMember(WAITING_PERIOD)) {
Value::MemberIterator o = d.FindMember(WAITING_PERIOD);
assert(o != d.MemberEnd());
assert(o->value.IsString());
std::string wp = o->value.GetString();
tariff->waiting_period = std::stoi(wp);
}
if (d.HasMember(FREE_OF_CHARGE)) {
Value::MemberIterator o = d.FindMember(FREE_OF_CHARGE);
assert(o != d.MemberEnd());
@ -98,6 +135,24 @@ parking_tariff_t *parking_tariff_t::parseTariff(const char *confFile) {
tariff->max_parking_price_units = (uint32_t)std::stoul(mp);
}
}
if (d.HasMember(PARKING_TIME_MIN)) {
Value::MemberIterator o = d.FindMember(PARKING_TIME_MIN);
assert(o != d.MemberEnd());
assert(o->value.IsString());
std::string mp = o->value.GetString();
tariff->parking_time_min = (uint32_t)std::stoul(mp);
}
if (d.HasMember(PARKING_TIME_MAX)) {
Value::MemberIterator o = d.FindMember(PARKING_TIME_MAX);
assert(o != d.MemberEnd());
assert(o->value.IsString());
std::string mp = o->value.GetString();
if (mp == "unlimited") {
tariff->parking_time_max = ~0;
} else {
tariff->parking_time_max = (uint32_t)std::stoul(mp);
}
}
if (d.HasMember(MAX_PRICE_FOR_24_HOURS)) {
Value::MemberIterator o = d.FindMember(MAX_PRICE_FOR_24_HOURS);
assert(o != d.MemberEnd());
@ -109,17 +164,6 @@ parking_tariff_t *parking_tariff_t::parseTariff(const char *confFile) {
tariff->max_price_for_24_hours = (uint32_t)std::stoul(mp);
}
}
if (d.HasMember(MAX_PARKING_TIME)) {
Value::MemberIterator o = d.FindMember(MAX_PARKING_TIME);
assert(o != d.MemberEnd());
assert(o->value.IsString());
std::string mp = o->value.GetString();
if (mp == "unlimited") {
tariff->max_parking_time = ~0;
} else {
tariff->max_parking_time = (uint32_t)std::stoul(mp);
}
}
QDate today = QDate::currentDate();

View File

@ -9,6 +9,12 @@
#include <QPair>
#include <QList>
#define FAHRZEUG_AUSWAHL_PKW (uint64_t)(0x0000000000000001)
#define FAHRZEUG_AUSWAHL_BUS (uint64_t)(0x0000000000000002)
#define FAHRZEUG_AUSWAHL_LKW (uint64_t)(0x0000000000000004)
#define VERANSTALTUNG_AUSWAHL_SPORT (uint64_t)(0x0000000000000008)
#define VERANSTALTUNG_AUSWAHL_KULTUR (uint64_t)(0x0000000000000010)
struct parking_tariff_t {
// parking_tariff_t();
static parking_tariff_t *parseTariff(const char *confFile);
@ -38,18 +44,13 @@ struct parking_tariff_t {
///
/// \brief waiting_period
/// @note Also called "Karenzzeit". Allowed values: [0, 3]
// minute_t waiting_period;
minute_t waiting_period;
///
/// \brief free_of_charge
///
minute_t free_of_charge;
///
/// \brief max_parking_time
///
minute_t max_parking_time = -1;
///
/// \brief max_parking_price_units
///
@ -60,6 +61,31 @@ struct parking_tariff_t {
///
uint32_t max_price_for_24_hours; // 24h limit (default -1)
///
/// \brief tariff_version
///
char tariff_version[64];
///
/// \brief tariff_features
///
uint64_t tariff_features;
///
/// \brief _tariff_features
///
uint64_t _tariff_features[64];
///
/// \brief parking_time_min
///
minute_t parking_time_min;
///
/// \brief parking_time_max
///
minute_t parking_time_max;
#if 0
/// Minimal amount of money for buying a ticket.
///

View File

@ -1,12 +1,27 @@
{
"name" : "Germersheim (23.01.2023)",
"version" : "1.0.0",
"spec1" : "Freiparkzeit: 90min kostenlos",
"spec2" : "Stundentariff (7.00 - 20:00): 3.50 Euro/h",
"spec3" : "Tagesmaximum 18 Euro, gueltig 24Std. ab Einfahrt",
"spec3.1" : "(d.h gueltig bis 24h nach Einfahrt)",
"spec4" : "Nachttarif (20.00 - 7.00): 8 Euro",
"comment_tariff_features" : [ "unused",
"FAHRZEUG_AUSWAHL_PKW",
"FAHRZEUG_AUSWAHL_BUS",
"FAHRZEUG_AUSWAHL_LKW",
"VERANSTALTUNG_AUSWAHL_SPORT",
"VERANSTALTUNG_AUSWAHL_KULTUR"
],
"tariff_features" : [],
"comment_waiting_period" : "karenzzeit",
"waiting_period" : "0",
"comment_free_of_charge" : "Freiparkzeit: 90min kostenlos",
"free_of_charge" : "90",
@ -25,8 +40,11 @@
"comment_max_price_for_24_hours" : "preis fuer 24h ticket (18 Euro)",
"max_price_for_24_hours" : "1800000",
"comment_max_parking_time" : "maximale parkzeit (in minuten)",
"max_parking_time" : "20160",
"comment_parking_time_max" : "maximale parkzeit (in minuten)",
"parking_time_max" : "20160",
"comment_parking_time_min" : "minimale parkzeit (in minuten)",
"parking_time_min" : "0",
"week1" : {
"Monday": {