Billing/Graph: Remove ParseGraphData()
This commit is contained in:
@ -17,8 +17,7 @@ namespace Elwig.Helpers.Billing {
|
|||||||
|
|
||||||
public Graph(Dictionary<double, decimal> data, int minX, int maxX) {
|
public Graph(Dictionary<double, decimal> data, int minX, int maxX) {
|
||||||
DataX = DataGen.Range(minX, maxX + 1);
|
DataX = DataGen.Range(minX, maxX + 1);
|
||||||
DataY = DataGen.Zeros(maxX - minX + 1);
|
DataY = DataX.Select(i => (double)BillingData.GetCurveValueAt(data, i)).ToArray();
|
||||||
ParseGraphData(data, minX, maxX);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Graph(double[] dataX, double[] dataY) {
|
public Graph(double[] dataX, double[] dataY) {
|
||||||
@ -42,51 +41,6 @@ namespace Elwig.Helpers.Billing {
|
|||||||
return DataY[index];
|
return DataY[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ParseGraphData(Dictionary<double, decimal> 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) {
|
private void FlattenGraph(int begin, int end, double value) {
|
||||||
for (int i = begin; i <= end; i++) {
|
for (int i = begin; i <= end; i++) {
|
||||||
DataY[i] = value;
|
DataY[i] = value;
|
||||||
|
Reference in New Issue
Block a user