diff --git a/Elwig/Helpers/Billing/BillingData.cs b/Elwig/Helpers/Billing/BillingData.cs index 61fcfb1..4bd0f6b 100644 --- a/Elwig/Helpers/Billing/BillingData.cs +++ b/Elwig/Helpers/Billing/BillingData.cs @@ -257,7 +257,7 @@ namespace Elwig.Helpers.Billing { return curve; } - protected static void CollapsePaymentData(JsonObject data, IEnumerable vaributes) { + protected static void CollapsePaymentData(JsonObject data, IEnumerable vaributes, bool useDefault = true) { 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 >= vaributes.Count() / 2.0) { + if ((ks.Count >= vaributes.Count() * 0.5 && useDefault) || ks.Count == vaributes.Count()) { foreach (var k in ks) data.Remove(k); data["default"] = v; - CollapsePaymentData(data, vaributes); + CollapsePaymentData(data, vaributes, useDefault); return; } } foreach (var (v, ks) in rev2) { - if (ks.Count >= vaributes.Count() / 2.0) { + if ((ks.Count >= vaributes.Count() * 0.5 && useDefault) || ks.Count == vaributes.Count()) { foreach (var k in ks) data.Remove(k); data["default"] = v; - CollapsePaymentData(data, vaributes); + CollapsePaymentData(data, vaributes, useDefault); return; } } @@ -299,14 +299,14 @@ namespace Elwig.Helpers.Billing { 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) { + if (myKs.Count > 1 && ((myKs.Count >= len * 0.5 && useDefault) || myKs.Count == len)) { foreach (var k in myKs) data.Remove(k); data[idx] = v; } } foreach (var (v, ks) in rev2) { var myKs = ks.Where(k => k.EndsWith(idx)).ToList(); - if (myKs.Count > 1 && myKs.Count >= len / 2.0) { + if (myKs.Count > 1 && ((myKs.Count >= len * 0.5 && useDefault) || myKs.Count == len)) { foreach (var k in myKs) data.Remove(k); data[idx] = v; } @@ -314,7 +314,13 @@ namespace Elwig.Helpers.Billing { } } - public static JsonObject FromGraphEntries(IEnumerable graphEntries, BillingData? origData = null, IEnumerable? vaributes = null) { + public static JsonObject FromGraphEntries( + IEnumerable graphEntries, + BillingData? origData = null, + IEnumerable? vaributes = null, + bool useDefaultPayment = true, + bool useDefaultQuality = true + ) { var payment = new JsonObject(); var qualityWei = new JsonObject(); var curves = new JsonArray(); @@ -340,8 +346,8 @@ namespace Elwig.Helpers.Billing { } } - CollapsePaymentData(payment, vaributes ?? payment.Select(e => e.Key).ToList()); - CollapsePaymentData(qualityWei, vaributes ?? qualityWei.Select(e => e.Key).ToList()); + CollapsePaymentData(payment, vaributes ?? payment.Select(e => e.Key).ToList(), useDefaultPayment); + CollapsePaymentData(qualityWei, vaributes ?? qualityWei.Select(e => e.Key).ToList(), useDefaultQuality); var data = new JsonObject { ["mode"] = "elwig", @@ -359,16 +365,16 @@ namespace Elwig.Helpers.Billing { if (payment.Count == 0) { data["payment"] = 0; - } else if (payment.Count == 1) { + } else if (payment.Count == 1 && payment.First().Key == "default") { data["payment"] = payment.Single().Value?.DeepClone(); } else { data["payment"] = payment; } - if (qualityWei.Count == 1) { + if (qualityWei.Count == 1 && qualityWei.First().Key == "default") { data["quality"] = new JsonObject() { ["WEI"] = qualityWei.Single().Value?.DeepClone() }; - } else if (qualityWei.Count > 1) { + } else if (qualityWei.Count >= 1) { data["quality"] = new JsonObject() { ["WEI"] = qualityWei }; diff --git a/Elwig/Helpers/Billing/Varibute.cs b/Elwig/Helpers/Billing/Varibute.cs index 670a47e..7cfe8c0 100644 --- a/Elwig/Helpers/Billing/Varibute.cs +++ b/Elwig/Helpers/Billing/Varibute.cs @@ -4,8 +4,11 @@ using System; namespace Elwig.Helpers.Billing { public class Varibute : IComparable { - public readonly WineVar? Variety; - public readonly WineAttr? Attribute; + public WineVar? Variety { get; } + public WineAttr? Attribute { get; } + public int? AssignedGraphId { get; set; } + public int? AssignedAbgewGraphId { get; set; } + public string Listing => $"{Variety?.SortId}{Attribute?.AttrId}"; public string FullName => $"{Variety?.Name}" + (Variety != null && Attribute != null ? " " : "") + $"{Attribute?.Name}"; diff --git a/Elwig/Helpers/Utils.cs b/Elwig/Helpers/Utils.cs index 84bf92a..9f15a60 100644 --- a/Elwig/Helpers/Utils.cs +++ b/Elwig/Helpers/Utils.cs @@ -372,7 +372,7 @@ namespace Elwig.Helpers { return [.. (onlyDelivered ? delivered : delivered.Union(varieties)).Order()]; } - public static List GetVaributesForYear(AppDbContext ctx, int year, bool onlyDelivered = true) { + public static List GetVaributeList(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 GetVaributes(ctx, year, false, onlyDelivered) diff --git a/Elwig/Windows/ChartWindow.xaml b/Elwig/Windows/ChartWindow.xaml index 0118912..cd51090 100644 --- a/Elwig/Windows/ChartWindow.xaml +++ b/Elwig/Windows/ChartWindow.xaml @@ -61,14 +61,17 @@