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