From 9ee7f6baf13e325ce9afc6dcc8816e665d7db4e7 Mon Sep 17 00:00:00 2001 From: Lorenz Stechauner Date: Sat, 20 Jan 2024 02:35:59 +0100 Subject: [PATCH] Billing/Graph: Remove ParseGraphData() --- Elwig/Helpers/Billing/Graph.cs | 48 +--------------------------------- 1 file changed, 1 insertion(+), 47 deletions(-) diff --git a/Elwig/Helpers/Billing/Graph.cs b/Elwig/Helpers/Billing/Graph.cs index 95aa636..cc861c9 100644 --- a/Elwig/Helpers/Billing/Graph.cs +++ b/Elwig/Helpers/Billing/Graph.cs @@ -17,8 +17,7 @@ namespace Elwig.Helpers.Billing { public Graph(Dictionary data, int minX, int maxX) { DataX = DataGen.Range(minX, maxX + 1); - DataY = DataGen.Zeros(maxX - minX + 1); - ParseGraphData(data, minX, maxX); + DataY = DataX.Select(i => (double)BillingData.GetCurveValueAt(data, i)).ToArray(); } public Graph(double[] dataX, double[] dataY) { @@ -42,51 +41,6 @@ namespace Elwig.Helpers.Billing { return DataY[index]; } - private void ParseGraphData(Dictionary graphPoints, int minX, int maxX) { - 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++) { - decimal point1Value = graphPoints[keys[i]]; - if (i + 1 < keys.Length) { - decimal point2Value = graphPoints[keys[i + 1]]; - if (point1Value == point2Value) { - for (int j = (int)(keys[i] - minX); j < keys[i + 1] - minX; j++) { - DataY[j] = (double)point1Value; - } - } else { - int steps = (int)Math.Abs(keys[i + 1] - keys[i]); - decimal step = (point2Value - point1Value) / steps; - - DataY[(int)(keys[i] - minX)] = (double)point1Value; - DataY[(int)(keys[i + 1] - minX)] = (double)point2Value; - - for (int j = (int)(keys[i] - minX); j < keys[i + 1] - minX - 1; j++) { - DataY[j + 1] = Math.Round(DataY[j] + (double)step, 4); // TODO richtig runden - } - } - } - else { - for (int j = (int)(keys[i] - minX); j < DataX.Length; j++) { - DataY[j] = (double)point1Value; - } - } - } - } - private void FlattenGraph(int begin, int end, double value) { for (int i = begin; i <= end; i++) { DataY[i] = value;