public override void Execute(MeterDataSet meterDataSet) { CycleDataResource cycleDataResource = meterDataSet.GetResource <CycleDataResource>(); SagDataResource sagDataResource = meterDataSet.GetResource <SagDataResource>(); SwellDataResource swellDataResource = meterDataSet.GetResource <SwellDataResource>(); InterruptionDataResource interruptionDataResource = meterDataSet.GetResource <InterruptionDataResource>(); using (AdoDataConnection connection = meterDataSet.CreateDbConnection()) { TableOperations <Disturbance> disturbanceTable = new TableOperations <Disturbance>(connection); TableOperations <DisturbanceSeverity> disturbanceSeverityTable = new TableOperations <DisturbanceSeverity>(connection); TableOperations <VoltageEnvelope> voltageEnvelopeTable = new TableOperations <VoltageEnvelope>(connection); TableOperations <VoltageCurve> voltageCurveTable = new TableOperations <VoltageCurve>(connection); TableOperations <VoltageCurvePoint> voltageCurvePointTable = new TableOperations <VoltageCurvePoint>(connection); List <Disturbance> disturbances = disturbanceTable .QueryRecordsWhere("EventID IN (SELECT ID FROM Event WHERE FileGroupID = {0})", meterDataSet.FileGroup.ID) .ToList(); foreach (VoltageEnvelope voltageEnvelope in voltageEnvelopeTable.QueryRecords().ToList()) { List <VoltageCurve> voltageCurves = voltageCurveTable .QueryRecordsWhere("ID IN (SELECT VoltageCurveID FROM VoltageEnvelopeCurve WHERE VoltageEnvelopeID = {0})", voltageEnvelope.ID) .ToList(); foreach (VoltageCurve voltageCurve in voltageCurves) { voltageCurve.VoltageCurvePoints = voltageCurvePointTable .QueryRecordsWhere("VoltageCurveID = {0}", voltageCurve.ID) .ToList(); } foreach (Disturbance disturbance in disturbances) { int maxSeverityCode = voltageCurves .Select(voltageCurve => voltageCurve.GetMagnitude(disturbance.DurationSeconds)) .Select(curveMagnitude => (int)((1.0D - disturbance.PerUnitMagnitude) / (1.0D - curveMagnitude))) .DefaultIfEmpty(0) .Max(); if (maxSeverityCode < 0) { maxSeverityCode = 0; } else if (maxSeverityCode > 5) { maxSeverityCode = 5; } disturbanceSeverityTable.AddNewRecord(new DisturbanceSeverity() { VoltageEnvelopeID = voltageEnvelope.ID, DisturbanceID = disturbance.ID, SeverityCode = maxSeverityCode }); } } } }
private List <DbDisturbance> GetDisturbances(AdoDataConnection connection, MeterDataSet meterDataSet, DataGroup dataGroup) { SagDataResource sagDataResource = meterDataSet.GetResource <SagDataResource>(); SwellDataResource swellDataResource = meterDataSet.GetResource <SwellDataResource>(); InterruptionDataResource interruptionDataResource = meterDataSet.GetResource <InterruptionDataResource>(); TransientDataResource transientDataResource = meterDataSet.GetResource <TransientDataResource>(); List <DbDisturbance> dbDisturbances = new List <DbDisturbance>(); List <Disturbance> disturbances; TableOperations <Event> eventTable = new TableOperations <Event>(connection); if (dataGroup.Classification == DataClassification.Trend) { return(dbDisturbances); } if (dataGroup.Classification == DataClassification.Unknown) { return(dbDisturbances); } if (sagDataResource.Sags.TryGetValue(dataGroup, out disturbances)) { foreach (Disturbance sag in disturbances) { dbDisturbances.Add(GetDisturbanceRow(connection, sag)); } } if (swellDataResource.Swells.TryGetValue(dataGroup, out disturbances)) { foreach (Disturbance swell in disturbances) { dbDisturbances.Add(GetDisturbanceRow(connection, swell)); } } if (interruptionDataResource.Interruptions.TryGetValue(dataGroup, out disturbances)) { foreach (Disturbance interruption in disturbances) { dbDisturbances.Add(GetDisturbanceRow(connection, interruption)); } } if (transientDataResource.Transients.TryGetValue(dataGroup, out disturbances)) { foreach (Disturbance transient in disturbances) { dbDisturbances.Add(GetDisturbanceRow(connection, transient)); } } return(dbDisturbances); }
private void LoadDisturbances(MeterDataSet meterDataSet, List <DataGroup> dataGroups) { SagDataResource sagDataResource = SagDataResource.GetResource(meterDataSet, m_dbAdapterContainer); SwellDataResource swellDataResource = SwellDataResource.GetResource(meterDataSet, m_dbAdapterContainer); InterruptionDataResource interruptionDataResource = InterruptionDataResource.GetResource(meterDataSet, m_dbAdapterContainer); EventKey eventKey; List <Disturbance> disturbances; m_disturbanceTable = new MeterData.DisturbanceDataTable(); m_disturbanceList = new List <Tuple <EventKey, MeterData.DisturbanceRow> >(); foreach (DataGroup dataGroup in dataGroups) { if (dataGroup.Classification == DataClassification.Trend || dataGroup.Classification == DataClassification.Unknown) { continue; } eventKey = CreateEventKey(meterDataSet.FileGroup, dataGroup); if (sagDataResource.Sags.TryGetValue(dataGroup, out disturbances)) { foreach (Disturbance sag in disturbances) { AddDisturbanceRow(eventKey, dataGroup, sag); } } if (swellDataResource.Swells.TryGetValue(dataGroup, out disturbances)) { foreach (Disturbance swell in disturbances) { AddDisturbanceRow(eventKey, dataGroup, swell); } } if (interruptionDataResource.Interruptions.TryGetValue(dataGroup, out disturbances)) { foreach (Disturbance interruption in disturbances) { AddDisturbanceRow(eventKey, dataGroup, interruption); } } } }
public override void Execute(MeterDataSet meterDataSet) { CycleDataResource cycleDataResource = CycleDataResource.GetResource(meterDataSet, m_dbAdapterContainer); SagDataResource sagDataResource = SagDataResource.GetResource(meterDataSet, m_dbAdapterContainer); SwellDataResource swellDataResource = SwellDataResource.GetResource(meterDataSet, m_dbAdapterContainer); InterruptionDataResource interruptionDataResource = InterruptionDataResource.GetResource(meterDataSet, m_dbAdapterContainer); DisturbanceTableAdapter disturbanceAdapter = m_dbAdapterContainer.GetAdapter <DisturbanceTableAdapter>(); DisturbanceDataTable disturbanceTable = disturbanceAdapter.GetDataByFileGroup(meterDataSet.FileGroup.ID); SystemInfoDataContext systemInfo = m_dbAdapterContainer.GetAdapter <SystemInfoDataContext>(); m_disturbanceSeverityTable = new DisturbanceSeverityDataTable(); foreach (VoltageEnvelope envelope in systemInfo.VoltageEnvelopes) { foreach (DisturbanceRow disturbance in disturbanceTable) { IEnumerable <VoltageCurvePoint> points = envelope.VoltageCurves.Select(curve => curve.VoltageCurvePoints .Where(p => p.DurationSeconds <= disturbance.DurationSeconds) .OrderBy(p => p.LoadOrder) .LastOrDefault()); IEnumerable <int> severityCodes = points.Select(point => ((object)point != null) ? (int)((1.0D - disturbance.PerUnitMagnitude) / (1.0D - point.PerUnitMagnitude)) : 0); int maxSeverityCode = severityCodes .DefaultIfEmpty(0) .Max(); if (maxSeverityCode < 0) { maxSeverityCode = 0; } else if (maxSeverityCode > 5) { maxSeverityCode = 5; } m_disturbanceSeverityTable.AddDisturbanceSeverityRow(envelope.ID, disturbance.ID, maxSeverityCode); } } }