ChartWindow: Load GraphEntries correctly from EditBillingData
This commit is contained in:
@ -1,4 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text.Json.Nodes;
|
||||
|
||||
@ -16,7 +17,7 @@ namespace Elwig.Helpers.Billing {
|
||||
return new(ParseJson(json), attributeVariants);
|
||||
}
|
||||
|
||||
public IEnumerable<GraphEntry> GetPaymentGraphEntries() {
|
||||
public IEnumerable<GraphEntry> GetPaymentGraphEntries(AppDbContext context) {
|
||||
Dictionary<int, List<string>> dict1 = [];
|
||||
Dictionary<decimal, List<string>> dict2 = [];
|
||||
var p = GetPaymentEntry();
|
||||
@ -40,22 +41,38 @@ namespace Elwig.Helpers.Billing {
|
||||
dict2[idx].Add("default");
|
||||
}
|
||||
|
||||
var virtOffset = dict1.Count;
|
||||
Dictionary<int, Curve> curves = GetCurves();
|
||||
decimal[] virtCurves = [.. dict2.Keys.Order()];
|
||||
for (int i = 0; i < virtCurves.Length; i++) {
|
||||
var idx = virtCurves[i];
|
||||
dict1[1000 + i] = dict2[idx];
|
||||
curves[1000 + i] = new Curve(CurveMode.Oe, new() { { 73, idx } }, null);
|
||||
dict1[i + virtOffset] = dict2[idx];
|
||||
curves[i + virtOffset] = new Curve(CurveMode.Oe, new() { { 73, idx } }, null);
|
||||
}
|
||||
|
||||
Dictionary<int, List<string>> dict3 = [];
|
||||
Dictionary<int, List<string>> dict3 = curves.ToDictionary(c => c.Key, _ => new List<string>());
|
||||
foreach (var (selector, value) in GetSelection(p, AttributeVariants)) {
|
||||
int? idx = null;
|
||||
if (value.TryGetValue<decimal>(out var val)) {
|
||||
idx = Array.IndexOf(virtCurves, val) + virtOffset;
|
||||
} else if (value.TryGetValue<string>(out var str)) {
|
||||
idx = int.Parse(str.Split(":")[1]);
|
||||
}
|
||||
if (idx != null)
|
||||
dict3[(int)idx].Add(selector);
|
||||
}
|
||||
|
||||
var vars = context.WineVarieties.ToDictionary(v => v.SortId, v => v);
|
||||
var attrs = context.WineAttributes.ToDictionary(a => a.AttrId, a => a);
|
||||
|
||||
|
||||
return dict3.Select(e => new GraphEntry(e.Key, curves[e.Key], 50, 120)).ToList();
|
||||
return dict3
|
||||
.Select(e => new GraphEntry(e.Key, curves[e.Key], e.Value
|
||||
.Select(s => new ContractSelection(vars[s[..2]], s.Length > 2 ? attrs[s[2..]] : null))
|
||||
.ToList(), 50, 120))
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public IEnumerable<GraphEntry> GetQualityGraphEntries() {
|
||||
public IEnumerable<GraphEntry> GetQualityGraphEntries(AppDbContext context) {
|
||||
Dictionary<int, List<string>> dict1 = [];
|
||||
Dictionary<decimal, List<string>> dict2 = [];
|
||||
foreach (var (qualid, q) in GetQualityEntry() ?? []) {
|
||||
|
Reference in New Issue
Block a user