From 7be92b315a47d574140cb8ac919328156d301b00 Mon Sep 17 00:00:00 2001 From: mjjo53 Date: Mon, 19 Jun 2017 19:23:01 +0900 Subject: [PATCH] =?UTF-8?q?Analysis=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DataHandler.cs | 73 ++++++++++------ MainForm.cs | 4 +- PanelAnalysis.Designer.cs | 174 +++++++++++++++++++++++++++++++++++++- PanelAnalysis.cs | 46 ++++++++++ PanelMaterial.cs | 10 +-- 5 files changed, 273 insertions(+), 34 deletions(-) diff --git a/DataHandler.cs b/DataHandler.cs index c0056c4..e0bdba3 100644 --- a/DataHandler.cs +++ b/DataHandler.cs @@ -11,7 +11,7 @@ namespace friction { public class DataHandler { - public class CalcResult + public struct CalcResult { public int m_iCnt; public float m_fAvgRPN; @@ -40,11 +40,14 @@ namespace friction string m_strFileName = ""; string m_strFilePath = ""; + string m_strCurSpring = ""; + string m_strCurTable = ""; + List m_ColumnsNames = new List(); List m_ActiveColumns = new List(); List m_NonactiveColumns = new List(); - List m_MaterialSpring = new List(); - List m_MaterialTable = new List(); + List m_SpringList = new List(); + List m_TableList = new List(); Dictionary m_ColumnMap = new Dictionary(); @@ -97,8 +100,14 @@ namespace friction if (m_Data.Columns[iCol-1].DataType == typeof(float)) { float fData = 0; - if(value != null) - fData = (float)(double)value; + if (value != null) + { + if (value is string) + float.TryParse((string)value, out fData); + else + fData = (float)(double)value; + } + newRow[iCol - 1] = fData; } else @@ -123,10 +132,10 @@ namespace friction } - m_MaterialSpring = (from r in m_Data.AsEnumerable() + m_SpringList = (from r in m_Data.AsEnumerable() select r[m_ColumnMap["spring"]]).Distinct().Cast().ToList(); - m_MaterialTable = (from r in m_Data.AsEnumerable() + m_TableList = (from r in m_Data.AsEnumerable() select r[m_ColumnMap["table"]]).Distinct().Cast().ToList(); m_ColumnsNames = (from c in m_Data.Columns.Cast() @@ -188,6 +197,18 @@ namespace friction #region calculation + float CalcDependency(DataRow[] rows, string strColumn) + { + // 각 그룹의 평균들의 표준편차 + var AvgOfGroup = rows + .GroupBy(r => r[m_ColumnMap["force"]]) + .Select(t => t.Average(k => (float)k[m_ColumnMap["rpn"]])); + var Avg = AvgOfGroup.Average(); + var Squares = AvgOfGroup.Select(r => (r - Avg) * (r - Avg)); + var result = (float)Math.Sqrt(Squares.Average()); + return result; + } + public CalcResult GetCalc(string strSpring, string strTable) { CalcResult result = new CalcResult(); @@ -195,24 +216,24 @@ namespace friction string strQuery = string.Format("[{0}]='{1}' and [{2}]='{3}'", m_ColumnMap["spring"], strSpring, m_ColumnMap["table"], strTable); DataRow[] rows = m_Data.Select(strQuery); - result.m_iCnt = rows.Length; - result.m_fAvgRPN = rows.Average(r => (float)r[m_ColumnMap["rpn"]]); - result.m_fStdRPN = rows.Average(r => (float)Math.Pow((float)r[m_ColumnMap["rpn"]] - result.m_fAvgRPN, 2)); - result.m_fStdRPN = (float)Math.Sqrt(result.m_fStdRPN); + if(rows.Length > 0) + { + result.m_iCnt = rows.Length; + result.m_fAvgRPN = rows.Average(r => (float)r[m_ColumnMap["rpn"]]); + result.m_fStdRPN = rows.Average(r => (float)Math.Pow((float)r[m_ColumnMap["rpn"]] - result.m_fAvgRPN, 2)); + result.m_fStdRPN = (float)Math.Sqrt(result.m_fStdRPN); - var aa = rows - .GroupBy(r => r[m_ColumnMap["force"]]) - .Select(t => t.Average(k => (float)k[m_ColumnMap["rpn"]])); + result.m_fDiffByForce = CalcDependency(rows, "force"); + result.m_fDiffByTemp = CalcDependency(rows, "temp"); + result.m_fDiffByHumid = CalcDependency(rows, "humidity"); + result.m_fDiffByVel = CalcDependency(rows, "velocity"); + } + else + { - //foreach( var a in aa ) - //{ - // float fForce = (float)a.Key; - // float fAvg = a.Average(r => (float)r[m_ColumnMap["rpn"]]); - //} + } - //.Min(r => (float)r[m_ColumnMap["rpn"]]); - //aa.Min() - //float fMin = rows.GroupBy(r => r[m_ColumnMap["force"]])..Min(r => r[m_ColumnMap["rpn"]]); + return result; } @@ -235,14 +256,14 @@ namespace friction return m_strFileName; } - public List GetMaterialSpring() + public List GetSpringList() { - return m_MaterialSpring; + return m_SpringList; } - public List GetMaterialTable() + public List GetTableList() { - return m_MaterialTable; + return m_TableList; } public List GetColumns() diff --git a/MainForm.cs b/MainForm.cs index 812c30b..97543e6 100644 --- a/MainForm.cs +++ b/MainForm.cs @@ -95,8 +95,10 @@ namespace friction } #region Events from panels - public void OnApplyData() + public void OnApplyData(string strSpring, string strTable) { + m_DataHandler.SetSelectedMaterial(strSpring, strTable); + m_AnalysisPanel.UpdateData(m_DataHandler); OpenPanel(m_AnalysisPanel); } diff --git a/PanelAnalysis.Designer.cs b/PanelAnalysis.Designer.cs index 662b8f3..09a8c26 100644 --- a/PanelAnalysis.Designer.cs +++ b/PanelAnalysis.Designer.cs @@ -29,7 +29,19 @@ private void InitializeComponent() { this.dgvAnalysis = new System.Windows.Forms.DataGridView(); + this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel(); + this.label1 = new System.Windows.Forms.Label(); + this.label2 = new System.Windows.Forms.Label(); + this.label3 = new System.Windows.Forms.Label(); + this.label4 = new System.Windows.Forms.Label(); + this.label5 = new System.Windows.Forms.Label(); + this.label6 = new System.Windows.Forms.Label(); + this.label7 = new System.Windows.Forms.Label(); + this.label8 = new System.Windows.Forms.Label(); + this.label9 = new System.Windows.Forms.Label(); + this.label10 = new System.Windows.Forms.Label(); ((System.ComponentModel.ISupportInitialize)(this.dgvAnalysis)).BeginInit(); + this.tableLayoutPanel1.SuspendLayout(); this.SuspendLayout(); // // dgvAnalysis @@ -37,20 +49,165 @@ this.dgvAnalysis.AllowUserToAddRows = false; this.dgvAnalysis.AllowUserToDeleteRows = false; this.dgvAnalysis.AllowUserToOrderColumns = true; + this.dgvAnalysis.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); this.dgvAnalysis.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; this.dgvAnalysis.Location = new System.Drawing.Point(12, 12); this.dgvAnalysis.Name = "dgvAnalysis"; this.dgvAnalysis.ReadOnly = true; this.dgvAnalysis.RowTemplate.Height = 23; - this.dgvAnalysis.Size = new System.Drawing.Size(599, 442); + this.dgvAnalysis.Size = new System.Drawing.Size(856, 543); this.dgvAnalysis.TabIndex = 0; // + // tableLayoutPanel1 + // + this.tableLayoutPanel1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.tableLayoutPanel1.ColumnCount = 4; + this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 20F)); + this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 30F)); + this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 20F)); + this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 30F)); + this.tableLayoutPanel1.Controls.Add(this.label1, 0, 0); + this.tableLayoutPanel1.Controls.Add(this.label2, 2, 0); + this.tableLayoutPanel1.Controls.Add(this.label3, 1, 0); + this.tableLayoutPanel1.Controls.Add(this.label4, 1, 1); + this.tableLayoutPanel1.Controls.Add(this.label5, 1, 2); + this.tableLayoutPanel1.Controls.Add(this.label6, 3, 0); + this.tableLayoutPanel1.Controls.Add(this.label7, 3, 1); + this.tableLayoutPanel1.Controls.Add(this.label8, 3, 2); + this.tableLayoutPanel1.Controls.Add(this.label9, 3, 3); + this.tableLayoutPanel1.Controls.Add(this.label10, 3, 4); + this.tableLayoutPanel1.Location = new System.Drawing.Point(12, 561); + this.tableLayoutPanel1.Name = "tableLayoutPanel1"; + this.tableLayoutPanel1.RowCount = 5; + this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle()); + this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle()); + this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle()); + this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle()); + this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle()); + this.tableLayoutPanel1.Size = new System.Drawing.Size(856, 86); + this.tableLayoutPanel1.TabIndex = 1; + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Dock = System.Windows.Forms.DockStyle.Fill; + this.label1.Location = new System.Drawing.Point(3, 0); + this.label1.Name = "label1"; + this.tableLayoutPanel1.SetRowSpan(this.label1, 5); + this.label1.Size = new System.Drawing.Size(165, 86); + this.label1.TabIndex = 0; + this.label1.Text = "For smaller than 10 number of tests (marked red) results should be considered car" + + "efully"; + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(430, 0); + this.label2.Name = "label2"; + this.tableLayoutPanel1.SetRowSpan(this.label2, 5); + this.label2.Size = new System.Drawing.Size(135, 60); + this.label2.TabIndex = 1; + this.label2.Text = "For large standard deviations indicating a possible change of Stick-Slip Risk Cla" + + "ss (marked red)"; + // + // label3 + // + this.label3.AutoSize = true; + this.label3.BackColor = System.Drawing.Color.YellowGreen; + this.label3.Dock = System.Windows.Forms.DockStyle.Fill; + this.label3.Location = new System.Drawing.Point(174, 0); + this.label3.Name = "label3"; + this.label3.Size = new System.Drawing.Size(250, 12); + this.label3.TabIndex = 2; + this.label3.Text = "No Stick-Slip Risk"; + // + // label4 + // + this.label4.AutoSize = true; + this.label4.BackColor = System.Drawing.Color.Gold; + this.label4.Dock = System.Windows.Forms.DockStyle.Fill; + this.label4.Location = new System.Drawing.Point(174, 12); + this.label4.Name = "label4"; + this.label4.Size = new System.Drawing.Size(250, 12); + this.label4.TabIndex = 2; + this.label4.Text = "Potential S-Slip Risk"; + // + // label5 + // + this.label5.AutoSize = true; + this.label5.BackColor = System.Drawing.Color.DarkOrange; + this.label5.Dock = System.Windows.Forms.DockStyle.Fill; + this.label5.Location = new System.Drawing.Point(174, 24); + this.label5.Name = "label5"; + this.label5.Size = new System.Drawing.Size(250, 12); + this.label5.TabIndex = 2; + this.label5.Text = "High Stick-Slip Risk"; + // + // label6 + // + this.label6.AutoSize = true; + this.label6.BackColor = System.Drawing.Color.YellowGreen; + this.label6.Dock = System.Windows.Forms.DockStyle.Fill; + this.label6.Location = new System.Drawing.Point(601, 0); + this.label6.Name = "label6"; + this.label6.Size = new System.Drawing.Size(252, 12); + this.label6.TabIndex = 2; + this.label6.Text = "No Dependancy"; + // + // label7 + // + this.label7.AutoSize = true; + this.label7.BackColor = System.Drawing.Color.Gold; + this.label7.Dock = System.Windows.Forms.DockStyle.Fill; + this.label7.Location = new System.Drawing.Point(601, 12); + this.label7.Name = "label7"; + this.label7.Size = new System.Drawing.Size(252, 12); + this.label7.TabIndex = 2; + this.label7.Text = "Potential Dependancy"; + // + // label8 + // + this.label8.AutoSize = true; + this.label8.BackColor = System.Drawing.Color.DarkOrange; + this.label8.Dock = System.Windows.Forms.DockStyle.Fill; + this.label8.Location = new System.Drawing.Point(601, 24); + this.label8.Name = "label8"; + this.label8.Size = new System.Drawing.Size(252, 12); + this.label8.TabIndex = 2; + this.label8.Text = "Obvious Dependancy"; + // + // label9 + // + this.label9.AutoSize = true; + this.label9.BackColor = System.Drawing.Color.DarkGray; + this.label9.Dock = System.Windows.Forms.DockStyle.Fill; + this.label9.Location = new System.Drawing.Point(601, 36); + this.label9.Name = "label9"; + this.label9.Size = new System.Drawing.Size(252, 12); + this.label9.TabIndex = 2; + this.label9.Text = "Not Enough Data"; + // + // label10 + // + this.label10.AutoSize = true; + this.label10.BackColor = System.Drawing.Color.Snow; + this.label10.Dock = System.Windows.Forms.DockStyle.Fill; + this.label10.Location = new System.Drawing.Point(601, 48); + this.label10.Name = "label10"; + this.label10.Size = new System.Drawing.Size(252, 38); + this.label10.TabIndex = 2; + this.label10.Text = "Not Enough Data"; + // // PanelAnalysis // this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 12F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(623, 466); + this.ClientSize = new System.Drawing.Size(880, 649); this.ControlBox = false; + this.Controls.Add(this.tableLayoutPanel1); this.Controls.Add(this.dgvAnalysis); this.HideOnClose = true; this.Name = "PanelAnalysis"; @@ -58,6 +215,8 @@ this.TabText = "Analysis Table"; this.Text = "Analysis Table"; ((System.ComponentModel.ISupportInitialize)(this.dgvAnalysis)).EndInit(); + this.tableLayoutPanel1.ResumeLayout(false); + this.tableLayoutPanel1.PerformLayout(); this.ResumeLayout(false); } @@ -65,5 +224,16 @@ #endregion private System.Windows.Forms.DataGridView dgvAnalysis; + private System.Windows.Forms.TableLayoutPanel tableLayoutPanel1; + private System.Windows.Forms.Label label1; + private System.Windows.Forms.Label label2; + private System.Windows.Forms.Label label3; + private System.Windows.Forms.Label label4; + private System.Windows.Forms.Label label5; + private System.Windows.Forms.Label label6; + private System.Windows.Forms.Label label7; + private System.Windows.Forms.Label label8; + private System.Windows.Forms.Label label9; + private System.Windows.Forms.Label label10; } } \ No newline at end of file diff --git a/PanelAnalysis.cs b/PanelAnalysis.cs index cd66afa..d2b7001 100644 --- a/PanelAnalysis.cs +++ b/PanelAnalysis.cs @@ -32,6 +32,52 @@ namespace friction dgvAnalysis.Columns.Add("chTemp", "Temperature"); dgvAnalysis.Columns.Add("chHumi", "Rel. Humidity"); dgvAnalysis.Columns.Add("chVel", "Velocity"); + + Color green = Color.YellowGreen; + Color yellow = Color.Gold; + Color red = Color.DarkOrange; + Color gray = Color.DarkGray; + Color white = Color.Snow; + + string strSpring = data.GetCurSpring(); + foreach(string strTable in data.GetTableList()) + { + DataHandler.CalcResult result = data.GetCalc(strSpring, strTable); + + int iIdx = dgvAnalysis.Rows.Add(strTable, result.m_iCnt, result.m_fAvgRPN, result.m_fStdRPN, result.m_fDiffByForce, result.m_fDiffByTemp, result.m_fDiffByHumid, result.m_fDiffByVel); + + if (result.m_fAvgRPN <= 4) + dgvAnalysis.Rows[iIdx].Cells[2].Style.BackColor = green; + else if(result.m_fAvgRPN <= 7) + dgvAnalysis.Rows[iIdx].Cells[2].Style.BackColor = yellow; + else + dgvAnalysis.Rows[iIdx].Cells[2].Style.BackColor = red; + + if(result.m_iCnt <= 5) + { + dgvAnalysis.Rows[iIdx].Cells[3].Style.BackColor = white; + dgvAnalysis.Rows[iIdx].Cells[4].Style.BackColor = white; + dgvAnalysis.Rows[iIdx].Cells[5].Style.BackColor = white; + dgvAnalysis.Rows[iIdx].Cells[6].Style.BackColor = white; + dgvAnalysis.Rows[iIdx].Cells[7].Style.BackColor = white; + } + else if(result.m_iCnt <= 10) + { + dgvAnalysis.Rows[iIdx].Cells[3].Style.BackColor = gray; + dgvAnalysis.Rows[iIdx].Cells[4].Style.BackColor = gray; + dgvAnalysis.Rows[iIdx].Cells[5].Style.BackColor = gray; + dgvAnalysis.Rows[iIdx].Cells[6].Style.BackColor = gray; + dgvAnalysis.Rows[iIdx].Cells[7].Style.BackColor = gray; + } + else + { + dgvAnalysis.Rows[iIdx].Cells[3].Style.BackColor = (result.m_fStdRPN <= 1.5) ? green : red; + dgvAnalysis.Rows[iIdx].Cells[4].Style.BackColor = (result.m_fDiffByForce <= 1.5) ? green : red; + dgvAnalysis.Rows[iIdx].Cells[5].Style.BackColor = (result.m_fDiffByTemp <= 1.5) ? green : red; + dgvAnalysis.Rows[iIdx].Cells[6].Style.BackColor = (result.m_fDiffByHumid <= 1.5) ? green : red; + dgvAnalysis.Rows[iIdx].Cells[7].Style.BackColor = (result.m_fDiffByVel <= 1.5) ? green : red; + } + } } } } diff --git a/PanelMaterial.cs b/PanelMaterial.cs index 43dc4c1..37a1131 100644 --- a/PanelMaterial.cs +++ b/PanelMaterial.cs @@ -25,17 +25,17 @@ namespace friction public void UpdateData(DataHandler data) { - var MaterialSpring = data.GetMaterialSpring(); - var MaterialTable = data.GetMaterialTable(); + var SpringList = data.GetSpringList(); + var TableList = data.GetTableList(); cbMaterialSpring.Items.Clear(); - foreach (var x in MaterialSpring) + foreach (var x in SpringList) cbMaterialSpring.Items.Add(x); cbMaterialSpring.SelectedIndex = 0; cbMaterialTable.Items.Clear(); cbMaterialTable.Items.Add("All"); - foreach (var x in MaterialTable) + foreach (var x in TableList) cbMaterialTable.Items.Add(x); cbMaterialTable.SelectedIndex = 0; @@ -44,7 +44,7 @@ namespace friction private void btApply_Click(object sender, EventArgs e) { - m_Owner.OnApplyData(); + m_Owner.OnApplyData((string)cbMaterialSpring.SelectedItem, (string)cbMaterialTable.SelectedItem); } } }