Add PaymentChartWindow
This commit is contained in:
123
Elwig/Models/Graph.cs
Normal file
123
Elwig/Models/Graph.cs
Normal file
@ -0,0 +1,123 @@
|
||||
using Newtonsoft.Json.Linq;
|
||||
using ScottPlot;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.Contracts;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Markup;
|
||||
|
||||
namespace Elwig.Models {
|
||||
public class Graph : ICloneable {
|
||||
|
||||
public string Type { get; set; }
|
||||
public int Num { get; set; }
|
||||
private int MinX { get; set; }
|
||||
private int MaxX { get; set; }
|
||||
public string Contracts { get; set; }
|
||||
public double[] DataX { get; set; }
|
||||
public double[] DataY { get; set; }
|
||||
|
||||
public Graph(int num, int minX, int maxX) {
|
||||
Type = "oe";
|
||||
Num = num;
|
||||
Contracts = "";
|
||||
MinX = minX;
|
||||
MaxX = maxX;
|
||||
|
||||
DataX = DataGen.Range(MinX, MaxX + 1);
|
||||
DataY = DataGen.Zeros(MaxX - MinX + 1);
|
||||
}
|
||||
|
||||
public Graph(string type, int num, JToken graphData, string contracts, int minX, int maxX) {
|
||||
Type = type;
|
||||
Num = num;
|
||||
Contracts = contracts;
|
||||
MinX = minX;
|
||||
MaxX = maxX;
|
||||
|
||||
DataX = DataGen.Range(MinX, MaxX + 1);
|
||||
DataY = DataGen.Zeros(MaxX - MinX + 1);
|
||||
ParseGraphData(graphData);
|
||||
}
|
||||
|
||||
public Graph(string type, int num, int minX, int maxX, string contracts, double[] dataX, double[] dataY) {
|
||||
Type = type;
|
||||
Num = num;
|
||||
MinX = minX;
|
||||
MaxX = maxX;
|
||||
Contracts = contracts;
|
||||
DataX = dataX;
|
||||
DataY = dataY;
|
||||
}
|
||||
|
||||
private void ParseGraphData(JToken graphData) {
|
||||
var GraphPoints = graphData.Children().OfType<JProperty>().ToDictionary(p => int.Parse(p.Name[..^2]), p => (double)p.Value);
|
||||
|
||||
if (GraphPoints.Keys.Count < 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
var minKey = GraphPoints.Keys.Order().First();
|
||||
var maxKey = GraphPoints.Keys.OrderDescending().First();
|
||||
|
||||
if (!GraphPoints.ContainsKey(MinX)) {
|
||||
GraphPoints.Add(MinX, GraphPoints.GetValueOrDefault(minKey));
|
||||
}
|
||||
if (!GraphPoints.ContainsKey(MaxX)) {
|
||||
GraphPoints.Add(MaxX, GraphPoints.GetValueOrDefault(maxKey));
|
||||
}
|
||||
|
||||
var keys = GraphPoints.Keys.Order().ToArray();
|
||||
|
||||
for (int i = 0; i < keys.Length; i++) {
|
||||
double point1Value = GraphPoints[keys[i]];
|
||||
if (i + 1 < keys.Length) {
|
||||
double point2Value = GraphPoints[keys[i + 1]];
|
||||
if (point1Value == point2Value) {
|
||||
for (int j = keys[i] - MinX; j < keys[i + 1] - MinX; j++) {
|
||||
DataY[j] = point1Value;
|
||||
}
|
||||
} else {
|
||||
int steps = Math.Abs(keys[i + 1] - keys[i]);
|
||||
double step = (point2Value - point1Value) / steps;
|
||||
|
||||
DataY[keys[i] - MinX] = point1Value;
|
||||
DataY[keys[i + 1] - MinX] = point2Value;
|
||||
|
||||
for (int j = keys[i] - MinX; j < keys[i + 1] - MinX - 1; j++) {
|
||||
DataY[j + 1] = Math.Round(DataY[j] + step, 4); // TODO richtig runden
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
for (int j = keys[i] - MinX; j < DataX.Length; j++) {
|
||||
DataY[j] = point1Value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public JObject ToJson() {
|
||||
JObject graph = new();
|
||||
|
||||
if (DataY[0] != DataY[1]) {
|
||||
graph.Add(new JProperty(DataX[0] + Type.ToLower(), Math.Round(DataY[0], 4)));
|
||||
}
|
||||
for (int i = 1; i < DataX.Length - 1; i++) {
|
||||
if (Math.Round(DataY[i] - DataY[i - 1], 4) != Math.Round(DataY[i + 1] - DataY[i], 4)) {
|
||||
graph.Add(new JProperty(DataX[i] + Type.ToLower(), Math.Round(DataY[i], 4)));
|
||||
}
|
||||
}
|
||||
if (DataY[^1] != DataY[^2]) {
|
||||
graph.Add(new JProperty(DataX[^1] + Type.ToLower(), Math.Round(DataY[^1], 4)));
|
||||
}
|
||||
return graph;
|
||||
}
|
||||
|
||||
public object Clone() {
|
||||
return new Graph(Type, Num, MinX, MaxX, Contracts, (double[])DataX.Clone(), (double[])DataY.Clone());
|
||||
}
|
||||
}
|
||||
}
|
69
Elwig/Models/PaymentVar.cs
Normal file
69
Elwig/Models/PaymentVar.cs
Normal file
@ -0,0 +1,69 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace Elwig.Models {
|
||||
[Table("payment_variant"), PrimaryKey("Year", "AvNr")]
|
||||
public class PaymentVar {
|
||||
[Column("year")]
|
||||
public int Year { get; set; }
|
||||
|
||||
[Column("avnr")]
|
||||
public int AvNr { get; set; }
|
||||
|
||||
[Column("name")]
|
||||
public string Name { get; set; }
|
||||
|
||||
[Column("date")]
|
||||
public string DateString { get; set; }
|
||||
|
||||
[NotMapped]
|
||||
public DateOnly Date {
|
||||
get {
|
||||
return DateOnly.ParseExact(DateString, "yyyy-MM-dd");
|
||||
}
|
||||
set {
|
||||
DateString = value.ToString("yyyy-MM-dd");
|
||||
}
|
||||
}
|
||||
|
||||
[Column("test_variant")]
|
||||
public bool TestVariant { get; set; }
|
||||
|
||||
[Column("calc_time")]
|
||||
public int? CalcTime { get; set; }
|
||||
|
||||
[Column("bucket_1_name")]
|
||||
public string? Bucket1Name { get; set; }
|
||||
|
||||
[Column("bucket_2_name")]
|
||||
public string? Bucket2Name { get; set; }
|
||||
|
||||
[Column("bucket_3_name")]
|
||||
public string? Bucket3Name { get; set; }
|
||||
|
||||
[Column("bucket_4_name")]
|
||||
public string? Bucket4Name { get; set; }
|
||||
|
||||
[Column("bucket_5_name")]
|
||||
public string? Bucket5Name { get; set; }
|
||||
|
||||
[Column("bucket_6_name")]
|
||||
public string? Bucket6Name { get; set; }
|
||||
|
||||
[Column("bucket_7_name")]
|
||||
public string? Bucket7Name { get; set; }
|
||||
|
||||
[Column("bucket_8_name")]
|
||||
public string? Bucket8Name { get; set; }
|
||||
|
||||
[Column("bucket_9_name")]
|
||||
public string? Bucket9Name { get; set; }
|
||||
|
||||
[Column("comment")]
|
||||
public string? Comment { get; set; }
|
||||
|
||||
[Column("data")]
|
||||
public string Data { get; set; }
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user