public string GetDataInfoHead(string json) { ResultInfo resultInfo = new ResultInfo(); try { Request request = JsonConvert.DeserializeObject <Request>(json); string FilePath = request.filepath; DataHeadInfo header = citHelper.GetDataInfoHead(FilePath); string result = JsonConvert.SerializeObject(header); resultInfo.flag = 1; resultInfo.msg = ""; resultInfo.data = result; } catch (Exception ex) { resultInfo.flag = 0; resultInfo.msg = ex.Message; } return(JsonConvert.SerializeObject(resultInfo)); }
private void WriteBnyData(string fileName, string citPath, List <ChannelNew> channelNewList) { CitFileHelper citHelper = new CitFileHelper(); using (FileStream fs = new FileStream(citPath, FileMode.Append, FileAccess.Write, FileShare.ReadWrite)) { using (BinaryWriter bw = new BinaryWriter(fs, Encoding.Default)) { DataHeadInfo dhi = citHelper.GetDataInfoHead(citPath); long pos = bw.BaseStream.Length; List <DataChannelInfo> channelList = citHelper.GetDataChannelInfoHead(citPath); int iChannelNumberSize = dhi.iChannelNumber * 2; byte[] dataArray = new byte[iChannelNumberSize]; List <Byte> dataList = new List <Byte>(); short tmpRmsData = 0; Byte[] tmpBytes = new Byte[2]; while (true) { if (channelDataList.ContainsKey(fileName) && channelDataList[fileName].Count > 0) { List <float[]> channelData = channelDataList[fileName].Dequeue(); DateTime dt2 = DateTime.Now; if (channelData == null || isCancel) { break; } long iArrayLen = channelData[0].Length; for (int k = 0; k < iArrayLen; k++) { if (citHelper.IsEncrypt(dhi)) { for (int iTmp = 0; iTmp < channelNewList.Count; iTmp++) { if (channelNewList[iTmp].BNYChannelId > 6) { tmpRmsData = (short)((channelData[iTmp][k] / 10 - channelList[iTmp].fOffset) * channelList[iTmp].fScale); } else { tmpRmsData = (short)((channelData[iTmp][k] - channelList[iTmp].fOffset) * channelList[iTmp].fScale); } tmpBytes = CitFileHelper.ByteXORByte(BitConverter.GetBytes(tmpRmsData)); dataList.AddRange(tmpBytes); } } else { for (int iTmp = 0; iTmp < channelNewList.Count; iTmp++) { try { if (channelNewList[iTmp].BNYChannelId > 6) { tmpRmsData = (short)((channelData[iTmp][k] / 10 - channelList[iTmp].fOffset) * channelList[iTmp].fScale); } else { tmpRmsData = (short)((channelData[iTmp][k] - channelList[iTmp].fOffset) * channelList[iTmp].fScale); } dataList.AddRange(BitConverter.GetBytes(tmpRmsData)); } catch (Exception ex) { throw ex; } } } ///bw.BaseStream.Position = 100; bw.Write(dataList.ToArray()); bw.Flush(); dataList.Clear(); } } } //bw.Close(); //DateTime dt3 = DateTime.Now; //Console.WriteLine("two :" + (dt3 - dt2).TotalSeconds.ToString()); } //fs.Close(); } }
/// <summary> /// 获取BNY数据并向cit文件中写入数据 /// </summary> /// <param name="channelList"></param> private void GetBnyDataAndWriteCit(List <ChannelNew> channelList) { int[] bnyChannelArr = channelList.Where(s => s.BNYChannelId >= 0).Select(s => s.BNYChannelId).ToArray(); int sampleNum = 1000; long startPosition = 0; long endPosition = 0; long bnyFileLength = common.GetBNYLastPosition(bnyFilePath); int pageCount = Convert.ToInt32(bnyFileLength / (sampleNum * BNYFile.GetChannelSize())); List <float[]> bnyList = new List <float[]>(); try { using (FileStream fs = new FileStream(createCitFilePath, FileMode.Append, FileAccess.Write, FileShare.ReadWrite)) { using (BinaryWriter bw = new BinaryWriter(fs, Encoding.Default)) { DataHeadInfo dhi = citHelper.GetDataInfoHead(createCitFilePath); List <DataChannelInfo> channelInfoList = citHelper.GetDataChannelInfoHead(createCitFilePath); int iChannelNumberSize = dhi.iChannelNumber * 2; byte[] dataArray = new byte[iChannelNumberSize]; List <Byte> dataList = new List <Byte>(); short tmpRmsData = 0;; Byte[] tmpBytes = new Byte[2]; for (int i = 0; i < pageCount; i++) { bnyList = common.GetBNYData(bnyFilePath, sampleNum, startPosition, ref endPosition); startPosition = endPosition; List <float[]> resultList = new List <float[]>(); //Action<float> action = new Action<float>({ }); for (int j = 0; j < channelList.Count; j++) { float[] fvalue = new float[sampleNum]; if (channelList[j].BNYChannelId >= 0) { fvalue = bnyList[channelList[j].BNYChannelId]; } resultList.Add(fvalue); } long iArrayLen = resultList[0].Length; for (int k = 0; k < iArrayLen; k++) { if (citHelper.IsEncrypt(dhi)) { for (int iTmp = 0; iTmp < channelList.Count; iTmp++) { if (channelList[iTmp].BNYChannelId > 6) { tmpRmsData = (short)((resultList[iTmp][k] / 10 - channelInfoList[iTmp].fOffset) * channelInfoList[iTmp].fScale); } else { tmpRmsData = (short)((resultList[iTmp][k] - channelInfoList[iTmp].fOffset) * channelInfoList[iTmp].fScale); } tmpBytes = CitFileHelper.ByteXORByte(BitConverter.GetBytes(tmpRmsData)); dataList.AddRange(tmpBytes); } } else { for (int iTmp = 0; iTmp < channelList.Count; iTmp++) { try { if (channelList[iTmp].BNYChannelId > 6) { tmpRmsData = (short)((resultList[iTmp][k] / 10 - channelInfoList[iTmp].fOffset) * channelInfoList[iTmp].fScale); } else { tmpRmsData = (short)((resultList[iTmp][k] - channelInfoList[iTmp].fOffset) * channelInfoList[iTmp].fScale); } dataList.AddRange(BitConverter.GetBytes(tmpRmsData)); } catch (Exception ex) { throw ex; } } } ///bw.BaseStream.Position = 100; bw.Write(dataList.ToArray()); bw.Flush(); dataList.Clear(); } if (token.IsCancellationRequested) { token.ThrowIfCancellationRequested(); } } } } } catch (Exception ex) { throw ex; } }
private string _fixCit(string citFilePath, string curveFilePath, string abruptMileFilePath, int fs, double thresh_curve, int pointCount) { CalculateCorrugationClass calculateCorrugation = new CalculateCorrugationClass(); var header = citHelper.GetDataInfoHead(citFilePath); var channelList = citHelper.GetDataChannelInfoHead(citFilePath); string correctMileFilePath = citFilePath.Substring(0, citFilePath.Length - 4) + "correctMileStone.cit"; CreateCitHeader(correctMileFilePath, header, channelList); long startPos = citHelper.GetSamplePointStartOffset(header.iChannelNumber); long endPos = 0; //点位数 int sampleNum = Convert.ToInt32((citHelper.GetFileLength(citFilePath) - startPos) / (header.iChannelNumber * 2)); //循环次数 int count = Convert.ToInt32(sampleNum / pointCount); //是否有余点 int residue = Convert.ToInt32(sampleNum % pointCount); bool iszero = false; //是否执行一次 if (count == 0) { iszero = true; } //如果有余数循环次数加1 if (residue > 0) { count++; } double[,] wcCurveData; //台账曲率 double[,] abruptMileData; //长短链 wcCurveData = GetData(curveFilePath); abruptMileData = GetData(abruptMileFilePath); //if (count == 0) count = 1; for (int k = 0; k < count; k++) { List <double[]> dataList = null; if (iszero) { dataList = citHelper.GetAllChannelDataInRange(citFilePath, startPos, residue, ref endPos); } else { if (residue == 0) { dataList = citHelper.GetAllChannelDataInRange(citFilePath, startPos, pointCount, ref endPos); } else { if (k == (count - 1)) { dataList = citHelper.GetAllChannelDataInRange(citFilePath, startPos, residue, ref endPos); } else { dataList = citHelper.GetAllChannelDataInRange(citFilePath, startPos, pointCount, ref endPos); } } } List <double[]> dataList_input = new List <double[]>(); dataList_input.Add(dataList[0]); dataList_input.Add(dataList[1]); dataList_input.Add(dataList[7]); MWNumericArray array = calculateCorrugation.GetProcessAbnormalDispResultProcess(dataList_input); List <double[]> listData = calculateCorrugation.GetProcessAbnormalDispResult(array); double[] mileData; double[] curveData;//超高 mileData = listData[0]; curveData = listData[1]; MWNumericArray array2 = calculateCorrugation.GetVerifyKilometerResultProcess(mileData, curveData, wcCurveData, abruptMileData, fs, thresh_curve); var correctMileData = calculateCorrugation.GetVerifyKilometerResult(array2); double[] kmData = new double[correctMileData.Length]; double[] mData = new double[correctMileData.Length]; for (int i = 0; i < correctMileData.Length; i++) { kmData[i] = correctMileData[i] / 1000; mData[i] = correctMileData[i] % 1000; } dataList[0] = kmData; dataList[1] = mData; CreateCitData(correctMileFilePath, dataList); startPos = endPos; } return(correctMileFilePath); }