diff --git a/MainForm.Designer.cs b/MainForm.Designer.cs index 0385fcf..0895594 100644 --- a/MainForm.Designer.cs +++ b/MainForm.Designer.cs @@ -76,7 +76,7 @@ this.toolStripMain.Location = new System.Drawing.Point(0, 24); this.toolStripMain.Name = "toolStripMain"; this.toolStripMain.RenderMode = System.Windows.Forms.ToolStripRenderMode.Professional; - this.toolStripMain.Size = new System.Drawing.Size(947, 25); + this.toolStripMain.Size = new System.Drawing.Size(1184, 25); this.toolStripMain.TabIndex = 0; this.toolStripMain.Text = "toolStrip1"; // @@ -165,9 +165,9 @@ // this.statusStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { this.toolStripStatusLabel}); - this.statusStrip.Location = new System.Drawing.Point(0, 623); + this.statusStrip.Location = new System.Drawing.Point(0, 739); this.statusStrip.Name = "statusStrip"; - this.statusStrip.Size = new System.Drawing.Size(947, 22); + this.statusStrip.Size = new System.Drawing.Size(1184, 22); this.statusStrip.TabIndex = 1; this.statusStrip.Text = "statusStrip1"; // @@ -187,7 +187,7 @@ this.reportToolStripMenuItem}); this.menuStrip.Location = new System.Drawing.Point(0, 0); this.menuStrip.Name = "menuStrip"; - this.menuStrip.Size = new System.Drawing.Size(947, 24); + this.menuStrip.Size = new System.Drawing.Size(1184, 24); this.menuStrip.TabIndex = 3; this.menuStrip.Text = "menuStrip1"; // @@ -204,20 +204,20 @@ // openDBToolStripMenuItem // this.openDBToolStripMenuItem.Name = "openDBToolStripMenuItem"; - this.openDBToolStripMenuItem.Size = new System.Drawing.Size(152, 22); + this.openDBToolStripMenuItem.Size = new System.Drawing.Size(123, 22); this.openDBToolStripMenuItem.Text = "Open DB"; this.openDBToolStripMenuItem.Click += new System.EventHandler(this.openDBToolStripMenuItem_Click); // // recentToolStripMenuItem // this.recentToolStripMenuItem.Name = "recentToolStripMenuItem"; - this.recentToolStripMenuItem.Size = new System.Drawing.Size(152, 22); + this.recentToolStripMenuItem.Size = new System.Drawing.Size(123, 22); this.recentToolStripMenuItem.Text = "Recent"; // // exitToolStripMenuItem // this.exitToolStripMenuItem.Name = "exitToolStripMenuItem"; - this.exitToolStripMenuItem.Size = new System.Drawing.Size(152, 22); + this.exitToolStripMenuItem.Size = new System.Drawing.Size(123, 22); this.exitToolStripMenuItem.Text = "Exit"; this.exitToolStripMenuItem.Click += new System.EventHandler(this.exitToolStripMenuItem_Click); // @@ -233,14 +233,14 @@ // resultTableToolStripMenuItem // this.resultTableToolStripMenuItem.Name = "resultTableToolStripMenuItem"; - this.resultTableToolStripMenuItem.Size = new System.Drawing.Size(152, 22); + this.resultTableToolStripMenuItem.Size = new System.Drawing.Size(149, 22); this.resultTableToolStripMenuItem.Text = "Result Table"; this.resultTableToolStripMenuItem.Click += new System.EventHandler(this.resultTableToolStripMenuItem_Click); // // analysisTableToolStripMenuItem // this.analysisTableToolStripMenuItem.Name = "analysisTableToolStripMenuItem"; - this.analysisTableToolStripMenuItem.Size = new System.Drawing.Size(152, 22); + this.analysisTableToolStripMenuItem.Size = new System.Drawing.Size(149, 22); this.analysisTableToolStripMenuItem.Text = "Analysis Table"; this.analysisTableToolStripMenuItem.Click += new System.EventHandler(this.analysisTableToolStripMenuItem_Click); // @@ -256,7 +256,7 @@ // radarGraphToolStripMenuItem // this.radarGraphToolStripMenuItem.Name = "radarGraphToolStripMenuItem"; - this.radarGraphToolStripMenuItem.Size = new System.Drawing.Size(152, 22); + this.radarGraphToolStripMenuItem.Size = new System.Drawing.Size(140, 22); this.radarGraphToolStripMenuItem.Text = "Radar Graph"; this.radarGraphToolStripMenuItem.Click += new System.EventHandler(this.radarGraphToolStripMenuItem_Click); // @@ -264,7 +264,7 @@ // this.trendGraphToolStripMenuItem.Enabled = false; this.trendGraphToolStripMenuItem.Name = "trendGraphToolStripMenuItem"; - this.trendGraphToolStripMenuItem.Size = new System.Drawing.Size(152, 22); + this.trendGraphToolStripMenuItem.Size = new System.Drawing.Size(140, 22); this.trendGraphToolStripMenuItem.Text = "Trend Graph"; this.trendGraphToolStripMenuItem.Click += new System.EventHandler(this.trendGraphToolStripMenuItem_Click); // @@ -288,14 +288,14 @@ this.dockPanel.DocumentStyle = WeifenLuo.WinFormsUI.Docking.DocumentStyle.DockingWindow; this.dockPanel.Location = new System.Drawing.Point(0, 49); this.dockPanel.Name = "dockPanel"; - this.dockPanel.Size = new System.Drawing.Size(947, 574); + this.dockPanel.Size = new System.Drawing.Size(1184, 690); this.dockPanel.TabIndex = 2; // // MainForm // this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 12F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(947, 645); + this.ClientSize = new System.Drawing.Size(1184, 761); this.Controls.Add(this.dockPanel); this.Controls.Add(this.statusStrip); this.Controls.Add(this.toolStripMain); diff --git a/MainForm.resx b/MainForm.resx index 327f71c..e672d22 100644 --- a/MainForm.resx +++ b/MainForm.resx @@ -166,24 +166,24 @@ iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8 - YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAFdSURBVDhPYxh8wGfmJi6fSbtLfSfuPu85cffPyP27/hcd - OvI1a/uRTZlbDgtClWEHXlP2yvv2774O1PwfhlOOHvhfdeE0GBcfO/EjZeN+C6hyVACyGV0zCOedOgo3 - AGZI6O4z/FBtCOA7YU8Zumbvvp1X848d/45sAAhn7Dy2AaoNAYC2X0AxYNLOBKgUQ/qOw7ORDSg6eOQr - VAoBQAGGbDNUGA5ATocZUHnu1H+oMAIgG+A1cdcVqDAE/P/PuPbBmx+7X33+v/XFp/+rn77HNMC7f8c5 + YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAFdSURBVDhPYxh8wGfmJi6fSbtLfSfuPu8xcffPyP27/hcd + PPw1a/uRTZlbDgtClWEHXlP2yvv2774O1PwfhlOOHvhfdeE0GBcfO/EjZeN+C6hyVACyGV0zCOedOgo3 + AGZI6O4z/FB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+hvcIBiNQAE0nccds3YeVQMxCbLAHyKRooB - oBRWeOwYJ4hdf38/ByzaQACfHIWAgQEAN6n9aWy7jOIAAAAASUVORK5CYII= + j66o8vyZgKrzx6RBbKwGgELUY+Luv74Tdi0B8TEMuHC6H+hvcIBiNQAE0nccds3YeVQMxCbLAHyKRooB + oBRWeOwYJ4hdf38/ByzaQACfHIWAgQEAKbL9ZOjCSnkAAAAASUVORK5CYII= diff --git a/PanelTrendGraph.cs b/PanelTrendGraph.cs index 9d865fe..ccf4ae0 100644 --- a/PanelTrendGraph.cs +++ b/PanelTrendGraph.cs @@ -12,6 +12,7 @@ using LiveCharts; using LiveCharts.Wpf; using LiveCharts.WinForms; using LiveCharts.Defaults; +using System.Windows.Media; namespace friction { @@ -49,6 +50,42 @@ namespace friction Title = "RPN", MinValue = 0, MaxValue = 10, + + Sections = new SectionsCollection + { + new AxisSection + { + Value = 5, + SectionWidth = 5, + Fill = new SolidColorBrush + { + Color = System.Windows.Media.Color.FromArgb(Theme.Red.A, Theme.Red.R, Theme.Red.G, Theme.Red.B), + Opacity = .75 + } + }, + new AxisSection + { + //Label = "Good", + Value = 3, + SectionWidth = 2, + Fill = new SolidColorBrush + { + Color = System.Windows.Media.Color.FromArgb(Theme.Yellow.A, Theme.Yellow.R, Theme.Yellow.G, Theme.Yellow.B), + Opacity = .75 + } + }, + new AxisSection + { + //Label = "Bad", + Value = 0, + SectionWidth = 3, + Fill = new SolidColorBrush + { + Color = System.Windows.Media.Color.FromArgb(Theme.Green.A, Theme.Green.R, Theme.Green.G, Theme.Green.B), + Opacity = .75 + } + } + } }); trendChart.LegendLocation = LegendLocation.Right; @@ -93,20 +130,33 @@ namespace friction new ChartValues(), new ChartValues() }; + var Values = new List(); + foreach (var pnt in Chart) { if(pnt.TEMPERATURE < 0) - Points[0].Add(new ScatterPoint(pnt.HUMIDITY, pnt.RPN)); + Points[0].Add(new ScatterPoint(pnt.HUMIDITY, pnt.RPN, 2)); else if(pnt.TEMPERATURE > 30) - Points[2].Add(new ScatterPoint(pnt.HUMIDITY, pnt.RPN)); + Points[2].Add(new ScatterPoint(pnt.HUMIDITY, pnt.RPN, 2)); else - Points[1].Add(new ScatterPoint(pnt.HUMIDITY, pnt.RPN)); + Points[1].Add(new ScatterPoint(pnt.HUMIDITY, pnt.RPN, 2)); + + Values.Add(new TrendLine.POINT { X = pnt.HUMIDITY, Y = pnt.RPN }); } + + + Values.Sort((a, b) => (a.X == b.X) ? 0 : (a.X < b.X) ? -1 : 1); + TrendLine trendline = new TrendLine(Values); + ChartValues TrendPoints = new ChartValues(); + TrendPoints.Add(new ScatterPoint(Values[0].X, trendline.GetY(Values[0].X))); + TrendPoints.Add(new ScatterPoint(Values[Values.Count / 2].X, trendline.GetY(Values[Values.Count / 2].X))); + TrendPoints.Add(new ScatterPoint(Values[Values.Count - 1].X, trendline.GetY(Values[Values.Count - 1].X))); + System.Windows.Media.SolidColorBrush[] brushes = { - System.Windows.Media.Brushes.DodgerBlue.Clone(), - System.Windows.Media.Brushes.Green.Clone(), - System.Windows.Media.Brushes.IndianRed.Clone() }; + System.Windows.Media.Brushes.DodgerBlue.Clone(), + System.Windows.Media.Brushes.Green.Clone(), + System.Windows.Media.Brushes.IndianRed.Clone() }; foreach (var brush in brushes) brush.Opacity = 0.75; @@ -131,6 +181,13 @@ namespace friction Values = Points[2], Fill = brushes[2], }, + new LineSeries + { + Title = "Trend", + Values = TrendPoints, + PointGeometry = DefaultGeometries.None, + StrokeThickness = 4, + }, }; @@ -146,6 +203,7 @@ namespace friction ChartValues[] Points = { new ChartValues(), new ChartValues() }; + var Values = new List(); foreach (var pnt in Chart) { @@ -153,8 +211,17 @@ namespace friction Points[0].Add(new ScatterPoint(pnt.TEMPERATURE, pnt.RPN, 2)); else Points[1].Add(new ScatterPoint(pnt.TEMPERATURE, pnt.RPN, 2)); + + Values.Add(new TrendLine.POINT { X = pnt.TEMPERATURE, Y = pnt.RPN }); } + Values.Sort((a, b) => (a.X == b.X) ? 0 : (a.X TrendPoints = new ChartValues(); + TrendPoints.Add(new ScatterPoint(Values[0].X, trendline.GetY(Values[0].X))); + TrendPoints.Add(new ScatterPoint(Values[Values.Count / 2].X, trendline.GetY(Values[Values.Count / 2].X))); + TrendPoints.Add(new ScatterPoint(Values[Values.Count - 1].X, trendline.GetY(Values[Values.Count - 1].X))); + trendChart.Series = new SeriesCollection { new ScatterSeries @@ -169,6 +236,13 @@ namespace friction Values = Points[1], Foreground = System.Windows.Media.Brushes.DarkBlue, }, + new LineSeries + { + Title = "Trend", + Values = TrendPoints, + PointGeometry = DefaultGeometries.None, + StrokeThickness = 4, + }, }; dMin = Chart.Min(r => r.TEMPERATURE - 1); diff --git a/TrendLine.cs b/TrendLine.cs new file mode 100644 index 0000000..21b2aab --- /dev/null +++ b/TrendLine.cs @@ -0,0 +1,99 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace friction +{ + public class TrendLine + { + public struct POINT + { + public float X; + public float Y; + } + + + private readonly List AxisValues; + private int count; + private float xAxisValuesSum; + private float xxSum; + private float xySum; + private float yAxisValuesSum; + + //public TrendLine(IList xAxisValues, IList yAxisValues) + //{ + // this.xAxisValues = xAxisValues; + // this.yAxisValues = yAxisValues; + + + // this.Initialize(); + //} + + public TrendLine(List points) + { + AxisValues = points; + AxisValues.Sort((POINT a, POINT b) => (a.X == b.X) ? 0 : (a.X < b.X) ? -1 : 1); + + this.Initialize(); + } + + public float Slope { get; private set; } + public float Intercept { get; private set; } + public float Start { get; private set; } + public float End { get; private set; } + + private void Initialize() + { + this.count = this.AxisValues.Count; + this.yAxisValuesSum = this.AxisValues.Sum(e => e.Y); + this.xAxisValuesSum = this.AxisValues.Sum(e => e.X); + this.xxSum = 0; + this.xySum = 0; + + for (int i = 0; i < this.count; i++) + { + this.xySum += (this.AxisValues[i].X * this.AxisValues[i].Y); + this.xxSum += (this.AxisValues[i].X * this.AxisValues[i].X); + } + + this.Slope = this.CalculateSlope(); + this.Intercept = this.CalculateIntercept(); + this.Start = this.CalculateStart(); + this.End = this.CalculateEnd(); + } + + private float CalculateSlope() + { + try + { + return ((this.count * this.xySum) - (this.xAxisValuesSum * this.yAxisValuesSum)) / ((this.count * this.xxSum) - (this.xAxisValuesSum * this.xAxisValuesSum)); + } + catch (DivideByZeroException) + { + return 0; + } + } + + private float CalculateIntercept() + { + return (this.yAxisValuesSum - (this.Slope * this.xAxisValuesSum)) / this.count; + } + + private float CalculateStart() + { + return (this.Slope * this.AxisValues.First().X) + this.Intercept; + } + + private float CalculateEnd() + { + return (this.Slope * this.AxisValues.Last().X) + this.Intercept; + } + + public float GetY(float fX) + { + return (this.Slope * fX) + this.Intercept; + } + } +} diff --git a/friction.csproj b/friction.csproj index e4917f7..8e6fdff 100644 --- a/friction.csproj +++ b/friction.csproj @@ -110,6 +110,7 @@ PanelMaterial.cs + MainForm.cs