public int QueryHourOfWeekLimitCount(int channelId, string filterText) { TableOperations <HourOfWeekLimit> table = DataContext.Table <HourOfWeekLimit>(); RecordRestriction restriction = table.GetSearchRestriction(filterText); return(table.QueryRecordCount(new RecordRestriction("ChannelID = {0}", channelId) + restriction)); }
public int QueryCompanyCount(string filterText) { TableOperations <Company> tableOperations = DataContext.Table <Company>(); RecordRestriction restriction = tableOperations.GetSearchRestriction(filterText); return(tableOperations.QueryRecordCount(restriction)); }
public int QueryActiveMeasurementCount(string filterText) { TableOperations <ActiveMeasurement> tableOperations = DataContext.Table <ActiveMeasurement>(); tableOperations.RootQueryRestriction[0] = $"{GetSelectedInstanceName()}:%"; return(tableOperations.QueryRecordCount(filterText)); }
public int QueryConnectionProfileTaskCount(int parentID, string filterText) { TableOperations <ConnectionProfileTask> connectionProfileTaskTable = DataContext.Table <ConnectionProfileTask>(); connectionProfileTaskTable.RootQueryRestriction[0] = parentID; return(connectionProfileTaskTable.QueryRecordCount(filterText)); }
public int QueryChannelsWithNormalLimitsCount(int meterId, string filterText) { TableOperations <ChannelsWithNormalLimits> table = DataContext.Table <ChannelsWithNormalLimits>(); RecordRestriction restriction = table.GetSearchRestriction(filterText); return(table.QueryRecordCount(new RecordRestriction("MeterID = {0}", meterId) + restriction)); }
public int QueryMeasurementCount(string filterText) { TableOperations <Measurement> tableOperations = DataContext.Table <Measurement>(); RecordRestriction restriction = tableOperations.GetSearchRestriction(filterText); return(tableOperations.QueryRecordCount(restriction)); }
public int QueryVendorDeviceCount(string filterText) { TableOperations <VendorDevice> tableOperations = DataContext.Table <VendorDevice>(); RecordRestriction restriction = tableOperations.GetSearchRestriction(filterText); return(tableOperations.QueryRecordCount(restriction)); }
public int QueryIncidentEventCycleDataViewCount(string date, string name, string levels, string limits, string timeContext, string filterString) { TableOperations <IncidentEventCycleDataView> table = DataContext.Table <IncidentEventCycleDataView>(); RecordRestriction filterRestriction = table.GetSearchRestriction(filterString); DateTime startDate = DateTime.ParseExact(date, "yyyyMMddHH", CultureInfo.InvariantCulture); DateTime endDate = (DateTime)typeof(DateTime).GetMethod("Add" + timeContext).Invoke(startDate, new object[] { 1 }); return(table.QueryRecordCount(filterRestriction + new RecordRestriction("StartTime BETWEEN {0} AND {1}", startDate, endDate) + new RecordRestriction(levels + " = {0}", name))); }
public int QueryDeviceCount(Guid nodeID, string filterText) { TableOperations <Device> deviceTable = DataContext.Table <Device>(); RecordRestriction restriction = new RecordRestriction("NodeID = {0}", nodeID) + deviceTable.GetSearchRestriction(filterText); return(deviceTable.QueryRecordCount(restriction)); }
public int QueryPhasorCount(int deviceID, string filterText) { TableOperations <PhasorDetail> phasorDetailTable = DataContext.Table <PhasorDetail>(); RecordRestriction restriction = (deviceID > 0 ? new RecordRestriction("DeviceID = {0}", deviceID) : null) + phasorDetailTable.GetSearchRestriction(filterText); return(phasorDetailTable.QueryRecordCount(restriction)); }
public int QueryDeviceGroupCount(Guid nodeID, string filterText) { TableOperations <DeviceGroup> deviceGroupTable = DataContext.Table <DeviceGroup>(); RecordRestriction restriction = new RecordRestriction("NodeID = {0} AND ProtocolID = {1} AND AccessID = {2}", nodeID, VirtualProtocolID, DeviceGroup.DefaultAccessID) + deviceGroupTable.GetSearchRestriction(filterText); return(deviceGroupTable.QueryRecordCount(restriction)); }
public int QuerySNRMeasurmentCount(string filterText) { TableOperations <ReportMeasurements> tableOperations = m_reportOperations.Table(); if (tableOperations == null) { return(0); } return(tableOperations.QueryRecordCount(filterText)); }
public int GetDefaultIGridConnectionProfileID() { TableOperations <ConnectionProfileTaskQueue> profileTaskQueueTable = DataContext.Table <ConnectionProfileTaskQueue>(); TableOperations <ConnectionProfile> profileTable = DataContext.Table <ConnectionProfile>(); ConnectionProfile profile = profileTable.QueryRecordWhere("Name = {0}", DefaultIGridConnectionProfileName); if ((object)profile == null) { ConnectionProfileTaskQueue profileTaskQueue = profileTaskQueueTable.NewRecord(); profileTaskQueue.Name = DefaultIGridConnectionProfileTaskQueueName; profileTaskQueue.MaxThreadCount = 4; profileTaskQueue.UseBackgroundThreads = false; profileTaskQueue.Description = "Connection Profile Task for I-Grid Devices"; profileTaskQueueTable.AddNewRecord(profileTaskQueue); profileTaskQueue = profileTaskQueueTable.QueryRecordWhere("Name = {0}", DefaultIGridConnectionProfileTaskQueueName); profile = profileTable.NewRecord(); profile.Name = DefaultIGridConnectionProfileName; profile.Description = "Connection Profile for I-Grid Devices"; profile.DefaultTaskQueueID = profileTaskQueue.ID; profileTable.AddNewRecord(profile); profile.ID = GetDefaultIGridConnectionProfileID(); TableOperations <ConnectionProfileTask> profileTaskTable = DataContext.Table <ConnectionProfileTask>(); profileTaskTable.RootQueryRestriction[0] = profile.ID; int taskCount = profileTaskTable.QueryRecordCount(); if (taskCount == 0) { ConnectionProfileTask profileTask = profileTaskTable.NewRecord(); ConnectionProfileTaskSettings profileTaskSettings = profileTask.Settings; profileTask.ConnectionProfileID = profile.ID; profileTask.Name = "I-Grid Default Downloader Task"; profileTaskSettings.FileExtensions = "*.*"; profileTaskSettings.RemotePath = "/"; profileTaskSettings.LocalPath = Program.Host.Model.Global.DefaultLocalPath; profileTaskSettings.ExternalOperation = "IGridDownloader.exe <DeviceID> <TaskID>"; profileTaskSettings.DirectoryNamingExpression = @"<YYYY><MM>\<DeviceFolderName>"; profileTaskTable.AddNewRecord(profileTask); } } return(profile.ID); }
public int QueryActiveMeasurementCount(string filterText) { TableOperations <ActiveMeasurement> tableOperations = DataContext.Table <ActiveMeasurement>(); RecordRestriction restriction = tableOperations.GetSearchRestriction(filterText); if ((object)restriction == null) { restriction = new RecordRestriction("ID LIKE {0}", $"{GetSelectedInstanceName()}:%"); } else { List <object> parameters = new List <object>(restriction.Parameters); parameters.Add($"{GetSelectedInstanceName()}:%"); restriction = new RecordRestriction($"({restriction.FilterExpression}) AND ID LIKE {{{restriction.Parameters.Length}}}", parameters.ToArray()); } return(tableOperations.QueryRecordCount(restriction)); }
public void Parse(string filePath) { m_pqdifReader.Parse(filePath); using (AdoDataConnection connection = CreateDbConnection()) { Func <DateTime, IDbDataParameter> toDateTime2 = dateTime => ToDateTime2(connection, dateTime); TableOperations <Event> eventTable = new TableOperations <Event>(connection); string meterKey = GetMeterKey(filePath, m_filePattern); int meterID = connection.ExecuteScalar <int>("SELECT ID FROM Meter WHERE AssetKey = {0}", meterKey); Predicate <DataSeries> isDuplicate = dataSeries => { int samples = dataSeries.DataPoints.Count; if (samples == 0) { return(false); } DateTime startTime = dataSeries.DataPoints[0].Time; DateTime endTime = dataSeries.DataPoints[dataSeries.DataPoints.Count - 1].Time; RecordRestriction recordRestriction = new RecordRestriction("MeterID = {0}", meterID) & new RecordRestriction("StartTime = {0}", toDateTime2(startTime)) & new RecordRestriction("EndTime = {0}", toDateTime2(endTime)) & new RecordRestriction("Samples = {0}", samples); int eventCount = eventTable.QueryRecordCount(recordRestriction); return(eventCount > 0); }; MeterDataSet meterDataSet = m_pqdifReader.MeterDataSet; meterDataSet.DataSeries.RemoveAll(isDuplicate); meterDataSet.Digitals.RemoveAll(isDuplicate); } }
public int QueryActiveMeasurementCount(string filterText) { TableOperations <ActiveMeasurement> tableOperations = DataContext.Table <ActiveMeasurement>(); return(tableOperations.QueryRecordCount(filterText)); }
public int QueryConnectionProfileTaskCount(int parentID, string filterText) { TableOperations <ConnectionProfileTask> connectionProfileTaskTable = DataContext.Table <ConnectionProfileTask>(); return(connectionProfileTaskTable.QueryRecordCount(new RecordRestriction("ConnectionProfileID = {0}", parentID) + connectionProfileTaskTable.GetSearchRestriction(filterText))); }
private void IdentifyBreakerOperations(AdoDataConnection connection, FileGroup fileGroup, DataGroup dataGroup, VIDataGroup viDataGroup, VICycleDataGroup viCycleDataGroup) { TableOperations <Event> eventTable = new TableOperations <Event>(connection); TableOperations <BreakerChannel> breakerChannelTable = new TableOperations <BreakerChannel>(connection); TableOperations <BreakerOperation> breakerOperationTable = new TableOperations <BreakerOperation>(connection); List <int> channelIDs = dataGroup.DataSeries .Select(dataSeries => dataSeries.SeriesInfo.ChannelID) .Distinct() .ToList(); if (channelIDs.Count == 0) { return; } List <string> breakerNumbers = breakerChannelTable .QueryRecordsWhere($"ChannelID IN ({string.Join(",", channelIDs)})") .Select(breakerChannel => breakerChannel.BreakerNumber) .Distinct() .ToList(); // If the breaker currents are defined for breaker-and-a-half or ring bus configurations, // skip this data group so that timing is only applied to the breaker currents if (breakerNumbers.Count > 1 && breakerNumbers.Any(num => m_breakerCurrents.Contains(num))) { return; } Event evt = eventTable.GetEvent(fileGroup, dataGroup); if ((object)evt == null) { return; } foreach (string breakerNumber in breakerNumbers) { double breakerSpeed = connection.ExecuteScalar(double.NaN, "SELECT Speed FROM Breaker WHERE AssetKey = {0}", breakerNumber.TrimStart('0')); Func <DataSeries, bool> digitalFilter = dataSeries => { int channelID = dataSeries.SeriesInfo.ChannelID; RecordRestriction recordRestriction = new RecordRestriction("ChannelID = {0}", channelID) & new RecordRestriction("BreakerNumber = {0}", breakerNumber); int breakerChannelCount = breakerChannelTable.QueryRecordCount(recordRestriction); return(breakerChannelCount > 0); }; List <DataSeries> breakerDigitals = dataGroup.DataSeries .Where(dataSeries => dataSeries.SeriesInfo.Channel.MeasurementType.Name == "Digital") .Where(digitalFilter) .ToList(); List <DataSeries> tripCoilEnergizedChannels = breakerDigitals .Where(dataSeries => dataSeries.SeriesInfo.Channel.MeasurementCharacteristic.Name == "TCE") .ToList(); DataSeries breakerStatusChannel = breakerDigitals .FirstOrDefault(dataSeries => dataSeries.SeriesInfo.Channel.MeasurementCharacteristic.Name == "BreakerStatus"); List <XValue> tripCoilEnergizedTriggers = Range <XValue> .MergeAllOverlapping(tripCoilEnergizedChannels.SelectMany(FindTCERanges)) .Select(range => range.Start) .ToList(); foreach (XValue tripCoilEnergizedTrigger in tripCoilEnergizedTriggers) { BreakerTiming breakerTiming = new BreakerTiming(tripCoilEnergizedTrigger, breakerStatusChannel, m_systemFrequency, breakerSpeed, m_breakerSettings.MinWaitBeforeReclose); PhaseTiming aPhaseTiming = new PhaseTiming(viDataGroup.IA, viCycleDataGroup.IA, breakerTiming, m_breakerSettings, m_systemFrequency); PhaseTiming bPhaseTiming = new PhaseTiming(viDataGroup.IB, viCycleDataGroup.IB, breakerTiming, m_breakerSettings, m_systemFrequency); PhaseTiming cPhaseTiming = new PhaseTiming(viDataGroup.IC, viCycleDataGroup.IC, breakerTiming, m_breakerSettings, m_systemFrequency); BreakerOperation breakerOperation = GetBreakerOperation(connection, evt.ID, breakerNumber, breakerTiming, aPhaseTiming, bPhaseTiming, cPhaseTiming); breakerOperationTable.AddNewRecord(breakerOperation); } } }
public override void Execute(MeterDataSet meterDataSet) { // Get a time range for querying each system event that contains events in this meter data set SystemEventResource systemEventResource = meterDataSet.GetResource <SystemEventResource>(); List <SystemEventResource.SystemEvent> systemEvents = systemEventResource.SystemEvents; if (systemEvents.Count == 0) { return; } using (AdoDataConnection connection = meterDataSet.CreateDbConnection()) { TableOperations <openXDA.Model.Line> lineTable = new TableOperations <openXDA.Model.Line>(connection); TableOperations <AssetLocation> meterLocationLineTable = new TableOperations <AssetLocation>(connection); TableOperations <Event> eventTable = new TableOperations <Event>(connection); TableOperations <DoubleEndedFaultDistance> doubleEndedFaultDistanceTable = new TableOperations <DoubleEndedFaultDistance>(connection); TableOperations <FaultCurve> faultCurveTable = new TableOperations <FaultCurve>(connection); List <MappingNode> processedMappingNodes = new List <MappingNode>(); foreach (SystemEventResource.SystemEvent systemEvent in systemEvents) { // Get the full collection of events from the database that comprise the system event that overlaps this time range List <Event> dbSystemEvent = eventTable.GetSystemEvent(systemEvent.StartTime, systemEvent.EndTime, m_timeTolerance); foreach (IGrouping <int, Event> lineGrouping in dbSystemEvent.GroupBy(evt => evt.AssetID)) { // Make sure this line connects two known meter locations int meterLocationCount = meterLocationLineTable.QueryRecordCountWhere("AssetID = {0}", lineGrouping.Key); if (meterLocationCount != 2) { continue; } // Determine the length of the line double lineLength = lineTable .QueryRecordsWhere("ID = {0}", lineGrouping.Key) .Select(line => { line.ConnectionFactory = meterDataSet.CreateDbConnection; return(line.Path[0].Length); }) .DefaultIfEmpty(double.NaN) .First(); if (double.IsNaN(lineLength)) { continue; } // Determine the nominal impedance of the line ComplexNumber nominalImpedance = new ComplexNumber( lineTable.QueryRecordsWhere("ID = {0}", lineGrouping.Key).Select(line => { line.ConnectionFactory = meterDataSet.CreateDbConnection; return(line.Path[0].R1); }).FirstOrDefault(), lineTable.QueryRecordsWhere("ID = {0}", lineGrouping.Key).Select(line => { line.ConnectionFactory = meterDataSet.CreateDbConnection; return(line.Path[0].X1); }).FirstOrDefault()); if (!nominalImpedance.AllAssigned) { continue; } int leftEventID = 0; int rightEventID = 0; VICycleDataGroup leftCycleDataGroup = null; VICycleDataGroup rightCycleDataGroup = null; // Attempt to match faults during this system event that occurred // on one end of the line with faults that occurred during this // system even on the other end of the line List <Mapping> mappings = GetMappings(connection, lineGrouping); foreach (Mapping mapping in mappings) { if (mapping.Left.FaultType == FaultType.None || mapping.Right.FaultType == FaultType.None) { continue; } // Get the cycle data for each of the two mapped faults if (mapping.Left.Fault.EventID != leftEventID) { leftEventID = mapping.Left.Fault.EventID; leftCycleDataGroup = GetCycleData(connection, leftEventID); } if (mapping.Right.Fault.EventID != rightEventID) { rightEventID = mapping.Right.Fault.EventID; rightCycleDataGroup = GetCycleData(connection, rightEventID); } if (leftCycleDataGroup == null || rightCycleDataGroup == null) { continue; } if (leftCycleDataGroup.IA == null || leftCycleDataGroup.IB == null || leftCycleDataGroup.IC == null) { continue; } if (rightCycleDataGroup.IA == null || rightCycleDataGroup.IB == null || rightCycleDataGroup.IC == null) { continue; } // Make sure double-ended distance has not already been calculated and entered into the database RecordRestriction recordRestriction = new RecordRestriction("LocalFaultSummaryID = {0}", mapping.Left.Fault.ID) | new RecordRestriction("RemoteFaultSummaryID = {0}", mapping.Left.Fault.ID) | new RecordRestriction("LocalFaultSummaryID = {0}", mapping.Right.Fault.ID) | new RecordRestriction("RemoteFaultSummaryID = {0}", mapping.Right.Fault.ID); if (doubleEndedFaultDistanceTable.QueryRecordCount(recordRestriction) > 0) { continue; } // Initialize the mappings with additional data needed for double-ended fault location mapping.Left.Initialize(connection, leftCycleDataGroup, m_systemFrequency); mapping.Right.Initialize(connection, rightCycleDataGroup, m_systemFrequency); // Execute the double-ended fault location algorithm ExecuteFaultLocationAlgorithm(lineLength, nominalImpedance, mapping.Left, mapping.Right); ExecuteFaultLocationAlgorithm(lineLength, nominalImpedance, mapping.Right, mapping.Left); try { // Create rows in the DoubleEndedFaultDistance table DoubleEndedFaultDistance leftDistance = CreateDoubleEndedFaultDistance(lineLength, mapping.Left, mapping.Right); DoubleEndedFaultDistance rightDistance = CreateDoubleEndedFaultDistance(lineLength, mapping.Right, mapping.Left); doubleEndedFaultDistanceTable.AddNewRecord(leftDistance); doubleEndedFaultDistanceTable.AddNewRecord(rightDistance); // Add these nodes to the collection of processed mapping nodes processedMappingNodes.Add(mapping.Left); processedMappingNodes.Add(mapping.Right); } catch (Exception ex) { // Ignore errors regarding unique key constraints // which can occur as a result of a race condition bool isUniqueViolation = ExceptionHandler.IsUniqueViolation(ex); if (!isUniqueViolation) { throw; } } } } // Create a row in the FaultCurve table for every event that now has double-ended fault distance curves foreach (IGrouping <int, MappingNode> grouping in processedMappingNodes.GroupBy(node => node.Fault.EventID)) { FaultCurve faultCurve = CreateFaultCurve(connection, grouping); faultCurveTable.AddNewRecord(faultCurve); } } } }