diff --git a/DataHandler.cs b/DataHandler.cs index 842d0e0..a921f41 100644 --- a/DataHandler.cs +++ b/DataHandler.cs @@ -11,6 +11,19 @@ namespace friction { public class DataHandler { + public class CalcResult + { + public int m_iCnt; + public float m_fAvgRPN; + public float m_fStdRPN; + public float m_fDiffByForce; + public float m_fDiffByTemp; + public float m_fDiffByHumid; + public float m_fDiffByVel; + } + + + DataTable m_Data = new DataTable(); string m_strFileName = ""; @@ -19,8 +32,8 @@ namespace friction List m_ColumnsNames = new List(); List m_ActiveColumns = new List(); List m_NonactiveColumns = new List(); - List m_Material1 = new List(); - List m_Material2 = new List(); + List m_MaterialSpring = new List(); + List m_MaterialTable = new List(); Dictionary m_ColumnMap = new Dictionary(); @@ -28,14 +41,23 @@ namespace friction { m_ColumnMap["spring"] = "Material spring"; m_ColumnMap["table"] = "material 2 table"; - m_ColumnMap["priority"] = "Risk priority number"; + m_ColumnMap["rpn"] = "Risk priority number"; m_ColumnMap["force"] = "normal force"; m_ColumnMap["temp"] = "Temperature"; m_ColumnMap["humidity"] = "Relative humidity"; m_ColumnMap["velocity"] = "Relative velocity"; } - public void LoadData2(string strFilePath) + bool IsNumberColumn(string strColumn) + { + return (strColumn == m_ColumnMap["rpn"] || + strColumn == m_ColumnMap["force"] || + strColumn == m_ColumnMap["temp"] || + strColumn == m_ColumnMap["humidity"] || + strColumn == m_ColumnMap["velocity"]); + } + + public void LoadData(string strFilePath) { using (ExcelPackage package = new ExcelPackage()) { @@ -50,7 +72,7 @@ namespace friction for (int iCol = Sheet.Dimension.Start.Column; iCol <= Sheet.Dimension.End.Column; iCol++) { string strCol = (string)Sheet.Cells[Sheet.Dimension.Start.Row, iCol].Value; - m_Data.Columns.Add(new DataColumn(strCol)); + m_Data.Columns.Add(new DataColumn(strCol, IsNumberColumn(strCol) ? typeof(float) : typeof(string))); } // read data @@ -61,10 +83,11 @@ namespace friction for (int iCol = Sheet.Dimension.Start.Column; iCol <= Sheet.Dimension.End.Column; iCol++) { var value = Sheet.Cells[iRow, iCol].Value; - - if (value is double) + if (m_Data.Columns[iCol-1].DataType == typeof(float)) { - float fData = (float)(double)value; + float fData = 0; + if(value != null) + fData = (float)(double)value; newRow[iCol - 1] = fData; } else @@ -72,7 +95,7 @@ namespace friction string strData = ""; if (value != null) { - strData = (string)value; + strData = value.ToString(); strData = strData.Trim(); } @@ -82,13 +105,17 @@ namespace friction m_Data.Rows.Add(newRow); } + + m_strFilePath = strFilePath; + int iSeperate = strFilePath.LastIndexOf('\\'); + m_strFileName = strFilePath.Substring(iSeperate+1); } - m_Material1 = (from r in m_Data.AsEnumerable() + m_MaterialSpring = (from r in m_Data.AsEnumerable() select r[m_ColumnMap["spring"]]).Distinct().Cast().ToList(); - m_Material2 = (from r in m_Data.AsEnumerable() + m_MaterialTable = (from r in m_Data.AsEnumerable() select r[m_ColumnMap["table"]]).Distinct().Cast().ToList(); m_ColumnsNames = (from c in m_Data.Columns.Cast() @@ -111,21 +138,68 @@ namespace friction m_ActiveColumns.Add(m_ColumnsNames[i]); } } + + + //GetCalc("ABS", "ABS"); } + + #region calculation + public CalcResult GetCalc(string strSpring, string strTable) + { + CalcResult result = new CalcResult(); + + 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); + + var aa = rows + .GroupBy(r => r[m_ColumnMap["force"]]) + .Select(t => t.Average(k => (float)k[m_ColumnMap["rpn"]])); + + //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; + } + #endregion + + + #region get public DataTable GetData() { return m_Data; } + public string GetFilePath() + { + return m_strFilePath; + } + + public string GetFileName() + { + return m_strFileName; + } + public List GetMaterialSpring() { - return m_Material1; + return m_MaterialSpring; } public List GetMaterialTable() { - return m_Material2; + return m_MaterialTable; } public List GetColumns() @@ -142,5 +216,6 @@ namespace friction { return m_NonactiveColumns; } + #endregion } } diff --git a/MainForm.cs b/MainForm.cs index ff33fc5..59b6b0f 100644 --- a/MainForm.cs +++ b/MainForm.cs @@ -17,6 +17,9 @@ namespace friction DataHandler m_DataHandler = new DataHandler(); PanelMaterial m_MaterialPanel = null; PanelResult m_ResultPanel = null; + PanelAnalysis m_AnalysisPanel = null; + PanelRadarGraph m_RadarGraphPanel = null; + PanelTrendGraph m_TrendGraphPanel = null; public MainForm() { @@ -25,6 +28,9 @@ namespace friction dockPanel.Theme = new VS2015DarkTheme(); m_MaterialPanel = new PanelMaterial(this); m_ResultPanel = new PanelResult(this); + m_AnalysisPanel = new PanelAnalysis(this); + m_RadarGraphPanel = new PanelRadarGraph(this); + m_TrendGraphPanel = new PanelTrendGraph(this); } private void OpenPanel(DockContent panel) @@ -51,7 +57,7 @@ namespace friction if (result == DialogResult.OK) { m_DBFileName = ofd.FileName; - m_DataHandler.LoadData2(m_DBFileName); + m_DataHandler.LoadData(m_DBFileName); m_MaterialPanel.UpdateData(m_DataHandler); OpenPanel(m_MaterialPanel); @@ -75,23 +81,24 @@ namespace friction private void toolStripButtonAnalysis_Click(object sender, EventArgs e) { - + OpenPanel(m_AnalysisPanel); } private void toolStripButtonRadarGraph_Click(object sender, EventArgs e) { - + OpenPanel(m_RadarGraphPanel); } private void toolStripButtonTrendGraph_Click(object sender, EventArgs e) { - + OpenPanel(m_TrendGraphPanel); } #region Events from panels public void OnApplyData() { - + m_AnalysisPanel.UpdateData(m_DataHandler); + OpenPanel(m_AnalysisPanel); } public void OnColumnChecked(string strColumn, bool bChecked) diff --git a/PanelAnalysis.Designer.cs b/PanelAnalysis.Designer.cs new file mode 100644 index 0000000..662b8f3 --- /dev/null +++ b/PanelAnalysis.Designer.cs @@ -0,0 +1,69 @@ +namespace friction +{ + partial class PanelAnalysis + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.dgvAnalysis = new System.Windows.Forms.DataGridView(); + ((System.ComponentModel.ISupportInitialize)(this.dgvAnalysis)).BeginInit(); + this.SuspendLayout(); + // + // dgvAnalysis + // + this.dgvAnalysis.AllowUserToAddRows = false; + this.dgvAnalysis.AllowUserToDeleteRows = false; + this.dgvAnalysis.AllowUserToOrderColumns = true; + 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.TabIndex = 0; + // + // 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.ControlBox = false; + this.Controls.Add(this.dgvAnalysis); + this.HideOnClose = true; + this.Name = "PanelAnalysis"; + this.ShowHint = WeifenLuo.WinFormsUI.Docking.DockState.Document; + this.TabText = "Analysis Table"; + this.Text = "Analysis Table"; + ((System.ComponentModel.ISupportInitialize)(this.dgvAnalysis)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.DataGridView dgvAnalysis; + } +} \ No newline at end of file diff --git a/PanelAnalysis.cs b/PanelAnalysis.cs new file mode 100644 index 0000000..cd66afa --- /dev/null +++ b/PanelAnalysis.cs @@ -0,0 +1,37 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using WeifenLuo.WinFormsUI.Docking; + +namespace friction +{ + public partial class PanelAnalysis : DockContent + { + MainForm m_Owner = null; + + public PanelAnalysis(MainForm owner) + { + InitializeComponent(); + + m_Owner = owner; + } + + public void UpdateData(DataHandler data) + { + dgvAnalysis.Columns.Add("chTable", "Table"); + dgvAnalysis.Columns.Add("chNoTest", "No. of Tests"); + dgvAnalysis.Columns.Add("chAvg", "Average RPN"); + dgvAnalysis.Columns.Add("chSTD", "stdev RPN"); + dgvAnalysis.Columns.Add("chForce", "Normal Force"); + dgvAnalysis.Columns.Add("chTemp", "Temperature"); + dgvAnalysis.Columns.Add("chHumi", "Rel. Humidity"); + dgvAnalysis.Columns.Add("chVel", "Velocity"); + } + } +} diff --git a/PanelAnalysis.resx b/PanelAnalysis.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/PanelAnalysis.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/PanelMaterial.Designer.cs b/PanelMaterial.Designer.cs index 73085b9..2d5995e 100644 --- a/PanelMaterial.Designer.cs +++ b/PanelMaterial.Designer.cs @@ -31,7 +31,7 @@ this.cbMaterialTable = new System.Windows.Forms.ComboBox(); this.cbMaterialSpring = new System.Windows.Forms.ComboBox(); this.btApply = new System.Windows.Forms.Button(); - this.label1 = new System.Windows.Forms.Label(); + this.lbFileName = new System.Windows.Forms.Label(); this.label2 = new System.Windows.Forms.Label(); this.label3 = new System.Windows.Forms.Label(); this.SuspendLayout(); @@ -64,14 +64,14 @@ this.btApply.UseVisualStyleBackColor = true; this.btApply.Click += new System.EventHandler(this.btApply_Click); // - // label1 + // lbFileName // - this.label1.AutoSize = true; - this.label1.Font = new System.Drawing.Font("Malgun Gothic", 14.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(129))); - this.label1.Location = new System.Drawing.Point(12, 9); - this.label1.Name = "label1"; - this.label1.Size = new System.Drawing.Size(0, 25); - this.label1.TabIndex = 4; + this.lbFileName.AutoSize = true; + this.lbFileName.Font = new System.Drawing.Font("Malgun Gothic", 14.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(129))); + this.lbFileName.Location = new System.Drawing.Point(7, 9); + this.lbFileName.Name = "lbFileName"; + this.lbFileName.Size = new System.Drawing.Size(0, 25); + this.lbFileName.TabIndex = 4; // // label2 // @@ -99,7 +99,7 @@ this.ControlBox = false; this.Controls.Add(this.label3); this.Controls.Add(this.label2); - this.Controls.Add(this.label1); + this.Controls.Add(this.lbFileName); this.Controls.Add(this.btApply); this.Controls.Add(this.cbMaterialSpring); this.Controls.Add(this.cbMaterialTable); @@ -118,7 +118,7 @@ private System.Windows.Forms.ComboBox cbMaterialTable; private System.Windows.Forms.ComboBox cbMaterialSpring; private System.Windows.Forms.Button btApply; - private System.Windows.Forms.Label label1; + private System.Windows.Forms.Label lbFileName; private System.Windows.Forms.Label label2; private System.Windows.Forms.Label label3; } diff --git a/PanelMaterial.cs b/PanelMaterial.cs index 23420c8..43dc4c1 100644 --- a/PanelMaterial.cs +++ b/PanelMaterial.cs @@ -29,7 +29,6 @@ namespace friction var MaterialTable = data.GetMaterialTable(); cbMaterialSpring.Items.Clear(); - cbMaterialSpring.Items.Add("All"); foreach (var x in MaterialSpring) cbMaterialSpring.Items.Add(x); cbMaterialSpring.SelectedIndex = 0; @@ -39,6 +38,8 @@ namespace friction foreach (var x in MaterialTable) cbMaterialTable.Items.Add(x); cbMaterialTable.SelectedIndex = 0; + + lbFileName.Text = data.GetFileName(); } private void btApply_Click(object sender, EventArgs e) diff --git a/PanelRadarGraph.Designer.cs b/PanelRadarGraph.Designer.cs new file mode 100644 index 0000000..d88fa85 --- /dev/null +++ b/PanelRadarGraph.Designer.cs @@ -0,0 +1,50 @@ +namespace friction +{ + partial class PanelRadarGraph + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.SuspendLayout(); + // + // PanelRadarGraph + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 12F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(284, 261); + this.ControlBox = false; + this.HideOnClose = true; + this.Name = "PanelRadarGraph"; + this.ShowHint = WeifenLuo.WinFormsUI.Docking.DockState.Document; + this.TabText = "Radar Graph"; + this.Text = "Radar Graph"; + this.ResumeLayout(false); + + } + + #endregion + } +} \ No newline at end of file diff --git a/PanelRadarGraph.cs b/PanelRadarGraph.cs new file mode 100644 index 0000000..560de3e --- /dev/null +++ b/PanelRadarGraph.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using WeifenLuo.WinFormsUI.Docking; + +namespace friction +{ + public partial class PanelRadarGraph : DockContent + { + MainForm m_Owner = null; + + public PanelRadarGraph(MainForm owner) + { + InitializeComponent(); + + m_Owner = owner; + } + } +} diff --git a/PanelRadarGraph.resx b/PanelRadarGraph.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/PanelRadarGraph.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/PanelResult.Designer.cs b/PanelResult.Designer.cs index 52e4dde..6594064 100644 --- a/PanelResult.Designer.cs +++ b/PanelResult.Designer.cs @@ -39,6 +39,8 @@ // // dgvData // + this.dgvData.AllowUserToAddRows = false; + this.dgvData.AllowUserToDeleteRows = false; this.dgvData.AllowUserToOrderColumns = true; this.dgvData.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Left) @@ -46,6 +48,7 @@ this.dgvData.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; this.dgvData.Location = new System.Drawing.Point(3, 3); this.dgvData.Name = "dgvData"; + this.dgvData.ReadOnly = true; this.dgvData.RowTemplate.Height = 23; this.dgvData.Size = new System.Drawing.Size(713, 724); this.dgvData.TabIndex = 0; diff --git a/PanelResult.cs b/PanelResult.cs index 29a7951..7f2ac25 100644 --- a/PanelResult.cs +++ b/PanelResult.cs @@ -22,9 +22,9 @@ namespace friction m_Owner = owner; } - public void UpdateData(DataHandler dataHandler) + public void UpdateData(DataHandler data) { - dgvData.DataSource = dataHandler.GetData(); + dgvData.DataSource = data.GetData(); Dictionary CacheChecked = new Dictionary(); @@ -39,7 +39,7 @@ namespace friction lvColumn.Groups[1].Items.Clear(); lvColumn.Items.Clear(); - List> Columns = new List>() { dataHandler.GetActiveColumns(), dataHandler.GetNonactiveColumns() }; + List> Columns = new List>() { data.GetActiveColumns(), data.GetNonactiveColumns() }; for(int iGroup=0; iGroup + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.SuspendLayout(); + // + // PanelTrendGraph + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 12F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(284, 261); + this.ControlBox = false; + this.HideOnClose = true; + this.Name = "PanelTrendGraph"; + this.ShowHint = WeifenLuo.WinFormsUI.Docking.DockState.Document; + this.TabText = "Trend Graph"; + this.Text = "Trend Graph"; + this.ResumeLayout(false); + + } + + #endregion + } +} \ No newline at end of file diff --git a/PanelTrendGraph.cs b/PanelTrendGraph.cs new file mode 100644 index 0000000..5c5e46c --- /dev/null +++ b/PanelTrendGraph.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using WeifenLuo.WinFormsUI.Docking; + +namespace friction +{ + public partial class PanelTrendGraph : DockContent + { + MainForm m_Owner = null; + + public PanelTrendGraph(MainForm owner) + { + InitializeComponent(); + + m_Owner = owner; + } + } +} diff --git a/PanelTrendGraph.resx b/PanelTrendGraph.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/PanelTrendGraph.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/friction.csproj b/friction.csproj index 355d466..0f74541 100644 --- a/friction.csproj +++ b/friction.csproj @@ -57,6 +57,24 @@ MainForm.cs + + Form + + + PanelAnalysis.cs + + + Form + + + PanelRadarGraph.cs + + + Form + + + PanelTrendGraph.cs + @@ -74,6 +92,15 @@ MainForm.cs + + PanelAnalysis.cs + + + PanelRadarGraph.cs + + + PanelTrendGraph.cs + ResXFileCodeGenerator Resources.Designer.cs