private void CheckData(string targetCitFile)
        {
            _CorrResult.Clear();
            //左半边数据点个数,包括中间点
            foreach (var kvp in _fixedData)
            {
                int leftTargetCount = TargetSamplingCount + 1;

                long filePostion = _citProcess.GetCurrentPositionByMilestone(targetCitFile, kvp.Value[0].OriginalMileage, true);
                if (filePostion != -1)
                {
                    long targetStartPostion = _citProcess.GetAppointEndPostion(targetCitFile, filePostion, -1 * leftTargetCount);
                    long targetStartCount   = _citProcess.GetSampleCountByRange(targetCitFile, targetStartPostion, filePostion);

                    long targetEndPostion = _citProcess.GetAppointEndPostion(targetCitFile, filePostion, TargetSamplingCount);
                    long targetEndCount   = _citProcess.GetSampleCountByRange(targetCitFile, filePostion, targetEndPostion);



                    List <CorrelationResult> correlationResult = new List <CorrelationResult>();
                    foreach (var item in _fixedData[kvp.Key])
                    {
                        int      index     = -1;
                        double   lastValue = 0;
                        double[] newArr    = _citProcess.GetOneChannelDataInRange(targetCitFile, item.ChannelID, targetStartPostion, (int)(targetEndCount + targetStartCount));
                        double[] carr      = new double[item.Points.Length];
                        for (int i = 0; i < newArr.Length - item.Points.Length; i++)
                        {
                            Array.Clear(carr, 0, carr.Length);
                            Array.Copy(newArr, i, carr, 0, carr.Length);
                            //double per = Correlation.Pearson(item.Points, carr);
                            double per = correlationCalc(item.Points, carr);
                            if (per > lastValue)
                            {
                                lastValue = per;
                                index     = i;
                            }
                        }
                        FixParam          key    = FixParams.FirstOrDefault(p => p.ChannelID == item.ChannelID);
                        CorrelationResult result = new CorrelationResult();
                        if (key != null && lastValue > key.ThreShold)
                        {
                            result.FilePointer = targetStartPostion + index + item.FixPostion;
                            result.IsFind      = true;
                            result.ChannelID   = key.ChannelID;
                            result.ChannelName = key.ChannelName;
                        }
                        else
                        {
                            result.IsFind = false;
                        }
                        correlationResult.Add(result);
                    }
                    _CorrResult.Add(kvp.Key, correlationResult);
                }
            }
        }
Example #2
0
        /// <summary>
        /// 根据修正后的里程点得到文件中的原始偏移量
        /// </summary>
        /// <param name="mileStone">修正后的里程(米)</param>
        /// <returns>原始偏移量</returns>
        public long CalcPointFilePointerByFixedMilestone(float mileStone)
        {
            long targetPosion = -1;

            if (_fixData != null && _fixData.Count > 0)
            {
                for (int i = 0; i < _fixData.Count; i++)
                {
                    if (mileStone >= _fixData[i].MarkedStartPoint.UserSetMileage &&
                        mileStone <= FixData[i].MarkedEndPoint.UserSetMileage)
                    {
                        float diff        = mileStone - _fixData[i].MarkedStartPoint.UserSetMileage;
                        int   sampleCount = (int)(diff / _fixData[i].SampleRate) + 1;
                        targetPosion = _citProcess.GetAppointEndPostion(_citFilePath, _fixData[i].MarkedStartPoint.FilePointer, sampleCount);
                        break;
                    }
                }
            }
            return(targetPosion);
        }
        private void UnFixCalc(string citFilePath, int mileUnitValue, string exportFilePath, float startMile, float endMile)
        {
            /* 左高低_中波
             * 右高低_中波
             * 左轨向_中波
             * 右轨向_中波
             * 轨距
             * 水平
             * 三角坑
             * */
            string[] sTQIItem = new string[] { "L_Prof_SC", "R_Prof_SC", "L_Align_SC",
                                               "R_Align_SC", "Gage", "Crosslevel", "Short_Twist", "LACC", "VACC", "Speed" };
            int[] sTQIItemIndex = new int[sTQIItem.Length];

            channelList = citProcess.GetChannelDefinitionList(citFilePath);
            for (int i = 0; i < sTQIItem.Length; i++)
            {
                for (int j = 0; j < channelList.Count; j++)
                {
                    if (sTQIItem[i].Equals(channelList[j].sNameEn))
                    {
                        sTQIItemIndex[i] = j;
                        break;
                    }
                }
            }

            long startPos = 0;
            long endPos   = 0;

            long[] positions = citProcess.GetPositons(citFilePath);
            startPos = positions[0];
            endPos   = positions[1];

            if (startMile != 0)
            {
                startPos = citProcess.GetCurrentPositionByMilestone(citFilePath, startMile, true);
                if (startPos == -1)
                {
                    throw new Exception("未找到对应开始里程的位置");
                }
            }
            if (endMile != 0)
            {
                endPos = citProcess.GetCurrentPositionByMilestone(citFilePath, endMile, true);
                if (endPos == -1)
                {
                    throw new Exception("未找到对应结束里程的位置");
                }
            }
            long tempPos = 0;

            if (startPos > endPos)
            {
                tempPos  = startPos;
                startPos = endPos;
                endPos   = tempPos;
            }

            int  positionCount = mileUnitValue * 4;
            long range         = citProcess.GetSampleCountByRange(citFilePath, startPos, endPos);
            long divisor       = range / positionCount;
            long residue       = range % positionCount;

            long tempStartPos = startPos;
            long tempEndPos   = 0;

            for (int i = 0; i < divisor; i++)
            {
                tempEndPos = citProcess.GetAppointEndPostion(citFilePath, tempStartPos, positionCount);
                GetChannelData(citFilePath, tempStartPos, tempEndPos, sTQIItemIndex);

                tempStartPos = tempEndPos;
            }

            ExportExcel(exportFilePath, tqilist);
        }
Example #4
0
        /// <summary>
        /// 接口函数:无效数据滤除---处理多个通道数据
        /// </summary>
        /// <param name="FileName"></param>
        /// <param name="sAddFileName"></param>
        /// <returns></returns>
        private bool GetDataInfoMulti(string FileName, int pointCount, string sAddFileName)
        {
            // CIT文件相关操作类
            CITFileProcess cfprocess = new CITFileProcess();

            // 通道定义相关操作类
            ChannelDefinitionList cdlist = new ChannelDefinitionList();

            //matlab算法
            PreproceingDeviationClass pdc = new PreproceingDeviationClass();

            //获取文件信息
            FileInformation fileinfo = new FileInformation();

            try
            {
                long[] position = cfprocess.GetPositons(FileName);
                long   startPos = position[0]; //开始位置、结束位置
                long   endPos   = position[1];

                cdlist.channelDefinitionList = cfprocess.GetChannelDefinitionList(FileName);

                //分段读取方法////////////////////

                long totleSample = cfprocess.GetTotalSampleCount(FileName);
                //循环次数
                int count = Convert.ToInt32(totleSample / pointCount);
                //是否有余点
                int residue = Convert.ToInt32(totleSample % pointCount);

                bool iszero = false;
                //是否执行一次
                if (count == 0)
                {
                    iszero = true;
                }
                //如果有余数循环次数加1
                if (residue > 0)
                {
                    count++;
                }

                for (int z = 0; z < count; z++)
                {
                    if (iszero)
                    {
                        endPos = cfprocess.GetAppointEndPostion(FileName, startPos, residue);
                    }
                    else
                    {
                        if (residue == 0)
                        {
                            endPos = cfprocess.GetAppointEndPostion(FileName, startPos, pointCount);
                        }
                        else
                        {
                            if (z == (count - 1))
                            {
                                endPos = cfprocess.GetAppointEndPostion(FileName, startPos, residue);
                            }
                            else
                            {
                                endPos = cfprocess.GetAppointEndPostion(FileName, startPos, pointCount);
                            }
                        }
                    }

                    //分段读取方法////////////////////

                    //根据里程list获取里程数组
                    List <Milestone> dualmilelist = cfprocess.GetMileStoneByRange(FileName, startPos, endPos);
                    double[]         tt           = new double[dualmilelist.Count];
                    for (int i = 0; i < dualmilelist.Count; i++)
                    {
                        double obj = dualmilelist[i].GetMeter() / 1000;
                        tt[i] = obj;
                    }

                    double[] wvelo      = cfprocess.GetOneChannelDataInRange(FileName, cdlist.GetChannelIdByName("Speed", "速度"), startPos, endPos);
                    double[] L_Prof_SC  = cfprocess.GetOneChannelDataInRange(FileName, cdlist.GetChannelIdByName("L_Prof_SC", "左高低_中波"), startPos, endPos);
                    double[] R_Prof_SC  = cfprocess.GetOneChannelDataInRange(FileName, cdlist.GetChannelIdByName("R_Prof_SC", "右高低_中波"), startPos, endPos);
                    double[] L_Align_SC = cfprocess.GetOneChannelDataInRange(FileName, cdlist.GetChannelIdByName("L_Align_SC", "左轨向_中波"), startPos, endPos);
                    double[] R_Align_SC = cfprocess.GetOneChannelDataInRange(FileName, cdlist.GetChannelIdByName("R_Align_SC", "右轨向_中波"), startPos, endPos);
                    double[] Gage       = cfprocess.GetOneChannelDataInRange(FileName, cdlist.GetChannelIdByName("Gage", "轨距"), startPos, endPos);
                    double[] Crosslevel = cfprocess.GetOneChannelDataInRange(FileName, cdlist.GetChannelIdByName("Crosslevel", "水平"), startPos, endPos);

                    int      tmpChannelNumber = cdlist.GetChannelIdByName("Gage_L", "单边轨距左");
                    double[] Gage_L           = null;
                    if (tmpChannelNumber == -1)
                    {
                        Gage_L = new double[wvelo.Length];
                    }
                    else
                    {
                        Gage_L = cfprocess.GetOneChannelDataInRange(FileName, tmpChannelNumber, startPos, endPos);
                    }

                    tmpChannelNumber = cdlist.GetChannelIdByName("Gage_R", "单边轨距右");
                    double[] Gage_R = null;
                    if (tmpChannelNumber == -1)
                    {
                        Gage_R = new double[wvelo.Length];
                    }
                    else
                    {
                        Gage_R = cfprocess.GetOneChannelDataInRange(FileName, tmpChannelNumber, startPos, endPos);
                    }

                    DataProcessing dp = new DataProcessing();
                    //调用刘博士的算法---处理多个通道
                    dp.preProcess(tt, L_Prof_SC, R_Prof_SC, L_Align_SC, R_Align_SC, Gage, Crosslevel, wvelo, Gage_L, Gage_R, FileName, sAddFileName, "自动标识", true);

                    //分段读取方法////////////////////
                    startPos = endPos;
                }
                //分段读取方法////////////////////
            }
            catch (Exception ex)
            {
                throw new Exception(ex.ToString());
            }
            finally
            {
            }
            return(true);
        }
Example #5
0
        /// <summary>
        /// 接口函数:计算峰峰值指标
        /// </summary>
        /// <param name="citFileName">cit文件全路径</param>
        /// <param name="citFileName">idf文件全路径</param>
        /// <returns></returns>
        private List <String> PreProcessDeviation(String citFileName, int pointCount, string idfFileName = null)
        {
            //StreamWriter sw3 = new StreamWriter("d:/peakvalue_40000.csv", true, Encoding.Default);
            //StringBuilder sbtmp = new StringBuilder();
            //sbtmp.Append("d_tt,");
            //sbtmp.Append("d_wvelo,");
            //sbtmp.Append("d_gauge,");
            //sbtmp.Append("d_wx");
            //sw3.WriteLine(sbtmp.ToString());

            List <String> dataStrList = new List <String>();

            cdlist.channelDefinitionList = cfprocess.GetChannelDefinitionList(citFileName);

            fileinfo = cfprocess.GetFileInformation(citFileName);
            //int tds = fileinfo.iChannelNumber;

            long[] position = cfprocess.GetPositons(citFileName);
            long   startPos = position[0]; //开始位置、结束位置
            long   endPos   = position[1];

            //分段读取方法////////////////////

            long totleSample = cfprocess.GetTotalSampleCount(citFileName);
            //循环次数
            int count = Convert.ToInt32(totleSample / pointCount);
            //是否有余点
            int residue = Convert.ToInt32(totleSample % pointCount);

            bool iszero = false;

            //是否执行一次
            if (count == 0)
            {
                iszero = true;
            }
            //如果有余数循环次数加1
            if (residue > 0)
            {
                count++;
            }

            for (int z = 0; z < count; z++)
            {
                if (iszero)
                {
                    endPos = cfprocess.GetAppointEndPostion(citFileName, startPos, residue);
                }
                else
                {
                    if (residue == 0)
                    {
                        endPos = cfprocess.GetAppointEndPostion(citFileName, startPos, pointCount);
                    }
                    else
                    {
                        if (z == (count - 1))
                        {
                            endPos = cfprocess.GetAppointEndPostion(citFileName, startPos, residue);
                        }
                        else
                        {
                            endPos = cfprocess.GetAppointEndPostion(citFileName, startPos, pointCount);
                        }
                    }
                }

                //分段读取方法////////////////////

                List <Milestone> allmilelist;
                //List<Milestone> milelist = cfprocess.GetAllMileStone(citFileName);
                ///分段读取使用//////////////////////////
                List <Milestone> milelist = cfprocess.GetMileStoneByRange(citFileName, startPos, endPos);
                /////////////////////////////

                //验证是否修正
                if (!String.IsNullOrEmpty(idfFileName))
                {
                    IndexOperator _op = new IndexOperator();
                    _op.IndexFilePath = idfFileName;
                    MilestoneFix mile = new MilestoneFix(citFileName, _op);
                    mile.ReadMilestoneFixTable();
                    allmilelist = mile.GetMileageReviseData(milelist);
                }
                else
                {
                    allmilelist = milelist;
                }

                //开始里程  和结束里程
                double[] d_tt = new double[allmilelist.Count];
                for (int i = 0; i < allmilelist.Count; i++)
                {
                    double obj = allmilelist[i].GetMeter() / 1000;
                    d_tt[i] = obj;
                }

                double[] d_wvelo = cfprocess.GetOneChannelDataInRange(citFileName, cdlist.GetChannelIdByName("Speed", "速度"), startPos, endPos);
                double[] d_gauge = cfprocess.GetOneChannelDataInRange(citFileName, cdlist.GetChannelIdByName("Gage", "轨距"), startPos, endPos);

                double[] d_wx = cfprocess.GetOneChannelDataInRange(citFileName, cdlist.GetChannelIdByName("L_Prof_SC", "左高低_中波"), startPos, endPos);


                //for (int i = 0; i < d_tt.Length; i++)
                //{
                //    sw3.Write(d_tt[i]);
                //    sw3.Write(",");
                //    sw3.Write(d_wvelo[i]);
                //    sw3.Write(",");
                //    sw3.Write(d_gauge[i]);
                //    sw3.Write(",");
                //    sw3.Write(d_wx[i]);
                //    sw3.Write("\n");
                //}


                List <String> tmpDataStrList = pdc.WideGaugePreProcess("左高低_中波", d_tt, d_wx, d_wvelo, d_gauge, 8.0);
                dataStrList.AddRange(tmpDataStrList);

                d_wx = cfprocess.GetOneChannelDataInRange(citFileName, cdlist.GetChannelIdByName("R_Prof_SC", "右高低_中波"), startPos, endPos);

                tmpDataStrList = pdc.WideGaugePreProcess("右高低_中波", d_tt, d_wx, d_wvelo, d_gauge, 8.0);
                dataStrList.AddRange(tmpDataStrList);

                d_wx = cfprocess.GetOneChannelDataInRange(citFileName, cdlist.GetChannelIdByName("L_Align_SC", "左轨向_中波"), startPos, endPos);

                tmpDataStrList = pdc.WideGaugePreProcess("左轨向_中波", d_tt, d_wx, d_wvelo, d_gauge, 8.0);
                dataStrList.AddRange(tmpDataStrList);

                d_wx = cfprocess.GetOneChannelDataInRange(citFileName, cdlist.GetChannelIdByName("R_Align_SC", "右轨向_中波"), startPos, endPos);

                tmpDataStrList = pdc.WideGaugePreProcess("右轨向_中波", d_tt, d_wx, d_wvelo, d_gauge, 8.0);
                dataStrList.AddRange(tmpDataStrList);

                //分段读取方法////////////////////
                startPos = endPos;
            }

            //sw3.Close();

            //分段读取方法////////////////////
            return(dataStrList);
        }