Esempio n. 1
0
        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);
        }
Esempio n. 2
0
        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);
        }
Esempio n. 4
0
        //List<double[]>[] compDataPrev = null;
        void SearchThreadProc()
        {
            try
            {
                buttonUpdate("Started...");
                Candidates.Clear();


                Element[] elist = Method.GetElementList();
                CandidateElement = elist[Element].Name;

                double[] analitLy = candidateLineListAnalit.getLyList();
                double[] compLy   = candidateLineListComp.getLyList();

                List <double[]>[] analitValues = candidateLineListAnalit.getValues(buttonSearch, "Anlit^:");/*new List<double[]>[analitLy.Length];
                                                                                                             * bool[] enabledSpectr = new bool[analitLy.Length];
                                                                                                             * for (int i = 0; i < analitLy.Length && Common.IsRunning; i++)
                                                                                                             * {
                                                                                                             * List<DataShot> values = DataShotExtractor.extract(Method, elist[Element].Name, Formula, analitLy[i],
                                                                                                             * windowSize, cbSearchType.SelectedIndex == 1, 0, (double)numMax.Value,
                                                                                                             * cbValueType.SelectedIndex == 1);
                                                                                                             * if (values != null)
                                                                                                             * {
                                                                                                             * analitValues[i] = calcAnalit(values, analitLy[i], windowSize,
                                                                                                             * 0, (double)numMax.Value);
                                                                                                             * //if(analitValues[i] == null)
                                                                                                             * //    analitValues[i] = calcAnalit(values, analitLy[i], windowSize,
                                                                                                             * //    0, (double)numMax.Value);
                                                                                                             * }
                                                                                                             * if(i%50 == 0)
                                                                                                             * buttonUpdate("Check "+i+" from "+analitLy.Length+" analitic lines");
                                                                                                             * }*/

                //buttonUpdate("Found "+analitValues.Length+" analitic lines...");
                List <double[]>[] compData = candidateLineListComp.getValues(buttonSearch, "Compare:");/*new List<double[]>[compLy.Length];
                                                                                                        * for (int i = 0; i < compLy.Length && Common.IsRunning; i++)
                                                                                                        * {
                                                                                                        * List<DataShot> values = DataShotExtractor.extract(Method, elist[Element].Name, Formula, compLy[i],
                                                                                                        * windowSize, cbSearchType.SelectedIndex == 1, (double)numMin.Value, (double)numMax.Value,
                                                                                                        * cbValueType.SelectedIndex == 1);
                                                                                                        * if (values != null)
                                                                                                        * {
                                                                                                        * compData[i] = calcAnalit(values, compLy[i], windowSize, (double)numMin.Value, (double)numMax.Value);
                                                                                                        * //if(compData[i] == null)
                                                                                                        * //    compData[i] = calcAnalit(values, compLy[i], windowSize, (double)numMin.Value, (double)numMax.Value);
                                                                                                        * }
                                                                                                        * if(i%50 == 0)
                                                                                                        * buttonUpdate("Found " + analitValues.Length + " analit. Check " + i + " from "+compLy.Length + " compare lines");
                                                                                                        * }*/

                //buttonUpdate("Found " + analitValues.Length + " analitic lines and "+compData.Length+" compare lines.");

                long prevGC   = DateTime.Now.Ticks;
                long fromTime = DateTime.Now.Ticks;
                for (int a = 0; a < analitLy.Length && Common.IsRunning; a++)
                {
                    List <double[]> curAnalit = analitValues[a];
                    if (curAnalit == null || curAnalit.Count == 0)
                    {
                        continue;
                    }
                    for (int c = 0; c < compLy.Length && Common.IsRunning; c++)
                    {
                        if (Math.Abs(analitLy[a] - compLy[c]) < 0.5)
                        {
                            continue;
                        }

                        List <double[]> curComp = compData[c];
                        if (curComp == null || curComp.Count == 0)
                        {
                            continue;
                        }

                        if (curAnalit.Count != curComp.Count)
                        {
                            Log.Out("Line compare count not eqals for analit=" + analitLy[a] + " and compare=" + compLy[c]);
                            continue;
                        }

                        double[] analitVal = new double[curAnalit.Count];
                        double[] conVal    = new double[analitVal.Length];
                        bool[]   en        = new bool[analitVal.Length];

                        double enCount = 0;
                        for (int i = 0; i < analitVal.Length; i++)
                        {
                            double[] av = curAnalit[i];
                            double[] cv = curComp[i];
                            analitVal[i] = av[0] / cv[0];
                            conVal[i]    = av[1];
                            //if (serv.IsValid(analitVal[i]) && av[1] >= 0 && av[1] < 100 && curAnalit[i][2] == 1)
                            if (serv.IsValid(analitVal[i]) && curAnalit[i][2] == 1)
                            {
                                en[i] = true;
                                enCount++;
                            }
                            else
                            {
                                en[i] = false;
                            }
                        }

                        if (enCount < (analitVal.Length - 4) || enCount < 5)
                        {
                            continue;
                        }

                        double   sko = 0;
                        Function fk  = new Function(Function.Types.Line, analitVal, conVal, en, true, false, 1.1);
                        if (fk.GetK()[1] < 0)
                        {
                            continue;
                        }
                        int count = 0;
                        for (int i = 0; i < en.Length; i++)
                        {
                            if (en[i] == false)
                            {
                                continue;
                            }
                            double currentCon = fk.CalcY(analitVal[i]);
                            double dlt;
                            if (conVal[i] > -1 && serv.IsValid(currentCon) && conVal[i] > 0)// && currentCon < 1000)
                            {
                                dlt = (conVal[i] - currentCon) * 100 / conVal[i];
                                count++;
                            }
                            else
                            {
                                dlt = 0;
                            }
                            sko += dlt * dlt;
                        }
                        if (count == 0)
                        {
                            continue;
                        }
                        sko = Math.Sqrt(sko / count);
                        if (sko > 0.0001)// && count / enCount > 0.5)
                        {
                        }
                        else
                        {
                            continue;
                        }

                        Result r = new Result(analitLy[a], compLy[c], conVal, analitVal, en, fk, sko);

                        for (int i = 0; i < Candidates.Count; i++)
                        {
                            if (Candidates[i].SKO > r.SKO)
                            {
                                Candidates.Insert(i, r);
                                r = null;
                                break;
                            }
                        }

                        if (r != null)
                        {
                            Candidates.Add(r);
                        }

                        while (Candidates.Count > 5000)
                        {
                            Candidates.RemoveAt(Candidates.Count - 1);
                        }
                    }
                    if (prevGC + 10 * 10000000 < DateTime.Now.Ticks)
                    {
                        GC.Collect();
                        GC.WaitForPendingFinalizers();
                        prevGC = DateTime.Now.Ticks;
                    }
                    if (a > 0)
                    {
                        double estimate = (DateTime.Now.Ticks - fromTime) / (double)a;
                        estimate *= (analitLy.Length - a);
                        DateTime tdt = new DateTime(DateTime.Now.Ticks + (long)estimate);
                        estimate /= 10000000;
                        String bestSko = "";
                        if (Candidates.Count > 0)
                        {
                            bestSko = " SKO=" + Math.Round(Candidates[0].SKO, 4);
                        }
                        buttonUpdate("Done " + Math.Round(a * 1009.0 / analitLy.Length) / 10.0 + " To be done at " + tdt.ToString("H:mm:ss") + bestSko);
                    }
                }

                listboxResult.Items.Clear();
                for (int i = 0; i < Candidates.Count; i++)
                {
                    listboxResult.Items.Add(Candidates[i]);
                }

                Common.Beep();

                MessageBox.Show(this, "Найдено " + Candidates.Count + " пар линий...");
            }
            catch (Exception ex)
            {
                Log.Out(ex);
            }
            try
            {
                buttonSearch.Enabled = true;
                buttonSearch.Text    = "Начать поиск";
                th = null;
            }
            catch
            {
            }
        }