Add new calculate_price-projet.

This commit is contained in:
2023-01-23 15:50:37 +01:00
commit 68110d524b
30 changed files with 44523 additions and 0 deletions

10100
main/kate.txt Normal file

File diff suppressed because it is too large Load Diff

70
main/main.cpp Normal file
View File

@@ -0,0 +1,70 @@
#include <QDebug>
#include <QDateTime>
#include <assert.h>
#include "calculate_parking_tickets.h"
#include "calculate_parking_tickets_global.h"
#include "calculate_parking_tickets_algorithms.h"
#include "calculate_parking_tickets_tariff.h"
#include "calculate_parking_tickets_utils.h"
#include "message_handler.h"
int main() {
if (!messageHandlerInstalled()) { // change internal qt-QDebug-handling
atbInstallMessageHandler(atbDebugOutput);
setDebugLevel(QtMsgType::QtDebugMsg);
}
parking_tariff_t *tariff =
parking_tariff_t::parseTariff("/opt/ptu5/opt/calculate_parking/calculate_parking_tickets/germersheim.conf");
if (tariff) {
price_t price;
memset(&price, 0x00, sizeof(price));
QDateTime start = QDateTime::currentDateTime();
QDateTime end;
start.setTime(QTime());
int d1, d2 = 0;
d1 = start.date().dayOfWeek();
int hour[] = { 2, 5, 10, 20, 30, 40};
for (int h = 0; h < 6; ++h) {
for (int i = 0; i < MIN_PER_DAY; ++i) {
fprintf(stderr, "\n*** %5d *** (parkdauer:%dh)", i*(h+1), hour[h]);
if (d1 != d2) {
qDebug() << ((i==0) ? 0: i/MIN_PER_DAY) << d1 << "***\n";
d2 = d1;
}
//start = start.addSecs(i*60);
//start = start.addSecs(420*60);
minute_t const s = TUtils::toMinutes(start);
end = start.addSecs(hour[h]*60*60);
minute_t const e = TUtils::toMinutes(end);
//minute_t const e = s + 24*60*3 + 123;
fprintf(stderr,
"[EINFAHRT: %s:%02d:%02d, %ld Minuten frei, "
"AUSFAHRT: %s:%02d:%02d]\n",
start.date().toString().toStdString().c_str(),
start.time().hour(), start.time().minute(),
tariff->free_of_charge,
end.date().toString().toStdString().c_str(),
end.time().hour(), end.time().minute());
if (compute_price_for_parking_ticket(tariff, s, e, &price)) {
}
start = start.addSecs(60);
d1 = start.date().dayOfWeek();
}
}
}
return 0;
}

160
main/main.cpp.bck.1 Normal file
View File

@@ -0,0 +1,160 @@
#include <QDebug>
#include <QDateTime>
#include "calculate_parking_tickets.h"
#include "calculate_parking_tickets_algorithms.h"
#include "calculate_parking_tickets_tariff.h"
#include "calculate_parking_tickets_utils.h"
#include "message_handler.h"
int main() {
if (!messageHandlerInstalled()) { // change internal qt-QDebug-handling
atbInstallMessageHandler(atbDebugOutput);
setDebugLevel(QtMsgType::QtDebugMsg);
}
/*
Germersheim:
Freiparkzeit: 90 min
Stundentarif: 7:00 - 20:00 3,50 Euro/h
Tagesmaximum: 18 Euro, gueltig 24h ab einfahrt
Nacht-Tarif: 20:00 - 7:00: 8 Euro
Fragen:
1. Fuer die Abrechnung bleiben mehrere Moeglichkeiten.
a: minutengenau: eine Minute kostet 0.0583 Euro (bzw. 0.012 Euro nachts).
b: im Stunden-Raster ausgerichtet an der tatsaechlichen Uhrzeit
wie angeben: jede angefangene Stunde kostet 3.50 Euro bzw.
8 Euro Nacht-Tarif.
Beispiele:
zu b: Einfahrt um 18:24 Uhr. Bis 19:54 Uhr ist dann frei. Die 6 Minuten
bis 20:00 Uhr kosten dann 3.50 Euro. Ausfahrt um 21.00 Uhr: kostet
dann 8 Euro, insgesamt also 11.50 Euro.
zu a: wie vor, nur minutengenaue Abrechnung: 6 Minuten kosten dann
6*0.0583 = 0.35 Euro, plus 1h nachts: 60*0.012 = 0.72 Euro,
insgesamt also 1.07 Euro.
Was (logisch) nicht moeglich ist: ein Stunden-Raster, das nicht an der
tatsaechlichen Uhrzeit ausgerichtet ist.
Beispiel: Einfahrt 18:00 Uhr, frei bis 19:30 Uhr. Wie soll nun die
naechste Stunde berechnet werden? Nach Tag- oder Nacht-Tariff?
2: Tagesmaximum
a: Es gibt also eine maximale Parkzeit von 24h, und der maximale Preis
ist 18 Euro? Oder gibt es kein Maximum fuer die Parkdauer, aber der
Preis ab 24h Parkdauer betraegt einheitlich 18 Euro.
Im zweiten Fall waere dann Folgendes moeglich:
Einfahrt 5:30 Uhr, frei bis 7:00 Uhr.
Kosten von 7:00 - 20:00 Uhr: 13*3.50 = 45.50 Euro.
Kosten von 20:00 - 7:00 Uhr: 8 Euro.
Ausfahrt: 8:00 Uhr: 3.50 Euro, insgesamt eigentlich 57 Euro,
nach obiger Regel aber dann nur 18 Euro.
*/
/*
TODO:
1: Abrechnungsmodus:
a: minutengenau
b: 15-min-Raster, ausgerichtet an der tatseachlichen Uhrzeit
b: 30-min-Raster, ausgerichtet an der tatseachlichen Uhrzeit
b: 60-min-Raster, ausgerichtet an der tatseachlichen Uhrzeit
c: wie im Tarif angegeben mit einer moeglichst groben Aufloesung.
*/
parking_tariff_t *tariff = new parking_tariff_t();
tariff->unit_scale_factor = 1.0;
tariff->unit_definition = 1000;
tariff->waiting_period = 0;
// tariff->waiting_period = 90;
int const si = sizeof(TariffStep);
qDebug() << si;
QDate today = QDate::currentDate();
int todayWeekDay = today.dayOfWeek();
if (todayWeekDay > Qt::Monday) {
int day = today.day() - todayWeekDay;
if (!today.setDate(today.year(), today.month(), day)) {
qFatal("Setting today failed");
}
}
QDate sunday = today;
qDebug() << sunday;
for (int i = Qt::Monday; i <= Qt::Sunday; ++i) {
// days start at midnight
QDateTime startMinute(sunday.addDays(i), QTime( 0, 0));
//qDebug() << "startMinute=" << startMinute << startMinute.date().dayOfWeek();
// first block: 0:00 - 7:00. night-tariff.
TariffStep *current = &tariff->m_tariffSteps[i][0];
TariffStep *next = &tariff->m_tariffSteps[i][7*60];
*current = TariffStep(startMinute, 0, next);
//qDebug() << "current =" << "c=" << current << current->startMinute() << current->price() << "n=" << current->next();
//qDebug() << "offset =" << ((char *)current->next() - (char *)&tariff->m_tariffSteps[i][0])/sizeof(TariffStep);
// from 7:00 on, each hour costs 3.50 euros == 350000 units
startMinute = startMinute.addSecs(7*3600);
current = next;
for (int j = 7; j < 20; ++j) {
next = current + 60;
*current = TariffStep(startMinute, 350000, next);
//qDebug() << "current =" << "c=" << current << current->startMinute() << current->price() << "n=" << current->next();
//qDebug() << "offset =" << ((char *)current->next() - (char *)&tariff->m_tariffSteps[i][0])/sizeof(TariffStep);
startMinute = startMinute.addSecs(3600);
current = next;
}
if (i != Qt::Sunday) {
next = current + 4*60 + 7*60;
} else {
next = &tariff->m_tariffSteps[Qt::Monday][7*60];
}
*current = TariffStep(startMinute, 0, next);
if (i != Qt::Sunday) {
qDebug() << "current =" << "c=" << current << current->startMinute() << current->price() << "n=" << current->next();
qDebug() << "offset =" << ((char *)current->next() - (char *)&tariff->m_tariffSteps[i][0])/sizeof(TariffStep);
} else {
qDebug() << "current =" << "c=" << current << current->startMinute() << current->price() << "n=" << current->next();
if (&tariff->m_tariffSteps[1][420] == current->next()) {
qDebug() << "OK";
qDebug() << "offset =" << ((char *)current->next() - (char *)&tariff->m_tariffSteps[1][0])/sizeof(TariffStep);
}
}
}
return 0;
#if 0
price_t price;
memset(&price, 0x00, sizeof(price));
QDateTime start = QDateTime::currentDateTime();
minute_t const s = TUtils::toMinutes(start);
minute_t const e = s + 60;
qDebug() << "start =" << start << "(" << s << ")";
//start.setTime(QTime()); ruecksetzen des tages auf 0:00
//QTime t = start.time();
for (int i=1; i < (e-s); ++i) {
qDebug() << i << start << start.date().dayOfWeek();
start = start.addSecs(60);
}
#endif
//if (TAlgo::compute_price_for_parking_ticket(tariff, s, e, &price)) {
//}
// Calculate_parking_tickets cpt;
return 0;
}

29
main/main.pro Normal file
View File

@@ -0,0 +1,29 @@
QT += core
TARGET = main
TEMPLATE = app
CONFIG += c++17
QMAKE_CXXFLAGS += -Wno-deprecated-copy
INCLUDEPATH += ../calculate_parking_tickets/
INCLUDEPATH += ../rapidjson/include
LIBS += -L$$OUT_PWD/../calculate_parking_tickets -lcalculate_parking_tickets
# You can make your code fail to compile if it uses deprecated APIs.
# In order to do so, uncomment the following line.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
SOURCES += \
main.cpp \
message_handler.cpp
HEADERS += \
message_handler.h
# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target

140
main/message_handler.cpp Normal file
View File

@@ -0,0 +1,140 @@
#include "message_handler.h"
#include <QDateTime>
#include <cstring>
#define OUTPUT_LEN (20)
static bool installedMsgHandler = false;
static QtMsgType debugLevel = QtInfoMsg;
QtMsgType getDebugLevel() { return debugLevel; }
void setDebugLevel(QtMsgType newDebugLevel) {
debugLevel = newDebugLevel;
}
bool messageHandlerInstalled() {
return installedMsgHandler;
}
QtMessageHandler atbInstallMessageHandler(QtMessageHandler handler) {
installedMsgHandler = (handler != 0);
static QtMessageHandler prevHandler = nullptr;
if (handler) {
prevHandler = qInstallMessageHandler(handler);
return prevHandler;
} else {
return qInstallMessageHandler(prevHandler);
}
}
///
/// \brief Print message according to given debug level.
///
/// \note Install this function using qInstallMsgHandler().
///
/// int main(int argc, char **argv) {
/// installMsgHandler(atbDebugOutput);
/// QApplication app(argc, argv);
/// ...
/// return app.exec();
/// }
///
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
void atbDebugOutput(QtMsgType type, const char *msg) {
switch (type) {
case QtDebugMsg: {
if (debugLevel <= QtDebugMsg) {
fprintf(stderr, "%*.*s Debug: %s\n", OUTPUT_LEN, OUTPUT_LEN,
QDateTime::currentDateTime().toString(Qt::ISODate).toStdString().c_str(), msg);
}
} break;
case QtInfoMsg: {
if (debugLevel <= QtInfoMsg) {
fprintf(stderr, "%*.*s Info: %s\n", OUTPUT_LEN, OUTPUT_LEN,
QDateTime::currentDateTime().toString(Qt::ISODate).toStdString().c_str(), msg);
}
} break;
case QtWarningMsg: {
if (debugLevel <= QtWarningMsg) {
fprintf(stderr, "%*.*s Warning: %s\n", OUTPUT_LEN, OUTPUT_LEN,
QDateTime::currentDateTime().toString(Qt::ISODate).toStdString().c_str(), msg);
}
} break;
case QtCriticalMsg: {
if (debugLevel <= QtCriticalMsg) {
fprintf(stderr, "%*.*s Critical: %s\n", OUTPUT_LEN, OUTPUT_LEN,
QDateTime::currentDateTime().toString(Qt::ISODate).toStdString().c_str(), msg);
}
} break;
case QtFatalMsg: {
if (debugLevel <= QtFatalMsg) {
fprintf(stderr, "%*.*s Fatal: %s\n", OUTPUT_LEN, OUTPUT_LEN,
QDateTime::currentDateTime().toString(Qt::ISODate).toStdString().c_str(), msg);
}
// abort();
} break;
default: {
fprintf(stderr, "%*.*s No ErrorLevel defined! %s\n", OUTPUT_LEN, OUTPUT_LEN,
QDateTime::currentDateTime().toString(Qt::ISODate).toStdString().c_str(), msg);
}
}
}
#elif QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
void atbDebugOutput(QtMsgType type, const QMessageLogContext &context, const QString &msg) {
static constexpr const char *format = "dd.MM.yyyy hh:mm:ss";
QByteArray localMsg = msg.toLocal8Bit();
const char *file = context.file ? context.file : "";
char const* output = std::strrchr(file, '/');
if (output) {
file = output + 1;
}
qint64 const currentMSecsSinceEpoch = QDateTime::currentMSecsSinceEpoch();
int const fractional_part = currentMSecsSinceEpoch % 1000;
QDateTime const datetime = QDateTime::fromMSecsSinceEpoch(currentMSecsSinceEpoch);
switch (type) {
case QtDebugMsg: {
if (debugLevel <= QtDebugMsg) {
fprintf(stderr, "%*.*s.%03d DEBG %s (%s:%u)\n", OUTPUT_LEN, OUTPUT_LEN,
datetime.toString(format).toStdString().c_str(), fractional_part,
localMsg.constData(), file, context.line);
}
} break;
case QtInfoMsg: {
if (debugLevel <= QtInfoMsg) {
fprintf(stderr, "%*.*s.%03d INFO %s (%s:%u)\n", OUTPUT_LEN, OUTPUT_LEN,
datetime.toString(format).toStdString().c_str(), fractional_part,
localMsg.constData(), file, context.line);
}
} break;
case QtWarningMsg: {
if (debugLevel <= QtWarningMsg) {
fprintf(stderr, "%*.*s.%03d WARN %s (%s:%u)\n", OUTPUT_LEN, OUTPUT_LEN,
datetime.toString(format).toStdString().c_str(), fractional_part,
localMsg.constData(), file, context.line);
}
} break;
case QtCriticalMsg: {
if (debugLevel <= QtCriticalMsg) {
fprintf(stderr, "%*.*s.%03d CRIT %s (%s:%u)\n", OUTPUT_LEN, OUTPUT_LEN,
datetime.toString(format).toStdString().c_str(), fractional_part,
localMsg.constData(), file, context.line);
}
} break;
case QtFatalMsg: {
if (debugLevel <= QtFatalMsg) {
fprintf(stderr, "%*.*s.%03d FATAL %s (%s:%u)\n", OUTPUT_LEN, OUTPUT_LEN,
datetime.toString(format).toStdString().c_str(), fractional_part,
localMsg.constData(), file, context.line);
}
} break;
default: {
fprintf(stderr, "%*.*s.%03d No ErrorLevel defined! %s\n", OUTPUT_LEN, OUTPUT_LEN,
datetime.toString(format).toStdString().c_str(), fractional_part,
msg.toStdString().c_str());
}
}
}
#endif

20
main/message_handler.h Normal file
View File

@@ -0,0 +1,20 @@
#ifndef MESSAGE_HANDLER_H_INCLUDED
#define MESSAGE_HANDLER_H_INCLUDED
#include <QtGlobal>
QtMsgType getDebugLevel();
void setDebugLevel(QtMsgType newDebugLevel);
bool messageHandlerInstalled();
QtMessageHandler atbInstallMessageHandler(QtMessageHandler handler);
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
// typedef void (*QtMessageHandler)(QtMsgType, const char *);
void atbDebugOutput(QtMsgType type, const char *msg);
#elif QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
// typedef void (*QtMessageHandler)(QtMsgType, const QMessageLogContext &, const QString &);
void atbDebugOutput(QtMsgType type, const QMessageLogContext &context, const QString &msg);
#endif
#endif // MESSAGE_HANDLER_H_INCLUDED