From 09e55264bb63ffbbb5b81ee1fe47b8357ca94712 Mon Sep 17 00:00:00 2001 From: Lorenz Stechauner Date: Mon, 8 Jan 2024 19:31:13 +0100 Subject: [PATCH] BillingData: Implement WG Master parsing --- Elwig/Helpers/Billing/BillingData.cs | 12 +- .../Resources/Schemas/PaymentVariantData.json | 113 +++++++----------- Tests/Helpers/BillingDataTest.cs | 44 +++++++ 3 files changed, 90 insertions(+), 79 deletions(-) diff --git a/Elwig/Helpers/Billing/BillingData.cs b/Elwig/Helpers/Billing/BillingData.cs index 91e1ada..02cfc8d 100644 --- a/Elwig/Helpers/Billing/BillingData.cs +++ b/Elwig/Helpers/Billing/BillingData.cs @@ -35,7 +35,7 @@ namespace Elwig.Helpers.Billing { Data = data; var mode = Data["mode"]?.GetValue(); Mode = (mode == "elwig") ? CalculationMode.Elwig : CalculationMode.WgMaster; - Curves = GetCurves(data); + Curves = GetCurves(Data, Mode); PaymentData = GetPaymentData(attributeVariants); QualityData = GetQualityData(attributeVariants); } @@ -83,9 +83,9 @@ namespace Elwig.Helpers.Billing { return dict; } - public static Dictionary GetCurves(JsonObject data) { + public static Dictionary GetCurves(JsonObject data, CalculationMode mode) { var dict = new Dictionary(); - var curves = data["curves"]?.AsArray() ?? throw new InvalidOperationException(); + var curves = data[mode == CalculationMode.Elwig ? "curves" : "Kurven"]?.AsArray() ?? throw new InvalidOperationException(); foreach (var c in curves) { var obj = c?.AsObject() ?? throw new InvalidOperationException(); var id = obj["id"]?.GetValue() ?? throw new InvalidOperationException(); @@ -145,8 +145,7 @@ namespace Elwig.Helpers.Billing { } public Dictionary GetPaymentData(IEnumerable attributeVariants) { - // TODO parse wgmaster - var p = Data["payment"]; + var p = Data[Mode == CalculationMode.Elwig ? "payment" : "AuszahlungSorten"]; if (p is JsonValue val) { var c = LookupCurve(val); return attributeVariants.ToDictionary(e => e, _ => c); @@ -155,8 +154,7 @@ namespace Elwig.Helpers.Billing { } public Dictionary GetQualityData(IEnumerable attributeVariants) { - // TODO parse wgmaster - var q = Data["quality"]?.AsObject(); + var q = Data[Mode == CalculationMode.Elwig ? "quality" : "AuszahlungSortenQualitätsstufe"]?.AsObject(); Dictionary dict = []; if (q == null) return dict; diff --git a/Elwig/Resources/Schemas/PaymentVariantData.json b/Elwig/Resources/Schemas/PaymentVariantData.json index 08eecfb..3deabd0 100644 --- a/Elwig/Resources/Schemas/PaymentVariantData.json +++ b/Elwig/Resources/Schemas/PaymentVariantData.json @@ -8,25 +8,45 @@ "properties": { "mode": {"enum": ["elwig"]}, "version": {"enum": [1]}, - "payment": { - "type": ["number", "string", "object"], - "pattern": "^curve:[0-9]+$", - "additionalProperties": false, - "properties": { - "default": { - "type": ["number", "string"], - "pattern": "^curve:[0-9]+$" - } - }, - "patternProperties": { - "^([A-Z]{2})?(\/[A-Z]*)?$": { - "type": ["number", "string"], - "pattern": "^curve:[0-9]+$" - } + "payment": {"$ref": "#/definitions/payment_1"}, + "quality": {"$ref": "#/definitions/quality_1"}, + "curves": { + "type": "array", + "items": {"$ref": "#/definitions/curve"} + } + } + }, { + "required": ["AuszahlungSorten", "Kurven"], + "properties": { + "mode": {"enum": ["wgmaster"]}, + "AuszahlungSorten": {"$ref": "#/definitions/payment_1"}, + "AuszahlungSortenQualitätsstufe": {"$ref": "#/definitions/quality_1"}, + "Kurven": { + "type": "array", + "items": {"$ref": "#/definitions/curve"} + } + } + }], + "definitions": { + "payment_1": { + "type": ["number", "string", "object"], + "pattern": "^curve:[0-9]+$", + "additionalProperties": false, + "properties": { + "default": { + "type": ["number", "string"], + "pattern": "^curve:[0-9]+$" } }, - "quality": { - "type": "object", + "patternProperties": { + "^([A-Z]{2})?(\/[A-Z]*)?$": { + "type": ["number", "string"], + "pattern": "^curve:[0-9]+$" + } + } + }, + "quality_1": { + "type": "object", "additionalProperties": false, "patternProperties": { "^[A-Z]{3}$": { @@ -47,58 +67,7 @@ } } } - }, - "curves": { - "type": "array", - "items": {"$ref": "#/definitions/curve"} - } - } - }, { - "properties": { - "mode": {"enum": ["wgmaster"]}, - "AuszahlungSorten": { - "type": "object", - "additionalProperties": false, - "required": ["Kurven"], - "properties": { - "Kurven": { - "type": "array", - "items": { - "type": "object", - "additionalProperties": false, - "minProperties": 1, - "patternProperties": { - "^[0-9]+(\\.[0-9]+)?oe$": {"type": "number"} - } - } - } - }, - "patternProperties": { - "^[A-Z]{2}$": { - "type": "object", - "additionalProperties": false, - "patternProperties": { - "^[A-Z]*$": { - "type": "object", - "additionalProperties": false, - "properties": { - "Gebunden": { - "type": "integer", - "minimum": 0 - }, - "NichtGebunden": { - "type": "integer", - "minimum": 0 - } - } - } - } - } - } - } - } - }], - "definitions": { + }, "curve": { "type": "object", "required": ["id", "mode", "data"], @@ -111,15 +80,15 @@ "mode": {"enum": ["oe", "kmw"]}, "data": { "anyOf": [ - {"type": "number" }, + {"type": "number"}, {"$ref": "#/definitions/curve_data"} - ] + ] }, "geb": { "anyOf": [ {"type": "number"}, {"$ref": "#/definitions/curve_data"} - ] + ] } } }, diff --git a/Tests/Helpers/BillingDataTest.cs b/Tests/Helpers/BillingDataTest.cs index f8a317d..79f260e 100644 --- a/Tests/Helpers/BillingDataTest.cs +++ b/Tests/Helpers/BillingDataTest.cs @@ -301,5 +301,49 @@ namespace Tests.Helpers { TestCalcKmw(data, "WRS", 17.0, 0.95m, geb: true); }); } + + [Test] + public void Test_08_WgMaster() { + var data = BillingData.FromJson(""" + { + "mode": "wgmaster", + "Grundbetrag": 0.033, + "GBZS": 0.0, + "Ausgabefaktor": 1.0, + "Rebelzuschlag": 0.0, + "AufschlagVolllieferanten": 0.0, + "AuszahlungSorten": { + "BL/": 0.097, + "BP/": 0.097, + "GV/K": "curve:1", + "SL/": 0.097, + "ZW/": 0.097, + "default": "curve:0" + }, + "AuszahlungSortenQualitätsstufe": { + "WEI": 0.005 + }, + "Kurven": [{ + "id": 0, + "mode": "oe", + "data": 0.033, + "geb": 0 + }, { + "id": 1, + "mode": "oe", + "data": { + "88oe": 0.032, + "89oe": 0.065 + } + }] + } + """, AttributeVariants); + Assert.Multiple(() => { + TestCalcOe(data, "GVK", 73, 0.032m); + TestCalcOe(data, "ZWS", 74, 0.033m); + TestCalcOe(data, "GV", 75, 0.005m, qualid: "WEI"); + TestCalcOe(data, "GVK", 115, 0.065m); + }); + } } }