Exemplo n.º 1
0
        public override void Execute(MeterDataSet meterDataSet)
        {
            CycleDataResource cycleDataResource = meterDataSet.GetResource <CycleDataResource>();

            for (int i = 0; i < cycleDataResource.DataGroups.Count; i++)
            {
                EventKey         eventKey         = CreateEventKey(meterDataSet.FileGroup, cycleDataResource.DataGroups[i]);
                VICycleDataGroup viCycleDataGroup = cycleDataResource.VICycleDataGroups[i];
                int samplesPerCycle = (int)Math.Round(cycleDataResource.DataGroups[i].SamplesPerSecond / m_systemFrequency);
                Process(eventKey, viCycleDataGroup, samplesPerCycle);
            }

            m_meterDataSet = meterDataSet;

            using (AdoDataConnection connection = meterDataSet.CreateDbConnection())
            {
                // Query database for events and store them in a lookup table by event key
                TableOperations <Event>     eventAdapter     = new TableOperations <Event>(connection);
                TableOperations <CycleData> cycleDataAdapter = new TableOperations <CycleData>(connection);

                IEnumerable <Event> eventTable = eventAdapter.QueryRecordsWhere("FileGroupID = {0}", m_meterDataSet.FileGroup.ID);

                Dictionary <EventKey, Event> eventLookup = eventTable.ToDictionary(CreateEventKey);

                foreach (Tuple <EventKey, CycleData> tuple in m_cycleDataList)
                {
                    Event eventRow;
                    if (eventLookup.TryGetValue(tuple.Item1, out eventRow))
                    {
                        tuple.Item2.EventID = eventRow.ID;
                        cycleDataAdapter.AddNewRecord(tuple.Item2);
                    }
                }
            }
        }
Exemplo n.º 2
0
        private CycleData FirstCycle(VICycleDataGroup viCycleDataGroup)
        {
            CycleData cycle = new CycleData();

            Cycle[] cycles =
            {
                cycle.AN.V,
                cycle.BN.V,
                cycle.CN.V,
                cycle.AN.I,
                cycle.BN.I,
                cycle.CN.I
            };

            CycleDataGroup[] cycleDataGroups =
            {
                viCycleDataGroup.VA,
                viCycleDataGroup.VB,
                viCycleDataGroup.VC,
                viCycleDataGroup.IA,
                viCycleDataGroup.IB,
                viCycleDataGroup.IC
            };

            for (int i = 0; i < cycles.Length; i++)
            {
                cycles[i].RMS   = cycleDataGroups[i].RMS.DataPoints[0].Value;
                cycles[i].Phase = cycleDataGroups[i].Phase.DataPoints[0].Value;
                cycles[i].Peak  = cycleDataGroups[i].Peak.DataPoints[0].Value;
                cycles[i].Error = cycleDataGroups[i].Error.DataPoints[0].Value;
            }

            return(cycle);
        }
Exemplo n.º 3
0
        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 CycleData GetCycleAt(VICycleDataGroup viCycleDataGroup, int index)
        {
            CycleData cycle = new CycleData();

            Cycle[] cycles =
            {
                cycle.AN.V,
                cycle.BN.V,
                cycle.CN.V,
                cycle.AN.I,
                cycle.BN.I,
                cycle.CN.I
            };

            CycleDataGroup[] cycleDataGroups =
            {
                viCycleDataGroup.VA,
                viCycleDataGroup.VB,
                viCycleDataGroup.VC,
                viCycleDataGroup.IA,
                viCycleDataGroup.IB,
                viCycleDataGroup.IC
            };

            for (int i = 0; i < cycles.Length; i++)
            {
                cycles[i].RMS   = cycleDataGroups[i].RMS[index].Value;
                cycles[i].Phase = cycleDataGroups[i].Phase[index].Value;
                cycles[i].Peak  = cycleDataGroups[i].Peak[index].Value;
                cycles[i].Error = cycleDataGroups[i].Error[index].Value;
            }

            return(cycle);
        }
Exemplo n.º 5
0
        private void FindAllTrips(CycleDataResource cycleDataResource)
        {
            for (int i = 0; i < cycleDataResource.DataGroups.Count; i++)
            {
                DataGroup        dataGroup        = cycleDataResource.DataGroups[i];
                VICycleDataGroup viCycleDataGroup = cycleDataResource.VICycleDataGroups[i];

                IEnumerable <Trip> iaTrips = FindTrips(viCycleDataGroup.IA?.Peak)
                                             .Select(point => new Trip(Phase.AN, point.Time));

                IEnumerable <Trip> ibTrips = FindTrips(viCycleDataGroup.IB?.Peak)
                                             .Select(point => new Trip(Phase.BN, point.Time));

                IEnumerable <Trip> icTrips = FindTrips(viCycleDataGroup.IC?.Peak)
                                             .Select(point => new Trip(Phase.CN, point.Time));

                List <Trip> allTrips = Enumerable.Empty <Trip>()
                                       .Concat(iaTrips)
                                       .Concat(ibTrips)
                                       .Concat(icTrips)
                                       .ToList();

                if (allTrips.Any())
                {
                    TripLookup.Add(dataGroup, allTrips);
                }
            }
        }
Exemplo n.º 6
0
        public ActionResult Get(int eventID, int pixels)
        {
            using (AdoDataConnection connection = new AdoDataConnection(m_configuration["OpenXDA:ConnectionString"], m_configuration["OpenXDA:DataProviderString"]))
            {
                Event evt = new TableOperations <Event>(connection).QueryRecordWhere("ID = {0}", eventID);
                if (evt == null)
                {
                    return(BadRequest("Must provide a valid EventID"));
                }
                Meter meter = new TableOperations <Meter>(connection).QueryRecordWhere("ID = {0}", evt.MeterID);
                meter.ConnectionFactory = () => new AdoDataConnection(m_configuration["OpenXDA:ConnectionString"], m_configuration["OpenXDA:DataProviderString"]);

                Dictionary <string, IEnumerable <double[]> > returnData = new Dictionary <string, IEnumerable <double[]> >();
                DataGroupHelper  dataGroupHelper  = new DataGroupHelper(m_configuration, m_memoryCache);
                VICycleDataGroup vICycleDataGroup = dataGroupHelper.QueryVICycleDataGroup(eventID, meter);


                Dictionary <string, List <double[]> > returnList = new Dictionary <string, List <double[]> >();

                foreach (CycleDataGroup dg in vICycleDataGroup.CycleDataGroups)
                {
                    if (dg.RMS.SeriesInfo.Channel.MeasurementType.Name == "Voltage")
                    {
                        string name = "V" + dg.RMS.SeriesInfo.Channel.Phase.Name;
                        returnList.Add(name, GetRapidVoltageChangeSeries(dg.RMS));
                    }
                }

                return(Ok(returnList));
            }
        }
Exemplo n.º 7
0
        private IEnumerable <COMTRADEChannelData> GetCycleChannelData(VICycleDataGroup cycleDataGroup, IEnumerable <OutputChannel> outputChannels)
        {
            // Create a function to get the load order of a collection of
            // channels where collections should have no more than 1 channel
            Func <IEnumerable <OutputChannel>, int> getLoadOrder = channels => channels
                                                                   .Select(channel => channel.LoadOrder)
                                                                   .DefaultIfEmpty(int.MaxValue)
                                                                   .First();

            // Convert the cycle data set to a collection of cycle data groups
            List <Tuple <string, CycleDataGroup> > cycleDataGroups = new List <Tuple <string, CycleDataGroup> >
            {
                Tuple.Create("VA", cycleDataGroup.VA),
                Tuple.Create("VB", cycleDataGroup.VB),
                Tuple.Create("VC", cycleDataGroup.VC),
                Tuple.Create("IA", cycleDataGroup.IA),
                Tuple.Create("IB", cycleDataGroup.IB),
                Tuple.Create("IC", cycleDataGroup.IC),
                Tuple.Create("IR", cycleDataGroup.IR)
            };

            // Join the output channels to the cycle data groups, order them by LoadOrder, and then
            // return a collection containing only the RMS and Phase series from each cycle data group
            return(cycleDataGroups
                   .GroupJoin(outputChannels, tuple => tuple.Item1, outputChannel => outputChannel.ChannelKey, (tuple, channels) => new { LoadOrder = getLoadOrder(channels), ChannelKey = tuple.Item1, CycleDataGroup = tuple.Item2 })
                   .OrderBy(cycleDataGroupInfo => cycleDataGroupInfo.LoadOrder)
                   .ThenBy(cycleDataGroupInfo => cycleDataGroupInfo.ChannelKey)
                   .SelectMany((cycleDataGroupInfo, index) => ToAnalogChannelCollection(index, cycleDataGroupInfo.ChannelKey, cycleDataGroupInfo.CycleDataGroup)));
        }
        private EventClassification Classify(DataGroup dataGroup, VICycleDataGroup viCycleDataGroup)
        {
            double     nominalVoltage;
            DataSeries v1;
            DataSeries v2;
            DataSeries v3;

            // Get the line-to-neutral nominal voltage in volts
            nominalVoltage = dataGroup.Line.VoltageKV * 1000.0D / Math.Sqrt(3.0D);

            // Per-unit voltage waveforms based on nominal voltage
            v1 = viCycleDataGroup.VX1.RMS.Multiply(1.0D / nominalVoltage);
            v2 = viCycleDataGroup.VX2.RMS.Multiply(1.0D / nominalVoltage);
            v3 = viCycleDataGroup.VX3.RMS.Multiply(1.0D / nominalVoltage);

            if (HasInterruption(v1, v2, v3))
            {
                return(EventClassification.Interruption);
            }

            if (HasSwell(v1, v2, v3))
            {
                return(EventClassification.Swell);
            }

            if (HasSag(v1, v2, v3))
            {
                return(EventClassification.Sag);
            }

            return(EventClassification.Other);
        }
Exemplo n.º 9
0
            public void Initialize(AdoDataConnection connection, VICycleDataGroup viCycleDataGroup, double systemFrequency)
            {
                int samplesPerCycle = Transform.CalculateSamplesPerCycle(viCycleDataGroup.VA.RMS, systemFrequency);

                TableOperations <FaultSegment> faultSegmentTable = new TableOperations <FaultSegment>(connection);

                RecordRestriction recordRestriction =
                    new RecordRestriction("EventID = {0}", Fault.EventID) &
                    new RecordRestriction("StartTime = {0}", ToDateTime2(connection, Fault.Inception)) &
                    new RecordRestriction("(SELECT Name FROM SegmentType WHERE ID = SegmentTypeID) = 'Fault'");

                FaultSegment faultSegment = faultSegmentTable.QueryRecord(recordRestriction);

                if ((object)faultSegment == null)
                {
                    throw new InvalidOperationException($"Unable to find fault segment that matches fault summary for event {Fault.EventID}.");
                }

                StartSample    = faultSegment.StartSample;
                EndSample      = faultSegment.EndSample - samplesPerCycle + 1;
                CycleDataGroup = Rotate(viCycleDataGroup.ToSubSet(StartSample, EndSample));

                DistanceCurve.StartIndex = StartSample;
                AngleCurve.StartIndex    = StartSample;
            }
Exemplo n.º 10
0
        private void WriteResults(MeterDataSet meterDataSet, DataGroup dataGroup, VICycleDataGroup viCycleDataGroup, List <Fault> faults, string resultsFilePath)
        {
            XDocument resultsDocument;
            XElement  results;
            string    lineName;

            lineName = meterDataSet.Meter.MeterLines
                       .Where(ml => ml.LineID == dataGroup.Line.ID)
                       .Select(ml => ml.LineName)
                       .FirstOrDefault() ?? dataGroup.Line.AssetKey;

            results =
                new XElement("results",
                             new XElement("meter", meterDataSet.Meter.Name),
                             new XElement("disturbanceFiles", GetPathElements(meterDataSet.FileGroup)),
                             new XElement("line",
                                          new XElement("name", lineName),
                                          new XElement("length", dataGroup.Line.Length.ToString(DoubleFormat))
                                          ),
                             new XElement("prefault",
                                          new XElement("time", dataGroup.StartTime.ToString(DateTimeFormat)),
                                          GetCycleElements(viCycleDataGroup, 0)
                                          ),
                             GetFaultElements(faults)
                             );

            // Create the XML document
            resultsDocument =
                new XDocument(
                    new XElement("openFLE", results)
                    );

            resultsDocument.Save(resultsFilePath);
        }
Exemplo n.º 11
0
        private List <Fault> DetectFaults(VIDataGroup viDataGroup, VICycleDataGroup viCycleDataGroup)
        {
            List <Fault> iaFaults = DetectFaults(viDataGroup.IA, viCycleDataGroup.IA.RMS);
            List <Fault> ibFaults = DetectFaults(viDataGroup.IB, viCycleDataGroup.IB.RMS);
            List <Fault> icFaults = DetectFaults(viDataGroup.IC, viCycleDataGroup.IC.RMS);

            return(Merge(iaFaults, ibFaults, icFaults));
        }
Exemplo n.º 12
0
 private List <XElement> GetCycleElements(VICycleDataGroup viCycleDataGroup, int cycleIndex)
 {
     return(new List <XElement>()
     {
         GetCycleElement("VA", viCycleDataGroup.VA, cycleIndex),
         GetCycleElement("VB", viCycleDataGroup.VB, cycleIndex),
         GetCycleElement("VC", viCycleDataGroup.VC, cycleIndex),
         GetCycleElement("IA", viCycleDataGroup.IA, cycleIndex),
         GetCycleElement("IB", viCycleDataGroup.IB, cycleIndex),
         GetCycleElement("IC", viCycleDataGroup.IC, cycleIndex)
     });
 }
Exemplo n.º 13
0
        private double GetPostfaultPeak(Fault fault, DataGroup dataGroup, VICycleDataGroup viCycleDataGroup)
        {
            int samplesPerCycle = (int)Math.Round(dataGroup.SamplesPerSecond / m_systemFrequency);
            int start           = fault.EndSample + 1;
            int end             = Math.Min(start + 5 * samplesPerCycle, viCycleDataGroup.IA.RMS.DataPoints.Count) - 1;

            double ia = viCycleDataGroup.IA.Peak.ToSubSeries(start, end).Minimum;
            double ib = viCycleDataGroup.IB.Peak.ToSubSeries(start, end).Minimum;
            double ic = viCycleDataGroup.IC.Peak.ToSubSeries(start, end).Minimum;

            return(Common.Min(ia, ib, ic));
        }
Exemplo n.º 14
0
        private List <D3Series> QueryCurrentData(Meter meter, Event evt)
        {
            DataGroup dataGroup = OpenSEEController.QueryDataGroup(evt.ID, meter);

            List <D3Series> WaveForm = dataGroup.DataSeries.Where(ds => ds.SeriesInfo.Channel.MeasurementType.Name == "Current"
                                                                  ).Select(
                ds => new D3Series()
            {
                ChannelID   = ds.SeriesInfo.Channel.ID,
                ChartLabel  = OpenSEEController.GetChartLabel(ds.SeriesInfo.Channel),
                LegendGroup = ds.SeriesInfo.Channel.Asset.AssetName,
                DataPoints  = ds.DataPoints.Select(dataPoint => new double[] { dataPoint.Time.Subtract(m_epoch).TotalMilliseconds, dataPoint.Value }).ToList(),
            }).ToList();

            WaveForm.Sort((a, b) => {
                if (a.LegendGroup == b.LegendGroup)
                {
                    return(a.ChartLabel.CompareTo(b.ChartLabel));
                }
                return(a.LegendGroup.CompareTo(b.LegendGroup));
            });

            VICycleDataGroup viCycleDataGroup = OpenSEEController.QueryVICycleDataGroup(evt.ID, meter);

            List <D3Series> result = new List <D3Series>();

            foreach (D3Series w in WaveForm)
            {
                result.Add(w);
                int index = viCycleDataGroup.CycleDataGroups.FindIndex(item => item.RMS.SeriesInfo.ChannelID == w.ChannelID);
                if (index > -1)
                {
                    result.Add(new D3Series
                    {
                        ChannelID   = w.ChannelID,
                        DataPoints  = viCycleDataGroup.CycleDataGroups[index].RMS.DataPoints.Select(dataPoint => new double[] { dataPoint.Time.Subtract(m_epoch).TotalMilliseconds, dataPoint.Value }).ToList(),
                        ChartLabel  = w.ChartLabel + " RMS",
                        LegendGroup = w.LegendGroup,
                    });

                    result.Add(new D3Series
                    {
                        ChannelID   = w.ChannelID,
                        DataPoints  = viCycleDataGroup.CycleDataGroups[index].Phase.Multiply(180.0D / Math.PI).DataPoints.Select(dataPoint => new double[] { dataPoint.Time.Subtract(m_epoch).TotalMilliseconds, dataPoint.Value }).ToList(),
                        ChartLabel  = w.ChartLabel + " Phase",
                        LegendGroup = w.LegendGroup,
                    });
                }
            }


            return(result);
        }
Exemplo n.º 15
0
        private double GetPostfaultCurrent(Fault fault, DataGroup dataGroup, VICycleDataGroup viCycleDataGroup)
        {
            int samplesPerCycle = Transform.CalculateSamplesPerCycle(dataGroup.SamplesPerSecond, m_systemFrequency);
            int start           = fault.EndSample + 1;
            int end             = Math.Min(start + samplesPerCycle, viCycleDataGroup.IA.RMS.DataPoints.Count) - 1;

            double ia = viCycleDataGroup.IA.RMS.ToSubSeries(start, end).Minimum;
            double ib = viCycleDataGroup.IB.RMS.ToSubSeries(start, end).Minimum;
            double ic = viCycleDataGroup.IC.RMS.ToSubSeries(start, end).Minimum;

            return(Common.Min(ia, ib, ic));
        }
Exemplo n.º 16
0
        private double GetPrefaultCurrent(Fault fault, DataGroup dataGroup, VICycleDataGroup viCycleDataGroup)
        {
            int samplesPerCycle = Transform.CalculateSamplesPerCycle(dataGroup.SamplesPerSecond, m_systemFrequency);
            int start           = Math.Max(0, fault.StartSample - samplesPerCycle);
            int end             = fault.StartSample;

            double ia = viCycleDataGroup.IA.RMS.ToSubSeries(start, end).Minimum;
            double ib = viCycleDataGroup.IB.RMS.ToSubSeries(start, end).Minimum;
            double ic = viCycleDataGroup.IC.RMS.ToSubSeries(start, end).Minimum;

            return(Common.Min(ia, ib, ic));
        }
Exemplo n.º 17
0
        private double GetPrefaultCurrent(Fault fault, DataGroup dataGroup, VICycleDataGroup viCycleDataGroup)
        {
            int samplesPerCycle = (int)Math.Round(dataGroup[0].SampleRate / m_systemFrequency);
            int start           = Math.Max(0, fault.StartSample - samplesPerCycle);
            int end             = fault.StartSample;

            double ia = viCycleDataGroup.IA.RMS.ToSubSeries(start, end).Minimum;
            double ib = viCycleDataGroup.IB.RMS.ToSubSeries(start, end).Minimum;
            double ic = viCycleDataGroup.IC.RMS.ToSubSeries(start, end).Minimum;

            return(Common.Min(ia, ib, ic));
        }
Exemplo n.º 18
0
        private void Process(EventKey eventKey, VICycleDataGroup viCycleDataGroup, int samplesPerCycle)
        {
            int length = viCycleDataGroup.VX1.RMS.DataPoints.Count;

            int       sampleNumber = 0;
            CycleData row;

            for (int i = 0; i < length; i++)
            {
                row = new CycleData();

                row.CycleNumber  = i;
                row.SampleNumber = sampleNumber;
                row.Timestamp    = viCycleDataGroup.VX1.RMS[i].Time;

                row.VX1RMS   = viCycleDataGroup.VX1.RMS[i].Value;
                row.VX1Phase = viCycleDataGroup.VX1.Phase[i].Value;
                row.VX1Peak  = viCycleDataGroup.VX1.Peak[i].Value;
                row.VX2RMS   = viCycleDataGroup.VX2.RMS[i].Value;
                row.VX2Phase = viCycleDataGroup.VX2.Phase[i].Value;
                row.VX2Peak  = viCycleDataGroup.VX2.Peak[i].Value;
                row.VX3RMS   = viCycleDataGroup.VX3.RMS[i].Value;
                row.VX3Phase = viCycleDataGroup.VX3.Phase[i].Value;
                row.VX3Peak  = viCycleDataGroup.VX3.Peak[i].Value;

                row.VY1RMS   = viCycleDataGroup.VY1.RMS[i].Value;
                row.VY1Phase = viCycleDataGroup.VY1.Phase[i].Value;
                row.VY1Peak  = viCycleDataGroup.VY1.Peak[i].Value;
                row.VY2RMS   = viCycleDataGroup.VY2.RMS[i].Value;
                row.VY2Phase = viCycleDataGroup.VY2.Phase[i].Value;
                row.VY2Peak  = viCycleDataGroup.VY2.Peak[i].Value;
                row.VY3RMS   = viCycleDataGroup.VY3.RMS[i].Value;
                row.VY3Phase = viCycleDataGroup.VY3.Phase[i].Value;
                row.VY3Peak  = viCycleDataGroup.VY3.Peak[i].Value;

                row.I1RMS   = viCycleDataGroup.I1.RMS[i].Value;
                row.I1Phase = viCycleDataGroup.I1.Phase[i].Value;
                row.I1Peak  = viCycleDataGroup.I1.Peak[i].Value;
                row.I2RMS   = viCycleDataGroup.I2.RMS[i].Value;
                row.I2Phase = viCycleDataGroup.I2.Phase[i].Value;
                row.I2Peak  = viCycleDataGroup.I2.Peak[i].Value;
                row.I3RMS   = viCycleDataGroup.I3.RMS[i].Value;
                row.I3Phase = viCycleDataGroup.I3.Phase[i].Value;
                row.I3Peak  = viCycleDataGroup.I3.Peak[i].Value;
                row.IRRMS   = viCycleDataGroup.IR.RMS[i].Value;
                row.IRPhase = viCycleDataGroup.IR.Phase[i].Value;
                row.IRPeak  = viCycleDataGroup.IR.Peak[i].Value;

                m_cycleDataList.Add(Tuple.Create(eventKey, row));
                sampleNumber += samplesPerCycle;
            }
        }
Exemplo n.º 19
0
        private Dictionary <string, FlotSeries> GetFrequencyDataLookup(VICycleDataGroup vICycleDataGroup, string type)
        {
            IEnumerable <string>            names      = vICycleDataGroup.CycleDataGroups.Where(ds => ds.RMS.SeriesInfo.Channel.MeasurementType.Name == type).Select(ds => ds.RMS.SeriesInfo.Channel.Phase.Name);
            Dictionary <string, FlotSeries> dataLookup = new Dictionary <string, FlotSeries>();

            foreach (CycleDataGroup cdg in vICycleDataGroup.CycleDataGroups.Where(ds => ds.RMS.SeriesInfo.Channel.MeasurementType.Name == type))
            {
                FlotSeries flotSeriesRMS = new FlotSeries
                {
                    ChannelID                 = cdg.RMS.SeriesInfo.Channel.ID,
                    ChannelName               = cdg.RMS.SeriesInfo.Channel.Name,
                    ChannelDescription        = cdg.RMS.SeriesInfo.Channel.Description,
                    MeasurementCharacteristic = cdg.RMS.SeriesInfo.Channel.MeasurementCharacteristic.Name,
                    MeasurementType           = cdg.RMS.SeriesInfo.Channel.MeasurementType.Name,
                    Phase      = cdg.RMS.SeriesInfo.Channel.Phase.Name,
                    SeriesType = cdg.RMS.SeriesInfo.Channel.MeasurementType.Name,
                    DataPoints = cdg.RMS.DataPoints.Select(dataPoint => new double[] { dataPoint.Time.Subtract(m_epoch).TotalMilliseconds, dataPoint.Value }).ToList(),
                    ChartLabel = GetChartLabel(cdg.RMS.SeriesInfo.Channel, "RMS")
                };
                dataLookup.Add(flotSeriesRMS.ChartLabel, flotSeriesRMS);

                FlotSeries flotSeriesWaveAmp = new FlotSeries
                {
                    ChannelID                 = cdg.Peak.SeriesInfo.Channel.ID,
                    ChannelName               = cdg.Peak.SeriesInfo.Channel.Name,
                    ChannelDescription        = cdg.Peak.SeriesInfo.Channel.Description,
                    MeasurementCharacteristic = cdg.Peak.SeriesInfo.Channel.MeasurementCharacteristic.Name,
                    MeasurementType           = cdg.Peak.SeriesInfo.Channel.MeasurementType.Name,
                    Phase      = cdg.Peak.SeriesInfo.Channel.Phase.Name,
                    SeriesType = cdg.Peak.SeriesInfo.Channel.MeasurementType.Name,
                    DataPoints = cdg.Peak.DataPoints.Select(dataPoint => new double[] { dataPoint.Time.Subtract(m_epoch).TotalMilliseconds, dataPoint.Value }).ToList(),
                    ChartLabel = GetChartLabel(cdg.Peak.SeriesInfo.Channel, "Amplitude")
                };
                dataLookup.Add(flotSeriesWaveAmp.ChartLabel, flotSeriesWaveAmp);

                FlotSeries flotSeriesPolarAngle = new FlotSeries
                {
                    ChannelID                 = cdg.Phase.SeriesInfo.Channel.ID,
                    ChannelName               = cdg.Phase.SeriesInfo.Channel.Name,
                    ChannelDescription        = cdg.Phase.SeriesInfo.Channel.Description,
                    MeasurementCharacteristic = cdg.Phase.SeriesInfo.Channel.MeasurementCharacteristic.Name,
                    MeasurementType           = cdg.Phase.SeriesInfo.Channel.MeasurementType.Name,
                    Phase      = cdg.Phase.SeriesInfo.Channel.Phase.Name,
                    SeriesType = cdg.Phase.SeriesInfo.Channel.MeasurementType.Name,
                    DataPoints = cdg.Phase.DataPoints.Select(dataPoint => new double[] { dataPoint.Time.Subtract(m_epoch).TotalMilliseconds, dataPoint.Value }).ToList(),
                    ChartLabel = GetChartLabel(cdg.Phase.SeriesInfo.Channel, "Phase")
                };
                dataLookup.Add(flotSeriesPolarAngle.ChartLabel, flotSeriesPolarAngle);
            }

            return(dataLookup);
        }
Exemplo n.º 20
0
        private double?CalcFinalLLMW(VICycleDataGroup viCycleDataGroup)
        {
            if (viCycleDataGroup.VCA == null || viCycleDataGroup.VBC == null)
            {
                return(null);
            }

            Complex vca = Complex.FromPolarCoordinates(viCycleDataGroup.VCA.RMS.DataPoints.Last().Value, viCycleDataGroup.VCA.Phase.DataPoints.Last().Value);
            Complex ia  = Complex.Conjugate(Complex.FromPolarCoordinates(viCycleDataGroup.IA.RMS.DataPoints.Last().Value, viCycleDataGroup.IA.Phase.DataPoints.Last().Value));
            Complex vbc = Complex.FromPolarCoordinates(viCycleDataGroup.VBC.RMS.DataPoints.Last().Value, viCycleDataGroup.VBC.Phase.DataPoints.Last().Value);
            Complex ib  = Complex.Conjugate(Complex.FromPolarCoordinates(viCycleDataGroup.IB.RMS.DataPoints.Last().Value, viCycleDataGroup.IB.Phase.DataPoints.Last().Value));

            return((-1 * vca * ia + vbc * ib).Real / 1E6);
        }
Exemplo n.º 21
0
        private int GetCalculationCycle(Fault fault, VICycleDataGroup viCycleDataGroup, int samplesPerCycle)
        {
            double ia;
            double ib;
            double ic;
            double sum;

            double max;
            int    maxIndex;

            int startSample;
            int endSample;

            if (!fault.Curves.Any())
            {
                return(-1);
            }

            startSample = fault.StartSample + samplesPerCycle;
            endSample   = fault.StartSample + fault.Curves.Min(curve => curve.Series.DataPoints.Count) - 1;

            if (startSample > endSample)
            {
                startSample = fault.StartSample;
            }

            if (startSample > endSample)
            {
                return(-1);
            }

            max      = double.MinValue;
            maxIndex = -1;

            for (int i = startSample; i <= endSample; i++)
            {
                ia  = viCycleDataGroup.IA.RMS[i].Value;
                ib  = viCycleDataGroup.IB.RMS[i].Value;
                ic  = viCycleDataGroup.IC.RMS[i].Value;
                sum = ia + ib + ic;

                if (sum > max)
                {
                    maxIndex = i;
                    max      = sum;
                }
            }

            return(maxIndex);
        }
        public ActionResult Get(int eventID, string type, int pixels)
        {
            using (AdoDataConnection connection = new AdoDataConnection(m_configuration["OpenXDA:ConnectionString"], m_configuration["OpenXDA:DataProviderString"]))
            {
                DateTime epoch = new DateTime(1970, 1, 1);

                Event evt = new TableOperations <Event>(connection).QueryRecordWhere("ID = {0}", eventID);
                if (evt == null)
                {
                    return(BadRequest("Must provide a valid EventID"));
                }
                Meter meter = new TableOperations <Meter>(connection).QueryRecordWhere("ID = {0}", evt.MeterID);
                meter.ConnectionFactory = () => new AdoDataConnection(m_configuration["OpenXDA:ConnectionString"], m_configuration["OpenXDA:DataProviderString"]);

                Dictionary <string, IEnumerable <double[]> > returnData = new Dictionary <string, IEnumerable <double[]> >();
                DataGroupHelper dataGroupHelper = new DataGroupHelper(m_configuration, m_memoryCache);
                DataGroup       dataGroup       = dataGroupHelper.QueryDataGroup(eventID, meter);;

                foreach (var series in dataGroup.DataSeries)
                {
                    List <double[]> data = series.DataPoints.Select(dp => new double[2] {
                        (dp.Time - epoch).TotalMilliseconds, dp.Value
                    }).ToList();
                    if (series.SeriesInfo.Channel.MeasurementType.Name == type && series.SeriesInfo.Channel.MeasurementCharacteristic.Name == "Instantaneous")
                    {
                        returnData.Add((type == "Voltage" ? "V" : "I") + series.SeriesInfo.Channel.Phase.Name, data);
                    }
                }

                VICycleDataGroup viCycleDataGroup = dataGroupHelper.QueryVICycleDataGroup(eventID, meter);;

                foreach (CycleDataGroup cdg in viCycleDataGroup.CycleDataGroups.Where(ds => ds.RMS.SeriesInfo.Channel.MeasurementType.Name == type))
                {
                    List <double[]> rmsPoints = cdg.RMS.DataPoints.Select(dp => new double[2] {
                        (dp.Time - epoch).TotalMilliseconds, dp.Value
                    }).ToList();
                    returnData.Add((type == "Voltage" ? "V" : "I") + cdg.RMS.SeriesInfo.Channel.Phase.Name + " RMS", rmsPoints);
                    List <double[]> ampPoints = cdg.Peak.DataPoints.Select(dp => new double[2] {
                        (dp.Time - epoch).TotalMilliseconds, dp.Value
                    }).ToList();
                    returnData.Add((type == "Voltage" ? "V" : "I") + cdg.Peak.SeriesInfo.Channel.Phase.Name + " Amplitude", ampPoints);
                    List <double[]> phPoints = cdg.Phase.DataPoints.Select(dp => new double[2] {
                        (dp.Time - epoch).TotalMilliseconds, dp.Value * 180 / Math.PI
                    }).ToList();
                    returnData.Add((type == "Voltage" ? "V" : "I") + cdg.Phase.SeriesInfo.Channel.Phase.Name + " Phase", phPoints);
                }

                return(Ok(returnData));
            }
        }
Exemplo n.º 23
0
        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);
        }
Exemplo n.º 24
0
        private double?CalcFinalLGMW(VICycleDataGroup viCycleDataGroup)
        {
            if (viCycleDataGroup.VA == null || viCycleDataGroup.VB == null || viCycleDataGroup.VC == null)
            {
                return(null);
            }

            Complex va = Complex.FromPolarCoordinates(viCycleDataGroup.VA.RMS.DataPoints.Last().Value, viCycleDataGroup.VA.Phase.DataPoints.Last().Value);
            Complex ia = Complex.Conjugate(Complex.FromPolarCoordinates(viCycleDataGroup.IA.RMS.DataPoints.Last().Value, viCycleDataGroup.IA.Phase.DataPoints.Last().Value));
            Complex vb = Complex.FromPolarCoordinates(viCycleDataGroup.VB.RMS.DataPoints.Last().Value, viCycleDataGroup.VB.Phase.DataPoints.Last().Value);
            Complex ib = Complex.Conjugate(Complex.FromPolarCoordinates(viCycleDataGroup.IB.RMS.DataPoints.Last().Value, viCycleDataGroup.IB.Phase.DataPoints.Last().Value));
            Complex vc = Complex.FromPolarCoordinates(viCycleDataGroup.VC.RMS.DataPoints.Last().Value, viCycleDataGroup.VC.Phase.DataPoints.Last().Value);
            Complex ic = Complex.Conjugate(Complex.FromPolarCoordinates(viCycleDataGroup.IC.RMS.DataPoints.Last().Value, viCycleDataGroup.IC.Phase.DataPoints.Last().Value));

            return((va * ia + vb * ib + vc * ic).Real / 1E6);
        }
        public VICycleDataGroup QueryVICycleDataGroup(int eventID, Meter meter)
        {
            string target = $"VICycleDataGroup-{eventID}";

            VICycleDataGroup viCycleDataGroup = m_memoryCache.GetOrCreate(target, task =>
            {
                task.SlidingExpiration = TimeSpan.FromMinutes(10.0D);
                using (AdoDataConnection connection = new AdoDataConnection(m_configuration["OpenXDA:ConnectionString"], m_configuration["OpenXDA:DataProviderString"]))
                {
                    DataGroup dataGroup = QueryDataGroup(eventID, meter);
                    double freq         = connection.ExecuteScalar <double?>("SELECT Value FROM Setting WHERE Name = 'SystemFrequency'") ?? 60.0D;
                    return(Transform.ToVICycleDataGroup(new VIDataGroup(dataGroup), freq));
                }
            });

            return(viCycleDataGroup);
        }
Exemplo n.º 26
0
        private Dictionary <string, FlotSeries> QueryFrequencyData(int eventID, Meter meter, string type)
        {
            string target = "VICycleDataGroup" + eventID.ToString() + type;

            VICycleDataGroup vICycleDataGroup = (VICycleDataGroup)s_memoryCache.Get(target);

            if (vICycleDataGroup == null)
            {
                byte[]    frequencyDomainData = m_dataContext.Connection.ExecuteScalar <byte[]>("SELECT TimeDomainData FROM EventData WHERE ID = (SELECT EventDataID FROM Event WHERE ID = {0})", eventID);
                DataGroup dataGroup           = ToDataGroup(meter, frequencyDomainData);
                double    freq = m_dataContext.Connection.ExecuteScalar <double?>("SELECT Value FROM Setting WHERE Name = 'SystemFrequency'") ?? 60.0D;
                vICycleDataGroup = Transform.ToVICycleDataGroup(new VIDataGroup(dataGroup), 60);
                s_memoryCache.Add(target, vICycleDataGroup, new CacheItemPolicy {
                    SlidingExpiration = TimeSpan.FromMinutes(10.0D)
                });
            }
            return(GetFrequencyDataLookup(vICycleDataGroup, type));
        }
            private VICycleDataGroup Rotate(VICycleDataGroup viCycleDataGroup)
            {
                DataSeries referenceSeries = viCycleDataGroup.VA.Phase;

                DataGroup shiftedDataGroup = new DataGroup(new List <DataSeries>()
                {
                    viCycleDataGroup.VA.RMS,
                    Rotate(viCycleDataGroup.VA.Phase, referenceSeries),
                    viCycleDataGroup.VA.Peak,
                    viCycleDataGroup.VA.Error,

                    viCycleDataGroup.VB.RMS,
                    Rotate(viCycleDataGroup.VB.Phase, referenceSeries),
                    viCycleDataGroup.VB.Peak,
                    viCycleDataGroup.VB.Error,

                    viCycleDataGroup.VC.RMS,
                    Rotate(viCycleDataGroup.VC.Phase, referenceSeries),
                    viCycleDataGroup.VC.Peak,
                    viCycleDataGroup.VC.Error,

                    viCycleDataGroup.IA.RMS,
                    Rotate(viCycleDataGroup.IA.Phase, referenceSeries),
                    viCycleDataGroup.IA.Peak,
                    viCycleDataGroup.IA.Error,

                    viCycleDataGroup.IB.RMS,
                    Rotate(viCycleDataGroup.IB.Phase, referenceSeries),
                    viCycleDataGroup.IB.Peak,
                    viCycleDataGroup.IB.Error,

                    viCycleDataGroup.IC.RMS,
                    Rotate(viCycleDataGroup.IC.Phase, referenceSeries),
                    viCycleDataGroup.IC.Peak,
                    viCycleDataGroup.IC.Error,

                    viCycleDataGroup.IR.RMS,
                    Rotate(viCycleDataGroup.IR.Phase, referenceSeries),
                    viCycleDataGroup.IR.Peak,
                    viCycleDataGroup.IR.Error
                });

                return(new VICycleDataGroup(shiftedDataGroup));
            }
            public void Initialize(DbAdapterContainer dbAdapterContainer, VICycleDataGroup viCycleDataGroup, double systemFrequency)
            {
                int samplesPerCycle = Transform.CalculateSamplesPerCycle(viCycleDataGroup.VA.RMS, systemFrequency);

                FaultSegment faultSegment = dbAdapterContainer.GetAdapter <FaultLocationInfoDataContext>().FaultSegments
                                            .Where(segment => segment.EventID == Fault.EventID)
                                            .Where(segment => segment.StartTime == Fault.Inception)
                                            .FirstOrDefault(segment => segment.SegmentType.Name == "Fault");

                if ((object)faultSegment != null)
                {
                    StartSample    = faultSegment.StartSample;
                    EndSample      = faultSegment.EndSample - samplesPerCycle + 1;
                    CycleDataGroup = Rotate(viCycleDataGroup.ToSubSet(StartSample, EndSample));

                    DistanceCurve.StartIndex = StartSample;
                    AngleCurve.StartIndex    = StartSample;
                }
            }
        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());
        }
Exemplo n.º 30
0
        public override void Execute(MeterDataSet meterDataSet)
        {
            CycleDataResource cycleDataResource = meterDataSet.GetResource <CycleDataResource>();

            using (AdoDataConnection connection = meterDataSet.CreateDbConnection())
            {
                TableOperations <BreakerChannel> breakerChannelTable = new TableOperations <BreakerChannel>(connection);

                List <int> channelsIDs = cycleDataResource.DataGroups
                                         .Where(dataGroup => dataGroup.Asset.AssetTypeID == (int)AssetType.Breaker)
                                         .SelectMany(dataGroup => dataGroup.DataSeries)
                                         .Select(dataSeries => dataSeries.SeriesInfo.ChannelID)
                                         .Distinct()
                                         .ToList();

                // Look up the breaker numbers for the lines
                // that represent groupings of breaker current data
                m_breakerCurrents = new HashSet <string>();
                if (channelsIDs.Count > 0)
                {
                    m_breakerCurrents.UnionWith(breakerChannelTable
                                                .QueryRecordsWhere($"ChannelID IN ({string.Join(",", channelsIDs)})")
                                                .Select(breakerChannel => breakerChannel.BreakerNumber));
                }


                FileGroup fileGroup = meterDataSet.FileGroup;

                for (int i = 0; i < cycleDataResource.DataGroups.Count; i++)
                {
                    DataGroup        dataGroup        = cycleDataResource.DataGroups[i];
                    VIDataGroup      viDataGroup      = cycleDataResource.VIDataGroups[i];
                    VICycleDataGroup viCycleDataGroup = cycleDataResource.VICycleDataGroups[i];
                    IdentifyBreakerOperations(connection, fileGroup, dataGroup, viDataGroup, viCycleDataGroup);
                }
            }
        }