117 lines
5.6 KiB
C#
117 lines
5.6 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Drawing;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Windows.Forms.DataVisualization.Charting;
|
|
using Config.Entities;
|
|
using Results.Entities;
|
|
using Results.Resources;
|
|
|
|
namespace Results.Output
|
|
{
|
|
public class WMChart
|
|
{
|
|
public static Chart GetChart(WaterMeter wm)
|
|
{
|
|
return GetChart(wm, Config.Unit.lph, false);
|
|
}
|
|
|
|
public static Chart GetChart(WaterMeter wm, Config.Unit flowUnit, bool isQ4)
|
|
{
|
|
IList<PointF> unsortedPoints = new List<PointF>();
|
|
foreach (var mtr in wm.MeterTestRslts)
|
|
{
|
|
if (mtr.IsPilotRslt() && mtr.TestRslt.TestData.Evaluate && (mtr.TestTime > 0) && (mtr.TestRslt.PulsesMaster > 0))
|
|
{
|
|
double flow = Config.Units.ConvertTo(flowUnit, mtr.TestRslt.VolumeCTV / mtr.TestTime * 3.6 * mtr.PulsesMaster / mtr.TestRslt.PulsesMaster);
|
|
if (flow > 0)
|
|
{
|
|
unsortedPoints.Add(new PointF((float)flow, (float)mtr.Error));
|
|
}
|
|
}
|
|
}
|
|
IEnumerable<PointF> sortedPoints = unsortedPoints.OrderBy(x => x.X);
|
|
|
|
Chart chart = new Chart
|
|
{
|
|
Name = "chart",
|
|
Text = "chart",
|
|
Dock = System.Windows.Forms.DockStyle.Fill,
|
|
TabIndex = 0,
|
|
Size = new System.Drawing.Size(5, 5),
|
|
Location = new System.Drawing.Point(3, 3),
|
|
};
|
|
|
|
ChartArea chArea = new ChartArea { Name = "ChartArea1" };
|
|
chArea.AxisX.Title = Strings.Flow;
|
|
chArea.AxisX.IsLogarithmic = true;
|
|
chArea.AxisX.LogarithmBase = 10;
|
|
chArea.AxisX.IsLabelAutoFit = false;
|
|
|
|
List<double> xs = new List<double>() { 0.0001, 0.0002, 0.0005,
|
|
0.001, 0.002, 0.005,
|
|
0.01, 0.02, 0.05,
|
|
0.1, 0.2, 0.5,
|
|
1, 2, 5,
|
|
10, 20, 50,
|
|
100, 200, 500,
|
|
1000, 2000, 5000,
|
|
10000, 20000, 50000,
|
|
100000, 200000, 500000,
|
|
1000000, 2000000, 5000000 };
|
|
double spacer = 0.8;
|
|
double from = Config.Units.ConvertTo(flowUnit, wm.WaterMeterData.Q1_Qmin);
|
|
double to = Config.Units.ConvertTo(flowUnit, isQ4 ? wm.WaterMeterData.Q4_Qmax : wm.WaterMeterData.Q3_Qn);
|
|
for (int i = 1; i < xs.Count - 1; i++)
|
|
{
|
|
if ((xs[i + 1] > from) && (xs[i - 1] < to))
|
|
{
|
|
CustomLabel cl = new CustomLabel();
|
|
cl.Text = string.Format("{0} {1}", xs[i], flowUnit.ToDescription());
|
|
cl.FromPosition = Math.Log10(xs[i] * spacer);
|
|
cl.ToPosition = Math.Log10(xs[i] / spacer);
|
|
chArea.AxisX.CustomLabels.Add(cl);
|
|
}
|
|
}
|
|
|
|
chArea.AxisY.Title = Strings.Relative_error;
|
|
chArea.AxisY.Interval = 3;
|
|
chArea.AxisY.LabelStyle.Format = "{#} %";
|
|
|
|
Legend legend1 = new Legend { Name = "Legend1" };
|
|
|
|
Series upperLimit = new Series { Name = Strings.Upper_limit, ChartArea = "ChartArea1", ChartType = SeriesChartType.Line, Color = Color.Red };
|
|
upperLimit.Points.AddXY(Config.Units.ConvertTo(flowUnit, wm.WaterMeterData.Q1_Qmin), 5);
|
|
upperLimit.Points.AddXY(Config.Units.ConvertTo(flowUnit, wm.WaterMeterData.Q2_Qt), 5);
|
|
upperLimit.Points.AddXY(Config.Units.ConvertTo(flowUnit, wm.WaterMeterData.Q2_Qt), 2);
|
|
upperLimit.Points.AddXY(Config.Units.ConvertTo(flowUnit, wm.WaterMeterData.Q3_Qn), 2);
|
|
if (isQ4) upperLimit.Points.AddXY(Config.Units.ConvertTo(flowUnit, wm.WaterMeterData.Q4_Qmax), 2);
|
|
|
|
Series lowerLimit = new Series { Name = Strings.Lower_limit, ChartArea = "ChartArea1", ChartType = SeriesChartType.Line, Color = Color.Red };
|
|
lowerLimit.Points.AddXY(Config.Units.ConvertTo(flowUnit, wm.WaterMeterData.Q1_Qmin), -5);
|
|
lowerLimit.Points.AddXY(Config.Units.ConvertTo(flowUnit, wm.WaterMeterData.Q2_Qt), -5);
|
|
lowerLimit.Points.AddXY(Config.Units.ConvertTo(flowUnit, wm.WaterMeterData.Q2_Qt), -2);
|
|
lowerLimit.Points.AddXY(Config.Units.ConvertTo(flowUnit, wm.WaterMeterData.Q3_Qn), -2);
|
|
if (isQ4) lowerLimit.Points.AddXY(Config.Units.ConvertTo(flowUnit, wm.WaterMeterData.Q4_Qmax), -2);
|
|
|
|
Series line = new Series { Name = Strings.Relative_error, ChartArea = "ChartArea1", ChartType = SeriesChartType.Line, Color = Color.DeepSkyBlue };
|
|
Series dots = new Series { Name = Strings.Relative_error + " ", ChartArea = "ChartArea1", ChartType = SeriesChartType.Point, Color = Color.RoyalBlue };
|
|
foreach (var point in sortedPoints)
|
|
{
|
|
line.Points.AddXY(point.X, point.Y);
|
|
dots.Points.AddXY(point.X, point.Y);
|
|
}
|
|
|
|
chart.ChartAreas.Add(chArea);
|
|
chart.Legends.Add(legend1);
|
|
chart.Series.Add(upperLimit);
|
|
chart.Series.Add(lowerLimit);
|
|
chart.Series.Add(dots);
|
|
chart.Series.Add(line);
|
|
|
|
return chart;
|
|
}
|
|
}
|
|
}
|