Billing: Rename attributeVariants and contracts to vaributes
This commit is contained in:
@ -150,15 +150,15 @@ namespace Elwig.Helpers.Billing {
|
||||
return dict;
|
||||
}
|
||||
|
||||
protected static Dictionary<string, JsonValue> GetSelection(JsonNode value, IEnumerable<string> attributeVariants) {
|
||||
protected static Dictionary<string, JsonValue> GetSelection(JsonNode value, IEnumerable<string> vaributes) {
|
||||
if (value is JsonValue flatRate) {
|
||||
return attributeVariants.ToDictionary(e => e, _ => flatRate);
|
||||
return vaributes.ToDictionary(e => e, _ => flatRate);
|
||||
} if (value is not JsonObject data) {
|
||||
throw new InvalidOperationException();
|
||||
}
|
||||
Dictionary<string, JsonValue> dict;
|
||||
if (data["default"] is JsonValue def) {
|
||||
dict = attributeVariants.ToDictionary(e => e, _ => def);
|
||||
dict = vaributes.ToDictionary(e => e, _ => def);
|
||||
} else {
|
||||
dict = [];
|
||||
}
|
||||
@ -168,13 +168,13 @@ namespace Elwig.Helpers.Billing {
|
||||
var others = data.Where(p => !p.Key.StartsWith('/') && p.Key.Length > 2 && p.Key != "default");
|
||||
foreach (var (idx, v) in variants) {
|
||||
var curve = v?.AsValue() ?? throw new InvalidOperationException();
|
||||
foreach (var i in attributeVariants.Where(e => e.StartsWith(idx[..^1]))) {
|
||||
foreach (var i in vaributes.Where(e => e.StartsWith(idx[..^1]))) {
|
||||
dict[i] = curve;
|
||||
}
|
||||
}
|
||||
foreach (var (idx, v) in attributes) {
|
||||
var curve = v?.AsValue() ?? throw new InvalidOperationException();
|
||||
foreach (var i in attributeVariants.Where(e => e[2..] == idx[1..])) {
|
||||
foreach (var i in vaributes.Where(e => e[2..] == idx[1..])) {
|
||||
dict[i] = curve;
|
||||
}
|
||||
}
|
||||
@ -257,7 +257,7 @@ namespace Elwig.Helpers.Billing {
|
||||
return curve;
|
||||
}
|
||||
|
||||
protected static void CollapsePaymentData(JsonObject data, IEnumerable<string> attributeVariants) {
|
||||
protected static void CollapsePaymentData(JsonObject data, IEnumerable<string> vaributes) {
|
||||
Dictionary<string, List<string>> rev1 = [];
|
||||
Dictionary<decimal, List<string>> rev2 = [];
|
||||
foreach (var (k, v) in data) {
|
||||
@ -273,18 +273,18 @@ namespace Elwig.Helpers.Billing {
|
||||
}
|
||||
if (!data.ContainsKey("default")) {
|
||||
foreach (var (v, ks) in rev1) {
|
||||
if (ks.Count >= attributeVariants.Count() / 2.0) {
|
||||
if (ks.Count >= vaributes.Count() / 2.0) {
|
||||
foreach (var k in ks) data.Remove(k);
|
||||
data["default"] = v;
|
||||
CollapsePaymentData(data, attributeVariants);
|
||||
CollapsePaymentData(data, vaributes);
|
||||
return;
|
||||
}
|
||||
}
|
||||
foreach (var (v, ks) in rev2) {
|
||||
if (ks.Count >= attributeVariants.Count() / 2.0) {
|
||||
if (ks.Count >= vaributes.Count() / 2.0) {
|
||||
foreach (var k in ks) data.Remove(k);
|
||||
data["default"] = v;
|
||||
CollapsePaymentData(data, attributeVariants);
|
||||
CollapsePaymentData(data, vaributes);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -296,7 +296,7 @@ namespace Elwig.Helpers.Billing {
|
||||
.Distinct()
|
||||
.ToList();
|
||||
foreach (var idx in attributes) {
|
||||
var len = attributeVariants.Count(e => e.EndsWith(idx));
|
||||
var len = vaributes.Count(e => e.EndsWith(idx));
|
||||
foreach (var (v, ks) in rev1) {
|
||||
var myKs = ks.Where(k => k.EndsWith(idx)).ToList();
|
||||
if (myKs.Count > 1 && myKs.Count >= len / 2.0) {
|
||||
@ -314,7 +314,7 @@ namespace Elwig.Helpers.Billing {
|
||||
}
|
||||
}
|
||||
|
||||
public static JsonObject FromGraphEntries(IEnumerable<GraphEntry> graphEntries, BillingData? origData = null, IEnumerable<string>? attributeVariants = null) {
|
||||
public static JsonObject FromGraphEntries(IEnumerable<GraphEntry> graphEntries, BillingData? origData = null, IEnumerable<string>? vaributes = null) {
|
||||
var payment = new JsonObject();
|
||||
var qualityWei = new JsonObject();
|
||||
var curves = new JsonArray();
|
||||
@ -331,7 +331,7 @@ namespace Elwig.Helpers.Billing {
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
foreach (var c in entry.Contracts) {
|
||||
foreach (var c in entry.Vaributes) {
|
||||
if (entry.Abgewertet) {
|
||||
qualityWei[$"{c.Variety?.SortId}/{c.Attribute?.AttrId}"] = node.DeepClone();
|
||||
} else {
|
||||
@ -340,8 +340,8 @@ namespace Elwig.Helpers.Billing {
|
||||
}
|
||||
}
|
||||
|
||||
CollapsePaymentData(payment, attributeVariants ?? payment.Select(e => e.Key).ToList());
|
||||
CollapsePaymentData(qualityWei, attributeVariants ?? qualityWei.Select(e => e.Key).ToList());
|
||||
CollapsePaymentData(payment, vaributes ?? payment.Select(e => e.Key).ToList());
|
||||
CollapsePaymentData(qualityWei, vaributes ?? qualityWei.Select(e => e.Key).ToList());
|
||||
|
||||
var data = new JsonObject {
|
||||
["mode"] = "elwig",
|
||||
|
Reference in New Issue
Block a user