BillingData: Implement WG Master parsing

This commit is contained in:
2024-01-08 19:31:13 +01:00
parent f894c3b212
commit 09e55264bb
3 changed files with 90 additions and 79 deletions

View File

@ -35,7 +35,7 @@ namespace Elwig.Helpers.Billing {
Data = data; Data = data;
var mode = Data["mode"]?.GetValue<string>(); var mode = Data["mode"]?.GetValue<string>();
Mode = (mode == "elwig") ? CalculationMode.Elwig : CalculationMode.WgMaster; Mode = (mode == "elwig") ? CalculationMode.Elwig : CalculationMode.WgMaster;
Curves = GetCurves(data); Curves = GetCurves(Data, Mode);
PaymentData = GetPaymentData(attributeVariants); PaymentData = GetPaymentData(attributeVariants);
QualityData = GetQualityData(attributeVariants); QualityData = GetQualityData(attributeVariants);
} }
@ -83,9 +83,9 @@ namespace Elwig.Helpers.Billing {
return dict; return dict;
} }
public static Dictionary<int, Curve> GetCurves(JsonObject data) { public static Dictionary<int, Curve> GetCurves(JsonObject data, CalculationMode mode) {
var dict = new Dictionary<int, Curve>(); var dict = new Dictionary<int, Curve>();
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) { foreach (var c in curves) {
var obj = c?.AsObject() ?? throw new InvalidOperationException(); var obj = c?.AsObject() ?? throw new InvalidOperationException();
var id = obj["id"]?.GetValue<int>() ?? throw new InvalidOperationException(); var id = obj["id"]?.GetValue<int>() ?? throw new InvalidOperationException();
@ -145,8 +145,7 @@ namespace Elwig.Helpers.Billing {
} }
public Dictionary<string, Curve> GetPaymentData(IEnumerable<string> attributeVariants) { public Dictionary<string, Curve> GetPaymentData(IEnumerable<string> attributeVariants) {
// TODO parse wgmaster var p = Data[Mode == CalculationMode.Elwig ? "payment" : "AuszahlungSorten"];
var p = Data["payment"];
if (p is JsonValue val) { if (p is JsonValue val) {
var c = LookupCurve(val); var c = LookupCurve(val);
return attributeVariants.ToDictionary(e => e, _ => c); return attributeVariants.ToDictionary(e => e, _ => c);
@ -155,8 +154,7 @@ namespace Elwig.Helpers.Billing {
} }
public Dictionary<string, Curve> GetQualityData(IEnumerable<string> attributeVariants) { public Dictionary<string, Curve> GetQualityData(IEnumerable<string> attributeVariants) {
// TODO parse wgmaster var q = Data[Mode == CalculationMode.Elwig ? "quality" : "AuszahlungSortenQualitätsstufe"]?.AsObject();
var q = Data["quality"]?.AsObject();
Dictionary<string, Curve> dict = []; Dictionary<string, Curve> dict = [];
if (q == null) return dict; if (q == null) return dict;

View File

@ -8,25 +8,45 @@
"properties": { "properties": {
"mode": {"enum": ["elwig"]}, "mode": {"enum": ["elwig"]},
"version": {"enum": [1]}, "version": {"enum": [1]},
"payment": { "payment": {"$ref": "#/definitions/payment_1"},
"type": ["number", "string", "object"], "quality": {"$ref": "#/definitions/quality_1"},
"pattern": "^curve:[0-9]+$", "curves": {
"additionalProperties": false, "type": "array",
"properties": { "items": {"$ref": "#/definitions/curve"}
"default": { }
"type": ["number", "string"], }
"pattern": "^curve:[0-9]+$" }, {
} "required": ["AuszahlungSorten", "Kurven"],
}, "properties": {
"patternProperties": { "mode": {"enum": ["wgmaster"]},
"^([A-Z]{2})?(\/[A-Z]*)?$": { "AuszahlungSorten": {"$ref": "#/definitions/payment_1"},
"type": ["number", "string"], "AuszahlungSortenQualitätsstufe": {"$ref": "#/definitions/quality_1"},
"pattern": "^curve:[0-9]+$" "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": { "patternProperties": {
"type": "object", "^([A-Z]{2})?(\/[A-Z]*)?$": {
"type": ["number", "string"],
"pattern": "^curve:[0-9]+$"
}
}
},
"quality_1": {
"type": "object",
"additionalProperties": false, "additionalProperties": false,
"patternProperties": { "patternProperties": {
"^[A-Z]{3}$": { "^[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": { "curve": {
"type": "object", "type": "object",
"required": ["id", "mode", "data"], "required": ["id", "mode", "data"],
@ -111,15 +80,15 @@
"mode": {"enum": ["oe", "kmw"]}, "mode": {"enum": ["oe", "kmw"]},
"data": { "data": {
"anyOf": [ "anyOf": [
{"type": "number" }, {"type": "number"},
{"$ref": "#/definitions/curve_data"} {"$ref": "#/definitions/curve_data"}
] ]
}, },
"geb": { "geb": {
"anyOf": [ "anyOf": [
{"type": "number"}, {"type": "number"},
{"$ref": "#/definitions/curve_data"} {"$ref": "#/definitions/curve_data"}
] ]
} }
} }
}, },

View File

@ -301,5 +301,49 @@ namespace Tests.Helpers {
TestCalcKmw(data, "WRS", 17.0, 0.95m, geb: true); 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);
});
}
} }
} }