ChartWindow: Rework varibute selection
This commit is contained in:
@ -257,7 +257,7 @@ namespace Elwig.Helpers.Billing {
|
|||||||
return curve;
|
return curve;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static void CollapsePaymentData(JsonObject data, IEnumerable<string> vaributes) {
|
protected static void CollapsePaymentData(JsonObject data, IEnumerable<string> vaributes, bool useDefault = true) {
|
||||||
Dictionary<string, List<string>> rev1 = [];
|
Dictionary<string, List<string>> rev1 = [];
|
||||||
Dictionary<decimal, List<string>> rev2 = [];
|
Dictionary<decimal, List<string>> rev2 = [];
|
||||||
foreach (var (k, v) in data) {
|
foreach (var (k, v) in data) {
|
||||||
@ -273,18 +273,18 @@ namespace Elwig.Helpers.Billing {
|
|||||||
}
|
}
|
||||||
if (!data.ContainsKey("default")) {
|
if (!data.ContainsKey("default")) {
|
||||||
foreach (var (v, ks) in rev1) {
|
foreach (var (v, ks) in rev1) {
|
||||||
if (ks.Count >= vaributes.Count() / 2.0) {
|
if ((ks.Count >= vaributes.Count() * 0.5 && useDefault) || ks.Count == vaributes.Count()) {
|
||||||
foreach (var k in ks) data.Remove(k);
|
foreach (var k in ks) data.Remove(k);
|
||||||
data["default"] = v;
|
data["default"] = v;
|
||||||
CollapsePaymentData(data, vaributes);
|
CollapsePaymentData(data, vaributes, useDefault);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
foreach (var (v, ks) in rev2) {
|
foreach (var (v, ks) in rev2) {
|
||||||
if (ks.Count >= vaributes.Count() / 2.0) {
|
if ((ks.Count >= vaributes.Count() * 0.5 && useDefault) || ks.Count == vaributes.Count()) {
|
||||||
foreach (var k in ks) data.Remove(k);
|
foreach (var k in ks) data.Remove(k);
|
||||||
data["default"] = v;
|
data["default"] = v;
|
||||||
CollapsePaymentData(data, vaributes);
|
CollapsePaymentData(data, vaributes, useDefault);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -299,14 +299,14 @@ namespace Elwig.Helpers.Billing {
|
|||||||
var len = vaributes.Count(e => e.EndsWith(idx));
|
var len = vaributes.Count(e => e.EndsWith(idx));
|
||||||
foreach (var (v, ks) in rev1) {
|
foreach (var (v, ks) in rev1) {
|
||||||
var myKs = ks.Where(k => k.EndsWith(idx)).ToList();
|
var myKs = ks.Where(k => k.EndsWith(idx)).ToList();
|
||||||
if (myKs.Count > 1 && myKs.Count >= len / 2.0) {
|
if (myKs.Count > 1 && ((myKs.Count >= len * 0.5 && useDefault) || myKs.Count == len)) {
|
||||||
foreach (var k in myKs) data.Remove(k);
|
foreach (var k in myKs) data.Remove(k);
|
||||||
data[idx] = v;
|
data[idx] = v;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
foreach (var (v, ks) in rev2) {
|
foreach (var (v, ks) in rev2) {
|
||||||
var myKs = ks.Where(k => k.EndsWith(idx)).ToList();
|
var myKs = ks.Where(k => k.EndsWith(idx)).ToList();
|
||||||
if (myKs.Count > 1 && myKs.Count >= len / 2.0) {
|
if (myKs.Count > 1 && ((myKs.Count >= len * 0.5 && useDefault) || myKs.Count == len)) {
|
||||||
foreach (var k in myKs) data.Remove(k);
|
foreach (var k in myKs) data.Remove(k);
|
||||||
data[idx] = v;
|
data[idx] = v;
|
||||||
}
|
}
|
||||||
@ -314,7 +314,13 @@ namespace Elwig.Helpers.Billing {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static JsonObject FromGraphEntries(IEnumerable<GraphEntry> graphEntries, BillingData? origData = null, IEnumerable<string>? vaributes = null) {
|
public static JsonObject FromGraphEntries(
|
||||||
|
IEnumerable<GraphEntry> graphEntries,
|
||||||
|
BillingData? origData = null,
|
||||||
|
IEnumerable<string>? vaributes = null,
|
||||||
|
bool useDefaultPayment = true,
|
||||||
|
bool useDefaultQuality = true
|
||||||
|
) {
|
||||||
var payment = new JsonObject();
|
var payment = new JsonObject();
|
||||||
var qualityWei = new JsonObject();
|
var qualityWei = new JsonObject();
|
||||||
var curves = new JsonArray();
|
var curves = new JsonArray();
|
||||||
@ -340,8 +346,8 @@ namespace Elwig.Helpers.Billing {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CollapsePaymentData(payment, vaributes ?? payment.Select(e => e.Key).ToList());
|
CollapsePaymentData(payment, vaributes ?? payment.Select(e => e.Key).ToList(), useDefaultPayment);
|
||||||
CollapsePaymentData(qualityWei, vaributes ?? qualityWei.Select(e => e.Key).ToList());
|
CollapsePaymentData(qualityWei, vaributes ?? qualityWei.Select(e => e.Key).ToList(), useDefaultQuality);
|
||||||
|
|
||||||
var data = new JsonObject {
|
var data = new JsonObject {
|
||||||
["mode"] = "elwig",
|
["mode"] = "elwig",
|
||||||
@ -359,16 +365,16 @@ namespace Elwig.Helpers.Billing {
|
|||||||
|
|
||||||
if (payment.Count == 0) {
|
if (payment.Count == 0) {
|
||||||
data["payment"] = 0;
|
data["payment"] = 0;
|
||||||
} else if (payment.Count == 1) {
|
} else if (payment.Count == 1 && payment.First().Key == "default") {
|
||||||
data["payment"] = payment.Single().Value?.DeepClone();
|
data["payment"] = payment.Single().Value?.DeepClone();
|
||||||
} else {
|
} else {
|
||||||
data["payment"] = payment;
|
data["payment"] = payment;
|
||||||
}
|
}
|
||||||
if (qualityWei.Count == 1) {
|
if (qualityWei.Count == 1 && qualityWei.First().Key == "default") {
|
||||||
data["quality"] = new JsonObject() {
|
data["quality"] = new JsonObject() {
|
||||||
["WEI"] = qualityWei.Single().Value?.DeepClone()
|
["WEI"] = qualityWei.Single().Value?.DeepClone()
|
||||||
};
|
};
|
||||||
} else if (qualityWei.Count > 1) {
|
} else if (qualityWei.Count >= 1) {
|
||||||
data["quality"] = new JsonObject() {
|
data["quality"] = new JsonObject() {
|
||||||
["WEI"] = qualityWei
|
["WEI"] = qualityWei
|
||||||
};
|
};
|
||||||
|
@ -4,8 +4,11 @@ using System;
|
|||||||
namespace Elwig.Helpers.Billing {
|
namespace Elwig.Helpers.Billing {
|
||||||
public class Varibute : IComparable<Varibute> {
|
public class Varibute : IComparable<Varibute> {
|
||||||
|
|
||||||
public readonly WineVar? Variety;
|
public WineVar? Variety { get; }
|
||||||
public readonly WineAttr? Attribute;
|
public WineAttr? Attribute { get; }
|
||||||
|
public int? AssignedGraphId { get; set; }
|
||||||
|
public int? AssignedAbgewGraphId { get; set; }
|
||||||
|
|
||||||
public string Listing => $"{Variety?.SortId}{Attribute?.AttrId}";
|
public string Listing => $"{Variety?.SortId}{Attribute?.AttrId}";
|
||||||
public string FullName => $"{Variety?.Name}" + (Variety != null && Attribute != null ? " " : "") + $"{Attribute?.Name}";
|
public string FullName => $"{Variety?.Name}" + (Variety != null && Attribute != null ? " " : "") + $"{Attribute?.Name}";
|
||||||
|
|
||||||
|
@ -372,7 +372,7 @@ namespace Elwig.Helpers {
|
|||||||
return [.. (onlyDelivered ? delivered : delivered.Union(varieties)).Order()];
|
return [.. (onlyDelivered ? delivered : delivered.Union(varieties)).Order()];
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<Varibute> GetVaributesForYear(AppDbContext ctx, int year, bool onlyDelivered = true) {
|
public static List<Varibute> GetVaributeList(AppDbContext ctx, int year, bool onlyDelivered = true) {
|
||||||
var varieties = ctx.WineVarieties.ToDictionary(v => v.SortId, v => v);
|
var varieties = ctx.WineVarieties.ToDictionary(v => v.SortId, v => v);
|
||||||
var attributes = ctx.WineAttributes.ToDictionary(a => a.AttrId, a => a);
|
var attributes = ctx.WineAttributes.ToDictionary(a => a.AttrId, a => a);
|
||||||
return GetVaributes(ctx, year, false, onlyDelivered)
|
return GetVaributes(ctx, year, false, onlyDelivered)
|
||||||
|
@ -61,14 +61,17 @@
|
|||||||
</Grid.ColumnDefinitions>
|
</Grid.ColumnDefinitions>
|
||||||
|
|
||||||
<Label Content="Für:" Margin="10,-2,0,0" FontSize="14" Grid.Column="0" VerticalAlignment="Center"/>
|
<Label Content="Für:" Margin="10,-2,0,0" FontSize="14" Grid.Column="0" VerticalAlignment="Center"/>
|
||||||
<xctk:CheckComboBox x:Name="VaributeInput" Margin="50,0,0,0" Grid.Column="0"
|
<xctk:CheckComboBox x:Name="VaributeInput" Margin="50,0,0,0" Grid.Column="0" Width="500" Height="25" HorizontalAlignment="Left"
|
||||||
Delimiter=", " AllItemsSelectedContent="Alle" IsEnabled="False" ItemSelectionChanged="VaributeInput_Changed"
|
IsSelectAllActive="True" SelectAllContent="Alle Sorten" Delimiter=", " AllItemsSelectedContent="Alle Sorten"
|
||||||
Width="500" Height="25" HorizontalAlignment="Left">
|
IsEnabled="False" ItemSelectionChanged="VaributeInput_Changed">
|
||||||
<xctk:CheckComboBox.ItemTemplate>
|
<xctk:CheckComboBox.ItemTemplate>
|
||||||
<DataTemplate>
|
<DataTemplate>
|
||||||
<StackPanel Orientation="Horizontal">
|
<StackPanel Orientation="Horizontal">
|
||||||
<TextBlock Text="{Binding Variety.Name}" Width="150"/>
|
<TextBlock Text="{Binding Variety.Name}" Width="150"/>
|
||||||
<TextBlock Text="{Binding Attribute.Name}"/>
|
<TextBlock Text="{Binding Variety.Type}" Width="30"/>
|
||||||
|
<TextBlock Text="{Binding Attribute.Name}" Width="120"/>
|
||||||
|
<TextBlock Text="{Binding AssignedGraphId}" Width="30"/>
|
||||||
|
<TextBlock Text="{Binding AssignedAbgewGraphId}" Width="30"/>
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
</DataTemplate>
|
</DataTemplate>
|
||||||
</xctk:CheckComboBox.ItemTemplate>
|
</xctk:CheckComboBox.ItemTemplate>
|
||||||
|
@ -35,9 +35,9 @@ namespace Elwig.Windows {
|
|||||||
private Text TooltipPlot;
|
private Text TooltipPlot;
|
||||||
private LegendItem UngebundenLegend;
|
private LegendItem UngebundenLegend;
|
||||||
private LegendItem GebundenLegend;
|
private LegendItem GebundenLegend;
|
||||||
private LegendItem LDWLegend;
|
private LegendItem LdwLegend;
|
||||||
private LegendItem QUWLegend;
|
private LegendItem QuwLegend;
|
||||||
private LegendItem KABLegend;
|
private LegendItem KabLegend;
|
||||||
|
|
||||||
private (Graph? Graph, int Index) LastHighlighted = (null, -1);
|
private (Graph? Graph, int Index) LastHighlighted = (null, -1);
|
||||||
private (Graph? Graph, int Index) Highlighted = (null, -1);
|
private (Graph? Graph, int Index) Highlighted = (null, -1);
|
||||||
@ -50,6 +50,9 @@ namespace Elwig.Windows {
|
|||||||
|
|
||||||
private List<GraphEntry> GraphEntries = [];
|
private List<GraphEntry> GraphEntries = [];
|
||||||
private GraphEntry? SelectedGraphEntry => (GraphEntry)GraphList.SelectedItem;
|
private GraphEntry? SelectedGraphEntry => (GraphEntry)GraphList.SelectedItem;
|
||||||
|
private List<Varibute> Vaributes = [];
|
||||||
|
private bool AllVaributesAssigned => Vaributes.All(v => v.AssignedGraphId != null);
|
||||||
|
private bool AllVaributesAssignedAbgew => Vaributes.All(v => v.AssignedAbgewGraphId != null);
|
||||||
|
|
||||||
public ChartWindow(int year, int avnr) {
|
public ChartWindow(int year, int avnr) {
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
@ -88,12 +91,22 @@ namespace Elwig.Windows {
|
|||||||
var paymentEntries = data.GetPaymentGraphEntries(Context, Season);
|
var paymentEntries = data.GetPaymentGraphEntries(Context, Season);
|
||||||
GraphEntries = [
|
GraphEntries = [
|
||||||
..paymentEntries,
|
..paymentEntries,
|
||||||
..data.GetQualityGraphEntries(Context, Season, paymentEntries.Max(e => e.Id))
|
..data.GetQualityGraphEntries(Context, Season, paymentEntries.Any() ? paymentEntries.Max(e => e.Id) : 0)
|
||||||
];
|
];
|
||||||
|
Vaributes = Utils.GetVaributeList(Context, Year);
|
||||||
|
GraphEntries.ForEach(e => {
|
||||||
|
e.Vaributes.ForEach(v => {
|
||||||
|
var found = Vaributes.Find(a => a.Attribute?.AttrId == v.Attribute?.AttrId && a.Variety?.SortId == v.Variety?.SortId);
|
||||||
|
if (e.Abgewertet) {
|
||||||
|
found!.AssignedAbgewGraphId = e.Id;
|
||||||
|
} else {
|
||||||
|
found!.AssignedGraphId = e.Id;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
var vaributes = Utils.GetVaributesForYear(Context, Year);
|
|
||||||
FillingInputs = true;
|
FillingInputs = true;
|
||||||
ControlUtils.RenewItemsSource(VaributeInput, vaributes, g => (g as Varibute)?.Listing);
|
ControlUtils.RenewItemsSource(VaributeInput, Vaributes, v => (v as Varibute)?.Listing);
|
||||||
FillingInputs = false;
|
FillingInputs = false;
|
||||||
ControlUtils.RenewItemsSource(GraphList, GraphEntries, g => (g as GraphEntry)?.VaributeStringChange, GraphList_SelectionChanged, ControlUtils.RenewSourceDefault.First);
|
ControlUtils.RenewItemsSource(GraphList, GraphEntries, g => (g as GraphEntry)?.VaributeStringChange, GraphList_SelectionChanged, ControlUtils.RenewSourceDefault.First);
|
||||||
|
|
||||||
@ -174,21 +187,21 @@ namespace Elwig.Windows {
|
|||||||
Marker = new MarkerStyle(MarkerShape.FilledCircle, 5, ColorGebunden)
|
Marker = new MarkerStyle(MarkerShape.FilledCircle, 5, ColorGebunden)
|
||||||
};
|
};
|
||||||
|
|
||||||
LDWLegend = new LegendItem() {
|
LdwLegend = new LegendItem() {
|
||||||
Label = "68 °Oe (LDW)",
|
Label = "68 °Oe (LDW)",
|
||||||
LineWidth = 2,
|
LineWidth = 2,
|
||||||
LineColor = Colors.Red,
|
LineColor = Colors.Red,
|
||||||
Marker = MarkerStyle.None
|
Marker = MarkerStyle.None
|
||||||
};
|
};
|
||||||
|
|
||||||
QUWLegend = new LegendItem() {
|
QuwLegend = new LegendItem() {
|
||||||
Label = "73 °Oe (QUW)",
|
Label = "73 °Oe (QUW)",
|
||||||
LineWidth = 2,
|
LineWidth = 2,
|
||||||
LineColor = Colors.Orange,
|
LineColor = Colors.Orange,
|
||||||
Marker = MarkerStyle.None
|
Marker = MarkerStyle.None
|
||||||
};
|
};
|
||||||
|
|
||||||
KABLegend = new LegendItem() {
|
KabLegend = new LegendItem() {
|
||||||
Label = "84 °Oe (KAB)",
|
Label = "84 °Oe (KAB)",
|
||||||
LineWidth = 2,
|
LineWidth = 2,
|
||||||
LineColor = Colors.Green,
|
LineColor = Colors.Green,
|
||||||
@ -372,9 +385,9 @@ namespace Elwig.Windows {
|
|||||||
OechslePricePlot.Plot.Legend.Location = Alignment.UpperLeft;
|
OechslePricePlot.Plot.Legend.Location = Alignment.UpperLeft;
|
||||||
OechslePricePlot.Plot.Legend.IsVisible = true;
|
OechslePricePlot.Plot.Legend.IsVisible = true;
|
||||||
|
|
||||||
OechslePricePlot.Plot.Legend.ManualItems.Add(LDWLegend);
|
OechslePricePlot.Plot.Legend.ManualItems.Add(LdwLegend);
|
||||||
OechslePricePlot.Plot.Legend.ManualItems.Add(QUWLegend);
|
OechslePricePlot.Plot.Legend.ManualItems.Add(QuwLegend);
|
||||||
OechslePricePlot.Plot.Legend.ManualItems.Add(KABLegend);
|
OechslePricePlot.Plot.Legend.ManualItems.Add(KabLegend);
|
||||||
OechslePricePlot.Plot.Legend.ManualItems.Add(UngebundenLegend);
|
OechslePricePlot.Plot.Legend.ManualItems.Add(UngebundenLegend);
|
||||||
if (SelectedGraphEntry?.GebundenGraph != null) OechslePricePlot.Plot.Legend.ManualItems.Add(GebundenLegend);
|
if (SelectedGraphEntry?.GebundenGraph != null) OechslePricePlot.Plot.Legend.ManualItems.Add(GebundenLegend);
|
||||||
}
|
}
|
||||||
@ -635,7 +648,8 @@ namespace Elwig.Windows {
|
|||||||
|
|
||||||
private async void SaveButton_Click(object sender, RoutedEventArgs e) {
|
private async void SaveButton_Click(object sender, RoutedEventArgs e) {
|
||||||
var origData = BillingData.FromJson(PaymentVar.Data);
|
var origData = BillingData.FromJson(PaymentVar.Data);
|
||||||
var data = BillingData.FromGraphEntries(GraphEntries, origData, Utils.GetVaributes(Context, Year, withSlash: true));
|
var data = BillingData.FromGraphEntries(GraphEntries, origData, Utils.GetVaributes(Context, Year, withSlash: true),
|
||||||
|
AllVaributesAssigned, AllVaributesAssignedAbgew);
|
||||||
|
|
||||||
EntityEntry<PaymentVar>? tr = null;
|
EntityEntry<PaymentVar>? tr = null;
|
||||||
try {
|
try {
|
||||||
@ -716,20 +730,33 @@ namespace Elwig.Windows {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void VaributeInput_Changed(object sender, ItemSelectionChangedEventArgs e) {
|
private void VaributeInput_Changed(object sender, ItemSelectionChangedEventArgs e) {
|
||||||
if (FillingInputs) return;
|
if (FillingInputs || e.Item is not Varibute v) return;
|
||||||
if (e.IsSelected == true) {
|
var isOpen = VaributeInput.IsDropDownOpen;
|
||||||
bool success = RemoveVaributeFromOtherGraphEntries(e.Item.ToString());
|
if (e.IsSelected) {
|
||||||
if (!success) {
|
if (RemoveVaributeFromOthers(e.Item.ToString())) {
|
||||||
|
if (AbgewertetInput.IsChecked == true) {
|
||||||
|
v.AssignedAbgewGraphId = SelectedGraphEntry?.Id;
|
||||||
|
} else {
|
||||||
|
v.AssignedGraphId = SelectedGraphEntry?.Id;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
VaributeInput.SelectedItems.Remove(e.Item);
|
VaributeInput.SelectedItems.Remove(e.Item);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
if (AbgewertetInput.IsChecked == true) {
|
||||||
|
v.AssignedAbgewGraphId = null;
|
||||||
|
} else {
|
||||||
|
v.AssignedGraphId = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
var r = VaributeInput.SelectedItems.Cast<Varibute>();
|
SelectedGraphEntry!.Vaributes = VaributeInput.SelectedItems.Cast<Varibute>().ToList();
|
||||||
SelectedGraphEntry!.Vaributes = r.ToList();
|
|
||||||
SetHasChanged();
|
SetHasChanged();
|
||||||
GraphList.Items.Refresh();
|
GraphList.Items.Refresh();
|
||||||
|
VaributeInput.Items.Refresh();
|
||||||
|
VaributeInput.IsDropDownOpen = isOpen;
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool RemoveVaributeFromOtherGraphEntries(string? varibute) {
|
private bool RemoveVaributeFromOthers(string? varibute) {
|
||||||
if (varibute == null) return true;
|
if (varibute == null) return true;
|
||||||
foreach (var ge in GraphEntries) {
|
foreach (var ge in GraphEntries) {
|
||||||
if (ge != SelectedGraphEntry && ge.Abgewertet == SelectedGraphEntry?.Abgewertet) {
|
if (ge != SelectedGraphEntry && ge.Abgewertet == SelectedGraphEntry?.Abgewertet) {
|
||||||
|
@ -173,7 +173,7 @@ namespace Elwig.Windows {
|
|||||||
v.Name = "Neue Auszahlungsvariante";
|
v.Name = "Neue Auszahlungsvariante";
|
||||||
v.TestVariant = true;
|
v.TestVariant = true;
|
||||||
v.DateString = $"{DateTime.Today:yyyy-MM-dd}";
|
v.DateString = $"{DateTime.Today:yyyy-MM-dd}";
|
||||||
v.Data = "{\"mode\": \"elwig\", \"version\": 1, \"payment\": 1.0, \"quality\": {\"WEI\": 0}, \"curves\": []}";
|
v.Data = "{\"mode\": \"elwig\", \"version\": 1, \"payment\": {}, \"curves\": []}";
|
||||||
|
|
||||||
await Context.AddAsync(v);
|
await Context.AddAsync(v);
|
||||||
await Context.SaveChangesAsync();
|
await Context.SaveChangesAsync();
|
||||||
|
Reference in New Issue
Block a user