From 507b5d1b9c4e67ac462329808c85d9d3c78ccaf1 Mon Sep 17 00:00:00 2001 From: Gerhard Hoffmann Date: Fri, 19 Jul 2024 13:58:22 +0200 Subject: [PATCH] Add Interpolation, Prepaid and CarryOver structures to streamline Json-File layout. --- library/include/mobilisis/tariff_carryover.h | 70 +++++++++++++++ .../include/mobilisis/tariff_interpolation.h | 89 +++++++++++++++++++ library/include/mobilisis/tariff_prepaid.h | 29 ++++++ 3 files changed, 188 insertions(+) create mode 100644 library/include/mobilisis/tariff_carryover.h create mode 100644 library/include/mobilisis/tariff_interpolation.h create mode 100644 library/include/mobilisis/tariff_prepaid.h diff --git a/library/include/mobilisis/tariff_carryover.h b/library/include/mobilisis/tariff_carryover.h new file mode 100644 index 0000000..2a68dd3 --- /dev/null +++ b/library/include/mobilisis/tariff_carryover.h @@ -0,0 +1,70 @@ +#ifndef TARIFF_CARRYOVER_H_INCLUDED +#define TARIFF_CARRYOVER_H_INCLUDED + +#include + +struct ATBCarryOver { + struct week { + int day; + bool seemless; + bool never; + QTime static_start; + QTime static_end; + } carryover[8]; + + int id; + + + friend QDebug operator<<(QDebug debug, ATBCarryOver const &co) { + QDebugStateSaver saver(debug); + + debug.nospace() + << " id:" << co.id << "\n" + << " **** Monday **** \n" + << " day: " << co.carryover[(int)Qt::Monday].day << "\n" + << " static_start: " << co.carryover[(int)Qt::Monday].static_start.toString(Qt::ISODate) << "\n" + << " static_end: " << co.carryover[(int)Qt::Monday].static_end.toString(Qt::ISODate) << "\n" + << " anytime: " << co.carryover[(int)Qt::Monday].seemless << "\n" + << " never: " << co.carryover[(int)Qt::Monday].never << "\n" + << " **** Tuesday **** \n" + << " day: " << co.carryover[(int)Qt::Tuesday].day << "\n" + << " static_start: " << co.carryover[(int)Qt::Tuesday].static_start.toString(Qt::ISODate) << "\n" + << " static_end: " << co.carryover[(int)Qt::Tuesday].static_end.toString(Qt::ISODate) << "\n" + << " anytime: " << co.carryover[(int)Qt::Tuesday].seemless << "\n" + << " never: " << co.carryover[(int)Qt::Tuesday].never << "\n" + << " **** Wednesday **** \n" + << " day: " << co.carryover[(int)Qt::Wednesday].day << "\n" + << " static_start: " << co.carryover[(int)Qt::Wednesday].static_start.toString(Qt::ISODate) << "\n" + << " static_end: " << co.carryover[(int)Qt::Wednesday].static_end.toString(Qt::ISODate) << "\n" + << " anytime: " << co.carryover[(int)Qt::Wednesday].seemless << "\n" + << " never: " << co.carryover[(int)Qt::Wednesday].never << "\n" + << " **** Thursday **** \n" + << " day: " << co.carryover[(int)Qt::Thursday].day << "\n" + << " static_start: " << co.carryover[(int)Qt::Thursday].static_start.toString(Qt::ISODate) << "\n" + << " static_end: " << co.carryover[(int)Qt::Thursday].static_end.toString(Qt::ISODate) << "\n" + << " anytime: " << co.carryover[(int)Qt::Thursday].seemless << "\n" + << " never: " << co.carryover[(int)Qt::Thursday].never << "\n" + << " **** Friday **** \n" + << " day: " << co.carryover[(int)Qt::Friday].day << "\n" + << " static_start: " << co.carryover[(int)Qt::Friday].static_start.toString(Qt::ISODate) << "\n" + << " static_end: " << co.carryover[(int)Qt::Friday].static_end.toString(Qt::ISODate) << "\n" + << " anytime: " << co.carryover[(int)Qt::Friday].seemless << "\n" + << " never: " << co.carryover[(int)Qt::Friday].never << "\n" + << " **** Saturday **** \n" + << " day: " << co.carryover[(int)Qt::Saturday].day << "\n" + << " static_start: " << co.carryover[(int)Qt::Saturday].static_start.toString(Qt::ISODate) << "\n" + << " static_end: " << co.carryover[(int)Qt::Saturday].static_end.toString(Qt::ISODate) << "\n" + << " anytime: " << co.carryover[(int)Qt::Saturday].seemless << "\n" + << " never: " << co.carryover[(int)Qt::Saturday].never << "\n" + << " **** Sunday **** \n" + << " day: " << co.carryover[(int)Qt::Sunday].day << "\n" + << " static_start: " << co.carryover[(int)Qt::Sunday].static_start.toString(Qt::ISODate) << "\n" + << " static_end: " << co.carryover[(int)Qt::Sunday].static_end.toString(Qt::ISODate) << "\n" + << " anytime: " << co.carryover[(int)Qt::Sunday].seemless << "\n" + << " never: " << co.carryover[(int)Qt::Sunday].never << "\n"; + + return debug; + } +}; + +#endif // TARIFF_CARRYOVER_H_INCLUDED diff --git a/library/include/mobilisis/tariff_interpolation.h b/library/include/mobilisis/tariff_interpolation.h new file mode 100644 index 0000000..492dd4e --- /dev/null +++ b/library/include/mobilisis/tariff_interpolation.h @@ -0,0 +1,89 @@ +#ifndef TARIFF_INTERPOLATION_H_INCLUDED +#define TARIFF_INTERPOLATION_H_INCLUDED + +#include +#include + +struct ATBInterpolation { + + enum Type { + NO_INTERPOLATION = 1, + STATIC_WALLCLOCK_TIME_VALUES = 2, + STATIC_TIMEPOINT_AND_DURATION = 3, + DYNAMIC_TIMEPOINT_AND_STATIC_DURATION = 4, + DYNAMIC_ABSTRACT_TIMEPOINT_AND_STATIC_DURATION = 5, + DYNAMIC_ABSTRACT_TIMEPOINT_AND_PRICE = 6, + DYNAMIC_ABSTRACT_TIMEPOINT_AND_STATIC_END_TIME = 7 + }; + + static QString name(int i) { + switch(i) { + case (int)(NO_INTERPOLATION): + return QString("%1: NO_INTERPOLATION").arg(i); + case (int)(STATIC_WALLCLOCK_TIME_VALUES): + return QString("%1: STATIC_WALLCLOCK_TIME_VALUES").arg(i); + case (int)(STATIC_TIMEPOINT_AND_DURATION): + return QString("%1: STATIC_TIMEPOINT_AND_DURATION").arg(i); + case (int)(DYNAMIC_TIMEPOINT_AND_STATIC_DURATION): + return QString("%1: DYNAMIC_TIMEPOINT_AND_STATIC_DURATION").arg(i); + case (int)(DYNAMIC_ABSTRACT_TIMEPOINT_AND_STATIC_DURATION): + return QString("%1: DYNAMIC_ABSTRACT_TIMEPOINT_AND_STATIC_DURATION").arg(i); + case (int)(DYNAMIC_ABSTRACT_TIMEPOINT_AND_PRICE): + return QString("%1: DYNAMIC_ABSTRACT_TIMEPOINT_AND_PRICE").arg(i); + case (int)(DYNAMIC_ABSTRACT_TIMEPOINT_AND_STATIC_END_TIME): + return QString("%1: DYNAMIC_ABSTRACT_TIMEPOINT_AND_STATIC_END_TIME").arg(i); + default:; + } + return "ERROR"; + } + + explicit ATBInterpolation() + : id(0) + , static_start(QTime()) + , static_end(QTime()) + , static_start_str(QString()) + , static_end_str(QString()) + , static_duration(0) + , dynamic_start(QTime()) + , dynamic_end(QTime()) + , dynamic_start_str(QString()) + , dynamic_end_str(QString()) + , dynamic_duration(0) + , dynamic_until_price(0) { + } + + int id; + QTime static_start; + QTime static_end; + QString static_start_str; + QString static_end_str; + int static_duration; + QTime dynamic_start; + QTime dynamic_end; + QString dynamic_start_str; + QString dynamic_end_str; + int dynamic_duration; + int dynamic_until_price; + + friend QDebug operator<<(QDebug debug, ATBInterpolation const &i) { + QDebugStateSaver saver(debug); + + debug.nospace() + << " id: " << name(i.id) << "\n" + << " static_start: " << i.static_start.toString(Qt::ISODate) << "\n" + << " static_end: " << i.static_end.toString(Qt::ISODate) << "\n" + << " static_start_str: " << i.static_start_str << "\n" + << " static_end_str: " << i.static_end_str << "\n" + << " static_duration: " << i.static_duration << "\n" + << " dynamic_start: " << i.dynamic_start.toString(Qt::ISODate) << "\n" + << " dynamic_end: " << i.dynamic_end.toString(Qt::ISODate) << "\n" + << " dynamic_start_str: " << i.dynamic_start_str << "\n" + << " dynamic_end_str: " << i.dynamic_end_str << "\n" + << " dynamic_duration: " << i.dynamic_duration << "\n" + << "dynamic_until_price: " << i.dynamic_until_price << "\n"; + + return debug; + } +}; + +#endif // TARIFF_INTERPOLATION_H_INCLUDED diff --git a/library/include/mobilisis/tariff_prepaid.h b/library/include/mobilisis/tariff_prepaid.h new file mode 100644 index 0000000..5bbe505 --- /dev/null +++ b/library/include/mobilisis/tariff_prepaid.h @@ -0,0 +1,29 @@ +#ifndef TARIFF_PREPAID_H_INCLUDED +#define TARIFF_PREPAID_H_INCLUDED + +#include +#include + +struct ATBPrepaid { + explicit ATBPrepaid() = default; + int id; + bool anytime; + bool never; + QTime static_start; + QTime static_end; + + friend QDebug operator<<(QDebug debug, ATBPrepaid const &pp) { + QDebugStateSaver saver(debug); + + debug.nospace() + << " id: " << pp.id << "\n" + << " static_start: " << pp.static_start.toString(Qt::ISODate) << "\n" + << " static_end: " << pp.static_end.toString(Qt::ISODate) << "\n" + << " anytime: " << pp.anytime << "\n" + << " never: " << pp.never << "\n"; + + return debug; + } +}; + +#endif // TARIFF_PREPAID_H_INCLUDED