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); } } }
private void SaveToFile(string targetCitFile, bool diffFileName = false) { string idfFile = targetCitFile.Replace(".cit", ".idf"); if (diffFileName) { idfFile = targetCitFile.Replace(".cit", "_MileageFix.idf"); } IndexOperator indexOperator = new IndexOperator(); indexOperator.IndexFilePath = idfFile; FileInformation citHeaderInfo = _citProcess.GetFileInformation(targetCitFile); UserFixedTable fixedTable = new UserFixedTable(indexOperator, citHeaderInfo.iKmInc); fixedTable.Clear(); foreach (var kvp in _CorrResult) { FixParams.Sort(); bool isFind = false; UserMarkedPoint markedPoint = null; foreach (var item in FixParams) { CorrelationResult corrResult = kvp.Value.FirstOrDefault(p => p.ChannelID == item.ChannelID); if (corrResult != null) { if (item.Priority == 0 && !isFind) { isFind = true; continue; } if (isFind) { markedPoint = new UserMarkedPoint(); markedPoint.FilePointer = corrResult.FilePointer; markedPoint.UserSetMileage = kvp.Key.UserSetMileage; break; } } } if (markedPoint != null) { fixedTable.MarkedPoints.Add(markedPoint); } } if (fixedTable.MarkedPoints.Count > 0) { fixedTable.Save(); } }