Ejemplo n.º 1
0
        /// <summary>
        /// 漏水判断(-1:处于最大最小标准值中间,需要通过别的方法综合判断 1:漏水 0:不漏水)
        /// </summary>
        /// <param name="data">噪声原始数据32个值一组</param>
        /// <param name="standvalue">静态漏水标准幅度值</param>
        /// <returns></returns>
        public static int IsLeak1(int GroupID, int RecorderID, List <double[]> lstdatas, out double energyvalue, out double leakprobability)
        {
            energyvalue     = 0; //能量值
            leakprobability = 0; //漏水概率
            double maxstandvalue = Convert.ToDouble(Settings.Instance.GetString(SettingKeys.MaxStandardAMP));
            double minstandvalue = Convert.ToDouble(Settings.Instance.GetString(SettingKeys.MinStandardAMP));

            short[] standdata = NoiseDataBaseHelper.GetStandData(-1, RecorderID);  //GroupID全部取-1,因为ID不重复

            if (standdata == null)
            {
                return(-1);
            }

            int    i            = 0;
            double standaverage = 0;

            standaverage = GetAverage(standdata);

            List <double> lstaverage = new List <double>();

            if (lstdatas != null && lstdatas.Count > 0)
            {
                for (i = 0; i < lstdatas.Count; i++)
                {
                    lstaverage.Add(GetAverage(lstdatas[i]));
                }
            }

            int isleak = 1;

            double[] record_average = new double[lstaverage.Count];
            lstaverage.CopyTo(record_average);
            //for (i = 0; i < lstaverage.Count; i++)
            //{
            //    lstaverage[i] = Math.Abs(standaverage - lstaverage[i]);
            //    if (lstaverage[i] <= maxstandvalue)
            //    {
            //        isleak = 0;
            //    }
            //}

            energyvalue = GetAverage(record_average.ToArray());
            energyvalue = Math.Abs(standaverage - energyvalue);

            StreamWriter sw = new StreamWriter(string.Format("{0}能量强度变化数据.txt", GlobalValue.TestPath));

            sw.WriteLine(standaverage);  //先写入标准平均值
            sw.WriteLine(energyvalue);   //写入能量值
            for (i = 0; i < record_average.Length; i++)
            {
                sw.WriteLine(record_average[i]);
            }
            sw.Flush();
            sw.Close();

            if (energyvalue >= maxstandvalue)
            {
                isleak          = 1;
                leakprobability = 1;
            }
            else if (energyvalue <= minstandvalue)
            {
                isleak          = 0;
                leakprobability = 0;
            }
            else
            {
                isleak          = -1;
                leakprobability = 0.5 * (energyvalue - minstandvalue) / (maxstandvalue - minstandvalue);  //能量强度权重50%
            }

            return(isleak);
        }