public static void Write(Meter meter, DataGroup waveFormData, FaultLocationData.FaultCurveDataTable faultCurveTable, List<FaultSegment> segments, string originalFilePath, string filePath) { List<DataSeries> waveFormSeriesList = GetWaveFormSeriesList(waveFormData); DataGroup faultLocationData = GetFaultLocationData(meter, faultCurveTable); string absoluteFilePath = FilePath.GetAbsolutePath(filePath); using (StreamWriter fileStream = new StreamWriter(File.OpenWrite(absoluteFilePath))) { string originalDirectory; string originalRootFileName; string originalSchemaFilePath; string absoluteOriginalFilePath; Schema originalSchema = null; string headerRow; absoluteOriginalFilePath = FilePath.GetAbsolutePath(originalFilePath); if (File.Exists(absoluteOriginalFilePath)) { originalDirectory = FilePath.GetDirectoryName(absoluteOriginalFilePath); originalRootFileName = FilePath.GetFileNameWithoutExtension(originalFilePath); originalSchemaFilePath = Path.Combine(originalDirectory, originalRootFileName + ".cfg"); originalSchema = new Schema(originalSchemaFilePath); } headerRow = waveFormData.DataSeries .Select(series => GetOriginalChannelName(originalSchema, series)) .Concat(faultCurveTable.Select(row => string.Format("Fault Location ({0} Algorithm)", row.Algorithm))) .Aggregate("Time", (s, s1) => s + "," + s1); fileStream.WriteLine(headerRow); for (int i = 0; i < waveFormData.Samples; i++) { DateTime time = waveFormSeriesList[0].DataPoints[i].Time; double[] values = waveFormSeriesList .Select(series => series.DataPoints[i].Value) .Concat(faultLocationData.DataSeries.Select(series => series.DataPoints.Count > i ? series.DataPoints[i].Value : 0.0D)) .ToArray(); fileStream.WriteLine(values.Aggregate(time.ToString("yyyy-MM-dd HH:mm:ss.ffffff"), (s, d) => s + "," + d)); } } }
/// <summary> /// ToDataSeries /// </summary> /// <param name="faultCurve"></param> /// <returns></returns> private DataSeries ToDataSeries(FaultLocationData.FaultCurveRow faultCurve) { DataGroup dataGroup = new DataGroup(); dataGroup.FromData(faultCurve.Data); return dataGroup[0]; }
private static DataGroup GetFaultLocationData(Meter meter, FaultLocationData.FaultCurveDataTable faultCurveTable) { DataGroup faultLocationData = new DataGroup(); DataGroup parsedGroup = new DataGroup(); foreach (FaultLocationData.FaultCurveRow faultCurveRow in faultCurveTable) { parsedGroup.FromData(meter, faultCurveRow.Data); foreach (DataSeries series in parsedGroup.DataSeries) faultLocationData.Add(series); } return faultLocationData; }