void InitList() { MethodSimpleElementFormula msef = Method.GetElHeader(Element).Formula[Formula]; chFixList.Items.Clear(); for (int i = 0; i < msef.Formula.Founds.Count; i++) { chFixList.Items.Add(msef.Formula.Founds[i].ToString()); } }
public SpectrCalc(MethodSimple ms, int el_index, int formula_index) { MethodSimpleElement mse = ms.GetElHeader(el_index); Formula = mse.Formula[formula_index]; double ly = (double)Formula.Formula.analitParamCalc.methodLineCalc1.nmLy.Value; bool next = Formula.Formula.analitParamCalc.methodLineCalc1.cbFromSnNum.SelectedIndex == 1; int pr_count = ms.GetProbCount(); for (int pr = 0; pr < pr_count; pr++) { List <Data> prob_data = new List <SpectrCalc.Data>(); MethodSimpleProb msp = ms.GetProbHeader(pr); int sp_count = msp.MeasuredSpectrs.Count; for (int sp = 0; sp < sp_count; sp++) { MethodSimpleCell msc = ms.GetCell(el_index, pr); MethodSimpleCellFormulaResult mscfr = msc.GetData(sp, formula_index); MethodSimpleProbMeasuring mspm = msp.MeasuredSpectrs[sp]; if (mscfr.Enabled) { prob_data.Add(new Data(mspm.Sp, (float)msc.Con, ly, next)); } } DataSet.Add(prob_data); } }
public static List <MethodData> getData(MethodSimple method, int element, int formula, bool use_all, out int used) { MethodSimpleElementFormula msef = method.GetElHeader(element).Formula[formula]; bool[] used_frames = msef.Formula.GetUsedFrames(); List <MethodData> ret = new List <MethodData>(); int prob_count = method.GetProbCount(); used = 0; for (int pr = 0; pr < prob_count; pr++) { MethodSimpleProb m_prob = method.GetProbHeader(pr); MethodSimpleCell m_cell = method.GetCell(element, pr); double con = m_cell.Con; if (con < 0) { continue; } int sub_prob_count = method.GetSubProbCount(pr); for (int sub_pr = 0; sub_pr < sub_prob_count; sub_pr++) { MethodSimpleProbMeasuring m_prob_measuring = m_prob.MeasuredSpectrs[sub_pr]; Spectr sp = m_prob_measuring.Sp; if (sp == null) { continue; } bool en = m_cell.GetData(sub_pr, formula).Enabled; if (use_all == true) { en = true; } int short_count = sp.GetShotCount(); int[] shorts = sp.GetShotIndexes(); for (int short_index = 0; short_index < shorts.Length; short_index++) { bool fl = en & used_frames[short_index]; if (fl) { used++; } MethodData md = new MethodData(con, fl, pr, sub_pr, short_index, sp.GetViewsSet()[shorts[short_index]], sp.GetNullFor(shorts[short_index]), sp.GetCommonDispers()); ret.Add(md); } } } if (ret.Count == 0) { return(null); } return(ret); }
public String ShowSelector(MethodSimple ms, SimpleFormula editor) { cbElementSelector.Items.Clear(); for (int e = 0; e < ms.GetElementCount(); e++) { cbElementSelector.Items.Add(ms.GetElHeader(e).Element.Name); } ShowDialog(editor); if (cbElementSelector.SelectedIndex < 0) { return(null); } return((String)cbElementSelector.Items[cbElementSelector.SelectedIndex]); }
private void buttonSetInMethod_Click(object sender, EventArgs e) { try { Result res = Candidates[listboxResult.SelectedIndex]; MethodSimpleElementFormula msef = Method.GetElHeader(Element).Formula[Formula]; msef.Formula.analitParamCalc.methodLineCalc1.nmLy.Value = (decimal)res.ALy; msef.Formula.analitParamCalc.methodLineCalc2.nmLy.Value = (decimal)res.CLy; Hide(); } catch (Exception ex) { Log.Out(ex); } }
public void Init(MethodSimple ms, int element, int formula) { Method = ms; this.Element = element; Formula = formula; Element[] elist = ms.GetElementList(); MethodSimpleElementFormula msef = Method.GetElHeader(Element).Formula[Formula]; LyFrom = Common.Env.DefaultDisp.GetLyByLocalPixel(0, 10); int[] sizes = Common.Env.DefaultDisp.GetSensorSizes(); LyTo = Common.Env.DefaultDisp.GetLyByLocalPixel(sizes.Length - 1, sizes[sizes.Length - 1] - 10); candidateLineListAnalit.init(elist[element].Name, formula, ms, true, Convert.ToDouble(msef.Formula.analitParamCalc.methodLineCalc1.nmLy.Value), LyFrom, LyTo); candidateLineListComp.init(null, formula, ms, false, Convert.ToDouble(msef.Formula.analitParamCalc.methodLineCalc2.nmLy.Value), LyFrom, LyTo); }
public void Add(MethodSimple method, int prob, int sub_prob) { DateTime now = DateTime.Now; Element[] elem = method.GetElementList(); MethodSimpleProb msp = method.GetProbHeader(prob); for (int el = 0; el < elem.Length; el++) { MethodSimpleCell cell = method.GetCell(el, prob); MethodSimpleElement mse = method.GetElHeader(el); for (int f = 0; f < mse.Formula.Count; f++) { MethodSimpleElementFormula formula = mse.Formula[f]; MethodSimpleCellFormulaResult mscfr = cell.GetData(sub_prob, f); Records.Add(new StandartHistryRecord(mse, f, formula, mscfr, now)); } } Save(); }
static public List <DataShot> extract(MethodSimple method, string element, int formula, double ly, int widthPlusMinus, bool useConDlt, double min, double max, bool relative) { int mul_k = (int)Common.Conf.MultFactor; int is_ok = 0; int is_over = 0; List <DataShot> ret = new List <DataShot>(); Element[] list = method.GetElementList(); for (int el = 0; el < list.Length; el++) { if (list[el].Name.Equals(element) || element == null) { MethodSimpleElementFormula calcFormula = method.GetElHeader(el).Formula[formula]; bool[] frames = calcFormula.Formula.GetUsedFrames(); for (int prob_index = 0; prob_index < method.GetProbCount(); prob_index++) { MethodSimpleProb prob = method.GetProbHeader(prob_index); MethodSimpleCell msc = method.GetCell(el, prob_index); if (useConDlt == false) { double fkVal = msc.Con; double con = fkVal; /*if (useConDlt) * { * double sko, sko1; * double rcon = //msc.CalcRealCon(out sko, out sko1); * fkVal -= rcon; * }//*/ for (int measuring_index = 0; measuring_index < prob.MeasuredSpectrs.Count; measuring_index++) { MethodSimpleCellFormulaResult mscfr = msc.GetData(measuring_index, formula); if (mscfr.Enabled == false) { continue; } MethodSimpleProbMeasuring mspm = prob.MeasuredSpectrs[measuring_index]; Spectr sp = mspm.Sp; if (sp == null) { continue; } List <SpectrDataView> viewSet = sp.GetViewsSet(); int[] shotIndexes = sp.GetShotIndexes(); Dispers disp = sp.GetCommonDispers(); List <int> sensors = disp.FindSensors(ly); bool isEnabled; if (con >= 0) { isEnabled = msc.Enabled; } else { isEnabled = false; } for (int shot_index = 0; shot_index < shotIndexes.Length; shot_index++) { if (frames[shot_index] == false) { continue; } SpectrDataView sig = viewSet[shotIndexes[shot_index]]; SpectrDataView nul = sp.GetNullFor(shotIndexes[shot_index]); for (int sn = 0; sn < 1 && sn < sensors.Count; sn++) { int sensorIndex = sensors[sn]; int n = (int)disp.GetLocalPixelByLy(sensorIndex, ly); float[] sigData = sig.GetSensorData(sensorIndex); float[] nulData = nul.GetSensorData(sensorIndex); float minSignal = float.MaxValue; float[] signal = new float[sigData.Length]; for (int i = 0; i < signal.Length; i++) { signal[i] = sigData[i] - nulData[i]; } for (int i = 500; i < sigData.Length - 500; i++) { float val = (signal[i - 1] + signal[i] + signal[i + 1]) / 3; if (val < minSignal) { minSignal = val; } } float[] data = new float[widthPlusMinus * 2 + 1]; double maxSignal = -double.MaxValue; for (int i = 0; i < data.Length; i++) { int index = n - widthPlusMinus + i; if (index < 0 || index >= sigData.Length) { data[i] = -float.MaxValue; isEnabled = false; continue; } data[i] = signal[index];//sigData[index] - nulData[index]; if (data[i] > max) { isEnabled = false; } if (data[i] > maxSignal && i > widthPlusMinus - 4 && i < widthPlusMinus + 4) { maxSignal = data[i]; } } if (maxSignal < min) { isEnabled = false; } if (isEnabled) { is_ok++; } else { is_over++; } DataShot dsh = new DataShot(ly, fkVal, data, isEnabled); ret.Add(dsh); } } } } else { for (int measuring_index = 0; measuring_index < prob.MeasuredSpectrs.Count; measuring_index++) { MethodSimpleProbMeasuring mspm = prob.MeasuredSpectrs[measuring_index]; Spectr sp = mspm.Sp; if (sp == null) { continue; } List <SpectrDataView> viewSet = sp.GetViewsSet(); int[] shotIndexes = sp.GetShotIndexes(); Dispers disp = sp.GetCommonDispers(); List <int> sensors = disp.FindSensors(ly); bool isEnabled; if (msc.Con >= 0) { isEnabled = msc.Enabled; } else { isEnabled = false; } MethodSimpleCellFormulaResult result = msc.GetData(measuring_index, formula); int data_index = 0; for (int shot_index = 0; shot_index < shotIndexes.Length; shot_index++) { if (frames[shot_index] == false) { continue; } double tmpAnalit = result.AnalitValue[data_index]; double fkVal; if (relative == false) { fkVal = calcFormula.Formula.CalcCon(0, tmpAnalit, 0) - msc.Con; } else { if (msc.Con > 0.01) { fkVal = (calcFormula.Formula.CalcCon(0, tmpAnalit, 0) - msc.Con) / msc.Con; } else { fkVal = Double.NaN; } } SpectrDataView sig = viewSet[shotIndexes[shot_index]]; SpectrDataView nul = sp.GetNullFor(shotIndexes[shot_index]); for (int sn = 0; sn < sensors.Count; sn++) { int sensorIndex = sensors[sn]; int n = (int)disp.GetLocalPixelByLy(sensorIndex, ly); float[] sigData = sig.GetSensorData(sensorIndex); float[] nulData = nul.GetSensorData(sensorIndex); float[] data = new float[widthPlusMinus * 2 + 1]; for (int i = 0; i < data.Length; i++) { int index = n - widthPlusMinus + i; if (index < 0 || index >= sigData.Length) { data[i] = -float.MaxValue; isEnabled = false; continue; } data[i] = sigData[index] - nulData[index]; if (data[i] > max) { isEnabled = false; } } if (isEnabled) { is_ok++; } else { is_over++; } DataShot dsh = new DataShot(ly, fkVal, data, isEnabled); ret.Add(dsh); } data_index++; } } } } break; } } if (is_ok == 0 || is_over / is_ok > 0.1) { return(null); } return(ret); }
private void SearchThread() { try { Lines = new List <SpectrFunctions.LineInfo>(); Calibrations = new List <Calibrator>(); panel1.Enabled = false; btnStop.Enabled = true; MethodSimpleElementFormula msef = Method.GetElHeader(Element).Formula[Formula]; msef.Formula.Founds.Clear(); msef.Formula.Pairs.Clear(); Cons = DataExtractor.getData(Method, Element, Formula); if (Th != null && Cons != null) { Log("Загруженно " + Cons.Count + " прожигов."); int sn_count = Cons[0].DataMinusNull.Length; for (int sn = 0; sn < sn_count && Th != null; sn++) { SpectrFunctions.LineInfo candidat = new SpectrFunctions.LineInfo(sn, Cons); Dispers disp = Cons[0].Disp; int l = Cons[0].DataMinusNull[sn].Length; for (int p = 10; p < l - 10 && Th != null; p++) { double ly = disp.GetLyByLocalPixel(sn, p); bool found = false; double real_ly = 0; for (int sp = 0; sp < Cons.Count && Th != null; sp++) { try { int pixel = (int)Cons[sp].Disp.GetLocalPixelByLy(sn, ly); candidat.Values[sp] = SpectrFunctions.CheckLine(ref pixel, Cons[sp].DataMinusNull[sn], (int)numSearchMax.Value, (int)numMaxValue.Value, (int)numMinWidth.Value, (int)numMinValue.Value, ref candidat.Profile[sp]); if (candidat.Values[sp] <= 0) { found = false; break; } else { real_ly += Cons[sp].Disp.GetLyByLocalPixel(sn, pixel); found = true; } candidat.DLy = Math.Abs(Cons[sp].Disp.GetLyByLocalPixel(sn, pixel + 1) - Cons[sp].Disp.GetLyByLocalPixel(sn, pixel)); } catch (Exception ex) { found = false; } } if (found == true) { candidat.Ly = (float)(real_ly / Cons.Count); Lines.Add(candidat); candidat = new SpectrFunctions.LineInfo(sn, Cons); p += (int)numSearchMax.Value; } } } Log("Найдено " + Lines.Count + " линий."); int analitic_count = 0; //int element = Method.GetElHeader(Element).Element.Num-1; String element_name = Method.GetElHeader(Element).Element.Name; for (int l = 0; l < Lines.Count; l++) { if (chbAllLinesAnalize.Checked == false) { double ly = Lines[l].Ly; for (int i = 0; i < Common.LDb.Data.Count; i++) { String name = Common.LDb.Data[i].ElementName; if (name.Equals(element_name) && Math.Abs(Common.LDb.Data[i].Ly - ly) < Lines[l].DLy * 3) { Lines[l].HasLine = true; analitic_count++; break; } } } else { Lines[l].HasLine = true; } } Log("Из них " + analitic_count + " могут быть аналитическими."); cboxLyList.Items.Clear(); for (int i = 0; i < Lines.Count; i++) { String str = "" + Lines[i].Ly + ":" + Lines[i].Sn; if (Lines[i].HasLine) { str += " A"; } cboxLyList.Items.Add(str); } long out_time = DateTime.Now.Ticks; for (int l1 = 0; l1 < Lines.Count && Th != null; l1++) { if (Lines[l1].HasLine == false) { continue; } for (int l2 = 0; l2 < Lines.Count && Th != null; l2++) { if (l1 == l2 || chbAtTheSameSensor.Checked && Lines[l1].Sn != Lines[l2].Sn) { continue; } Calibrator cal = new Calibrator(Lines[l1], Lines[l2], Cons); cal.ReCalc(); for (int i = 0; i < Calibrations.Count; i++) { if (cal.SKO < Calibrations[i].SKO) { Calibrations.Insert(i, cal); cal = null; break; } } if (cal != null) { Calibrations.Add(cal); } while (Calibrations.Count > 1000) { Calibrations.RemoveAt(Calibrations.Count - 1); } if (DateTime.Now.Ticks - out_time > 10000000) { LogTmp("Найлучшее СКО: " + Calibrations[0].SKO + "%."); out_time = DateTime.Now.Ticks; } } } if (Calibrations.Count > 0) { Log("Найлучшее СКО: " + Calibrations[0].SKO + "%."); } else { Log("Не найдено отношений..."); } } else { Log("Не найдено данных по прожигам..."); } InitList(); chbViewFilter.Items.Clear(); chbViewFilter.Items.Add(""); for (int i = 0; i < Calibrations.Count; i++) { bool already_in_list = false; String ly = Calibrations[i].Ly1.ToString(); for (int j = 0; j < chbViewFilter.Items.Count; j++) { if (chbViewFilter.Items[j].Equals(ly)) { already_in_list = true; break; } } if (already_in_list == false) { chbViewFilter.Items.Add(ly); } } } catch (Exception ex) { Common.Log(ex); } btnStop.Enabled = false; panel1.Enabled = true; }