[#34] Second step of not using Bio as Attribute

This commit is contained in:
2024-02-20 16:36:12 +01:00
parent 049927f90c
commit c82e8de724
9 changed files with 140 additions and 77 deletions

View File

@ -7,40 +7,38 @@ namespace Elwig.Helpers.Billing {
public class PaymentBillingData : BillingData {
protected readonly Dictionary<int, Curve> Curves;
protected readonly Dictionary<string, Curve> PaymentData;
protected readonly Dictionary<string, Curve> QualityData;
protected readonly IEnumerable<string> Vaributes;
protected readonly Dictionary<RawVaribute, Curve> PaymentData;
protected readonly Dictionary<RawQualVaribute, Curve> QualityData;
protected readonly IEnumerable<RawVaribute> Vaributes;
public PaymentBillingData(JsonObject data, IEnumerable<string> vaributes) :
public PaymentBillingData(JsonObject data, IEnumerable<RawVaribute> vaributes) :
base(data) {
if (vaributes.Any(e => e.Any(c => c < 'A' || c > 'Z')))
throw new ArgumentException("Invalid vaributes");
Vaributes = vaributes;
Curves = GetCurves();
PaymentData = GetPaymentData();
QualityData = GetQualityData();
}
public static PaymentBillingData FromJson(string json, IEnumerable<string> vaributes) {
public static PaymentBillingData FromJson(string json, IEnumerable<RawVaribute> vaributes) {
return new(ParseJson(json), vaributes);
}
private Dictionary<string, Curve> GetData(JsonNode data) {
private Dictionary<RawVaribute, Curve> GetData(JsonNode data) {
return GetSelection(data, Vaributes).ToDictionary(e => e.Key, e => LookupCurve(e.Value));
}
protected Dictionary<string, Curve> GetPaymentData() {
protected Dictionary<RawVaribute, Curve> GetPaymentData() {
return GetData(GetPaymentEntry());
}
protected Dictionary<string, Curve> GetQualityData() {
Dictionary<string, Curve> dict = [];
protected Dictionary<RawQualVaribute, Curve> GetQualityData() {
Dictionary<RawQualVaribute, Curve> dict = [];
var q = GetQualityEntry();
if (q == null) return dict;
foreach (var (qualid, data) in q) {
foreach (var (idx, d) in GetData(data ?? throw new InvalidOperationException())) {
dict[$"{qualid}/{idx}"] = d;
dict[new(qualid, idx.SortId, idx.AttrId, idx.CultId)] = d;
}
}
@ -63,11 +61,11 @@ namespace Elwig.Helpers.Billing {
}
protected Curve GetCurve(string sortid, string? attrid) {
return PaymentData[$"{sortid}{attrid}"];
return PaymentData[new(sortid, attrid ?? "", null)];
}
protected Curve? GetQualityCurve(string qualid, string sortid, string? attrid) {
return QualityData.TryGetValue($"{qualid}/{sortid}{attrid}", out var curve) ? curve : null;
return QualityData.TryGetValue(new(qualid, sortid, attrid ?? "", null), out var curve) ? curve : null;
}
}
}