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",
|
||||
|
@ -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() {
|
||||
|
@ -7,15 +7,15 @@ using System.Text.Json.Nodes;
|
||||
namespace Elwig.Helpers.Billing {
|
||||
public class EditBillingData : BillingData {
|
||||
|
||||
protected readonly IEnumerable<string> AttributeVariants;
|
||||
protected readonly IEnumerable<string> Vaributes;
|
||||
|
||||
public EditBillingData(JsonObject data, IEnumerable<string> attributeVariants) :
|
||||
public EditBillingData(JsonObject data, IEnumerable<string> vaributes) :
|
||||
base(data) {
|
||||
AttributeVariants = attributeVariants;
|
||||
Vaributes = vaributes;
|
||||
}
|
||||
|
||||
public static EditBillingData FromJson(string json, IEnumerable<string> attributeVariants) {
|
||||
return new(ParseJson(json), attributeVariants);
|
||||
public static EditBillingData FromJson(string json, IEnumerable<string> vaributes) {
|
||||
return new(ParseJson(json), vaributes);
|
||||
}
|
||||
|
||||
private (Dictionary<int, Curve>, Dictionary<int, List<string>>) GetGraphEntries(JsonNode root) {
|
||||
@ -56,7 +56,7 @@ namespace Elwig.Helpers.Billing {
|
||||
}
|
||||
|
||||
Dictionary<int, List<string>> dict3 = curves.ToDictionary(c => c.Key, _ => new List<string>());
|
||||
foreach (var (selector, value) in GetSelection(root, AttributeVariants)) {
|
||||
foreach (var (selector, value) in GetSelection(root, Vaributes)) {
|
||||
int? idx = null;
|
||||
if (value.TryGetValue<decimal>(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<GraphEntry> 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<GraphEntry> 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;
|
||||
|
@ -36,10 +36,10 @@ namespace Elwig.Helpers.Billing {
|
||||
}
|
||||
}
|
||||
|
||||
public List<ContractSelection> 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<Varibute> 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<double, decimal> data, Dictionary<double, decimal>? 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<ContractSelection> contracts) :
|
||||
public GraphEntry(int id, int precision, BillingData.Curve curve, List<Varibute> 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<ContractSelection> contracts) {
|
||||
private GraphEntry(int id, int precision, BillingData.CurveMode mode, Graph dataGraph, Graph? gebundenGraph, List<Varibute> vaributes) {
|
||||
Id = id;
|
||||
Precision = precision;
|
||||
Mode = mode;
|
||||
DataGraph = dataGraph;
|
||||
GebundenGraph = gebundenGraph;
|
||||
Contracts = contracts;
|
||||
Vaributes = vaributes;
|
||||
}
|
||||
|
||||
public void AddGebundenGraph() {
|
||||
|
@ -9,24 +9,24 @@ namespace Elwig.Helpers.Billing {
|
||||
protected readonly Dictionary<int, Curve> Curves;
|
||||
protected readonly Dictionary<string, Curve> PaymentData;
|
||||
protected readonly Dictionary<string, Curve> QualityData;
|
||||
protected readonly IEnumerable<string> AttributeVariants;
|
||||
protected readonly IEnumerable<string> Vaributes;
|
||||
|
||||
public PaymentBillingData(JsonObject data, IEnumerable<string> attributeVariants) :
|
||||
public PaymentBillingData(JsonObject data, IEnumerable<string> 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<string> attributeVariants) {
|
||||
return new(ParseJson(json), attributeVariants);
|
||||
public static PaymentBillingData FromJson(string json, IEnumerable<string> vaributes) {
|
||||
return new(ParseJson(json), vaributes);
|
||||
}
|
||||
|
||||
private Dictionary<string, Curve> 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<string, Curve> GetPaymentData() {
|
||||
|
@ -2,14 +2,14 @@
|
||||
using System;
|
||||
|
||||
namespace Elwig.Helpers.Billing {
|
||||
public class ContractSelection : IComparable<ContractSelection> {
|
||||
public class Varibute : IComparable<Varibute> {
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
@ -362,7 +362,7 @@ namespace Elwig.Helpers {
|
||||
return output.OrderByDescending(l => l.Count());
|
||||
}
|
||||
|
||||
public static List<string> GetAttributeVarieties(AppDbContext ctx, int year, bool withSlash = false, bool onlyDelivered = true) {
|
||||
public static List<string> 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<ContractSelection> GetContractsForYear(AppDbContext ctx, int year, bool onlyDelivered = true) {
|
||||
public static List<Varibute> 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();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user