Compare commits

...

3 Commits

5 changed files with 94 additions and 92 deletions
+36
View File
@@ -145,5 +145,41 @@ namespace Elwig.Helpers.Billing {
}
return dict;
}
protected static Dictionary<string, JsonValue> GetSelection(JsonNode value, IEnumerable<string> attributeVariants) {
if (value is JsonValue flatRate) {
return attributeVariants.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);
} else {
dict = [];
}
var variants = data.Where(p => !p.Key.StartsWith('/') && p.Key.Length == 2);
var attributes = data.Where(p => p.Key.StartsWith('/'));
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]))) {
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..])) {
dict[i] = curve;
}
}
foreach (var (idx, v) in others) {
var curve = v?.AsValue() ?? throw new InvalidOperationException();
dict[idx.Replace("/", "")] = curve;
}
return dict;
}
}
}
+25 -8
View File
@@ -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() ?? []) {
+2 -1
View File
@@ -31,11 +31,12 @@ namespace Elwig.Helpers.Billing {
if (gebunden != null) GebundenGraph = new Graph(gebunden, minX, maxX);
}
public GraphEntry(int id, BillingData.Curve curve, int minX, int maxX) :
public GraphEntry(int id, BillingData.Curve curve, List<ContractSelection> contracts, int minX, int maxX) :
this(id, curve.Mode, minX, maxX) {
DataGraph = new Graph(curve.Normal, minX, maxX);
if (curve.Gebunden != null)
GebundenGraph = new Graph(curve.Gebunden, minX, maxX);
Contracts = contracts;
}
private GraphEntry(int id, BillingData.CurveMode mode, Graph dataGraph, Graph? gebundenGraph,
+4 -45
View File
@@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text.Json.Nodes;
@@ -26,45 +25,12 @@ namespace Elwig.Helpers.Billing {
return new(ParseJson(json), attributeVariants);
}
private Dictionary<string, Curve> GetData(JsonObject data) {
Dictionary<string, Curve> dict;
if (data["default"] is JsonValue def) {
var c = LookupCurve(def);
dict = AttributeVariants.ToDictionary(e => e, _ => c);
} else {
dict = [];
}
var variants = data.Where(p => !p.Key.StartsWith('/') && p.Key.Length == 2);
var attributes = data.Where(p => p.Key.StartsWith('/'));
var others = data.Where(p => !p.Key.StartsWith('/') && p.Key.Length > 2);
foreach (var (idx, v) in variants) {
var curve = LookupCurve(v?.AsValue() ?? throw new InvalidOperationException());
foreach (var i in AttributeVariants.Where(e => e.StartsWith(idx[..^1]))) {
dict[i] = curve;
}
}
foreach (var (idx, v) in attributes) {
var curve = LookupCurve(v?.AsValue() ?? throw new InvalidOperationException());
foreach (var i in AttributeVariants.Where(e => e[2..] == idx[1..])) {
dict[i] = curve;
}
}
foreach (var (idx, v) in others) {
var curve = LookupCurve(v?.AsValue() ?? throw new InvalidOperationException());
dict[idx.Replace("/", "")] = curve;
}
return dict;
private Dictionary<string, Curve> GetData(JsonNode data) {
return GetSelection(data, AttributeVariants).ToDictionary(e => e.Key, e => LookupCurve(e.Value));
}
protected Dictionary<string, Curve> GetPaymentData() {
var p = GetPaymentEntry();
if (p is JsonValue val) {
var c = LookupCurve(val);
return AttributeVariants.ToDictionary(e => e, _ => c);
}
return GetData(p?.AsObject() ?? throw new InvalidOperationException());
return GetData(GetPaymentEntry());
}
protected Dictionary<string, Curve> GetQualityData() {
@@ -73,14 +39,7 @@ namespace Elwig.Helpers.Billing {
if (q == null) return dict;
foreach (var (qualid, data) in q) {
Dictionary<string, Curve> qualDict;
if (data is JsonValue val) {
var c = LookupCurve(val);
qualDict = AttributeVariants.ToDictionary(e => e, _ => c);
} else {
qualDict = GetData(data?.AsObject() ?? throw new InvalidOperationException());
}
foreach (var (idx, d) in qualDict) {
foreach (var (idx, d) in GetData(data ?? throw new InvalidOperationException())) {
dict[$"{qualid}/{idx}"] = d;
}
}
+27 -38
View File
@@ -58,10 +58,7 @@ namespace Elwig.Windows {
private async Task RefreshGraphList() {
await Context.PaymentVariants.LoadAsync();
await RefreshGraphListQuery();
}
private async Task RefreshGraphListQuery() {
var attrVariants = Context.DeliveryParts
.Where(d => d.Year == Year)
.Select(d => $"{d.SortId}{d.AttrId}")
@@ -71,37 +68,18 @@ namespace Elwig.Windows {
.Order()
.ToList();
var data = EditBillingData.FromJson(PaymentVar.Data, attrVariants);
GraphEntries.AddRange(data.GetPaymentGraphEntries());
GraphEntries.AddRange(data.GetQualityGraphEntries());
GraphEntries = [ ..data.GetPaymentGraphEntries(Context), ..data.GetQualityGraphEntries(Context)];
//var contracts = ContractSelection.GetContractsForYear(Context, Year).DistinctBy(c => c.Listing).Order().ToList();
//ControlUtils.RenewItemsSource(ContractInput, contracts, g => (g as GraphEntry)?.Id);
ControlUtils.RenewItemsSource(ContractInput, attrVariants, g => g);
ControlUtils.RenewItemsSource(GraphList, GraphEntries, g => (g as GraphEntry)?.Id, null, ControlUtils.RenewSourceDefault.IfOnly);
var contracts = ContractSelection.GetContractsForYear(Context, Year).DistinctBy(c => c.Listing).Order().ToList();
ControlUtils.RenewItemsSource(ContractInput, contracts, g => (g as ContractSelection)?.ToString());
ControlUtils.RenewItemsSource(GraphList, GraphEntries, g => (g as GraphEntry)?.Id, null, ControlUtils.RenewSourceDefault.First);
RefreshInputs();
}
private string ParseContracts(JsonObject auszahlungsSorten, int num) {
return "";
}
private void RefreshInputs(bool validate = false) {
private void RefreshInputs() {
ResetPlot();
if (!PaymentVar.TestVariant) {
AddButton.IsEnabled = false;
CopyButton.IsEnabled = false;
DeleteButton.IsEnabled = false;
DisableUnitTextBox(OechsleInput);
DisableUnitTextBox(PriceInput);
GebundenTypeFixed.IsEnabled = false;
GebundenTypeGraph.IsEnabled = false;
GebundenTypeNone.IsEnabled = false;
ContractInput.IsEnabled = false;
EnableOptionButtons();
FillInputs();
} else if (SelectedGraphEntry != null) {
if (SelectedGraphEntry != null) {
CopyButton.IsEnabled = true;
DeleteButton.IsEnabled = true;
//EnableUnitTextBox(OechsleInput);
@@ -117,21 +95,31 @@ namespace Elwig.Windows {
DisableUnitTextBox(OechsleInput);
DisableOptionButtons();
}
GC.Collect();
if (!PaymentVar.TestVariant) {
AddButton.IsEnabled = false;
CopyButton.IsEnabled = false;
DeleteButton.IsEnabled = false;
DisableUnitTextBox(OechsleInput);
DisableUnitTextBox(PriceInput);
GebundenTypeFixed.IsEnabled = false;
GebundenTypeGraph.IsEnabled = false;
GebundenTypeNone.IsEnabled = false;
ContractInput.IsEnabled = false;
}
}
private void FillInputs() {
GraphNum.Text = SelectedGraphEntry.Id.ToString();
GraphNum.Text = SelectedGraphEntry?.Id.ToString();
if (SelectedGraphEntry.GebundenFlatBonus != null) {
if (SelectedGraphEntry?.GebundenFlatBonus != null) {
GebundenTypeFixed.IsChecked = true;
} else if (SelectedGraphEntry.GebundenGraph != null) {
} else if (SelectedGraphEntry?.GebundenGraph != null) {
GebundenTypeGraph.IsChecked = true;
} else {
GebundenTypeNone.IsChecked = true; ;
}
ControlUtils.SelectCheckComboBoxItems(ContractInput, SelectedGraphEntry.Contracts, i => (i as ContractSelection)?.Listing);
ControlUtils.SelectCheckComboBoxItems(ContractInput, SelectedGraphEntry?.Contracts ?? [], i => (i as ContractSelection)?.Listing);
InitPlot();
OechslePricePlot.IsEnabled = true;
@@ -149,13 +137,13 @@ namespace Elwig.Windows {
GebundenPlot.MarkerSize = 9;
}
DataPlot = OechslePricePlot.Plot.AddScatter(SelectedGraphEntry.DataGraph.DataX, SelectedGraphEntry.DataGraph.DataY);
DataPlot = OechslePricePlot.Plot.AddScatter(SelectedGraphEntry!.DataGraph.DataX, SelectedGraphEntry!.DataGraph.DataY);
DataPlot.LineColor = Color.Blue;
DataPlot.MarkerColor = Color.Blue;
DataPlot.MarkerSize = 9;
if (SelectedGraphEntry.GebundenGraph == null) {
ChangeActiveGraph(SelectedGraphEntry.DataGraph);
if (SelectedGraphEntry?.GebundenGraph == null) {
ChangeActiveGraph(SelectedGraphEntry?.DataGraph);
}
OechslePricePlot.RightClicked -= OechslePricePlot.DefaultRightClickEvent;
@@ -470,7 +458,7 @@ namespace Elwig.Windows {
HighlightedPointPlot.IsVisible = true;
HoverChanged = true ^ HoverActive;
HoverActive = true;
HandleTooltip(mouseOnGebunden.Value.x, mouseOnGebunden.Value.y, mouseOnGebunden.Value.index, SelectedGraphEntry!.GebundenGraph);
HandleTooltip(mouseOnGebunden.Value.x, mouseOnGebunden.Value.y, mouseOnGebunden.Value.index, SelectedGraphEntry!.GebundenGraph!);
} else {
ChangeMarker(HighlightedPointPlot, false);
HoverChanged = false ^ HoverActive;
@@ -604,7 +592,7 @@ namespace Elwig.Windows {
}
private void GraphList_SelectionChanged(object sender, SelectionChangedEventArgs e) {
SelectedGraphEntry = (GraphEntry)GraphList.SelectedItem;
SelectedGraphEntry = GraphList.SelectedItem as GraphEntry;
RefreshInputs();
//var x = OechslePricePlot.Plot.GetPlottables().OfType<ScatterPlot>();
@@ -629,6 +617,7 @@ namespace Elwig.Windows {
private void ContractInput_Changed(object sender, RoutedEventArgs e) {
var r = ContractInput.SelectedItems.Cast<ContractSelection>();
SelectedGraphEntry!.Contracts = r.ToList();
// FIXME when using arrow keys, selection does not work nicely
GraphList.Items.Refresh();
}