Ejemplo n.º 1
0
        double CheckSensK(SpectrDataView etalon_sig, SpectrDataView etalon_nul,
                          SpectrDataView cur_sig, SpectrDataView cur_nul,
                          int sn, double shifts)
        {
            float[] esig_data = etalon_sig.GetSensorData(sn);
            float[] enul_data = etalon_nul.GetSensorData(sn);

            float[] csig_data = cur_sig.GetSensorData(sn);
            float[] cnul_data = cur_nul.GetSensorData(sn);

            float[] etalon = new float[esig_data.Length];
            float[] cur    = new float[esig_data.Length];

            for (int i = 0; i < etalon.Length; i++)
            {
                etalon[i] = esig_data[i] - enul_data[i];
                cur[i]    = csig_data[i] - cnul_data[i];
            }

            float[] etalon_hi = SpectrFunctions.FoldingGaus(etalon, 1F, 10);
            float[] cur_hi    = SpectrFunctions.FoldingGaus(cur, 1F, 10);
            return(CheckSensK(etalon_hi, cur_hi, sn, shifts * 10));//*/
            //return CheckSensK(etalon, cur, sn, shifts);
        }
Ejemplo n.º 2
0
        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;
        }
Ejemplo n.º 3
0
        public override bool RunProc()
        {
            try
            {
                Shifts = null;
                SensK  = null;

                DbFolder folder  = Common.Db.GetFolder(Common.DbNameSystemFolder);
                Spectr   sp_base = new Spectr(folder, Common.DbObjectNamesLinkMatrixFile);

                folder = Common.Db.GetFolder(Common.DbNameTestingFolder);

                Spectr sp_cur;
                if (DevTest.DoNotStart == false)
                {
                    Common.Dev.Measuring(sp_base.GetMeasuringCondition(), null);
                    sp_cur = Common.Dev.GetLetestDataAsSpectr();
                    string path = folder.GetRecordPath(Common.DbObjectNamesLinkMatrixFile + "_last");
                    sp_cur.SaveAs(path);
                }
                else
                {
                    //string path = folder.GetRecordPath(Common.DbObjectNamesLinkMatrixFile + "_last");
                    sp_cur = new Spectr(folder, Common.DbObjectNamesLinkMatrixFile + "_last");
                }

                Res = GetReportPrefix();
                //Res += Common.MLS.Get(MLSConst, "Спектр промерен и сохранён... ")+serv.Endl;

                int[] ss = Common.Dev.Reg.GetSensorSizes();

                sp_cur.OFk.ResetSens();
                sp_cur.ResetDefaultView();

                SpectrDataView base_view = sp_base.GetDefultView();
                SpectrDataView cur_view  = sp_cur.GetDefultView();
                double[]       shifts    = new double[ss.Length];
                int            max_shift = 800;
                Res += Common.MLS.Get(MLSConst, "Проверка сдвижек на сенсоре:") + serv.Endl + "   ";
                for (int s = Common.Conf.ValidSensorFrom - 1;
                     s < ss.Length && s < Common.Conf.ValidSensorTo;
                     s++)
                {
                    //Res += Common.MLS.Get(MLSConst, "Проверка сдвижек на сенсоре #") + (s + 1);

                    float[] input_data = base_view.GetSensorData(s);
                    float[] hi_base    = SpectrFunctions.FoldingGaus(input_data, 1F, 10);
                    float[] rez_data   = cur_view.GetSensorData(s);
                    float[] hi_rez     = SpectrFunctions.FoldingGaus(rez_data, 1F, 10);

                    double crit  = 0;
                    int    shift = 0;
                    for (int sh = -max_shift; sh <= max_shift; sh++)
                    {
                        double cand = SpectrFunctions.CalcCorel(hi_base, hi_rez, sh, max_shift + 10);
                        if (serv.IsValid(cand) == false || cand < 0 || cand > 32000.0 * 32000.0 * hi_rez.Length)
                        {
                            cand = SpectrFunctions.CalcCorel(hi_base, hi_rez, sh, max_shift + 10);
                            continue;
                        }
                        if (cand > crit)
                        {
                            crit  = cand;
                            shift = sh;
                            SpectroWizard.gui.MainForm.MForm.SetupPersents(100.0 * (s * 1001 + sh) / (ss.Length * 1001));
                        }
                    }
                    shifts[s] = -(shift / 10.0);
                    //Res += Common.MLS.Get(MLSConst, " Значение сдвижки:") + shifts[s];
                    Res += "   " + Math.Round(shifts[s], 1) + "   ";
                    if (Math.Abs(shifts[s]) > max_shift / 20)
                    {
                        Res += Common.MLS.Get(MLSConst, " Слишком много!") + serv.Endl;
                        Res += serv.Endl;
                    }
                }

                Res += serv.Endl;

                for (int i = 0; i < Common.Conf.ValidSensorFrom - 1; i++)
                {
                    shifts[i] = shifts[Common.Conf.ValidSensorFrom - 1];
                }

                for (int i = Common.Conf.ValidSensorTo; i < shifts.Length; i++)
                {
                    shifts[i] = shifts[Common.Conf.ValidSensorTo - 1];
                }

                for (int i = 0; i < shifts.Length; i++)
                {
                    if (Math.Abs(shifts[i]) > max_shift / 20)
                    {
                        Res += Common.MLS.Get(MLSConst, "Слишком большие сдвижки.") + serv.Endl;
                        return(false);
                    }
                }

                for (int i = 2; i < shifts.Length; i += 2)
                {
                    if (Math.Abs(shifts[i] - shifts[i - 2]) > Common.Conf.ValidSensorDiff)
                    {
                        Res += Common.MLS.Get(MLSConst, "Слишком большая разница между сдвижками.") + shifts[i] + " " + shifts[i - 2] +
                               Common.MLS.Get(MLSConst, " Допустимый максимум: ") + Common.Conf.ValidSensorDiff + serv.Endl;
                        return(false);
                    }
                }

                for (int i = 3; i < shifts.Length; i += 2)
                {
                    if (Math.Abs(shifts[i] - shifts[i - 2]) > Common.Conf.ValidSensorDiff)
                    {
                        Res += Common.MLS.Get(MLSConst, "Слишком большая разница между сдвижками.") + shifts[i] + " " + shifts[i - 2] +
                               Common.MLS.Get(MLSConst, " Допустимый максимум: ") + Common.Conf.ValidSensorDiff + serv.Endl;
                        return(false);
                    }
                }

                double[] sensk = new double[ss.Length];
                bool     is_ok = true;
                if (Common.Conf.UseLineAmpl)
                {
                    Res += Common.MLS.Get(MLSConst, "Проверка уровня освещённости сенсоров:") + serv.Endl + "   ";

                    List <SpectrDataView> views = sp_base.GetViewsSet();
                    int[] active_indexes        = sp_base.GetShotIndexes();
                    int   use_view = -1;
                    float use_max  = -1;
                    for (int i = 0; i < active_indexes.Length; i++)
                    {
                        SpectrDataView data = views[active_indexes[i]];
                        if (data.GetCondition().Lines[0].CommonTime > use_max)
                        {
                            use_view = active_indexes[i];
                            use_max  = data.GetCondition().Lines[0].CommonTime;
                        }
                    }

                    SpectrDataView base_sig = views[use_view];
                    SpectrDataView base_nul = sp_base.GetNullFor(use_view);

                    views = sp_cur.GetViewsSet();
                    SpectrDataView cur_sig = views[use_view];
                    SpectrDataView cur_nul = sp_cur.GetNullFor(use_view);

                    for (int s = 0; s < ss.Length; s++)
                    {
                        float[] input_data = base_view.GetSensorData(s);
                        float[] rez_data   = cur_view.GetSensorData(s);

                        //double sens = CheckSensK(input_data, rez_data, s, shifts[s]);
                        double sens = CheckSensK(base_sig, base_nul, cur_sig, cur_nul, s, shifts[s]);
                        if (double.IsNaN(sens))
                        {
                            sens = 1;
                            Res += Common.MLS.Get(MLSConst, "Неполучилось сбалансировать линейку №") + (s + 1) + " " +
                                   Common.MLS.Get(MLSConst, "Причина :") + CheckSensKErrors;
                            Res  += serv.Endl;
                            is_ok = false;
                        }
                        else
                        {
                            //Res += " ";
                            Res += "   " + Math.Round(sens, 3) + "   ";
                        }

                        sensk[s] = sens;
                    }

                    if (is_ok == true)
                    {
                        Res += serv.Endl;
                        StatLineBalansCompiler(ref sensk);
                        //sp_cur.ApplyLineLevelK(sensk);
                        //sp_cur.ResetDefaultView();
                    }//*/
                }
                else
                {
                    //Res += Common.MLS.Get(MLSConst, "Проверка уровней засветок не проводилась т.к. данная опция на включена в конфигурации...") + serv.Endl;
                    for (int s = 0; s < ss.Length; s++)
                    {
                        sensk[s] = 1;
                    }
                }

                Res += serv.Endl;
                //for (int s = 0; s < ss.Length; s++)
                //    sp_cur.GetCommonDispers().ApplyShifts(shifts[s], s);
                sp_cur.ApplySifts(shifts);
                sp_cur.Save();

                if (is_ok == true)
                {
                    Shifts = shifts;
                    SensK  = sensk;
                    Common.Env.Store();
                }
                else
                {
                    return(false);
                }


                return(true);
            }
            catch (Exception ex)
            {
                Common.Log(ex);
                Res += Common.MLS.Get(MLSConst, "Критическая ошибка! ") + ex;
                return(false);
            }
            //return true;
        }