Exemplo n.º 1
0
        /// <summary>
        /// 计算总平均值
        /// </summary>
        /// <param name="dataTable">原始数据</param>
        /// <param name="xAvgList">每组样本平均值</param>
        /// <returns>总平均值</returns>
        public static double CalculateTotalXAverage(DataTable dataTable, DataTable dataTable_Group, out List <SpcPoints> xAvgList)
        {
            decimal xTotalAvg = 0; //总平均值

            xAvgList = new List <SpcPoints>();

            foreach (DataRow dr in dataTable_Group.Rows)
            {
                DataRow[] dr_dataTable = dataTable.Select(string.Format("EDC_INS_KEY='{0}'", dr["EDC_INS_KEY"].ToString()));
                if (dr_dataTable == null || dr_dataTable.Length == 0)
                {
                    continue;
                }


                decimal   xAvg   = 0; //每组样本平均值
                SpcPoints points = new SpcPoints();
                for (int i = 0; i < dr_dataTable.Length; i++)
                {
                    string  colKey = dr_dataTable[i][SPC_PARAM_DATA_FIELDS.COL_KEY].ToString();
                    decimal value  = Convert.ToDecimal(dr_dataTable[i][SPC_PARAM_DATA_FIELDS.PARAM_VALUE]);
                    KeyValuePair <string, decimal> kvp = new KeyValuePair <string, decimal>(colKey, value);
                    points.listPoint.Add(kvp);
                    xAvg += value;
                }

                //是否被修改过
                points.editFlag = Convert.ToInt32(dr_dataTable[0][SPC_PARAM_DATA_FIELDS.EDIT_FLAG].ToString());
                //点的创建日期
                points.createTime = dr[SPC_PARAM_DATA_FIELDS.CREATE_TIME].ToString();
                //点的供应商
                points.supplier = dr[SPC_PARAM_DATA_FIELDS.SUPPLIER].ToString();
                //点的批次号
                points.lotNumber = dr[SPC_PARAM_DATA_FIELDS.LOT_NUMBER].ToString();
                //数据采集键值
                points.edc_ins_key = dr[SPC_PARAM_DATA_FIELDS.EDC_INS_KEY].ToString();

                //xAvg = xAvg / n;
                xAvg         = xAvg / points.listPoint.Count;
                points.value = Convert.ToDouble(Math.Round(xAvg, 4));
                xAvgList.Add(points);
                xTotalAvg += xAvg;
            }
            //xTotalAvg=xTotalAvg/(dataTable.Rows.Count/n);
            //xTotalAvg = xTotalAvg / Math.Ceiling(Convert.ToDecimal(dataTable.Rows.Count / dataTable_Group.Rows.Count));

            xTotalAvg = xTotalAvg / dataTable_Group.Rows.Count; //dataTable_Group.Rows.Count 表示点数
            //返回总的平均值
            return(Convert.ToDouble(Math.Round(xTotalAvg, 5)));
        }
Exemplo n.º 2
0
        /// <summary>
        /// 计算总平均值
        /// </summary>
        /// <param name="dataTable">原始数据</param>
        /// <param name="n">样本容量大小</param>
        /// <param name="xAvgList">每组样本平均值</param>
        /// <returns>总平均值</returns>
        public static double CalculateTotalXAverage(DataTable dataTable, int n, out List <SpcPoints> xAvgList)
        {
            //总平均值
            decimal xTotalAvg = 0;

            //存放子组数量
            xAvgList = new List <SpcPoints>();

            for (int i = 0; i < dataTable.Rows.Count; i = i + n)
            {
                //每组样本平均值
                decimal xAvg = 0;
                //单点
                SpcPoints points = new SpcPoints();
                for (int j = 0; j < n; j++)
                {
                    if ((i + j) < dataTable.Rows.Count)
                    {
                        string  colKey = dataTable.Rows[i + j][SPC_PARAM_DATA_FIELDS.COL_KEY].ToString();
                        decimal value  = Convert.ToDecimal(dataTable.Rows[i + j][SPC_PARAM_DATA_FIELDS.PARAM_VALUE]);
                        KeyValuePair <string, decimal> kvp = new KeyValuePair <string, decimal>(colKey, value);
                        points.listPoint.Add(kvp);
                        xAvg += value;
                    }
                }
                //xAvg = xAvg / n;
                xAvg         = xAvg / points.listPoint.Count;
                points.value = Convert.ToDouble(Math.Round(xAvg, 4));
                xAvgList.Add(points);
                xTotalAvg += xAvg;
            }
            //计算总的平均值
            //xTotalAvg=xTotalAvg/(dataTable.Rows.Count/n);
            xTotalAvg = xTotalAvg / Math.Ceiling(Convert.ToDecimal(dataTable.Rows.Count / n));
            return(Convert.ToDouble(Math.Round(xTotalAvg, 10)));
        }