BillingData: Implement GetQualtyGraphEntries
This commit is contained in:
@ -7,7 +7,6 @@ using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text.Json.Nodes;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
|
||||
namespace Elwig.Helpers.Billing {
|
||||
public class BillingData {
|
||||
|
@ -18,11 +18,10 @@ namespace Elwig.Helpers.Billing {
|
||||
return new(ParseJson(json), attributeVariants);
|
||||
}
|
||||
|
||||
public IEnumerable<GraphEntry> GetPaymentGraphEntries(AppDbContext context, Season season) {
|
||||
private (Dictionary<int, Curve>, Dictionary<int, List<string>>) GetGraphEntries(JsonNode root) {
|
||||
Dictionary<int, List<string>> dict1 = [];
|
||||
Dictionary<decimal, List<string>> dict2 = [];
|
||||
var p = GetPaymentEntry();
|
||||
if (p is JsonObject paymentObj) {
|
||||
if (root is JsonObject paymentObj) {
|
||||
foreach (var (selector, node) in paymentObj) {
|
||||
var val = node?.AsValue();
|
||||
if (val == null) {
|
||||
@ -36,7 +35,7 @@ namespace Elwig.Helpers.Billing {
|
||||
dict1[idx].Add(selector);
|
||||
}
|
||||
}
|
||||
} else if (p is JsonValue paymentVal) {
|
||||
} else if (root is JsonValue paymentVal) {
|
||||
if (paymentVal.TryGetValue<decimal>(out var price)) {
|
||||
if (!dict2.ContainsKey(price)) dict2[price] = [];
|
||||
dict2[price].Add("default");
|
||||
@ -57,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(p, AttributeVariants)) {
|
||||
foreach (var (selector, value) in GetSelection(root, AttributeVariants)) {
|
||||
int? idx = null;
|
||||
if (value.TryGetValue<decimal>(out var val)) {
|
||||
idx = Array.IndexOf(virtCurves, val) + virtOffset;
|
||||
@ -68,51 +67,35 @@ namespace Elwig.Helpers.Billing {
|
||||
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 (curves, dict3);
|
||||
}
|
||||
|
||||
return dict3
|
||||
.Select(e => new GraphEntry(e.Key, season.Precision, curves[e.Key], e.Value
|
||||
private static List<GraphEntry> CreateGraphEntries(AppDbContext ctx, int precision, Dictionary<int, Curve> curves, Dictionary<int, List<string>> entries) {
|
||||
var vars = ctx.WineVarieties.ToDictionary(v => v.SortId, v => v);
|
||||
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))
|
||||
.ToList()))
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public IEnumerable<GraphEntry> GetQualityGraphEntries(AppDbContext context, Season season) {
|
||||
Dictionary<int, List<string>> dict1 = [];
|
||||
Dictionary<decimal, List<string>> dict2 = [];
|
||||
foreach (var (qualid, q) in GetQualityEntry() ?? []) {
|
||||
if (q is JsonObject qualityObj) {
|
||||
foreach (var (selector, node) in qualityObj) {
|
||||
var val = node?.AsValue();
|
||||
if (val == null) {
|
||||
continue;
|
||||
} else if (val.TryGetValue<decimal>(out var price)) {
|
||||
if (!dict2.ContainsKey(price)) dict2[price] = [];
|
||||
dict2[price].Add(selector);
|
||||
} else if (val.TryGetValue<string>(out var curve)) {
|
||||
var idx = int.Parse(curve.Split(":")[1] ?? "0");
|
||||
if (!dict1.ContainsKey(idx)) dict1[idx] = [];
|
||||
dict1[idx].Add(selector);
|
||||
}
|
||||
}
|
||||
} else if (q is JsonValue qualityVal) {
|
||||
if (qualityVal.TryGetValue<decimal>(out var price)) {
|
||||
if (!dict2.ContainsKey(price)) dict2[price] = [];
|
||||
dict2[price].Add("default");
|
||||
} else if (qualityVal.TryGetValue<string>(out var curve)) {
|
||||
var idx = int.Parse(curve.Split(":")[1] ?? "0");
|
||||
if (!dict1.ContainsKey(idx)) dict1[idx] = [];
|
||||
dict1[idx].Add("default");
|
||||
}
|
||||
}
|
||||
public IEnumerable<GraphEntry> GetPaymentGraphEntries(AppDbContext ctx, Season season) {
|
||||
var root = GetPaymentEntry();
|
||||
var (curves, entries) = GetGraphEntries(root);
|
||||
return CreateGraphEntries(ctx, season.Precision, curves, entries);
|
||||
}
|
||||
|
||||
// TODO
|
||||
|
||||
List<GraphEntry> list = [];
|
||||
// set abgewertet = true
|
||||
|
||||
public IEnumerable<GraphEntry> GetQualityGraphEntries(AppDbContext ctx, Season season, int idOffset = 0) {
|
||||
var root = GetQualityEntry();
|
||||
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);
|
||||
foreach (var e in list) {
|
||||
e.Id += idOffset;
|
||||
e.Abgewertet = true;
|
||||
}
|
||||
return list;
|
||||
}
|
||||
}
|
||||
|
@ -9,13 +9,11 @@ using Elwig.Controls;
|
||||
using Elwig.Helpers;
|
||||
using Elwig.Helpers.Billing;
|
||||
using Elwig.Models.Entities;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.ChangeTracking;
|
||||
using ScottPlot.Plottables;
|
||||
using ScottPlot;
|
||||
using Xceed.Wpf.Toolkit.Primitives;
|
||||
using ScottPlot.Control;
|
||||
using LinqKit;
|
||||
|
||||
namespace Elwig.Windows {
|
||||
public partial class ChartWindow : ContextWindow {
|
||||
@ -87,9 +85,10 @@ namespace Elwig.Windows {
|
||||
Season = await Context.Seasons.FindAsync(Year) ?? throw new ArgumentException("Season not found");
|
||||
|
||||
var data = EditBillingData.FromJson(PaymentVar.Data, Utils.GetAttributeVarieties(Context, Year));
|
||||
var paymentEntries = data.GetPaymentGraphEntries(Context, Season);
|
||||
GraphEntries = [
|
||||
..data.GetPaymentGraphEntries(Context, Season),
|
||||
..data.GetQualityGraphEntries(Context, Season)
|
||||
..paymentEntries,
|
||||
..data.GetQualityGraphEntries(Context, Season, paymentEntries.Max(e => e.Id))
|
||||
];
|
||||
|
||||
var contracts = Utils.GetContractsForYear(Context, Year);
|
||||
|
Reference in New Issue
Block a user