Continued
This commit is contained in:
parent
05c9a1dcf2
commit
dfb074e4ce
@ -1,7 +1,6 @@
|
||||
QT += core
|
||||
QT += serialport network
|
||||
|
||||
TARGET = ATBDownloadDCFirmware
|
||||
TARGET = util
|
||||
|
||||
VERSION="0.1.0"
|
||||
win32 {
|
||||
@ -63,11 +62,11 @@ contains( CONFIG, DesktopLinux ) {
|
||||
SOURCES += \
|
||||
main.cpp \
|
||||
tariff_json_template.cpp \
|
||||
tariff_json_parser.cpp
|
||||
tariff_editor.cpp
|
||||
|
||||
HEADERS += \
|
||||
tariff_json_template.h \
|
||||
tariff_json_parser.h
|
||||
tariff_editor.h
|
||||
|
||||
OTHER_FILES += \
|
||||
tariff.json \
|
||||
|
@ -1,9 +1,51 @@
|
||||
|
||||
#include <QtGlobal>
|
||||
#include <QFile>
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonObject>
|
||||
#include <QDebug>
|
||||
|
||||
#include "tariff_editor.h"
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
Q_UNUSED(argc);
|
||||
Q_UNUSED(argv);
|
||||
|
||||
TariffEditor editor;
|
||||
editor.writeToDocument("Project", "Szeged");
|
||||
editor.writeToDocument("Version", "1.0.0");
|
||||
editor.writeToDocument("Date", "01.01.1970");
|
||||
editor.writeToDocument("Commiter" , "");
|
||||
editor.writeToDocument("Info", "");
|
||||
|
||||
editor.writeToDocument(editor.create("TariffType"));
|
||||
editor.writeToDocument(editor.create("TariffAccuracy"));
|
||||
editor.writeToDocument(editor.create("TariffPrice"));
|
||||
editor.writeToDocument(editor.create("TariffProducts"));
|
||||
editor.writeToDocument(editor.create("TariffConfig"));
|
||||
editor.writeToDocument(editor.create("TimeRanges"));
|
||||
|
||||
|
||||
qCritical().noquote() << editor.document().toJson();
|
||||
|
||||
return 0;
|
||||
|
||||
QFile currentFile("/home/linux/ATBTariffCalculator/Utilities/tariff.template.json");
|
||||
if (currentFile.open(QIODevice::ReadOnly)) {
|
||||
|
||||
qCritical() << __LINE__;
|
||||
QByteArray json = currentFile.readAll();
|
||||
|
||||
QJsonParseError e;
|
||||
QJsonDocument doc = QJsonDocument::fromJson(json, &e);
|
||||
if (e.error == QJsonParseError::NoError) {
|
||||
qCritical().noquote() << doc.toJson(QJsonDocument::JsonFormat::Indented);
|
||||
} else {
|
||||
qCritical() << e.errorString();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -6,6 +6,22 @@ Tarif-Datei Szeged in Zone 1 (expandiert, Vorschlag):
|
||||
"Commiter":"",
|
||||
"Info":"",
|
||||
|
||||
"TariffType": [
|
||||
{
|
||||
"tariff_type_id": 1,
|
||||
"tariff_type_label": "uniform-to-the-minute",
|
||||
"comment": "same price for all computational units (minutes)"
|
||||
}
|
||||
],
|
||||
"TariffAccuracy": [
|
||||
{
|
||||
"tariff_accuracy_id": 1,
|
||||
"tariff_accuracy_label": "computation per minute",
|
||||
"tariff_accuracy_value": 1,
|
||||
"comment": "accuracy of tariff computation is individual minutes"
|
||||
}
|
||||
],
|
||||
|
||||
"Products" : [
|
||||
{
|
||||
"tariff_product_id": 0,
|
||||
@ -18,33 +34,6 @@ Tarif-Datei Szeged in Zone 1 (expandiert, Vorschlag):
|
||||
"tariff_product_time_ranges" : [100001]
|
||||
}
|
||||
],
|
||||
"TariffAccuracy": [
|
||||
{
|
||||
"tariff_accuracy_id": 1,
|
||||
"tariff_accuracy_label": "computation per minute",
|
||||
"tariff_accuracy_value": 1,
|
||||
"comment": "accuracy of tariff computation is individual minutes"
|
||||
}
|
||||
],
|
||||
"TariffType": [
|
||||
{
|
||||
"tariff_type_id": 1,
|
||||
"tariff_type_label": "linear",
|
||||
"comment": "same price for all computational units, typically minutes"
|
||||
}
|
||||
],
|
||||
"TariffTimeBase": [
|
||||
{
|
||||
"tariff_timebase_id": 1,
|
||||
"tariff_timebase_label": "dynamic-timebase",
|
||||
"comment": "computation starts at minute 0 (can be any minute during the day)"
|
||||
},
|
||||
{
|
||||
"tariff_timebase_id": 2,
|
||||
"tariff_timebase_label": "wall-clock-timebase",
|
||||
"comment": "computation starts at fixed wall-clock time"
|
||||
}
|
||||
],
|
||||
"TariffPriceCustomer": [
|
||||
{
|
||||
"tariff_price_customer_id": 1,
|
||||
@ -92,10 +81,12 @@ Tarif-Datei Szeged in Zone 1 (expandiert, Vorschlag):
|
||||
},
|
||||
"MinimalPrice": {
|
||||
"value" : 1,
|
||||
"editable": true,
|
||||
"comment": "price-id of customer entered price (for hour) expressed in minimal time: 15*(165/60) = 41.25"
|
||||
},
|
||||
"MaximalPrice": {
|
||||
"value" : 1,
|
||||
"editable": true,
|
||||
"comment": "price-id of customer entered price (for hour) expressed in maximal time: 360*(165/60) = 990"
|
||||
},
|
||||
"tariff_config_time_base": 1,
|
||||
|
@ -58,7 +58,7 @@
|
||||
"comment": "price for dayticket as entered by customer"
|
||||
}
|
||||
],
|
||||
"TariffConfig": [
|
||||
"TariffConfig": {
|
||||
"tariff_config_id": 1,
|
||||
"tariff_config_label": "Tariff Config 1",
|
||||
"tariff_config_accuracy": 1,
|
||||
@ -84,7 +84,7 @@
|
||||
"tariff_config_time_base": 1,
|
||||
"tariff_config_carry_over": true,
|
||||
"tariff_config_prepaid": true
|
||||
],
|
||||
},
|
||||
"TimeRanges" : [
|
||||
{
|
||||
"time_range_id": 0,
|
||||
@ -5564,6 +5564,7 @@
|
||||
}
|
||||
],
|
||||
"DayConfigurations": [
|
||||
{
|
||||
"DayConfig_1": {
|
||||
"day_config_id": 0,
|
||||
"day_config_date_range": 6,
|
||||
@ -5572,11 +5573,7 @@
|
||||
"comment_2": "short-time-parking or day-ticket on this day",
|
||||
"day_config_day_time_ranges": [
|
||||
{
|
||||
// hier die time-ranges. werden mittels eines noch zu schrebenden tools erzeugt
|
||||
// 100002: zeitbereich von 00:00-08:00
|
||||
// 0-1079: jeweils eine minute
|
||||
// 100003: zeitbereich von 18:00-24:00
|
||||
"day_time_ranges_short_time_parking":" [
|
||||
"day_time_ranges_short_time_parking": [
|
||||
100002,
|
||||
0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
|
||||
10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
|
||||
@ -5690,64 +5687,82 @@
|
||||
]
|
||||
},
|
||||
{
|
||||
"day_time_ranges_day_ticket":" [100001]
|
||||
"day_time_ranges_day_ticket": [100001]
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"DayConfig_2": {
|
||||
"day_config_id": 1,
|
||||
"day_config_date_range": 6,
|
||||
"day_config_product_ids": [1],
|
||||
"day_config_day_time_ranges": [
|
||||
{
|
||||
"day_time_ranges_day_ticket":" [100001]
|
||||
"day_time_ranges_day_ticket": [100001]
|
||||
}
|
||||
]
|
||||
}
|
||||
// usw. auch fuer verkaufsoffene Tage
|
||||
}
|
||||
],
|
||||
"TariffDays": [
|
||||
{
|
||||
"Mon": {
|
||||
"day_id": 1,
|
||||
"day_config_id": 0
|
||||
}
|
||||
},
|
||||
{
|
||||
"Tue": {
|
||||
"day_id": 2,
|
||||
"day_config_id": 0
|
||||
}
|
||||
},
|
||||
{
|
||||
"Wed": {
|
||||
"day_id": 3,
|
||||
"day_config_id": 0
|
||||
}
|
||||
},
|
||||
{
|
||||
"Thu": {
|
||||
"day_id": 4,
|
||||
"day_config_id": 0
|
||||
}
|
||||
},
|
||||
{
|
||||
"Fri": {
|
||||
"day_id": 5,
|
||||
"day_config_id": 0
|
||||
}
|
||||
},
|
||||
{
|
||||
"Sat": {
|
||||
"day_id": 6,
|
||||
"day_config_id": 0
|
||||
}
|
||||
},
|
||||
{
|
||||
"Sun": {
|
||||
"day_id": 7,
|
||||
"day_config_id": 0
|
||||
}
|
||||
},
|
||||
{
|
||||
"Christmas_1st_day": {
|
||||
"day_id": 8,
|
||||
"day_config_id": 1,
|
||||
"day_date": "2024-12-25",
|
||||
"day_moveable": false
|
||||
}
|
||||
},
|
||||
{
|
||||
"Christmas_2nd_day": {
|
||||
"day_id": 9,
|
||||
"day_config_id": 1,
|
||||
"day_date": "2024-12-26",
|
||||
"day_moveable": false
|
||||
}
|
||||
// usw. die anderen Feiertage und verkaufsoffende Tage
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
5753
Utilities/tariff.template.json.bck
Normal file
5753
Utilities/tariff.template.json.bck
Normal file
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,181 @@
|
||||
#include "tariff_editor.h"
|
||||
|
||||
#include <QJsonObject>
|
||||
#include <QJsonArray>
|
||||
#include <QDebug>
|
||||
#include <QPair>
|
||||
|
||||
#include <initializer_list>
|
||||
|
||||
TariffEditor::TariffEditor() {
|
||||
m_doc = QJsonDocument();
|
||||
// m_doc.setObject(QJsonObject());
|
||||
}
|
||||
|
||||
QJsonObject TariffEditor::create(QString const &key) {
|
||||
QJsonArray a;
|
||||
if (key.compare("TariffType", Qt::CaseInsensitive) == 0) {
|
||||
a.push_back(QJsonObject({
|
||||
QPair(QString("tariff_type_id"), QJsonValue(1)),
|
||||
QPair(QString("tariff_type_label"), QJsonValue("uniform-to-the-minute")),
|
||||
QPair(QString("comment"), QJsonValue("same price for all computational units, typically minutes"))}));
|
||||
} else
|
||||
if (key.compare("TariffAccuracy", Qt::CaseInsensitive) == 0) {
|
||||
a.push_back(QJsonObject({
|
||||
QPair(QString("tariff_accuracy_id"), QJsonValue(1)),
|
||||
QPair(QString("tariff_accuracy_label"), QJsonValue("computation per minute")),
|
||||
QPair(QString("tariff_accuracy_value"), QJsonValue(1)),
|
||||
QPair(QString("comment"), QJsonValue("accuracy of tariff computation is individual minutes"))
|
||||
}));
|
||||
} else
|
||||
if (key.compare("TariffPrice", Qt::CaseInsensitive) == 0) {
|
||||
a.push_back(QJsonObject({
|
||||
QPair(QString("tariff_price_id"), QJsonValue(1)),
|
||||
QPair(QString("tariff_price"), QJsonValue(165)),
|
||||
QPair(QString("editable"), QJsonValue(true)),
|
||||
QPair(QString("comment"), QJsonValue("price per hour as entered by customer"))
|
||||
}));
|
||||
a.push_back(QJsonObject({
|
||||
QPair(QString("tariff_price_id"), QJsonValue(2)),
|
||||
QPair(QString("tariff_price"), QJsonValue(990)),
|
||||
QPair(QString("editable"), QJsonValue(true)),
|
||||
QPair(QString("comment"), QJsonValue("price for dayticket as entered by customer"))
|
||||
}));
|
||||
} else
|
||||
if (key.compare("TariffConfig", Qt::CaseInsensitive) == 0) {
|
||||
a.push_back(QJsonObject({
|
||||
QPair(QString("tariff_config_id"), QJsonValue(1)),
|
||||
QPair(QString("tariff_config_label"), QJsonValue("Tariff-Config")),
|
||||
QPair(QString("tariff_config_accuracy"), QJsonValue(1)),
|
||||
QPair(QString("tariff_config_type"), QJsonValue(1)),
|
||||
QPair(QString("tariff_config_carry_over"), QJsonValue(true)),
|
||||
QPair(QString("tariff_config_prepaid"), QJsonValue(true))
|
||||
}));
|
||||
a.push_back(QJsonObject({
|
||||
QPair(QString("MinimalTime"),
|
||||
QJsonValue(QJsonObject({
|
||||
QPair(QString("value"), QJsonValue(15)),
|
||||
QPair(QString("editable"), QJsonValue(true)),
|
||||
QPair(QString("comment"), QJsonValue("minimal parking time in minutes (net)"))})))}));
|
||||
a.push_back(QJsonObject({
|
||||
QPair(QString("MaximalTime"),
|
||||
QJsonValue(QJsonObject({
|
||||
QPair(QString("value"), QJsonValue(360)),
|
||||
QPair(QString("editable"), QJsonValue(true)),
|
||||
QPair(QString("comment"), QJsonValue("maximal parking time in minutes (net)"))})))}));
|
||||
a.push_back(QJsonObject({
|
||||
QPair(QString("MinimalPrice"),
|
||||
QJsonValue(QJsonObject({
|
||||
QPair(QString("value"), QJsonValue(15)),
|
||||
QPair(QString("editable"), QJsonValue(true)),
|
||||
QPair(QString("comment"), QJsonValue("customer entered price (for hour) expressed in minimal time: 15*(165/60) = 41.25"))})))}));
|
||||
a.push_back(QJsonObject({
|
||||
QPair(QString("MaximalPrice"),
|
||||
QJsonValue(QJsonObject({
|
||||
QPair(QString("value"), QJsonValue(990)),
|
||||
QPair(QString("editable"), QJsonValue(true)),
|
||||
QPair(QString("comment"), QJsonValue("customer entered price (for hour) expressed in maximal time: 15*(165/60) = 41.25"))})))}));
|
||||
} else
|
||||
if (key.compare("TariffProducts", Qt::CaseInsensitive) == 0) {
|
||||
a.push_back(QJsonObject({
|
||||
QPair(QString("ShortTimeParking"),
|
||||
QJsonValue(QJsonObject({
|
||||
QPair(QString("tariff_product_id"), QJsonValue(1)),
|
||||
QPair(QString("tariff_product_price_id"), QJsonValue(1))})))}));
|
||||
a.push_back(QJsonObject({
|
||||
QPair(QString("DayTicket"),
|
||||
QJsonValue(QJsonObject({
|
||||
QPair(QString("tariff_product_id"), QJsonValue(2)),
|
||||
QPair(QString("tariff_product_price_id"), QJsonValue(2))})))}));
|
||||
} else
|
||||
if (key.compare("TimeRanges", Qt::CaseInsensitive) == 0) {
|
||||
// if prepaid, unrestricted
|
||||
QJsonArray b;
|
||||
|
||||
QJsonValue v;
|
||||
|
||||
v = QJsonObject({
|
||||
QPair(QString("tariff_range_id"), QJsonValue(100001)),
|
||||
QPair(QString("tariff_range_start"), QJsonValue("00:00:00")),
|
||||
QPair(QString("tariff_range_end"), QJsonValue("00:00:00")),
|
||||
QPair(QString("tariff_range_price_id"), QJsonValue(0)),
|
||||
QPair(QString("comment"), QJsonValue(QString("start block is free of charge")))});
|
||||
|
||||
v = QJsonObject({QPair(QString("Block-Start-0"), v)});
|
||||
b.append(v);
|
||||
|
||||
v = QJsonObject({
|
||||
QPair(QString("tariff_range_id"), QJsonValue(100002)),
|
||||
QPair(QString("tariff_range_start"), QJsonValue("00:00:00")),
|
||||
QPair(QString("tariff_range_end"), QJsonValue("00:00:00")),
|
||||
QPair(QString("tariff_range_price_id"), QJsonValue(0)),
|
||||
QPair(QString("comment"), QJsonValue(QString("end block is free of charge")))}),
|
||||
v = QJsonObject({QPair(QString("Block-End-0"), v)});
|
||||
b.append(v);
|
||||
|
||||
v = QJsonObject({
|
||||
QPair(QString("tariff_range_id"), QJsonValue(100003)),
|
||||
QPair(QString("tariff_range_start"), QJsonValue("00:00:00")),
|
||||
QPair(QString("tariff_range_end"), QJsonValue("08:00:00")),
|
||||
QPair(QString("tariff_range_price_id"), QJsonValue(0)),
|
||||
QPair(QString("comment"), QJsonValue(QString("start block is free of charge")))});
|
||||
v = QJsonObject({QPair(QString("Block-Start-1"), v)});
|
||||
b.append(v);
|
||||
|
||||
v = QJsonObject({
|
||||
QPair(QString("tariff_range_id"), QJsonValue(100004)),
|
||||
QPair(QString("tariff_range_start"), QJsonValue("18:00:00")),
|
||||
QPair(QString("tariff_range_end"), QJsonValue("00:00:00")),
|
||||
QPair(QString("tariff_range_price_id"), QJsonValue(0)),
|
||||
QPair(QString("comment"), QJsonValue(QString("end block is free of charge")))});
|
||||
v = QJsonObject({QPair(QString("Block-End-1"), v)});
|
||||
b.append(v);
|
||||
|
||||
v = QJsonObject({
|
||||
QPair(QString("tariff_range_id"), QJsonValue(100005)),
|
||||
QPair(QString("tariff_range_start"), QJsonValue("00:00:00")),
|
||||
QPair(QString("tariff_range_end"), QJsonValue("08:00:00")),
|
||||
QPair(QString("tariff_range_price_id"), QJsonValue(0)),
|
||||
QPair(QString("comment"), QJsonValue(QString("start block is free of charge")))});
|
||||
v = QJsonObject({QPair(QString("Block-Start-1"), v)});
|
||||
b.append(v);
|
||||
|
||||
v = QJsonObject({
|
||||
QPair(QString("tariff_range_id"), QJsonValue(100006)),
|
||||
QPair(QString("tariff_range_start"), QJsonValue("12:00:00")),
|
||||
QPair(QString("tariff_range_end"), QJsonValue("00:00:00")),
|
||||
QPair(QString("tariff_range_price_id"), QJsonValue(0)),
|
||||
QPair(QString("comment"), QJsonValue(QString("end block is free of charge")))});
|
||||
v = QJsonObject({QPair(QString("Block-End-1"), v)});
|
||||
b.append(v);
|
||||
|
||||
a.push_back(QJsonObject({QPair(QString("OperationTimes"), b)}));
|
||||
}
|
||||
#if 0
|
||||
{
|
||||
"time_range_id": 100001,
|
||||
"time_range_start": "00:00:00",
|
||||
"time_range_end": "00:00:00",
|
||||
"time_range_start_minute": 0,
|
||||
"time_range_end_minute": 1440,
|
||||
"time_range_price_id": 2,
|
||||
"comment": "[ 00:00-00:00 [ = [ 00:00-24:00 ["
|
||||
},
|
||||
|
||||
#endif
|
||||
|
||||
return QJsonObject({QPair(key, QJsonValue(a))});
|
||||
}
|
||||
|
||||
QJsonDocument &TariffEditor::writeToDocument(QJsonObject const &object) {
|
||||
QJsonArray a = m_doc.array();
|
||||
a.push_back(object);
|
||||
//a.push_back(object);
|
||||
//a.push_back(QJsonObject(std::initializer_list{QPair(key, value)}));
|
||||
m_doc.setArray(a);
|
||||
return m_doc;
|
||||
}
|
||||
|
||||
QJsonDocument &TariffEditor::writeToDocument(QString const &key, QString const &value) {
|
||||
return writeToDocument(std::initializer_list{QPair(key, QJsonValue(value))});
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
#ifndef TARIFF_EDITOR_H_INCLUDED
|
||||
#define TARIFF_EDITOR_H_INCLUDED
|
||||
|
||||
#include <QJsonDocument>
|
||||
#include <QString>
|
||||
#include <QJsonObject>
|
||||
|
||||
|
||||
class TariffEditor {
|
||||
QJsonDocument m_doc;
|
||||
|
||||
public:
|
||||
explicit TariffEditor();
|
||||
|
||||
QJsonObject create(QString const &key);
|
||||
QJsonDocument &document() { return m_doc; }
|
||||
QJsonDocument const &document() const { return m_doc; }
|
||||
QJsonDocument &writeToDocument(QString const &key, QString const &value);
|
||||
QJsonDocument &writeToDocument(QJsonObject const &value);
|
||||
};
|
||||
|
||||
#endif // TARIFF_EDITOR_H_INCLUDED
|
@ -8,7 +8,7 @@
|
||||
#include <QJsonValue>
|
||||
|
||||
|
||||
struct Tariff : public QJsonObject {
|
||||
struct TariffTemplate : public QJsonObject {
|
||||
QJsonValue m_project;
|
||||
QJsonValue m_version;
|
||||
QJsonValue m_date;
|
||||
|
Loading…
Reference in New Issue
Block a user