diff --git a/Elwig/Helpers/Billing/BillingData.cs b/Elwig/Helpers/Billing/BillingData.cs index 87bc21a..9c16a78 100644 --- a/Elwig/Helpers/Billing/BillingData.cs +++ b/Elwig/Helpers/Billing/BillingData.cs @@ -150,15 +150,15 @@ namespace Elwig.Helpers.Billing { return dict; } - protected static Dictionary GetSelection(JsonNode value, IEnumerable attributeVariants) { + protected static Dictionary GetSelection(JsonNode value, IEnumerable 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 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 attributeVariants) { + protected static void CollapsePaymentData(JsonObject data, IEnumerable vaributes) { Dictionary> rev1 = []; Dictionary> 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 graphEntries, BillingData? origData = null, IEnumerable? attributeVariants = null) { + public static JsonObject FromGraphEntries(IEnumerable graphEntries, BillingData? origData = null, IEnumerable? 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", diff --git a/Elwig/Helpers/Billing/BillingVariant.cs b/Elwig/Helpers/Billing/BillingVariant.cs index c1b8506..b913241 100644 --- a/Elwig/Helpers/Billing/BillingVariant.cs +++ b/Elwig/Helpers/Billing/BillingVariant.cs @@ -15,7 +15,7 @@ namespace Elwig.Helpers.Billing { public BillingVariant(int year, int avnr) : base(year) { AvNr = avnr; PaymentVariant = Context.PaymentVariants.Find(Year, AvNr) ?? throw new ArgumentException("PaymentVar not found"); - Data = PaymentBillingData.FromJson(PaymentVariant.Data, Utils.GetAttributeVarieties(Context, Year, onlyDelivered: false)); + Data = PaymentBillingData.FromJson(PaymentVariant.Data, Utils.GetVaributes(Context, Year, onlyDelivered: false)); } public async Task Calculate() { diff --git a/Elwig/Helpers/Billing/EditBillingData.cs b/Elwig/Helpers/Billing/EditBillingData.cs index cac12e5..5824b56 100644 --- a/Elwig/Helpers/Billing/EditBillingData.cs +++ b/Elwig/Helpers/Billing/EditBillingData.cs @@ -7,15 +7,15 @@ using System.Text.Json.Nodes; namespace Elwig.Helpers.Billing { public class EditBillingData : BillingData { - protected readonly IEnumerable AttributeVariants; + protected readonly IEnumerable Vaributes; - public EditBillingData(JsonObject data, IEnumerable attributeVariants) : + public EditBillingData(JsonObject data, IEnumerable vaributes) : base(data) { - AttributeVariants = attributeVariants; + Vaributes = vaributes; } - public static EditBillingData FromJson(string json, IEnumerable attributeVariants) { - return new(ParseJson(json), attributeVariants); + public static EditBillingData FromJson(string json, IEnumerable vaributes) { + return new(ParseJson(json), vaributes); } private (Dictionary, Dictionary>) GetGraphEntries(JsonNode root) { @@ -56,7 +56,7 @@ namespace Elwig.Helpers.Billing { } Dictionary> dict3 = curves.ToDictionary(c => c.Key, _ => new List()); - foreach (var (selector, value) in GetSelection(root, AttributeVariants)) { + foreach (var (selector, value) in GetSelection(root, Vaributes)) { int? idx = null; if (value.TryGetValue(out var val)) { idx = Array.IndexOf(virtCurves, val) + virtOffset; @@ -75,7 +75,7 @@ namespace Elwig.Helpers.Billing { var attrs = ctx.WineAttributes.ToDictionary(a => a.AttrId, a => a); return entries .Select(e => new GraphEntry(e.Key, precision, curves[e.Key], e.Value - .Select(s => new ContractSelection(vars[s[..2]], s.Length > 2 ? attrs[s[2..]] : null)) + .Select(s => new Varibute(vars[s[..2]], s.Length > 2 ? attrs[s[2..]] : null)) .ToList())) .ToList(); } @@ -83,7 +83,7 @@ namespace Elwig.Helpers.Billing { public IEnumerable GetPaymentGraphEntries(AppDbContext ctx, Season season) { var root = GetPaymentEntry(); var (curves, entries) = GetGraphEntries(root); - return CreateGraphEntries(ctx, season.Precision, curves, entries).Where(e => e.Contracts.Count > 0); + return CreateGraphEntries(ctx, season.Precision, curves, entries).Where(e => e.Vaributes.Count > 0); } public IEnumerable GetQualityGraphEntries(AppDbContext ctx, Season season, int idOffset = 0) { @@ -91,7 +91,7 @@ namespace Elwig.Helpers.Billing { if (root == null || root["WEI"] is not JsonNode qualityWei) return []; var (curves, entries) = GetGraphEntries(qualityWei); - var list = CreateGraphEntries(ctx, season.Precision, curves, entries).Where(e => e.Contracts.Count > 0); + var list = CreateGraphEntries(ctx, season.Precision, curves, entries).Where(e => e.Vaributes.Count > 0); foreach (var e in list) { e.Id += idOffset; e.Abgewertet = true; diff --git a/Elwig/Helpers/Billing/GraphEntry.cs b/Elwig/Helpers/Billing/GraphEntry.cs index e1098a2..1b0bd74 100644 --- a/Elwig/Helpers/Billing/GraphEntry.cs +++ b/Elwig/Helpers/Billing/GraphEntry.cs @@ -36,10 +36,10 @@ namespace Elwig.Helpers.Billing { } } - public List Contracts { get; set; } - public string ContractsStringSimple => (Abgewertet ? "Abgew.: " : "") + (Contracts.Count != 0 ? (Contracts.Count >= 25 ? "Restliche Sorten" : string.Join(", ", Contracts.Select(c => c.Listing))) : "-"); - public string ContractsString => Contracts.Count != 0 ? string.Join("\n", Contracts.Select(c => c.FullName)) : "-"; - public string ContractsStringChange => (Abgewertet ? "A." : "") + string.Join(",", Contracts.Select(c => c.Listing)); + public List Vaributes { get; set; } + public string VaributeStringSimple => (Abgewertet ? "Abgew.: " : "") + (Vaributes.Count != 0 ? (Vaributes.Count >= 25 ? "Restliche Sorten" : string.Join(", ", Vaributes.Select(c => c.Listing))) : "-"); + public string VaributeString => Vaributes.Count != 0 ? string.Join("\n", Vaributes.Select(c => c.FullName)) : "-"; + public string VaributeStringChange => (Abgewertet ? "A." : "") + string.Join(",", Vaributes.Select(c => c.Listing)); private readonly int Precision; public GraphEntry(int id, int precision, BillingData.CurveMode mode) { @@ -47,7 +47,7 @@ namespace Elwig.Helpers.Billing { Precision = precision; Mode = mode; DataGraph = new Graph(precision, MinX, MaxX); ; - Contracts = []; + Vaributes = []; } public GraphEntry(int id, int precision, BillingData.CurveMode mode, Dictionary data, Dictionary? gebunden) : @@ -56,21 +56,21 @@ namespace Elwig.Helpers.Billing { if (gebunden != null) GebundenGraph = new Graph(gebunden, precision, MinXGeb, MaxX); } - public GraphEntry(int id, int precision, BillingData.Curve curve, List contracts) : + public GraphEntry(int id, int precision, BillingData.Curve curve, List vaributes) : this(id, precision, curve.Mode) { DataGraph = new Graph(curve.Normal, precision, MinX, MaxX); if (curve.Gebunden != null) GebundenGraph = new Graph(curve.Gebunden, precision, MinXGeb, MaxX); - Contracts = contracts; + Vaributes = vaributes; } - private GraphEntry(int id, int precision, BillingData.CurveMode mode, Graph dataGraph, Graph? gebundenGraph, List contracts) { + private GraphEntry(int id, int precision, BillingData.CurveMode mode, Graph dataGraph, Graph? gebundenGraph, List vaributes) { Id = id; Precision = precision; Mode = mode; DataGraph = dataGraph; GebundenGraph = gebundenGraph; - Contracts = contracts; + Vaributes = vaributes; } public void AddGebundenGraph() { diff --git a/Elwig/Helpers/Billing/PaymentBillingData.cs b/Elwig/Helpers/Billing/PaymentBillingData.cs index b906408..ba33ed1 100644 --- a/Elwig/Helpers/Billing/PaymentBillingData.cs +++ b/Elwig/Helpers/Billing/PaymentBillingData.cs @@ -9,24 +9,24 @@ namespace Elwig.Helpers.Billing { protected readonly Dictionary Curves; protected readonly Dictionary PaymentData; protected readonly Dictionary QualityData; - protected readonly IEnumerable AttributeVariants; + protected readonly IEnumerable Vaributes; - public PaymentBillingData(JsonObject data, IEnumerable attributeVariants) : + public PaymentBillingData(JsonObject data, IEnumerable vaributes) : base(data) { - if (attributeVariants.Any(e => e.Any(c => c < 'A' || c > 'Z'))) - throw new ArgumentException("Invalid attributeVariants"); - AttributeVariants = attributeVariants; + 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 attributeVariants) { - return new(ParseJson(json), attributeVariants); + public static PaymentBillingData FromJson(string json, IEnumerable vaributes) { + return new(ParseJson(json), vaributes); } private Dictionary GetData(JsonNode data) { - return GetSelection(data, AttributeVariants).ToDictionary(e => e.Key, e => LookupCurve(e.Value)); + return GetSelection(data, Vaributes).ToDictionary(e => e.Key, e => LookupCurve(e.Value)); } protected Dictionary GetPaymentData() { diff --git a/Elwig/Helpers/Billing/ContractSelection.cs b/Elwig/Helpers/Billing/Varibute.cs similarity index 75% rename from Elwig/Helpers/Billing/ContractSelection.cs rename to Elwig/Helpers/Billing/Varibute.cs index 8479958..d75326c 100644 --- a/Elwig/Helpers/Billing/ContractSelection.cs +++ b/Elwig/Helpers/Billing/Varibute.cs @@ -2,14 +2,14 @@ using System; namespace Elwig.Helpers.Billing { - public class ContractSelection : IComparable { + public class Varibute : IComparable { public WineVar? Variety { get; } public WineAttr? Attribute { get; } public string Listing => $"{Variety?.SortId}{Attribute?.AttrId}"; public string FullName => $"{Variety?.Name}" + (Variety != null && Attribute != null ? " " : "") + $"{Attribute?.Name}"; - public ContractSelection(WineVar? var, WineAttr? attr) { + public Varibute(WineVar? var, WineAttr? attr) { Variety = var; Attribute = attr; } @@ -18,7 +18,7 @@ namespace Elwig.Helpers.Billing { return Listing; } - public int CompareTo(ContractSelection? other) { + public int CompareTo(Varibute? other) { return Listing.CompareTo(other?.Listing); } } diff --git a/Elwig/Helpers/Utils.cs b/Elwig/Helpers/Utils.cs index b4107e7..84bf92a 100644 --- a/Elwig/Helpers/Utils.cs +++ b/Elwig/Helpers/Utils.cs @@ -362,7 +362,7 @@ namespace Elwig.Helpers { return output.OrderByDescending(l => l.Count()); } - public static List GetAttributeVarieties(AppDbContext ctx, int year, bool withSlash = false, bool onlyDelivered = true) { + public static List GetVaributes(AppDbContext ctx, int year, bool withSlash = false, bool onlyDelivered = true) { var varieties = ctx.WineVarieties.Select(v => v.SortId).ToList(); var delivered = ctx.DeliveryParts .Where(d => d.Year == year) @@ -372,11 +372,11 @@ namespace Elwig.Helpers { return [.. (onlyDelivered ? delivered : delivered.Union(varieties)).Order()]; } - public static List GetContractsForYear(AppDbContext ctx, int year, bool onlyDelivered = true) { + public static List GetVaributesForYear(AppDbContext ctx, int year, bool onlyDelivered = true) { var varieties = ctx.WineVarieties.ToDictionary(v => v.SortId, v => v); var attributes = ctx.WineAttributes.ToDictionary(a => a.AttrId, a => a); - return GetAttributeVarieties(ctx, year, false, onlyDelivered) - .Select(s => new ContractSelection(varieties[s[..2]], s.Length > 2 ? attributes[s[2..]] : null)) + return GetVaributes(ctx, year, false, onlyDelivered) + .Select(s => new Varibute(varieties[s[..2]], s.Length > 2 ? attributes[s[2..]] : null)) .ToList(); } } diff --git a/Elwig/Windows/ChartWindow.xaml b/Elwig/Windows/ChartWindow.xaml index 7e2eeda..0118912 100644 --- a/Elwig/Windows/ChartWindow.xaml +++ b/Elwig/Windows/ChartWindow.xaml @@ -61,8 +61,8 @@