public override void Initialize(MeterDataSet meterDataSet) { List <DataGroup> dataGroups; DataGroup dataGroup; dataGroups = new List <DataGroup>(); foreach (IGrouping <Line, DataSeries> lineGroup in meterDataSet.DataSeries.Concat(meterDataSet.Digitals).GroupBy(GetLine)) { foreach (IGrouping <DateTime, DataSeries> startTimeGroup in lineGroup.GroupBy(dataSeries => dataSeries.DataPoints[0].Time)) { foreach (IGrouping <DateTime, DataSeries> endTimeGroup in startTimeGroup.GroupBy(dataSeries => dataSeries.DataPoints[dataSeries.DataPoints.Count - 1].Time)) { foreach (IGrouping <int, DataSeries> sampleCountGroup in endTimeGroup.GroupBy(dataSeries => dataSeries.DataPoints.Count)) { dataGroup = new DataGroup(); foreach (DataSeries dataSeries in sampleCountGroup) { dataGroup.Add(dataSeries); } dataGroups.Add(dataGroup); } } } } m_dataGroups = dataGroups; }
private byte[] Serialize(DataSeries series) { DataGroup group = new DataGroup(); group.Add(series); return(group.ToData()); }
private FaultCurve CreateFaultCurve(AdoDataConnection connection, IGrouping <int, MappingNode> grouping) { VICycleDataGroup viCycleDataGroup = GetCycleData(connection, grouping.Key); DataGroup faultCurveGroup = new DataGroup(); DataGroup faultCurveAngleGroup = new DataGroup(); faultCurveGroup.Add(viCycleDataGroup.VA.RMS.Multiply(double.NaN)); faultCurveAngleGroup.Add(faultCurveGroup[0].Copy()); foreach (MappingNode node in grouping) { for (int i = node.StartSample; node.DistanceCurve.HasData(i); i++) { faultCurveGroup[0][i].Value = node.DistanceCurve[i].Value; faultCurveAngleGroup[0][i].Value = node.AngleCurve[i].Value; } } return(new FaultCurve() { EventID = grouping.Key, Algorithm = "DoubleEnded", Data = faultCurveGroup.ToData()[0], AngleData = faultCurveAngleGroup.ToData()[0] }); }
private void CreateFaultCurveRow(IGrouping <int, MappingNode> grouping) { VICycleDataGroup viCycleDataGroup = GetCycleData(grouping.Key); DataGroup faultCurveGroup = new DataGroup(); faultCurveGroup.Add(viCycleDataGroup.VA.RMS.Multiply(double.NaN)); faultCurveGroup.Add(faultCurveGroup[0].Copy()); foreach (MappingNode node in grouping) { for (int i = node.StartSample; node.DistanceCurve.HasData(i); i++) { faultCurveGroup[0][i].Value = node.DistanceCurve[i].Value; faultCurveGroup[1][i].Value = node.AngleCurve[i].Value; } } m_faultCurveTable.AddFaultCurveRow(grouping.Key, "DoubleEnded", faultCurveGroup.ToData()); }
public static DataGroup Combine(params DataGroup[] dataGroups) { DataGroup combination = new DataGroup(); foreach (DataGroup dataGroup in dataGroups) { foreach (DataSeries dataSeries in dataGroup.DataSeries) combination.Add(dataSeries); } return combination; }
private Dictionary <string, DataSeries> QueryEventData(AdoDataConnection connection, Meter meter, DateTime startTime, DateTime endTime) { Func <IEnumerable <DataSeries>, DataSeries> merge = grouping => { DataSeries mergedSeries = DataSeries.Merge(grouping); mergedSeries.SeriesInfo = grouping.First().SeriesInfo; return(mergedSeries); }; double systemFrequency = connection.ExecuteScalar <double?>("SELECT Value FROM Setting WHERE Name = 'SystemFrequency'") ?? 60.0D; DataTable dataTable = connection.RetrieveData("SELECT ID FROM Event WHERE MeterID = {0} AND EndTime >= {1} AND StartTime <= {2})", meter.ID, ToDateTime2(connection, startTime), ToDateTime2(connection, endTime)); Dictionary <string, DataSeries> dict = new Dictionary <string, DataSeries>(); IEnumerable <DataGroup> dataGroups = dataTable .Select() .Select(row => row.ConvertField <int>("ID")) .Select(id => ToDataGroup(meter, ChannelData.DataFromEvent(id, connection))) .OrderBy(subGroup => subGroup.StartTime) .ToList(); List <DataSeries> mergedSeriesList = dataGroups .SelectMany(dataGroup => dataGroup.DataSeries) .GroupBy(dataSeries => dataSeries.SeriesInfo.Channel.Name) .Select(merge) .ToList(); DataGroup mergedGroup = new DataGroup(); mergedSeriesList.ForEach(mergedSeries => mergedGroup.Add(mergedSeries)); foreach (DataSeries dataSeries in mergedGroup.DataSeries) { string key = dataSeries.SeriesInfo.Channel.Name; dict.GetOrAdd(key, _ => dataSeries.ToSubSeries(startTime, endTime)); } VICycleDataGroup viCycleDataGroup = Transform.ToVICycleDataGroup(new VIDataGroup(mergedGroup), systemFrequency); foreach (CycleDataGroup cycleDataGroup in viCycleDataGroup.CycleDataGroups) { DataGroup dg = cycleDataGroup.ToDataGroup(); string key = dg.DataSeries.First().SeriesInfo.Channel.Name; dict.GetOrAdd(key + " RMS", _ => cycleDataGroup.RMS.ToSubSeries(startTime, endTime)); dict.GetOrAdd(key + " Angle", _ => cycleDataGroup.Phase.ToSubSeries(startTime, endTime)); } return(dict); }
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); }
public override void Initialize(MeterDataSet meterDataSet) { List <DataGroup> dataGroups = new List <DataGroup>(); foreach (IGrouping <Line, DataSeries> lineGroup in meterDataSet.DataSeries.Concat(meterDataSet.Digitals).GroupBy(GetLine)) { foreach (IGrouping <DateTime, DataSeries> startTimeGroup in lineGroup.GroupBy(dataSeries => dataSeries.DataPoints[0].Time)) { foreach (IGrouping <DateTime, DataSeries> endTimeGroup in startTimeGroup.GroupBy(dataSeries => dataSeries.DataPoints[dataSeries.DataPoints.Count - 1].Time)) { foreach (IGrouping <int, DataSeries> sampleCountGroup in endTimeGroup.GroupBy(dataSeries => dataSeries.DataPoints.Count)) { DataGroup dataGroup = new DataGroup(); foreach (DataSeries dataSeries in sampleCountGroup) { dataGroup.Add(dataSeries); } dataGroups.Add(dataGroup); } } } } if (meterDataSet.Meter.MeterLines.Count == 1) { foreach (ReportedDisturbance disturbance in meterDataSet.ReportedDisturbances.OrderBy(dist => dist.Time)) { DataGroup dataGroup = dataGroups.FirstOrDefault(dg => dg.Add(disturbance)); if ((object)dataGroup == null) { dataGroup = new DataGroup(); dataGroup.Add(disturbance); dataGroups.Add(dataGroup); } } } m_dataGroups = dataGroups; }
public static CycleDataGroup ToCycleDataGroup(DataSeries dataSeries, double frequency) { DataGroup dataGroup = new DataGroup(); DataSeries rmsSeries = new DataSeries(); DataSeries phaseSeries = new DataSeries(); DataSeries peakSeries = new DataSeries(); DataSeries errorSeries = new DataSeries(); int samplesPerCycle; double[] yValues; double[] tValues; double sum; DateTime cycleTime; SineWave sineFit; if ((object)dataSeries == null) return null; // Set series info to the source series info rmsSeries.SeriesInfo = dataSeries.SeriesInfo; phaseSeries.SeriesInfo = dataSeries.SeriesInfo; peakSeries.SeriesInfo = dataSeries.SeriesInfo; errorSeries.SeriesInfo = dataSeries.SeriesInfo; // Get samples per cycle of the data series based on the given frequency samplesPerCycle = CalculateSamplesPerCycle(dataSeries, frequency); // Initialize arrays of y-values and t-values for calculating cycle data yValues = new double[samplesPerCycle]; tValues = new double[samplesPerCycle]; // Obtain a list of time gaps in the data series List<int> gapIndexes = Enumerable.Range(0, dataSeries.DataPoints.Count - 1) .Where(index => { DataPoint p1 = dataSeries[index]; DataPoint p2 = dataSeries[index + 1]; double cycleDiff = (p2.Time - p1.Time).TotalSeconds * frequency; return (cycleDiff >= 0.25); }) .ToList(); for (int i = 0; i <= dataSeries.DataPoints.Count - samplesPerCycle; i++) { // If the cycle following i contains a data gap, do not calculate cycle data if (gapIndexes.Any(index => i <= index && (i + samplesPerCycle - 1) > index)) continue; // Use the time of the first data point in the cycle as the time of the cycle cycleTime = dataSeries.DataPoints[i].Time; sum = 0.0D; // Copy values from the original data series into the y-value and t-value arrays for (int j = 0; j < samplesPerCycle; j++) { yValues[j] = dataSeries.DataPoints[i + j].Value; tValues[j] = (dataSeries.DataPoints[i + j].Time - cycleTime).TotalSeconds; sum += yValues[j] * yValues[j]; } // Use a curve fitting algorithm to estimate the sine wave over this cycle sineFit = WaveFit.SineFit(yValues, tValues, frequency); // Add data points to each of the cycle data series rmsSeries.DataPoints.Add(new DataPoint() { Time = cycleTime, Value = Math.Sqrt(sum / samplesPerCycle) }); phaseSeries.DataPoints.Add(new DataPoint() { Time = cycleTime, Value = sineFit.Phase }); peakSeries.DataPoints.Add(new DataPoint() { Time = cycleTime, Value = sineFit.Amplitude }); errorSeries.DataPoints.Add(new DataPoint() { Time = cycleTime, Value = tValues .Select(sineFit.CalculateY) .Zip(yValues, (estimate, value) => Math.Abs(estimate - value)) .Sum() }); } // Add a series to the data group for each series of cycle data dataGroup.Add(rmsSeries); dataGroup.Add(phaseSeries); dataGroup.Add(peakSeries); dataGroup.Add(errorSeries); return new CycleDataGroup(dataGroup); }
/// <summary> /// Transforms the group. /// </summary> /// <param name="inputGroup">The input group.</param> /// <returns>Two result groups as result of one transformation step.</returns> private DataGroup[] TransformGroup(DataGroup inputGroup) { var addGroup = new DataGroup("+"); for (int i = 0; i < inputGroup.Count; i += 2) { var val = (inputGroup[i] + inputGroup[i + 1]) / Math.Sqrt(2.0); var roundedVal = Math.Round(val, 3); addGroup.Add(roundedVal); } var subGroup = new DataGroup("-"); for (int i = 0; i < inputGroup.Count; i += 2) { var val = (inputGroup[i] - inputGroup[i + 1]) / Math.Sqrt(2.0); var roundedVal = Math.Round(val, 3); subGroup.Add(roundedVal); } return new[] { addGroup, subGroup }; }
public override void Initialize(MeterDataSet meterDataSet) { List <DataGroup> dataGroups = new List <DataGroup>(); foreach (IGrouping <DateTime, DataSeries> startTimeGroup in meterDataSet.DataSeries.Concat(meterDataSet.Digitals).GroupBy(dataSeries => dataSeries.DataPoints[0].Time)) { foreach (IGrouping <DateTime, DataSeries> endTimeGroup in startTimeGroup.GroupBy(dataSeries => dataSeries.DataPoints[dataSeries.DataPoints.Count - 1].Time)) { foreach (IGrouping <int, DataSeries> sampleCountGroup in endTimeGroup.GroupBy(dataSeries => dataSeries.DataPoints.Count)) { List <int> completedAsset = new List <int>(); foreach (IGrouping <Asset, DataSeries> assetGroup in sampleCountGroup.GroupBy(GetAsset)) { completedAsset.Add(assetGroup.Key.ID); DataGroup dataGroup = new DataGroup(); foreach (DataSeries dataSeries in assetGroup) { dataGroup.Add(dataSeries); } foreach (DataSeries dataSeries in GetConnectedSeries(sampleCountGroup, assetGroup.Key)) { dataGroup.Add(dataSeries); } dataGroups.Add(dataGroup); } //Add Any Datagroups for Assets that have no directly connected Assets foreach (Asset asset in meterDataSet.Meter.MeterAssets.Select(item => item.Asset)) { if (completedAsset.Contains(asset.ID)) { continue; } DataGroup dataGroup = new DataGroup(asset); foreach (DataSeries dataSeries in GetConnectedSeries(sampleCountGroup, asset)) { dataGroup.Add(dataSeries); } dataGroups.Add(dataGroup); } } } } if (meterDataSet.Meter.MeterAssets.Count == 1) { foreach (ReportedDisturbance disturbance in meterDataSet.ReportedDisturbances.OrderBy(dist => dist.Time)) { DataGroup dataGroup = dataGroups.FirstOrDefault(dg => dg.Add(disturbance)); if ((object)dataGroup == null) { dataGroup = new DataGroup(); dataGroup.Add(disturbance); dataGroups.Add(dataGroup); } } } m_dataGroups = dataGroups; }
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; }