ChartWindow/Billing: Misc improvements
This commit is contained in:
@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using Elwig.Models.Entities;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text.Json.Nodes;
|
||||
@ -17,7 +18,7 @@ namespace Elwig.Helpers.Billing {
|
||||
return new(ParseJson(json), attributeVariants);
|
||||
}
|
||||
|
||||
public IEnumerable<GraphEntry> GetPaymentGraphEntries(AppDbContext context) {
|
||||
public IEnumerable<GraphEntry> GetPaymentGraphEntries(AppDbContext context, Season season) {
|
||||
Dictionary<int, List<string>> dict1 = [];
|
||||
Dictionary<decimal, List<string>> dict2 = [];
|
||||
var p = GetPaymentEntry();
|
||||
@ -66,13 +67,13 @@ namespace Elwig.Helpers.Billing {
|
||||
var attrs = context.WineAttributes.ToDictionary(a => a.AttrId, a => a);
|
||||
|
||||
return dict3
|
||||
.Select(e => new GraphEntry(e.Key, curves[e.Key], e.Value
|
||||
.Select(e => new GraphEntry(e.Key, season, curves[e.Key], e.Value
|
||||
.Select(s => new ContractSelection(vars[s[..2]], s.Length > 2 ? attrs[s[2..]] : null))
|
||||
.ToList(), 50, 140))
|
||||
.ToList(), 50, 73, 140))
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public IEnumerable<GraphEntry> GetQualityGraphEntries(AppDbContext context) {
|
||||
public IEnumerable<GraphEntry> GetQualityGraphEntries(AppDbContext context, Season season) {
|
||||
Dictionary<int, List<string>> dict1 = [];
|
||||
Dictionary<decimal, List<string>> dict2 = [];
|
||||
foreach (var (qualid, q) in GetQualityEntry() ?? []) {
|
||||
|
@ -1,3 +1,4 @@
|
||||
using Elwig.Models.Entities;
|
||||
using ScottPlot;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@ -7,20 +8,32 @@ using System.Text.Json.Nodes;
|
||||
namespace Elwig.Helpers.Billing {
|
||||
public class Graph : ICloneable {
|
||||
|
||||
private readonly Season Season;
|
||||
public double[] DataX { get; set; }
|
||||
public double[] DataY { get; set; }
|
||||
public int MinX { get; set; }
|
||||
public int MaxX { get; set; }
|
||||
|
||||
public Graph(int minX, int maxX) {
|
||||
public Graph(Season season, int minX, int maxX) {
|
||||
Season = season;
|
||||
MinX = minX;
|
||||
MaxX = maxX;
|
||||
DataX = DataGen.Range(minX, maxX + 1);
|
||||
DataY = DataGen.Zeros(maxX - minX + 1);
|
||||
}
|
||||
|
||||
public Graph(Dictionary<double, decimal> data, int minX, int maxX) {
|
||||
public Graph(Dictionary<double, decimal> data, Season season, int minX, int maxX) {
|
||||
Season = season;
|
||||
MinX = minX;
|
||||
MaxX = maxX;
|
||||
DataX = DataGen.Range(minX, maxX + 1);
|
||||
DataY = DataX.Select(i => (double)BillingData.GetCurveValueAt(data, i)).ToArray();
|
||||
}
|
||||
|
||||
public Graph(double[] dataX, double[] dataY) {
|
||||
private Graph(double[] dataX, double[] dataY, Season season, int minX, int maxX) {
|
||||
Season = season;
|
||||
MinX = minX;
|
||||
MaxX = maxX;
|
||||
DataX = dataX;
|
||||
DataY = dataY;
|
||||
}
|
||||
@ -57,7 +70,7 @@ namespace Elwig.Helpers.Billing {
|
||||
|
||||
private void LinearIncreaseGraph(int begin, int end, double inc) {
|
||||
for (int i = begin; i < end; i++) {
|
||||
DataY[i + 1] = Math.Round(DataY[i] + inc, 4); //TODO richtig runden
|
||||
DataY[i + 1] = Math.Round(DataY[i] + inc, Season.Precision);
|
||||
}
|
||||
}
|
||||
|
||||
@ -74,7 +87,7 @@ namespace Elwig.Helpers.Billing {
|
||||
double step = (DataY[highIndex] - DataY[lowIndex]) / steps;
|
||||
|
||||
for (int i = lowIndex; i < highIndex - 1; i++) {
|
||||
DataY[i + 1] = Math.Round(DataY[i] + step, 4); // TODO richtig runden
|
||||
DataY[i + 1] = Math.Round(DataY[i] + step, Season.Precision);
|
||||
}
|
||||
}
|
||||
|
||||
@ -86,21 +99,21 @@ namespace Elwig.Helpers.Billing {
|
||||
var data = new JsonObject();
|
||||
|
||||
if (DataY[0] != DataY[1]) {
|
||||
data.Add(new KeyValuePair<string, JsonNode?>(DataX[0] + mode, Math.Round(DataY[0], 4)));
|
||||
data.Add(new KeyValuePair<string, JsonNode?>(DataX[0] + mode, Math.Round(DataY[0], Season.Precision)));
|
||||
}
|
||||
for (int i = 1; i < DataX.Length - 1; i++) {
|
||||
if (Math.Round(DataY[i] - DataY[i - 1], 10) != Math.Round(DataY[i + 1] - DataY[i], 10)) {
|
||||
data.Add(new KeyValuePair<string, JsonNode?>(DataX[i] + mode, Math.Round(DataY[i], 4)));
|
||||
data.Add(new KeyValuePair<string, JsonNode?>(DataX[i] + mode, Math.Round(DataY[i], Season.Precision)));
|
||||
}
|
||||
}
|
||||
if (DataY[^1] != DataY[^2]) {
|
||||
data.Add(new KeyValuePair<string, JsonNode?>(DataX[^1] + mode, Math.Round(DataY[^1], 4)));
|
||||
data.Add(new KeyValuePair<string, JsonNode?>(DataX[^1] + mode, Math.Round(DataY[^1], Season.Precision)));
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
public object Clone() {
|
||||
return new Graph((double[])DataX.Clone(), (double[])DataY.Clone());
|
||||
return new Graph((double[])DataX.Clone(), (double[])DataY.Clone(), Season, MinX, MaxX);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using Elwig.Models.Entities;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text.Json.Nodes;
|
||||
|
||||
@ -6,7 +7,9 @@ namespace Elwig.Helpers.Billing {
|
||||
public class GraphEntry {
|
||||
|
||||
public int Id { get; set; }
|
||||
private readonly Season Season;
|
||||
public BillingData.CurveMode Mode { get; set; }
|
||||
public bool Abgewertet { get; set; }
|
||||
public Graph DataGraph { get; set; }
|
||||
public Graph? GebundenGraph { get; set; }
|
||||
public decimal? GebundenFlatBonus { get; set; }
|
||||
@ -14,36 +17,42 @@ namespace Elwig.Helpers.Billing {
|
||||
public string ContractsStringSimple => Contracts.Any() ? string.Join(", ", Contracts.Select(c => c.Listing)) : "-";
|
||||
public string ContractsString => Contracts.Any() ? string.Join("\n", Contracts.Select(c => c.FullName)) : "-";
|
||||
private int MinX { get; set; }
|
||||
private int MinXGebunden { get; set; }
|
||||
private int MaxX { get; set; }
|
||||
|
||||
public GraphEntry(int id, BillingData.CurveMode mode, int minX, int maxX) {
|
||||
public GraphEntry(int id, Season season, BillingData.CurveMode mode, int minX, int minXGebunden, int maxX) {
|
||||
Id = id;
|
||||
Season = season;
|
||||
Mode = mode;
|
||||
Abgewertet = false;
|
||||
MinX = minX;
|
||||
MinXGebunden = minXGebunden;
|
||||
MaxX = maxX;
|
||||
DataGraph = new Graph(minX, maxX);
|
||||
DataGraph = new Graph(season, minX, maxX);
|
||||
Contracts = [];
|
||||
}
|
||||
|
||||
public GraphEntry(int id, BillingData.CurveMode mode, Dictionary<double, decimal> data, Dictionary<double, decimal>? gebunden,
|
||||
int minX, int maxX) : this(id, mode, minX, maxX) {
|
||||
DataGraph = new Graph(data, minX, maxX);
|
||||
if (gebunden != null) GebundenGraph = new Graph(gebunden, minX, maxX);
|
||||
public GraphEntry(int id, Season season, BillingData.CurveMode mode, Dictionary<double, decimal> data, Dictionary<double, decimal>? gebunden,
|
||||
int minX, int minXGebunden, int maxX) : this(id, season, mode, minX, minXGebunden, maxX) {
|
||||
DataGraph = new Graph(data, season, minX, maxX);
|
||||
if (gebunden != null) GebundenGraph = new Graph(gebunden, season, minXGebunden, 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);
|
||||
public GraphEntry(int id, Season season, BillingData.Curve curve, List<ContractSelection> contracts, int minX, int minXGebunden, int maxX) :
|
||||
this(id, season, curve.Mode, minX, minXGebunden, maxX) {
|
||||
DataGraph = new Graph(curve.Normal, season, minX, maxX);
|
||||
if (curve.Gebunden != null)
|
||||
GebundenGraph = new Graph(curve.Gebunden, 73, maxX);
|
||||
GebundenGraph = new Graph(curve.Gebunden, season, minXGebunden, maxX);
|
||||
Contracts = contracts;
|
||||
}
|
||||
|
||||
private GraphEntry(int id, BillingData.CurveMode mode, Graph dataGraph, Graph? gebundenGraph,
|
||||
decimal? gebundenFlatPrice, List<ContractSelection> contracts, int minX, int maxX) {
|
||||
private GraphEntry(int id, Season season, BillingData.CurveMode mode, Graph dataGraph, Graph? gebundenGraph,
|
||||
decimal? gebundenFlatPrice, List<ContractSelection> contracts, int minX, int minXGebunden, int maxX) {
|
||||
Id = id;
|
||||
Season = season;
|
||||
Mode = mode;
|
||||
MinX = minX;
|
||||
MinXGebunden = minXGebunden;
|
||||
MaxX = maxX;
|
||||
DataGraph = dataGraph;
|
||||
GebundenGraph = gebundenGraph;
|
||||
@ -52,7 +61,7 @@ namespace Elwig.Helpers.Billing {
|
||||
}
|
||||
|
||||
public void AddGebundenGraph() {
|
||||
GebundenGraph ??= new Graph(MinX, MaxX);
|
||||
GebundenGraph ??= new Graph(Season, MinXGebunden, MaxX);
|
||||
}
|
||||
|
||||
public void RemoveGebundenGraph() {
|
||||
@ -81,7 +90,7 @@ namespace Elwig.Helpers.Billing {
|
||||
}
|
||||
|
||||
public GraphEntry Copy(int id) {
|
||||
return new GraphEntry(id, Mode, (Graph)DataGraph.Clone(), (Graph?)GebundenGraph?.Clone(), GebundenFlatBonus, [], MinX, MaxX);
|
||||
return new GraphEntry(id, Season, Mode, (Graph)DataGraph.Clone(), (Graph?)GebundenGraph?.Clone(), GebundenFlatBonus, [], MinX, MinXGebunden, MaxX);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user