private void RefreshInformation() { pralgthHelper = new PriAlgorithmHelper();//数据操作类 RemoveTipBean rtb = pralgthHelper.RemoveStepJumpTip(datain, dataselect, DataProcessMethod.RemoveJump, num_simple, lr); this.richTxtboxNote.Text = rtb.Tip; this.lbExpectOffsetV.Text = rtb.Offset.ToString(); this.radioGroup.Properties.Items[0].Description = rtb.BothAve; this.radioGroup.Properties.Items[1].Description = rtb.LeftAve; this.radioGroup.Properties.Items[2].Description = rtb.RightAve; }
private void RefreshInformation() { string selectexStr = this.radioGroup.Properties.Items[this.radioGroup.SelectedIndex].ToString(); if (selectexStr == string.Empty) { return; } pralgthHelper = new PriAlgorithmHelper(); int num_simple = int.Parse(this.spinEditAvgSimpling.Text); RemoveTipBean rtb = pralgthHelper.RemoveStepJumpTip(datain, dataselect, DataProcessMethod.RemoveStep, num_simple, selectexStr.Contains("消除左侧") ? Left_Right.left : Left_Right.right); this.richTxtboxNote.Text = rtb.Tip; this.lbExpectOffsetV.Text = rtb.Offset.ToString(); this.radioGroup.Properties.Items[0].Description = rtb.LeftAve; this.radioGroup.Properties.Items[1].Description = rtb.RightAve; this.lbDataCount.Text = selectexStr.Contains("消除左侧") ? "左侧" + rtb.Totaleft.ToString() + "个" : "右侧" + rtb.Totalright.ToString() + "个"; }
/// <summary> ///为未初始化消突跳或台阶做预处理 /// </summary> /// <param name="dataIn"></param> /// <param name="datasel"></param> /// <param name="oper"></param> /// <param name="Num_Sample">采样数</param> /// <returns></returns> public RemoveTipBean RemoveStepJumpTip(DataTable dataIn, DataTable datasel, DataProcessMethod oper, int Num_Sample, Left_Right LRB) { RemoveTipBean rt = new RemoveTipBean(); // Num_Sample = 5; try { DateTime startSel = DateTime.Parse(datasel.Rows[0][0].ToString()); DateTime endSel = DateTime.Parse(datasel.Rows[datasel.Rows.Count - 1][0].ToString()); double val_left = double.Parse(datasel.Rows[0][1].ToString()); double val_right = double.Parse(datasel.Rows[datasel.Rows.Count - 1][1].ToString()); int tatal = dataIn.Rows.Count; int select = datasel.Rows.Count; //选择数据总数 /*获取相邻观测值差的绝对值最大的两个值对应的序列号*/ int index_stepL = 0, index_stepR = 0; for (int i = 0; i < select - 1; i++) { double biggest = 0; double step = System.Math.Abs(double.Parse(datasel.Rows[i][1].ToString()) - double.Parse(datasel.Rows[i + 1][1].ToString())); if (step > biggest) { index_stepL = i; index_stepR = i + 1; biggest = step; } } int index = 0; foreach (DataRow dr in dataIn.Rows) { if (DateTime.Parse(dr[0].ToString()).CompareTo(startSel) == 0) { index_left = index; } if (DateTime.Parse(dr[0].ToString()).CompareTo(endSel) == 0) { index_right = index; break; } index++; } //消台阶或消突跳 switch (oper) { case DataProcessMethod.RemoveJump: //消突跳 { foreach (DataRow dr in dataIn.Rows) { DateTime t = DateTime.Parse(dr[0].ToString()); if (t.CompareTo(startSel) < 0) { n_left++; } if ((t.CompareTo(endSel) > 0) && (n_right < Num_Sample)) { n_right++; ave_right += double.Parse(dr[1].ToString()); } } ave_left = double.Parse(dataIn.Rows[n_left][1].ToString()); double cal = 0; int n_cal = 0; int Sample = Num_Sample; if (n_left > 0) { for (int i = n_left - 1; i >= 0; i--) { if (Sample == 0) { break; } cal += double.Parse(dataIn.Rows[i][1].ToString()); n_cal++; Sample--; } } if (n_cal > 0) { ave_left = cal / n_cal; } ave_right = ave_right / n_right; //移动台阶左侧(偏移%f) double left_ave = ave_left; //移动台阶右侧(偏移%f) double right_ave = ave_right; //偏移量选择 double var = 0; switch (LRB) { case Left_Right.left: var = ave_left - val_left; break; case Left_Right.right: var = ave_right - val_right; break; case Left_Right.both: var = (ave_left + ave_right) / 2 - (val_left + val_right) / 2; break; default: break; } m_offset = var; //实例化提示信息 rt.LeftAve = "左侧采样平均值(" + Convert.ToString(ave_left) + ")"; rt.RightAve = "右侧采样平均值(" + Convert.ToString(ave_right) + ")"; rt.BothAve = "两侧采样平均值(" + Convert.ToString((ave_left + ave_right) / 2) + ")"; rt.TargetNum = "待处理目标数量:" + Convert.ToString(select) + ")"; rt.Offset = m_offset; //偏移量 rt.Tip = "[突跳消除@" + DateTime.Now.ToShortDateString() + "]\r\n偏移值:" + Math.Round(m_offset, 2).ToString() + "\r\n偏移区间:" + startSel.ToShortDateString() + "-" + endSel.ToShortDateString(); TipLeftIndex = n_left; TipRightIndex = n_left + datasel.Rows.Count - 1; Tipstr = rt.Tip; } break; case DataProcessMethod.RemoveStep: DateTime dateL = DateTime.Parse(datasel.Rows[index_stepL][0].ToString()); DateTime dateR = DateTime.Parse(datasel.Rows[index_stepR][0].ToString()); //计算消除左台阶起算索引 nLeftStep = index_stepL + index_left; //左 nRightStep = nLeftStep + 1; //消除右侧台阶起算索引 //计算左侧平均偏移量 int nL = 0; double totalright = 0; foreach (DataRow dr in dataIn.Rows) { if (DateTime.Parse(dr[0].ToString()).CompareTo(dateR) >= 0 && nL < Num_Sample) { nL++; totalright += double.Parse(dr[1].ToString()); } } ave_left = totalright / nL; //计算右侧平均偏移量 int nR = 0; double totalleft = 0; int RSample = Num_Sample; for (int i = nLeftStep; i >= 0; i--) { if (RSample == 0) { break; } totalleft += double.Parse(dataIn.Rows[i][1].ToString()); nR++; RSample--; } ave_right = totalleft / nR; //偏移量 m_offset = (LRB == Left_Right.left) ? (ave_left - ave_right) : (ave_right - ave_left); //实例化提示语句 rt.LeftAve = "消除左侧(平均值" + Convert.ToString(ave_left) + ")"; rt.RightAve = "消除右侧(平均值" + Convert.ToString(ave_right) + ")"; rt.Totalright = dataIn.Rows.Count - (index_stepL + index_left + 1 + 1); rt.Totaleft = index_stepL + index_left; rt.Offset = m_offset; rt.Tip = "[台阶消除@" + DateTime.Now.ToShortDateString() + "]\r\n偏移值:" + Math.Round(m_offset, 2).ToString(); TipLeftIndex = nLeftStep; TipRightIndex = nLeftStep + datasel.Rows.Count - 1; Tipstr = rt.Tip; break; default: break; } } catch (Exception ex) { rt = null; throw new Exception(ex.Message); } return(rt); }