private Disturbance ToDisturbance(Line line, ReportedDisturbance reportedDisturbance)
        {
            double nominalValue = line.VoltageKV * 1000.0D;

            if (new[] { Phase.AN, Phase.BN, Phase.CN }.Contains(reportedDisturbance.Phase))
            {
                nominalValue /= Math.Sqrt(3.0D);
            }

            Disturbance disturbance = new Disturbance();

            double value = m_isMoreSevere(reportedDisturbance.Maximum, reportedDisturbance.Minimum)
                ? reportedDisturbance.Maximum
                : reportedDisturbance.Minimum;

            if (reportedDisturbance.Units == QuantityUnits.Percent)
            {
                value *= nominalValue / 100.0D;
            }
            else if (reportedDisturbance.Units == QuantityUnits.PerUnit)
            {
                value *= nominalValue;
            }

            disturbance.EventType        = m_eventType;
            disturbance.Phase            = reportedDisturbance.Phase;
            disturbance.StartTime        = reportedDisturbance.Time;
            disturbance.EndTime          = reportedDisturbance.Time + reportedDisturbance.Duration;
            disturbance.Magnitude        = value;
            disturbance.PerUnitMagnitude = value / nominalValue;

            return(disturbance);
        }
        private bool IsDisturbed(Disturbance disturbance)
        {
            DataPoint dataPoint = new DataPoint();

            dataPoint.Time  = disturbance.StartTime;
            dataPoint.Value = disturbance.Magnitude;
            return(m_isDisturbed(dataPoint));
        }
        private Disturbance ToDisturbance(DataSeries rms, Range <int> range, Phase phase)
        {
            Disturbance disturbance = new Disturbance();

            disturbance.EventType  = m_eventType;
            disturbance.Phase      = phase;
            disturbance.StartIndex = range.Start;
            disturbance.EndIndex   = range.End;
            disturbance.StartTime  = rms[range.Start].Time;
            disturbance.EndTime    = rms[range.End].Time;
            disturbance.Magnitude  = m_getMagnitude(rms.ToSubSeries(range.Start, range.End));

            return(disturbance);
        }
        private void DetectDisturbances(DataGroup dataGroup, VICycleDataGroup viCycleDataGroup)
        {
            List <Range <int> > aPhaseDisturbanceRanges  = DetectDisturbanceRanges(ToPerUnit(viCycleDataGroup.VA?.RMS));
            List <Range <int> > bPhaseDisturbanceRanges  = DetectDisturbanceRanges(ToPerUnit(viCycleDataGroup.VB?.RMS));
            List <Range <int> > cPhaseDisturbanceRanges  = DetectDisturbanceRanges(ToPerUnit(viCycleDataGroup.VC?.RMS));
            List <Range <int> > abPhaseDisturbanceRanges = DetectDisturbanceRanges(ToPerUnit(viCycleDataGroup.VAB?.RMS));
            List <Range <int> > bcPhaseDisturbanceRanges = DetectDisturbanceRanges(ToPerUnit(viCycleDataGroup.VBC?.RMS));
            List <Range <int> > caPhaseDisturbanceRanges = DetectDisturbanceRanges(ToPerUnit(viCycleDataGroup.VCA?.RMS));

            List <Disturbance> disturbanceList = aPhaseDisturbanceRanges.Select(range => ToDisturbance(viCycleDataGroup.VA.RMS, range, Phase.AN))
                                                 .Concat(bPhaseDisturbanceRanges.Select(range => ToDisturbance(viCycleDataGroup.VB.RMS, range, Phase.BN)))
                                                 .Concat(cPhaseDisturbanceRanges.Select(range => ToDisturbance(viCycleDataGroup.VC.RMS, range, Phase.CN)))
                                                 .Concat(abPhaseDisturbanceRanges.Select(range => ToDisturbance(viCycleDataGroup.VAB.RMS, range, Phase.AB)))
                                                 .Concat(bcPhaseDisturbanceRanges.Select(range => ToDisturbance(viCycleDataGroup.VBC.RMS, range, Phase.BC)))
                                                 .Concat(caPhaseDisturbanceRanges.Select(range => ToDisturbance(viCycleDataGroup.VCA.RMS, range, Phase.CA)))
                                                 .ToList();

            IEnumerable <Range <int> > allDisturbanceRanges = aPhaseDisturbanceRanges
                                                              .Concat(bPhaseDisturbanceRanges)
                                                              .Concat(cPhaseDisturbanceRanges)
                                                              .Concat(abPhaseDisturbanceRanges)
                                                              .Concat(bcPhaseDisturbanceRanges)
                                                              .Concat(caPhaseDisturbanceRanges);

            IEnumerable <Disturbance> worstDisturbances = Range <int> .MergeAllOverlapping(allDisturbanceRanges)
                                                          .Select(range =>
            {
                Disturbance worst = null;

                foreach (Disturbance disturbance in disturbanceList.Where(disturbance => ToRange(disturbance).Overlaps(range)))
                {
                    if ((object)worst == null || m_isMoreSevere(disturbance.PerUnitMagnitude, worst.PerUnitMagnitude))
                    {
                        worst = disturbance;
                    }
                }

                worst       = worst.Clone();
                worst.Phase = Phase.Worst;
                return(worst);
            });

            disturbanceList.AddRange(worstDisturbances);

            if (disturbanceList.Any())
            {
                m_disturbances.Add(dataGroup, disturbanceList);
            }
        }
        private Disturbance ToDisturbance(DataSeries rms, Range <int> range, Phase phase)
        {
            Disturbance disturbance = new Disturbance();

            disturbance.EventType        = m_eventType;
            disturbance.Phase            = phase;
            disturbance.StartIndex       = range.Start;
            disturbance.EndIndex         = range.End;
            disturbance.StartTime        = rms[range.Start].Time;
            disturbance.EndTime          = rms[range.End].Time;
            disturbance.Magnitude        = GetMagnitude(rms.ToSubSeries(range.Start, range.End));
            disturbance.PerUnitMagnitude = disturbance.Magnitude / rms.SeriesInfo.Channel.PerUnitValue.GetValueOrDefault();

            return(disturbance);
        }
        private Disturbance ToDisturbance(DataSeries rms, Range <int> range, Phase phase)
        {
            double      nominalValue = rms.SeriesInfo.Channel.PerUnitValue ?? GetLineVoltage(rms);
            Disturbance disturbance  = new Disturbance();

            disturbance.EventType        = m_eventType;
            disturbance.Phase            = phase;
            disturbance.StartIndex       = range.Start;
            disturbance.EndIndex         = range.End;
            disturbance.StartTime        = rms[range.Start].Time;
            disturbance.EndTime          = rms[range.End].Time;
            disturbance.Magnitude        = GetMagnitude(rms.ToSubSeries(range.Start, range.End));
            disturbance.PerUnitMagnitude = disturbance.Magnitude / nominalValue;

            return(disturbance);
        }
        private Disturbance ToDisturbance(Asset asset, ReportedDisturbance reportedDisturbance)
        {
            double nominalValue = asset.VoltageKV * 1000.0D;

            if (asset.AssetTypeID == (int)AssetType.Transformer)
            {
                //Special Case that needs to be treated seperately No Solution Yet
                nominalValue = 0 * 1000.0D;
            }

            if (new[] { Phase.AN, Phase.BN, Phase.CN }.Contains(reportedDisturbance.Phase))
            {
                nominalValue /= Math.Sqrt(3.0D);
            }

            Disturbance disturbance = new Disturbance();

            double value = m_isMoreSevere(reportedDisturbance.Maximum, reportedDisturbance.Minimum)
                ? reportedDisturbance.Maximum
                : reportedDisturbance.Minimum;

            if (reportedDisturbance.Units == QuantityUnits.Percent)
            {
                value *= nominalValue / 100.0D;
            }
            else if (reportedDisturbance.Units == QuantityUnits.PerUnit)
            {
                value *= nominalValue;
            }

            disturbance.EventType        = m_eventType;
            disturbance.Phase            = reportedDisturbance.Phase;
            disturbance.StartTime        = reportedDisturbance.Time;
            disturbance.EndTime          = reportedDisturbance.Time + reportedDisturbance.Duration;
            disturbance.Magnitude        = value;
            disturbance.PerUnitMagnitude = value / nominalValue;

            return(disturbance);
        }
Example #8
0
        private DbDisturbance GetDisturbanceRow(AdoDataConnection connection, Disturbance disturbance)
        {
            TableOperations <EventType> eventTypeTable = new TableOperations <EventType>(connection);
            EventType eventType = eventTypeTable.GetOrAdd(disturbance.EventType.ToString());

            TableOperations <Phase> phaseTable = new TableOperations <Phase>(connection);
            Phase phase = phaseTable.GetOrAdd(disturbance.Phase.ToString());

            DbDisturbance dbDisturbance = new DbDisturbance();

            dbDisturbance.EventTypeID      = eventType.ID;
            dbDisturbance.PhaseID          = phase.ID;
            dbDisturbance.Magnitude        = disturbance.Magnitude;
            dbDisturbance.PerUnitMagnitude = ToDbFloat(disturbance.PerUnitMagnitude);
            dbDisturbance.StartTime        = disturbance.StartTime;
            dbDisturbance.EndTime          = disturbance.EndTime;
            dbDisturbance.DurationSeconds  = disturbance.DurationSeconds;
            dbDisturbance.DurationCycles   = disturbance.GetDurationCycles(m_systemFrequency);
            dbDisturbance.StartIndex       = disturbance.StartIndex;
            dbDisturbance.EndIndex         = disturbance.EndIndex;

            return(dbDisturbance);
        }
 private Range<int> ToRange(Disturbance disturbance)
 {
     return new Range<int>(disturbance.StartIndex, disturbance.EndIndex);
 }
        private Disturbance ToDisturbance(DataSeries rms, Range<int> range, Phase phase)
        {
            Disturbance disturbance = new Disturbance();

            disturbance.EventType = m_eventType;
            disturbance.Phase = phase;
            disturbance.StartIndex = range.Start;
            disturbance.EndIndex = range.End;
            disturbance.StartTime = rms[range.Start].Time;
            disturbance.EndTime = rms[range.End].Time;
            disturbance.Magnitude = GetMagnitude(rms.ToSubSeries(range.Start, range.End));
            disturbance.PerUnitMagnitude = disturbance.Magnitude / rms.SeriesInfo.Channel.PerUnitValue.GetValueOrDefault();

            return disturbance;
        }
 private Range <DateTime> ToDateRange(Disturbance disturbance)
 {
     return(new Range <DateTime>(disturbance.StartTime, disturbance.EndTime));
 }
 private Range <int> ToRange(Disturbance disturbance)
 {
     return(new Range <int>(disturbance.StartIndex, disturbance.EndIndex));
 }
        private void ProcessReportedDisturbances(Meter meter, DataGroup dataGroup)
        {
            Line line = dataGroup.Line;

            if ((object)line == null)
            {
                if (meter.MeterLocation.MeterLocationLines.Count != 1)
                {
                    return;
                }

                line = meter.MeterLocation.MeterLocationLines.Single().Line;
            }

            List <Disturbance> disturbanceList = dataGroup.Disturbances
                                                 .Select(disturbance => ToDisturbance(line, disturbance))
                                                 .Where(IsDisturbed)
                                                 .ToList();

            if (dataGroup.Samples > 0)
            {
                DateTime startTime = dataGroup.StartTime;
                DateTime endTime   = dataGroup.EndTime;
                TimeSpan duration  = (endTime - startTime);

                foreach (Disturbance disturbance in disturbanceList)
                {
                    TimeSpan startDuration = disturbance.StartTime - startTime;
                    TimeSpan endDuration   = disturbance.EndTime - startTime;
                    disturbance.StartIndex = (int)((startDuration.TotalSeconds / duration.TotalSeconds) * dataGroup.Samples);
                    disturbance.EndIndex   = (int)((endDuration.TotalSeconds / duration.TotalSeconds) * dataGroup.Samples);
                }
            }

            IEnumerable <Range <DateTime> > allDisturbanceRanges = disturbanceList
                                                                   .Select(ToDateRange);

            IEnumerable <Disturbance> worstDisturbances = Range <DateTime> .MergeAllOverlapping(allDisturbanceRanges)
                                                          .Select(range =>
            {
                Disturbance worst = null;

                foreach (Disturbance disturbance in disturbanceList.Where(disturbance => ToDateRange(disturbance).Overlaps(range)))
                {
                    if ((object)worst == null || m_isMoreSevere(disturbance.PerUnitMagnitude, worst.PerUnitMagnitude))
                    {
                        worst = disturbance;
                    }
                }

                worst       = worst.Clone();
                worst.Phase = Phase.Worst;
                return(worst);
            });

            disturbanceList.AddRange(worstDisturbances);

            if (disturbanceList.Any())
            {
                m_disturbances.Add(dataGroup, disturbanceList);
            }
        }