Analysis 구현

This commit is contained in:
2017-06-19 19:23:01 +09:00
parent 7603deef0d
commit 7be92b315a
5 changed files with 273 additions and 34 deletions

View File

@@ -11,7 +11,7 @@ namespace friction
{ {
public class DataHandler public class DataHandler
{ {
public class CalcResult public struct CalcResult
{ {
public int m_iCnt; public int m_iCnt;
public float m_fAvgRPN; public float m_fAvgRPN;
@@ -40,11 +40,14 @@ namespace friction
string m_strFileName = ""; string m_strFileName = "";
string m_strFilePath = ""; string m_strFilePath = "";
string m_strCurSpring = "";
string m_strCurTable = "";
List<string> m_ColumnsNames = new List<string>(); List<string> m_ColumnsNames = new List<string>();
List<string> m_ActiveColumns = new List<string>(); List<string> m_ActiveColumns = new List<string>();
List<string> m_NonactiveColumns = new List<string>(); List<string> m_NonactiveColumns = new List<string>();
List<string> m_MaterialSpring = new List<string>(); List<string> m_SpringList = new List<string>();
List<string> m_MaterialTable = new List<string>(); List<string> m_TableList = new List<string>();
Dictionary<string, string> m_ColumnMap = new Dictionary<string, string>(); Dictionary<string, string> m_ColumnMap = new Dictionary<string, string>();
@@ -97,8 +100,14 @@ namespace friction
if (m_Data.Columns[iCol-1].DataType == typeof(float)) if (m_Data.Columns[iCol-1].DataType == typeof(float))
{ {
float fData = 0; float fData = 0;
if(value != null) if (value != null)
{
if (value is string)
float.TryParse((string)value, out fData);
else
fData = (float)(double)value; fData = (float)(double)value;
}
newRow[iCol - 1] = fData; newRow[iCol - 1] = fData;
} }
else 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<string>().ToList(); select r[m_ColumnMap["spring"]]).Distinct().Cast<string>().ToList();
m_MaterialTable = (from r in m_Data.AsEnumerable() m_TableList = (from r in m_Data.AsEnumerable()
select r[m_ColumnMap["table"]]).Distinct().Cast<string>().ToList(); select r[m_ColumnMap["table"]]).Distinct().Cast<string>().ToList();
m_ColumnsNames = (from c in m_Data.Columns.Cast<DataColumn>() m_ColumnsNames = (from c in m_Data.Columns.Cast<DataColumn>()
@@ -188,6 +197,18 @@ namespace friction
#region calculation #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) public CalcResult GetCalc(string strSpring, string strTable)
{ {
CalcResult result = new CalcResult(); 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); string strQuery = string.Format("[{0}]='{1}' and [{2}]='{3}'", m_ColumnMap["spring"], strSpring, m_ColumnMap["table"], strTable);
DataRow[] rows = m_Data.Select(strQuery); DataRow[] rows = m_Data.Select(strQuery);
if(rows.Length > 0)
{
result.m_iCnt = rows.Length; result.m_iCnt = rows.Length;
result.m_fAvgRPN = rows.Average(r => (float)r[m_ColumnMap["rpn"]]); 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 = rows.Average(r => (float)Math.Pow((float)r[m_ColumnMap["rpn"]] - result.m_fAvgRPN, 2));
result.m_fStdRPN = (float)Math.Sqrt(result.m_fStdRPN); result.m_fStdRPN = (float)Math.Sqrt(result.m_fStdRPN);
var aa = rows result.m_fDiffByForce = CalcDependency(rows, "force");
.GroupBy(r => r[m_ColumnMap["force"]]) result.m_fDiffByTemp = CalcDependency(rows, "temp");
.Select(t => t.Average(k => (float)k[m_ColumnMap["rpn"]])); 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; return result;
} }
@@ -235,14 +256,14 @@ namespace friction
return m_strFileName; return m_strFileName;
} }
public List<string> GetMaterialSpring() public List<string> GetSpringList()
{ {
return m_MaterialSpring; return m_SpringList;
} }
public List<string> GetMaterialTable() public List<string> GetTableList()
{ {
return m_MaterialTable; return m_TableList;
} }
public List<string> GetColumns() public List<string> GetColumns()

View File

@@ -95,8 +95,10 @@ namespace friction
} }
#region Events from panels #region Events from panels
public void OnApplyData() public void OnApplyData(string strSpring, string strTable)
{ {
m_DataHandler.SetSelectedMaterial(strSpring, strTable);
m_AnalysisPanel.UpdateData(m_DataHandler); m_AnalysisPanel.UpdateData(m_DataHandler);
OpenPanel(m_AnalysisPanel); OpenPanel(m_AnalysisPanel);
} }

View File

@@ -29,7 +29,19 @@
private void InitializeComponent() private void InitializeComponent()
{ {
this.dgvAnalysis = new System.Windows.Forms.DataGridView(); 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(); ((System.ComponentModel.ISupportInitialize)(this.dgvAnalysis)).BeginInit();
this.tableLayoutPanel1.SuspendLayout();
this.SuspendLayout(); this.SuspendLayout();
// //
// dgvAnalysis // dgvAnalysis
@@ -37,20 +49,165 @@
this.dgvAnalysis.AllowUserToAddRows = false; this.dgvAnalysis.AllowUserToAddRows = false;
this.dgvAnalysis.AllowUserToDeleteRows = false; this.dgvAnalysis.AllowUserToDeleteRows = false;
this.dgvAnalysis.AllowUserToOrderColumns = true; 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.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.dgvAnalysis.Location = new System.Drawing.Point(12, 12); this.dgvAnalysis.Location = new System.Drawing.Point(12, 12);
this.dgvAnalysis.Name = "dgvAnalysis"; this.dgvAnalysis.Name = "dgvAnalysis";
this.dgvAnalysis.ReadOnly = true; this.dgvAnalysis.ReadOnly = true;
this.dgvAnalysis.RowTemplate.Height = 23; 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; 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 // PanelAnalysis
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 12F); this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 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.ControlBox = false;
this.Controls.Add(this.tableLayoutPanel1);
this.Controls.Add(this.dgvAnalysis); this.Controls.Add(this.dgvAnalysis);
this.HideOnClose = true; this.HideOnClose = true;
this.Name = "PanelAnalysis"; this.Name = "PanelAnalysis";
@@ -58,6 +215,8 @@
this.TabText = "Analysis Table"; this.TabText = "Analysis Table";
this.Text = "Analysis Table"; this.Text = "Analysis Table";
((System.ComponentModel.ISupportInitialize)(this.dgvAnalysis)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.dgvAnalysis)).EndInit();
this.tableLayoutPanel1.ResumeLayout(false);
this.tableLayoutPanel1.PerformLayout();
this.ResumeLayout(false); this.ResumeLayout(false);
} }
@@ -65,5 +224,16 @@
#endregion #endregion
private System.Windows.Forms.DataGridView dgvAnalysis; 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;
} }
} }

View File

@@ -32,6 +32,52 @@ namespace friction
dgvAnalysis.Columns.Add("chTemp", "Temperature"); dgvAnalysis.Columns.Add("chTemp", "Temperature");
dgvAnalysis.Columns.Add("chHumi", "Rel. Humidity"); dgvAnalysis.Columns.Add("chHumi", "Rel. Humidity");
dgvAnalysis.Columns.Add("chVel", "Velocity"); 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;
}
}
} }
} }
} }

View File

@@ -25,17 +25,17 @@ namespace friction
public void UpdateData(DataHandler data) public void UpdateData(DataHandler data)
{ {
var MaterialSpring = data.GetMaterialSpring(); var SpringList = data.GetSpringList();
var MaterialTable = data.GetMaterialTable(); var TableList = data.GetTableList();
cbMaterialSpring.Items.Clear(); cbMaterialSpring.Items.Clear();
foreach (var x in MaterialSpring) foreach (var x in SpringList)
cbMaterialSpring.Items.Add(x); cbMaterialSpring.Items.Add(x);
cbMaterialSpring.SelectedIndex = 0; cbMaterialSpring.SelectedIndex = 0;
cbMaterialTable.Items.Clear(); cbMaterialTable.Items.Clear();
cbMaterialTable.Items.Add("All"); cbMaterialTable.Items.Add("All");
foreach (var x in MaterialTable) foreach (var x in TableList)
cbMaterialTable.Items.Add(x); cbMaterialTable.Items.Add(x);
cbMaterialTable.SelectedIndex = 0; cbMaterialTable.SelectedIndex = 0;
@@ -44,7 +44,7 @@ namespace friction
private void btApply_Click(object sender, EventArgs e) private void btApply_Click(object sender, EventArgs e)
{ {
m_Owner.OnApplyData(); m_Owner.OnApplyData((string)cbMaterialSpring.SelectedItem, (string)cbMaterialTable.SelectedItem);
} }
} }
} }