protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { if (Request["eventId"] != null) { postedEventId = Request["eventId"]; using (MeterDataQualitySummaryTableAdapter meterdataqualityAdapter = new DbAdapterContainer(connectionstring).GetAdapter <MeterDataQualitySummaryTableAdapter>()) using (MeterInfoDataContext meterInfo = new MeterInfoDataContext(connectionstring)) { try { DataQuality.MeterDataQualitySummaryRow theevent = meterdataqualityAdapter.GetDataByID(Convert.ToInt32(postedEventId)).First(); Meter themeter = meterInfo.Meters.Single(m => m.ID == theevent.MeterID); postedDate = theevent.Date.ToShortDateString(); postedMeterId = theevent.MeterID.ToString(); postedMeterName = themeter.Name; } catch (Exception ex) { postedDate = ""; postedEventId = ""; postedMeterId = ""; postedMeterName = ""; } finally { } } } } }
private List <MeterDataSet> LoadMeterDataSets(DbAdapterContainer dbAdapterContainer, FileGroup fileGroup) { List <MeterDataSet> meterDataSets = new List <MeterDataSet>(); MeterInfoDataContext meterInfo = dbAdapterContainer.GetAdapter <MeterInfoDataContext>(); EventTableAdapter eventAdapter = dbAdapterContainer.GetAdapter <EventTableAdapter>(); EventDataTableAdapter eventDataAdapter = dbAdapterContainer.GetAdapter <EventDataTableAdapter>(); MeterData.EventDataTable eventTable = eventAdapter.GetDataByFileGroup(fileGroup.ID); MeterDataSet meterDataSet; DataGroup dataGroup; foreach (IGrouping <int, MeterData.EventRow> eventGroup in eventTable.GroupBy(evt => evt.MeterID)) { meterDataSet = new MeterDataSet(); meterDataSet.Meter = meterInfo.Meters.SingleOrDefault(meter => meter.ID == eventGroup.Key); foreach (MeterData.EventRow evt in eventGroup) { dataGroup = new DataGroup(); dataGroup.FromData(meterDataSet.Meter, eventDataAdapter.GetTimeDomainData(evt.EventDataID)); foreach (DataSeries dataSeries in dataGroup.DataSeries) { meterDataSet.DataSeries.Add(dataSeries); } } meterDataSets.Add(meterDataSet); } return(meterDataSets); }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { if (Request["eventid"] != null) { postedEventId = Request["eventid"]; using (EventTableAdapter eventAdapter = new EventTableAdapter()) using (MeterInfoDataContext meterInfo = new MeterInfoDataContext(connectionstring)) { try { eventAdapter.Connection.ConnectionString = connectionstring; MeterData.EventRow theevent = eventAdapter.GetDataByID(Convert.ToInt32(postedEventId)).First(); Meter themeter = meterInfo.Meters.Single(m => m.ID == theevent.MeterID); postedDate = theevent.StartTime.ToShortDateString() + " " + theevent.StartTime.TimeOfDay.ToString(); postedMeterId = theevent.MeterID.ToString(); postedMeterName = themeter.Name; } catch (Exception ex) { postedDate = ""; postedEventId = ""; postedMeterId = ""; postedMeterName = ""; } finally { } } } } }
public override void Initialize(MeterDataSet meterDataSet) { MeterInfoDataContext meterInfo = m_dbAdapterContainer.GetAdapter <MeterInfoDataContext>(); DataGroupsResource dataGroupsResource = meterDataSet.GetResource <DataGroupsResource>(); Stopwatch stopwatch = new Stopwatch(); m_dataGroups = dataGroupsResource.DataGroups .Where(dataGroup => dataGroup.Classification == DataClassification.Event) .Where(dataGroup => dataGroup.SamplesPerSecond / m_systemFrequency >= 3.999D) .ToList(); Log.Info(string.Format("Found data for {0} events.", m_dataGroups.Count)); m_viDataGroups = m_dataGroups .Select(dataGroup => { VIDataGroup viDataGroup = new VIDataGroup(dataGroup); dataGroup.Add(viDataGroup.CalculateMissingCurrentChannel(meterInfo)); return(viDataGroup); }) .ToList(); Log.Info(string.Format("Calculating cycle data for all {0} events.", m_dataGroups.Count)); stopwatch.Start(); m_viCycleDataGroups = m_viDataGroups .Select(viDataGroup => Transform.ToVICycleDataGroup(viDataGroup, m_systemFrequency)) .ToList(); Log.Debug(string.Format("Cycle data calculated in {0}.", stopwatch.Elapsed)); }
/// <summary> /// Given three of the four current channels, calculates the /// missing channel based on the relationship IR = IA + IB + IC. /// </summary> /// <param name="meterInfo">Data context for accessing configuration tables in the database.</param> public DataSeries CalculateMissingCurrentChannel(MeterInfoDataContext meterInfo) { Meter meter; DataSeries missingSeries; // If the data group does not have exactly 3 channels, // then there is no missing channel or there is not // enough data to calculate the missing channel if (DefinedCurrents != 3) { return(null); } // Get the meter associated with the channels in this data group meter = (IA ?? IB).SeriesInfo.Channel.Meter; if (m_iaIndex == -1) { // Calculate IA = IR - IB - IC missingSeries = IR.Add(IB.Negate()).Add(IC.Negate()); missingSeries.SeriesInfo = GetSeriesInfo(meterInfo, meter, m_dataGroup, "Current", "AN"); m_iaIndex = m_dataGroup.DataSeries.Count; m_dataGroup.Add(missingSeries); } else if (m_ibIndex == -1) { // Calculate IB = IR - IA - IC missingSeries = IR.Add(IA.Negate()).Add(IC.Negate()); missingSeries.SeriesInfo = GetSeriesInfo(meterInfo, meter, m_dataGroup, "Current", "BN"); m_ibIndex = m_dataGroup.DataSeries.Count; m_dataGroup.Add(missingSeries); } else if (m_icIndex == -1) { // Calculate IC = IR - IA - IB missingSeries = IR.Add(IA.Negate()).Add(IB.Negate()); missingSeries.SeriesInfo = GetSeriesInfo(meterInfo, meter, m_dataGroup, "Current", "CN"); m_icIndex = m_dataGroup.DataSeries.Count; m_dataGroup.Add(missingSeries); } else { // Calculate IR = IA + IB + IC missingSeries = IA.Add(IB).Add(IC); missingSeries.SeriesInfo = GetSeriesInfo(meterInfo, meter, m_dataGroup, "Current", "RES"); m_irIndex = m_dataGroup.DataSeries.Count; m_dataGroup.Add(missingSeries); } return(missingSeries); }
private VICycleDataGroup GetVICycleDataGroup() { MeterInfoDataContext meterInfo = m_dbAdapterContainer.GetAdapter <MeterInfoDataContext>(); EventTableAdapter eventAdapter = m_dbAdapterContainer.GetAdapter <EventTableAdapter>(); EventDataTableAdapter eventDataAdapter = m_dbAdapterContainer.GetAdapter <EventDataTableAdapter>(); MeterData.EventRow eventRow = eventAdapter.GetDataByID(m_eventID)[0]; MeterData.EventDataRow eventDataRow = eventDataAdapter.GetDataBy(m_eventID)[0]; Meter meter = meterInfo.Meters.Single(m => m.ID == eventRow.MeterID); DataGroup dataGroup = new DataGroup(); dataGroup.FromData(meter, eventDataRow.FrequencyDomainData); return(new VICycleDataGroup(dataGroup)); }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { if (Request["channelid"] != null) { postedchannelid = Request["channelid"]; posteddate = Request["date"]; postedmeterid = Request["meterid"]; postedmeasurementtype = Request["measurementtype"]; postedcharacteristic = Request["characteristic"]; postedphasename = Request["phasename"]; using (MeterInfoDataContext meterInfo = new MeterInfoDataContext(connectionstring)) { try { Meter themeter = meterInfo.Meters.Single(m => m.ID == Int32.Parse(postedmeterid)); postedmetername = themeter.Name; Int32 thelineid = meterInfo.Channels.First(row => row.ID == Int32.Parse(postedchannelid)).LineID; postedlinename = meterInfo.MeterLines.Where(row => row.LineID == thelineid) .Where(row => row.MeterID == Int32.Parse(postedmeterid)) .Select(row => row.LineName).First(); } catch (Exception ex) { postedmeterid = ""; postedchannelid = ""; posteddate = ""; postedmeasurementtype = ""; postedcharacteristic = ""; postedphasename = ""; postedmetername = ""; postedlinename = ""; } finally { } } } } }
public static void Write(string connectionString, int eventID, string originalFilePath, string filePath) { MeterInfoDataContext meterInfo = new MeterInfoDataContext(connectionString); FaultLocationInfoDataContext faultLocationInfo = new FaultLocationInfoDataContext(connectionString); MeterData.EventRow eventRow; Meter meter; DataGroup waveFormData; FaultLocationData.FaultCurveDataTable faultCurveTable; List <FaultSegment> segments; using (EventTableAdapter eventAdapter = new EventTableAdapter()) { eventAdapter.Connection.ConnectionString = connectionString; eventRow = eventAdapter.GetDataByID(eventID).FirstOrDefault(); } if ((object)eventRow == null) { throw new InvalidOperationException(string.Format("Event with ID {0} not found", eventID)); } meter = meterInfo.Meters.FirstOrDefault(dbMeter => dbMeter.ID == eventRow.MeterID); waveFormData = new DataGroup(); waveFormData.FromData(meter, eventRow.Data); using (FaultCurveTableAdapter faultCurveAdapter = new FaultCurveTableAdapter()) { faultCurveAdapter.Connection.ConnectionString = connectionString; faultCurveTable = faultCurveAdapter.GetDataBy(eventID); } segments = faultLocationInfo.FaultSegments .Where(segment => segment.EventID == eventID) .OrderBy(segment => segment.StartSample) .ToList(); Write(meter, waveFormData, faultCurveTable, segments, originalFilePath, filePath); }
public static List <FlotSeries> GetFlotInfo(int eventID) { using (DbAdapterContainer dbAdapterContainer = new DbAdapterContainer(ConnectionString)) using (AdoDataConnection connection = new AdoDataConnection(dbAdapterContainer.Connection, typeof(SqlDataAdapter), false)) { EventTableAdapter eventAdapter = dbAdapterContainer.GetAdapter <EventTableAdapter>(); MeterInfoDataContext meterInfo = dbAdapterContainer.GetAdapter <MeterInfoDataContext>(); FaultLocationInfoDataContext faultInfo = dbAdapterContainer.GetAdapter <FaultLocationInfoDataContext>(); MeterData.EventRow eventRow = eventAdapter.GetDataByID(eventID).FirstOrDefault(); if ((object)eventRow == null) { return(new List <FlotSeries>()); } return(GetWaveformInfo(meterInfo.Series, eventRow.MeterID, eventRow.LineID) .Select(ToFlotSeries) .Concat(CycleDataInfo) .Concat(GetFaultCurveInfo(connection, eventID).Select(ToFlotSeries)) .ToList()); } }
public static List <FlotSeries> GetFlotInfo(int eventID) { using (DbAdapterContainer dbAdapterContainer = new DbAdapterContainer(ConnectionString)) using (AdoDataConnection connection = new AdoDataConnection(dbAdapterContainer.Connection, typeof(SqlDataAdapter), false)) { EventTableAdapter eventAdapter = dbAdapterContainer.GetAdapter <EventTableAdapter>(); MeterInfoDataContext meterInfo = dbAdapterContainer.GetAdapter <MeterInfoDataContext>(); FaultLocationInfoDataContext faultInfo = dbAdapterContainer.GetAdapter <FaultLocationInfoDataContext>(); MeterData.EventRow eventRow = eventAdapter.GetDataByID(eventID).FirstOrDefault(); if ((object)eventRow == null) { return(new List <FlotSeries>()); } List <Series> waveformInfo = GetWaveformInfo(meterInfo.Series, eventRow.MeterID, eventRow.LineID); var lookup = waveformInfo .Where(info => info.Channel.MeasurementCharacteristic.Name == "Instantaneous") .Where(info => new string[] { "Instantaneous", "Values" }.Contains(info.SeriesType.Name)) .Select(info => new { MeasurementType = info.Channel.MeasurementType.Name, Phase = info.Channel.Phase.Name }) .Distinct() .ToDictionary(info => info); IEnumerable <FlotSeries> cycleDataInfo = CycleDataInfo .Where(info => lookup.ContainsKey(new { info.MeasurementType, info.Phase })) .Select(info => info.Clone()); return(GetWaveformInfo(meterInfo.Series, eventRow.MeterID, eventRow.LineID) .Select(ToFlotSeries) .Concat(cycleDataInfo) .Concat(GetFaultCurveInfo(connection, eventID).Select(ToFlotSeries)) .ToList()); } }
private Dictionary <string, Line> GetLineLookup(List <XElement> lineElements, MeterInfoDataContext meterInfo) { List <string> lineIDs = lineElements .Select(lineElement => (string)lineElement.Attribute("id")) .Where(id => (object)id != null) .Distinct() .ToList(); return(meterInfo.Lines .Where(line => lineIDs.Contains(line.AssetKey)) .ToDictionary(line => line.AssetKey, StringComparer.OrdinalIgnoreCase)); }
private Dictionary <string, SeriesType> GetSeriesTypeLookup(MeterInfoDataContext meterInfo) { return(meterInfo.SeriesTypes.ToDictionary(seriesType => seriesType.Name, StringComparer.OrdinalIgnoreCase)); }
private static void Migrate(string connectionString, string deviceDefinitionsFile) { LookupTables lookupTables; MeterLocation meterLocation; MeterLocation remoteMeterLocation; MeterLocationLine localLink; MeterLocationLine remoteLink; Meter meter; Line line; Series series; Channel channel; OutputChannel outputChannel; Dictionary <string, Tuple <Series, OutputChannel> > channelLookup; Tuple <Series, OutputChannel> tuple; string channelKey; int outputChannelIndex; LineImpedance lineImpedance; SourceImpedance localSourceImpedance; SourceImpedance remoteSourceImpedance; XDocument document = XDocument.Load(deviceDefinitionsFile); List <XElement> deviceElements = document.Elements().Elements("device").ToList(); XElement deviceAttributes; XElement impedancesElement; List <Tuple <Line, LineImpedance> > lineImpedances = new List <Tuple <Line, LineImpedance> >(); List <Tuple <MeterLocationLine, SourceImpedance> > sourceImpedances = new List <Tuple <MeterLocationLine, SourceImpedance> >(); List <Tuple <Series, OutputChannel> > outputChannels = new List <Tuple <Series, OutputChannel> >(); ProgressTracker progressTracker = new ProgressTracker(deviceElements.Count); using (MeterInfoDataContext meterInfo = new MeterInfoDataContext(connectionString)) using (FaultLocationInfoDataContext faultLocationInfo = new FaultLocationInfoDataContext(connectionString)) { // Load existing fault location configuration from the database progressTracker.StartPendingMessage("Loading existing fault location configuration from database..."); lookupTables = new LookupTables(meterInfo, faultLocationInfo); lookupTables.CreateLookups(document); progressTracker.EndPendingMessage(); // Load updates to fault location algorithms into the database progressTracker.StartPendingMessage("Loading updates to fault location algorithms into the database..."); foreach (XElement analyticsElement in document.Elements().Elements("analytics")) { LoadFaultLocationAlgorithms(analyticsElement, faultLocationInfo); } faultLocationInfo.SubmitChanges(); progressTracker.EndPendingMessage(); // Load updates to device configuration into the database progressTracker.WriteMessage(string.Format("Beginning migration of {0} device configurations...", deviceElements.Count)); foreach (XElement deviceElement in deviceElements) { lineImpedances.Clear(); sourceImpedances.Clear(); outputChannels.Clear(); // Get the element representing a device's attributes deviceAttributes = deviceElement.Element("attributes") ?? new XElement("attributes"); // Attempt to find existing configuration for this device and update the meter with any changes to the device's attributes meter = lookupTables.MeterLookup.GetOrAdd((string)deviceElement.Attribute("id"), assetKey => new Meter() { AssetKey = assetKey }); LoadMeterAttributes(meter, deviceAttributes); // Now that we know what meter we are processing, display a message to indicate that we are parsing this meter's configuration progressTracker.StartPendingMessage(string.Format("Loading configuration for meter {0} ({1})...", meter.Name, meter.AssetKey)); // Attempt to find existing configuration for the location of the meter and update with configuration changes meterLocation = lookupTables.MeterLocationLookup.GetOrAdd((string)deviceAttributes.Element("stationID"), assetKey => new MeterLocation() { AssetKey = assetKey }); LoadMeterLocationAttributes(meterLocation, deviceAttributes); // Link the meter location to the meter meter.MeterLocation = meterLocation; // Load updates to line configuration into the database foreach (XElement lineElement in deviceElement.Elements("lines").Elements("line")) { // Attempt to find existing configuration for the line and update with configuration changes line = lookupTables.LineLookup.GetOrAdd((string)lineElement.Attribute("id"), assetKey => new Line() { AssetKey = assetKey }); LoadLineAttributes(line, lineElement); // Provide a link between this line and the location housing the meter Link(meter, line, lineElement, lookupTables.MeterLineLookup); localLink = Link(meterLocation, line, lookupTables.MeterLocationLineLookup); if ((string)lineElement.Element("endStationID") != null) { // Attempt to find existing configuration for the location of the other end of the line and update with configuration changes remoteMeterLocation = lookupTables.MeterLocationLookup.GetOrAdd((string)lineElement.Element("endStationID"), assetKey => new MeterLocation() { AssetKey = assetKey }); LoadRemoteMeterLocationAttributes(remoteMeterLocation, lineElement); // Provide a link between this line and the remote location remoteLink = Link(remoteMeterLocation, line, lookupTables.MeterLocationLineLookup); } else { // Set remote meter location to null so we // know later that there isn't one defined remoteMeterLocation = null; remoteLink = null; } // Get a lookup table for the channels monitoring this line channelLookup = lookupTables.GetChannelLookup(meter, line); outputChannelIndex = 0; foreach (XElement channelElement in lineElement.Elements("channels").Elements()) { channelKey = channelElement.Name.LocalName; // Attempt to find an existing channel corresponding to this element if (channelLookup.TryGetValue(channelKey, out tuple)) { series = tuple.Item1; channel = series.Channel; outputChannel = tuple.Item2; } else { channel = new Channel(); series = new Series(); outputChannel = new OutputChannel(); channelLookup.Add(channelKey, Tuple.Create(series, outputChannel)); } // Load updates to channel configuration into the database LoadChannelAttributes(meter, line, remoteMeterLocation, channel, channelKey, lookupTables); LoadSeriesAttributes(channel, series, channelElement, lookupTables); outputChannel.ChannelKey = channelKey; outputChannel.LoadOrder = outputChannelIndex; outputChannels.Add(Tuple.Create(series, outputChannel)); outputChannelIndex++; } impedancesElement = lineElement.Element("impedances") ?? new XElement("impedances"); // Attempt to find existing impedance configuration for the line and update with configuration changes lineImpedance = lookupTables.LineImpedanceLookup.GetOrAdd(line, ln => new LineImpedance()); LoadLineImpedanceAttributes(lineImpedance, impedancesElement); lineImpedances.Add(Tuple.Create(line, lineImpedance)); // Attempt to find existing impedance configuration for the meter's location and update with configuration changes localSourceImpedance = lookupTables.SourceImpedanceLookup.GetOrAdd(localLink, location => new SourceImpedance()); LoadLocalSourceImpedanceAttributes(localSourceImpedance, impedancesElement); sourceImpedances.Add(Tuple.Create(localLink, localSourceImpedance)); if ((object)remoteLink != null) { // Attempt to find existing impedance configuration for the remote location and update with configuration changes remoteSourceImpedance = lookupTables.SourceImpedanceLookup.GetOrAdd(remoteLink, location => new SourceImpedance()); LoadRemoteSourceImpedanceAttributes(remoteSourceImpedance, impedancesElement); sourceImpedances.Add(Tuple.Create(remoteLink, remoteSourceImpedance)); } } if (meter.ID == 0) { meterInfo.Meters.InsertOnSubmit(meter); } meterInfo.SubmitChanges(); // Load updates to line impedance configuration into the database foreach (Tuple <Line, LineImpedance> mapping in lineImpedances) { line = mapping.Item1; lineImpedance = mapping.Item2; lineImpedance.LineID = line.ID; if (lineImpedance.ID == 0) { faultLocationInfo.LineImpedances.InsertOnSubmit(lineImpedance); } } // Load updates to source impedance configuration into the database foreach (Tuple <MeterLocationLine, SourceImpedance> mapping in sourceImpedances) { localLink = mapping.Item1; localSourceImpedance = mapping.Item2; localSourceImpedance.MeterLocationLineID = localLink.ID; if (localSourceImpedance.ID == 0 && (localSourceImpedance.RSrc != 0.0D || localSourceImpedance.XSrc != 0.0D)) { faultLocationInfo.SourceImpedances.InsertOnSubmit(localSourceImpedance); } } // Load updates to source impedance configuration into the database foreach (Tuple <Series, OutputChannel> mapping in outputChannels) { series = mapping.Item1; outputChannel = mapping.Item2; outputChannel.SeriesID = series.ID; if (outputChannel.ID == 0) { faultLocationInfo.OutputChannels.InsertOnSubmit(outputChannel); } } faultLocationInfo.SubmitChanges(); progressTracker.EndPendingMessage(); // Increment the progress counter progressTracker.MakeProgress(); } } }
private Dictionary <string, MeasurementCharacteristic> GetMeasurementCharacteristicLookup(MeterInfoDataContext meterInfo) { return(meterInfo.MeasurementCharacteristics.ToDictionary(measurementCharacteristic => measurementCharacteristic.Name, StringComparer.OrdinalIgnoreCase)); }
private Dictionary <string, Phase> GetPhaseLookup(MeterInfoDataContext meterInfo) { return(meterInfo.Phases.ToDictionary(phase => phase.Name, StringComparer.OrdinalIgnoreCase)); }
private Dictionary <Tuple <string, string>, MeterLocationLine> GetMeterLocationLineLookup(IEnumerable <MeterLocation> meterLocations, IEnumerable <Line> lines, MeterInfoDataContext meterInfo) { List <int> meterLocationIDs = meterLocations .Select(meterLocation => meterLocation.ID) .ToList(); List <int> lineIDs = lines .Select(line => line.ID) .ToList(); return(meterInfo.MeterLocationLines .Where(meterLocationLine => meterLocationIDs.Contains(meterLocationLine.MeterLocationID)) .Where(meterLocationLine => lineIDs.Contains(meterLocationLine.LineID)) .ToDictionary(meterLocationLine => Tuple.Create(meterLocationLine.MeterLocation.AssetKey, meterLocationLine.Line.AssetKey), TupleIgnoreCase.Default)); }
private Dictionary <string, MeasurementType> GetMeasurementTypeLookup(MeterInfoDataContext meterInfo) { return(meterInfo.MeasurementTypes.ToDictionary(measurementType => measurementType.Name, StringComparer.OrdinalIgnoreCase)); }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { if (Request["eventId"] != null) { if (Request["faultcurves"] != null) { postedShowFaultCurves = Request["faultcurves"]; } if (Request["breakerdigitals"] != null) { postedShowBreakerDigitals = Request["breakerdigitals"]; } postedURLQueryString = string.Concat(Request.QueryString.AllKeys .Where(key => !key.Equals("eventId", StringComparison.OrdinalIgnoreCase)) .Select(key => "&" + HttpUtility.UrlEncode(key) + "=" + HttpUtility.UrlEncode(Request.QueryString[key]))); postedEventId = Request["eventId"]; using (DbAdapterContainer dbAdapterContainer = new DbAdapterContainer(connectionString)) { try { EventTypeTableAdapter eventTypeAdapter = dbAdapterContainer.GetAdapter <EventTypeTableAdapter>(); EventTableAdapter eventAdapter = dbAdapterContainer.GetAdapter <EventTableAdapter>(); MeterInfoDataContext meterInfo = dbAdapterContainer.GetAdapter <MeterInfoDataContext>(); FaultSummaryTableAdapter summaryInfo = dbAdapterContainer.GetAdapter <FaultSummaryTableAdapter>(); DisturbanceTableAdapter disturbanceAdapter = dbAdapterContainer.GetAdapter <DisturbanceTableAdapter>(); MeterData.EventRow theevent = eventAdapter.GetDataByID(Convert.ToInt32(postedEventId)).First(); JavaScriptSerializer serializer = new JavaScriptSerializer(); postedSeriesList = serializer.Serialize(signalService.GetFlotInfo(theevent.ID)); postedMeterId = theevent.MeterID.ToString(); postedDate = theevent.StartTime.ToShortDateString(); postedEventId = theevent.ID.ToString(); postedEventDate = theevent.StartTime.ToString("yyyy-MM-dd HH:mm:ss.fffffff"); postedEventMilliseconds = theevent.StartTime.Subtract(new DateTime(1970, 1, 1)).TotalMilliseconds.ToString(); postedMeterName = meterInfo.Meters.Single(m => m.ID == theevent.MeterID).Name; MeterData.EventTypeDataTable eventTypes = eventTypeAdapter.GetData(); postedAdjacentEventIds = GetPreviousAndNextEventIds(theevent.ID, dbAdapterContainer.Connection); postedLineName = meterInfo.MeterLines.Where(row => row.LineID == theevent.LineID) .Where(row => row.MeterID == theevent.MeterID) .Select(row => row.LineName) .FirstOrDefault() ?? ""; postedLineLength = meterInfo.Lines .Where(row => row.ID == theevent.LineID) .Select(row => row.Length) .AsEnumerable() .Select(length => length.ToString()) .FirstOrDefault() ?? ""; postedEventName = eventTypes .Where(row => row.ID == theevent.EventTypeID) .Select(row => row.Name) .DefaultIfEmpty("") .Single(); if (postedEventName.Equals("Fault")) { FaultLocationData.FaultSummaryDataTable thesummarydatatable = summaryInfo.GetDataBy(Convert.ToInt32(postedEventId)); FaultLocationData.FaultSummaryRow thesummary = thesummarydatatable .Where(row => row.IsSelectedAlgorithm == 1) .OrderBy(row => row.IsSuppressed) .ThenBy(row => row.Inception) .FirstOrDefault(); if ((object)thesummary != null) { postedStartTime = thesummary.Inception.TimeOfDay.ToString(); postedDurationPeriod = thesummary.DurationCycles.ToString("##.##", CultureInfo.InvariantCulture) + " cycles"; postedMagnitude = thesummary.CurrentMagnitude.ToString("####.#", CultureInfo.InvariantCulture) + " Amps (RMS)"; } } else if (new[] { "Sag", "Swell" }.Contains(postedEventName)) { MeterData.DisturbanceDataTable disturbanceTable = disturbanceAdapter.GetDataBy(theevent.ID); MeterData.DisturbanceRow disturbance = disturbanceTable .Where(row => row.EventTypeID == theevent.EventTypeID) .OrderBy(row => row.StartTime) .FirstOrDefault(); if ((object)disturbance != null) { postedStartTime = disturbance.StartTime.TimeOfDay.ToString(); postedDurationPeriod = disturbance.DurationCycles.ToString("##.##", CultureInfo.InvariantCulture) + " cycles"; if (disturbance.PerUnitMagnitude != -1.0e308) { postedMagnitude = disturbance.PerUnitMagnitude.ToString("N3", CultureInfo.InvariantCulture) + " pu (RMS)"; } } } } catch (Exception ex) { postedErrorMessage = ex.Message; } } } } }
public List <FlotSeries> GetFlotData(int eventID, List <int> seriesIndexes) { List <FlotSeries> flotSeriesList = new List <FlotSeries>(); using (DbAdapterContainer dbAdapterContainer = new DbAdapterContainer(ConnectionString)) using (AdoDataConnection connection = new AdoDataConnection(dbAdapterContainer.Connection, typeof(SqlDataAdapter), false)) { EventTableAdapter eventAdapter = dbAdapterContainer.GetAdapter <EventTableAdapter>(); EventDataTableAdapter eventDataAdapter = dbAdapterContainer.GetAdapter <EventDataTableAdapter>(); FaultCurveTableAdapter faultCurveAdapter = dbAdapterContainer.GetAdapter <FaultCurveTableAdapter>(); MeterInfoDataContext meterInfo = dbAdapterContainer.GetAdapter <MeterInfoDataContext>(); FaultLocationInfoDataContext faultLocationInfo = dbAdapterContainer.GetAdapter <FaultLocationInfoDataContext>(); MeterData.EventRow eventRow = eventAdapter.GetDataByID(eventID).FirstOrDefault(); Meter meter = meterInfo.Meters.First(m => m.ID == eventRow.MeterID); List <FlotSeries> flotInfo = GetFlotInfo(eventID); DateTime epoch = new DateTime(1970, 1, 1); Lazy <Dictionary <int, DataSeries> > waveformData = new Lazy <Dictionary <int, DataSeries> >(() => { return(ToDataGroup(meter, eventDataAdapter.GetTimeDomainData(eventRow.EventDataID)).DataSeries .ToDictionary(dataSeries => dataSeries.SeriesInfo.ID)); }); Lazy <DataGroup> cycleData = new Lazy <DataGroup>(() => ToDataGroup(meter, eventDataAdapter.GetFrequencyDomainData(eventRow.EventDataID))); Lazy <Dictionary <string, DataSeries> > faultCurveData = new Lazy <Dictionary <string, DataSeries> >(() => { return(faultCurveAdapter .GetDataBy(eventRow.ID) .Select(faultCurve => new { Algorithm = faultCurve.Algorithm, DataGroup = ToDataGroup(meter, faultCurve.Data) }) .Where(obj => obj.DataGroup.DataSeries.Count > 0) .ToDictionary(obj => obj.Algorithm, obj => obj.DataGroup[0])); }); foreach (int index in seriesIndexes) { DataSeries dataSeries = null; FlotSeries flotSeries; if (index >= flotInfo.Count) { continue; } flotSeries = flotInfo[index]; if (flotSeries.FlotType == FlotSeriesType.Waveform) { if (!waveformData.Value.TryGetValue(flotSeries.SeriesID, out dataSeries)) { continue; } } else if (flotSeries.FlotType == FlotSeriesType.Cycle) { dataSeries = cycleData.Value.DataSeries .Where(series => series.SeriesInfo.Channel.MeasurementType.Name == flotSeries.MeasurementType) .Where(series => series.SeriesInfo.Channel.Phase.Name == flotSeries.Phase) .Skip(flotSeries.SeriesID) .FirstOrDefault(); if ((object)dataSeries == null) { continue; } } else if (flotSeries.FlotType == FlotSeriesType.Fault) { string algorithm = flotSeries.ChannelName; if (!faultCurveData.Value.TryGetValue(algorithm, out dataSeries)) { continue; } } else { continue; } foreach (DataPoint dataPoint in dataSeries.DataPoints) { if (!double.IsNaN(dataPoint.Value)) { flotSeries.DataPoints.Add(new double[] { dataPoint.Time.Subtract(epoch).TotalMilliseconds, dataPoint.Value }); } } flotSeriesList.Add(flotSeries); } } return(flotSeriesList); }
// Static Methods private static Series GetSeriesInfo(MeterInfoDataContext meterInfo, Meter meter, DataGroup dataGroup, string measurementTypeName, string phaseName) { int lineID; string measurementCharacteristicName; string seriesTypeName; char typeDesignation; char phaseDesignation; string channelName; DataContextLookup <ChannelKey, Channel> channelLookup; DataContextLookup <SeriesKey, Series> seriesLookup; DataContextLookup <string, MeasurementType> measurementTypeLookup; DataContextLookup <string, MeasurementCharacteristic> measurementCharacteristicLookup; DataContextLookup <string, Phase> phaseLookup; DataContextLookup <string, SeriesType> seriesTypeLookup; ChannelKey channelKey; SeriesKey seriesKey; lineID = dataGroup.Line.ID; measurementCharacteristicName = "Instantaneous"; seriesTypeName = "Values"; typeDesignation = (measurementTypeName == "Current") ? 'I' : measurementTypeName[0]; phaseDesignation = (phaseName == "RES") ? 'R' : phaseName[0]; channelName = string.Concat(typeDesignation, phaseDesignation); channelLookup = new DataContextLookup <ChannelKey, Channel>(meterInfo, channel => new ChannelKey(channel)) .WithFilterExpression(channel => channel.MeterID == meter.ID) .WithFilterExpression(channel => channel.LineID == dataGroup.Line.ID) .WithFilterExpression(channel => channel.MeasurementType.Name == measurementTypeName) .WithFilterExpression(channel => channel.MeasurementCharacteristic.Name == measurementCharacteristicName) .WithFilterExpression(channel => channel.Phase.Name == phaseName); seriesLookup = new DataContextLookup <SeriesKey, Series>(meterInfo, series => new SeriesKey(series)) .WithFilterExpression(series => series.Channel.Meter.ID == meter.ID) .WithFilterExpression(series => series.Channel.Line.ID == dataGroup.Line.ID) .WithFilterExpression(series => series.Channel.MeasurementType.Name == measurementTypeName) .WithFilterExpression(series => series.Channel.MeasurementCharacteristic.Name == measurementCharacteristicName) .WithFilterExpression(series => series.Channel.Phase.Name == phaseName) .WithFilterExpression(series => series.SeriesType.Name == seriesTypeName); measurementTypeLookup = new DataContextLookup <string, MeasurementType>(meterInfo, measurementType => measurementType.Name); measurementCharacteristicLookup = new DataContextLookup <string, MeasurementCharacteristic>(meterInfo, measurementCharacteristic => measurementCharacteristic.Name); phaseLookup = new DataContextLookup <string, Phase>(meterInfo, phase => phase.Name); seriesTypeLookup = new DataContextLookup <string, SeriesType>(meterInfo, seriesType => seriesType.Name); channelKey = new ChannelKey(lineID, 0, channelName, measurementTypeName, measurementCharacteristicName, phaseName); seriesKey = new SeriesKey(channelKey, seriesTypeName); return(seriesLookup.GetOrAdd(seriesKey, key => { SeriesType seriesType = seriesTypeLookup.GetOrAdd(key.SeriesType, name => new SeriesType() { Name = name, Description = name }); Channel channel = channelLookup.GetOrAdd(channelKey, chKey => { MeasurementType measurementType = measurementTypeLookup.GetOrAdd(chKey.MeasurementType, name => new MeasurementType() { Name = name, Description = name }); MeasurementCharacteristic measurementCharacteristic = measurementCharacteristicLookup.GetOrAdd(chKey.MeasurementCharacteristic, name => new MeasurementCharacteristic() { Name = name, Description = name }); Phase phase = phaseLookup.GetOrAdd(chKey.Phase, name => new Phase() { Name = name, Description = name }); return new Channel() { Meter = meter, Line = dataGroup.Line, MeasurementType = measurementType, MeasurementCharacteristic = measurementCharacteristic, Phase = phase, Name = chKey.Name, SamplesPerHour = dataGroup.SamplesPerHour, PerUnitValue = 0, HarmonicGroup = 0, Description = string.Concat(measurementCharacteristic.Name, " ", measurementType.Name, " ", phase.Name), Enabled = 1 }; }); return new Series() { SeriesType = seriesType, Channel = channel, SourceIndexes = string.Empty }; })); }
private bool?CheckFaultDetectionLogic(MeterDataSet meterDataSet, DataGroup dataGroup) { MeterInfoDataContext meterInfo = m_dbAdapterContainer.GetAdapter <MeterInfoDataContext>(); FaultLocationInfoDataContext faultInfo = m_dbAdapterContainer.GetAdapter <FaultLocationInfoDataContext>(); string expressionText; int meterLineID; expressionText = null; // Find MeterLine record corresponding to the meter that produced // the data and the line associated with the data group meterLineID = meterInfo.MeterLines .Where(meterLine => meterLine.MeterID == meterDataSet.Meter.ID) .Where(meterLine => meterLine.LineID == dataGroup.Line.ID) .Select(meterLine => (int?)meterLine.ID) .FirstOrDefault() ?? -1; if (meterLineID > 0) { // Find fault detection logic defined for the meter and line expressionText = faultInfo.FaultDetectionLogics .Where(logic => logic.MeterLineID == meterLineID) .Select(logic => logic.Expression) .FirstOrDefault(); } try { if ((object)expressionText == null) { throw new Exception($"Expression text is not defined for line '{dataGroup.Line.AssetKey}'."); } // Parse fault detection logic into a boolean expression BooleanExpression expression = new BooleanExpression(expressionText); // Put digital values into a lookup table Dictionary <string, bool> digitalLookup = dataGroup.DataSeries .Where(series => series.SeriesInfo.Channel.MeasurementType.Name.Equals("Digital", StringComparison.OrdinalIgnoreCase)) .GroupBy(series => series.SeriesInfo.Channel.Name) .Where(grouping => grouping.Count() == 1) .ToDictionary(grouping => grouping.Key, grouping => grouping.Single().DataPoints.Any(dataPoint => Convert.ToBoolean(dataPoint.Value)), StringComparer.OrdinalIgnoreCase); // Apply the digital values to the variables in the boolean expression foreach (BooleanExpression.Variable variable in expression.Variables) { if (!digitalLookup.TryGetValue(variable.Identifier, out variable.Value)) { throw new Exception($"Channel '{variable.Identifier}' that was required for fault detection logic was missing from the meter data set."); } } // Evaluate the boolean expression return(expression.Evaluate()); } catch (Exception ex) { // Log the exception as a warning Log.Warn(ex.Message, ex); return(null); } }
protected void Page_Load(object sender, EventArgs e) { SqlConnection conn = null; SqlDataReader rdr = null; if (!IsPostBack) { if (Request["eventId"] != null) { postedEventId = Request["eventId"]; using (EventTypeTableAdapter eventTypeAdapter = new EventTypeTableAdapter()) using (EventTableAdapter eventAdapter = new EventTableAdapter()) using (MeterInfoDataContext meterInfo = new MeterInfoDataContext(connectionstring)) using (FaultSummaryTableAdapter summaryInfo = new FaultSummaryTableAdapter()) { try { eventAdapter.Connection.ConnectionString = connectionstring; eventTypeAdapter.Connection.ConnectionString = connectionstring; summaryInfo.Connection.ConnectionString = connectionstring; MeterData.EventRow theevent = eventAdapter.GetDataByID(Convert.ToInt32(postedEventId)).First(); FaultLocationData.FaultSummaryDataTable thesummarydatatable = summaryInfo.GetDataBy(Convert.ToInt32(postedEventId)); FaultLocationData.FaultSummaryRow thesummary = thesummarydatatable .OrderBy(row => row.IsSuppressed) .ThenByDescending(row => row.IsSelectedAlgorithm) .ThenBy(row => row.Inception) .FirstOrDefault(); if ((object)thesummary == null) { postedFaultType = "Invalid"; postedInceptionTime = "Invalid"; postedDurationPeriod = "Invalid"; postedFaultCurrent = "Invalid"; postedDistanceMethod = "Invalid"; postedSingleEndedDistance = "Invalid"; postedDeltaTime = "Invalid"; postedDoubleEndedDistance = "Invalid"; postedDoubleEndedConfidence = "Invalid"; return; } postedFaultType = thesummary.FaultType; postedInceptionTime = thesummary.Inception.TimeOfDay.ToString(); postedDurationPeriod = (thesummary.DurationSeconds * 1000).ToString("##.###", CultureInfo.InvariantCulture) + "msec (" + thesummary.DurationCycles.ToString("##.##", CultureInfo.InvariantCulture) + " cycles)"; postedFaultCurrent = thesummary.CurrentMagnitude.ToString("####.#", CultureInfo.InvariantCulture) + " Amps (RMS)"; postedDistanceMethod = thesummary.Algorithm; postedSingleEndedDistance = thesummary.Distance.ToString("####.###", CultureInfo.InvariantCulture) + " miles"; double deltatime = (thesummary.Inception - theevent.StartTime).Ticks / 10000000.0; postedDeltaTime = deltatime.ToString(); postedStartTime = theevent.StartTime.TimeOfDay.ToString(); Meter themeter = meterInfo.Meters.Single(m => m.ID == theevent.MeterID); postedMeterName = themeter.Name + " - " + themeter.AssetKey; postedMeterId = theevent.MeterID.ToString(); conn = new SqlConnection(connectionstring); conn.Open(); SqlCommand cmd = new SqlCommand("dbo.selectDoubleEndedFaultDistanceForEventID", conn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add(new SqlParameter("@EventID", postedEventId)); cmd.CommandTimeout = 300; rdr = cmd.ExecuteReader(); if (rdr.HasRows) { while (rdr.Read()) { postedDoubleEndedDistance = ((double)rdr["Distance"]).ToString("####.###", CultureInfo.InvariantCulture) + " miles"; postedDoubleEndedConfidence = ((double)rdr["Angle"]).ToString("####.####", CultureInfo.InvariantCulture) + " degrees"; } } } catch (Exception ex) { postedExceptionMessage = ex.Message; } finally { if (rdr != null) { rdr.Dispose(); } if (conn != null) { conn.Dispose(); } } } } } }
public List <FlotSeries> GetFlotData(int eventID, List <int> seriesIndexes) { List <FlotSeries> flotSeriesList = new List <FlotSeries>(); using (DbAdapterContainer dbAdapterContainer = new DbAdapterContainer(ConnectionString)) using (AdoDataConnection connection = new AdoDataConnection(dbAdapterContainer.Connection, typeof(SqlDataAdapter), false)) { EventTableAdapter eventAdapter = dbAdapterContainer.GetAdapter <EventTableAdapter>(); EventDataTableAdapter eventDataAdapter = dbAdapterContainer.GetAdapter <EventDataTableAdapter>(); FaultCurveTableAdapter faultCurveAdapter = dbAdapterContainer.GetAdapter <FaultCurveTableAdapter>(); MeterInfoDataContext meterInfo = dbAdapterContainer.GetAdapter <MeterInfoDataContext>(); FaultLocationInfoDataContext faultLocationInfo = dbAdapterContainer.GetAdapter <FaultLocationInfoDataContext>(); MeterData.EventRow eventRow = eventAdapter.GetDataByID(eventID).FirstOrDefault(); Meter meter = meterInfo.Meters.First(m => m.ID == eventRow.MeterID); List <Series> waveformInfo = GetWaveformInfo(meterInfo.Series, eventRow.MeterID, eventRow.LineID); List <string> faultCurveInfo = GetFaultCurveInfo(connection, eventID); DateTime epoch = new DateTime(1970, 1, 1); Lazy <Dictionary <int, DataSeries> > waveformData = new Lazy <Dictionary <int, DataSeries> >(() => { return(ToDataGroup(meter, eventDataAdapter.GetTimeDomainData(eventRow.EventDataID)).DataSeries .ToDictionary(dataSeries => dataSeries.SeriesInfo.ID)); }); Lazy <DataGroup> cycleData = new Lazy <DataGroup>(() => ToDataGroup(meter, eventDataAdapter.GetFrequencyDomainData(eventRow.EventDataID))); Lazy <Dictionary <string, DataSeries> > faultCurveData = new Lazy <Dictionary <string, DataSeries> >(() => { return(faultCurveAdapter .GetDataBy(eventRow.ID) .Select(faultCurve => new { Algorithm = faultCurve.Algorithm, DataGroup = ToDataGroup(meter, faultCurve.Data) }) .Where(obj => obj.DataGroup.DataSeries.Count > 0) .ToDictionary(obj => obj.Algorithm, obj => obj.DataGroup[0])); }); foreach (int index in seriesIndexes) { DataSeries dataSeries = null; FlotSeries flotSeries = null; int waveformIndex = index; int cycleIndex = waveformIndex - waveformInfo.Count; int faultCurveIndex = cycleIndex - CycleDataInfo.Count; if (waveformIndex < waveformInfo.Count) { if (!waveformData.Value.TryGetValue(waveformInfo[index].ID, out dataSeries)) { continue; } flotSeries = ToFlotSeries(waveformInfo[index]); } else if (cycleIndex < CycleDataInfo.Count) { if (cycleIndex >= cycleData.Value.DataSeries.Count) { continue; } dataSeries = cycleData.Value[cycleIndex]; flotSeries = new FlotSeries() { MeasurementType = CycleDataInfo[cycleIndex].MeasurementType, MeasurementCharacteristic = CycleDataInfo[cycleIndex].MeasurementCharacteristic, Phase = CycleDataInfo[cycleIndex].Phase, SeriesType = CycleDataInfo[cycleIndex].SeriesType }; } else if (faultCurveIndex < faultCurveInfo.Count) { string algorithm = faultCurveInfo[faultCurveIndex]; if (!faultCurveData.Value.TryGetValue(algorithm, out dataSeries)) { continue; } flotSeries = ToFlotSeries(faultCurveInfo[faultCurveIndex]); } else { continue; } foreach (DataPoint dataPoint in dataSeries.DataPoints) { if (!double.IsNaN(dataPoint.Value)) { flotSeries.DataPoints.Add(new double[] { dataPoint.Time.Subtract(epoch).TotalMilliseconds, dataPoint.Value }); } } flotSeriesList.Add(flotSeries); } } return(flotSeriesList); }
/// <summary> /// FetchMeterEventCycleData /// </summary> /// <param name="EventInstanceID"></param> /// <param name="MeasurementName"></param> /// <param name="theset"></param> /// <returns></returns> private eventSet FetchMeterEventCycleData(string EventInstanceID, string MeasurementName, eventSet theset) { DataGroup eventDataGroup = new DataGroup(); List <DataGroup> cycleCurves; List <MeterData.EventDataRow> cycleDataRows; if (MeasurementName != "Voltage" && MeasurementName != "Current") { return(theset); } using (MeterInfoDataContext meterInfo = new MeterInfoDataContext(ConnectionString)) using (EventTableAdapter eventAdapter = new EventTableAdapter()) using (EventDataTableAdapter cycleDataAdapter = new EventDataTableAdapter()) { cycleDataAdapter.Connection.ConnectionString = ConnectionString; eventAdapter.Connection.ConnectionString = ConnectionString; theset.Yaxis0name = MeasurementName; theset.Yaxis1name = ""; MeterData.EventRow theevent = eventAdapter.GetDataByID(Convert.ToInt32(EventInstanceID)).First(); Meter themeter = meterInfo.Meters.Single(m => theevent.MeterID == m.ID); Line theline = meterInfo.Lines.Single(l => theevent.LineID == l.ID); cycleDataRows = cycleDataAdapter.GetDataBy(Convert.ToInt32(EventInstanceID)).ToList(); cycleCurves = cycleDataRows.Select(ToDataSeries).ToList(); //RMS, Phase angle, Peak, and Error //VAN, VBN, VCN, IAN, IBN, ICN, IR char typeChar = MeasurementName == "Voltage" ? 'V' : 'I'; // Defines the names of the series that will be added to theset in the order that they will appear string[] seriesOrder = new string[] { "RMS", "Peak", "Angle" } .SelectMany(category => new string[] { "AN", "BN", "CN" }.Select(phase => string.Format("{0} {1}{2}", category, typeChar, phase))) .ToArray(); // Defines the names of the series as they appear in cycleCurves string[] seriesNames = { "RMS VAN", "Angle VAN", "Peak VAN", "Error VAN", "RMS VBN", "Angle VBN", "Peak VBN", "Error VBN", "RMS VCN", "Angle VCN", "Peak VCN", "Error VCN", "RMS IAN", "Angle IAN", "Peak IAN", "Error IAN", "RMS IBN", "Angle IBN", "Peak IBN", "Error IBN", "RMS ICN", "Angle ICN", "Peak ICN", "Error ICN", "RMS IR", "Angle IR", "Peak IR", "Error IR" }; // Lookup table to find a DataSeries by name Dictionary <string, DataSeries> seriesNameLookup = cycleCurves[0].DataSeries .Select((series, index) => new { Name = seriesNames[index], Series = series }) .ToDictionary(obj => obj.Name, obj => obj.Series); int i = 0; if (cycleCurves.Count > 0) { foreach (string seriesName in seriesOrder) { DataSeries theseries = seriesNameLookup[seriesName]; int datacount = theseries.DataPoints.Count(); signalDetail theitem = new signalDetail(); theitem.name = seriesName; theitem.data = new double[datacount]; theitem.type = "line"; theitem.yAxis = 0; if (theitem.name.Contains("Angle")) { theitem.showInTooltip = false; theitem.visible = false; theitem.showInLegend = false; } if (theitem.name.Contains("RMS")) { theitem.showInTooltip = false; theitem.visible = false; } if (theitem.name.Contains("Peak")) { theitem.showInTooltip = false; theitem.visible = false; } int j = 0; DateTime beginticks = theseries.DataPoints[0].Time; foreach (FaultData.DataAnalysis.DataPoint thepoint in theseries.DataPoints) { double elapsed = thepoint.Time.Subtract(beginticks).TotalSeconds; //theset.xAxis[j] = elapsed.ToString(); theitem.data[j] = thepoint.Value; j++; } theset.data.Add(theitem); } } } return(theset); }
private eventSet FetchMeterEventFaultCurveByID(string EventInstanceID) { eventSet theset = new eventSet(); theset.data = new List <signalDetail>(); theset.Yaxis0name = "Miles"; theset.Yaxis1name = ""; if (EventInstanceID == "0") { return(theset); } DataGroup eventDataGroup = new DataGroup(); List <DataSeries> faultCurves; List <FaultLocationData.FaultCurveRow> FaultCurves; using (MeterInfoDataContext meterInfo = new MeterInfoDataContext(ConnectionString)) using (FaultSummaryTableAdapter summaryInfo = new FaultSummaryTableAdapter()) using (EventTableAdapter eventAdapter = new EventTableAdapter()) using (FaultCurveTableAdapter faultCurveAdapter = new FaultCurveTableAdapter()) { faultCurveAdapter.Connection.ConnectionString = ConnectionString; eventAdapter.Connection.ConnectionString = ConnectionString; summaryInfo.Connection.ConnectionString = ConnectionString; theset.Yaxis0name = "Miles"; theset.Yaxis1name = ""; MeterData.EventRow theevent = eventAdapter.GetDataByID(Convert.ToInt32(EventInstanceID)).First(); Meter themeter = meterInfo.Meters.Single(m => theevent.MeterID == m.ID); Line theline = meterInfo.Lines.Single(l => theevent.LineID == l.ID); FaultLocationData.FaultSummaryRow thesummary = (FaultLocationData.FaultSummaryRow)summaryInfo.GetDataBy(Convert.ToInt32(EventInstanceID)).Select("IsSelectedAlgorithm = 1").FirstOrDefault(); if ((object)thesummary == null) { return(theset); } FaultCurves = faultCurveAdapter.GetDataBy(Convert.ToInt32(EventInstanceID)).ToList(); if (FaultCurves.Count == 0) { return(theset); } faultCurves = FaultCurves.Select(ToDataSeries).ToList(); foreach (DataSeries faultCurve in faultCurves) { FixFaultCurve(faultCurve, theline); } double CyclesPerSecond = thesummary.DurationCycles / thesummary.DurationSeconds; List <faultSegmentDetail> thedetails = new List <faultSegmentDetail>(); theset.detail = thedetails; faultSegmentDetail thedetail = new faultSegmentDetail(); thedetail.type = "" + thesummary.Inception.TimeOfDay.ToString();//; + "-" + new TimeSpan(thesummary.Inception.TimeOfDay.Ticks + thesummary.DurationSeconds).ToString(); thedetail.StartSample = thesummary.CalculationCycle; thedetail.EndSample = thesummary.CalculationCycle + 8; thedetails.Add(thedetail); //faultSegmentDetail thedetail2 = new faultSegmentDetail(); //thedetail2.type = ""; //thedetail2.StartSample = thesummary.CalculationCycle + (int)(Math.Round((faultCurves.First().SampleRate) / CyclesPerSecond)); //thedetail2.EndSample = thedetail2.StartSample - 4; //thedetails.Add(thedetail2); int i = 0; foreach (DataSeries theseries in faultCurves) { int datacount = theseries.DataPoints.Count(); if (theset.xAxis == null) { theset.xAxis = new string[datacount]; } //theset.data[i] = new signalDetail(); signalDetail theitem = new signalDetail(); theitem.name = FaultCurves[i].Algorithm; theitem.data = new double[datacount]; theitem.type = "line"; theitem.yAxis = 0; int j = 0; DateTime beginticks = theseries.DataPoints[0].Time; foreach (DataPoint thepoint in theseries.DataPoints) { double elapsed = thepoint.Time.Subtract(beginticks).TotalSeconds; if (theset.xAxis[j] == null) { theset.xAxis[j] = elapsed.ToString(); } theitem.data[j] = thepoint.Value; j++; } i++; theset.data.Add(theitem); } } return(theset); }
public eventSet getSignalDataByIDAndType(string EventInstanceID, String DataType) { eventSet theset = new eventSet(); theset.data = new List <signalDetail>(); MeterData.EventDataTable events; DataGroup eventDataGroup = new DataGroup(); using (MeterInfoDataContext meterInfo = new MeterInfoDataContext(ConnectionString)) using (EventTableAdapter eventAdapter = new EventTableAdapter()) using (EventDataTableAdapter eventDataAdapter = new EventDataTableAdapter()) { eventAdapter.Connection.ConnectionString = ConnectionString; eventDataAdapter.Connection.ConnectionString = ConnectionString; events = eventAdapter.GetDataByID(Convert.ToInt32(EventInstanceID)); foreach (MeterData.EventRow evt in events) { Meter meter = meterInfo.Meters.Single(m => m.ID == evt.MeterID); FaultData.Database.Line line = meterInfo.Lines.Single(l => l.ID == evt.LineID); eventDataGroup.FromData(meter, eventDataAdapter.GetTimeDomainData(evt.EventDataID)); //eventDataGroup.FromData(meter, evt.Data); int i = -1; int datacount = eventDataGroup.DataSeries[0].DataPoints.Count(); theset.xAxis = new string[datacount]; foreach (DataSeries theseries in eventDataGroup.DataSeries) { i++; signalDetail theitem = new signalDetail(); string measurementType = "I"; // Assume Current, sorry this is ugly string phasename = theseries.SeriesInfo.Channel.Phase.Name; if (theseries.SeriesInfo.Channel.MeasurementType.Name.Equals("Voltage")) { measurementType = "V"; } if (theseries.SeriesInfo.Channel.MeasurementType.Name.Equals("Power")) { measurementType = "P"; } if (theseries.SeriesInfo.Channel.MeasurementType.Name.Equals("Energy")) { measurementType = "E"; } if (theseries.SeriesInfo.Channel.MeasurementType.Name.Equals("Digital")) { if (theseries.SeriesInfo.Channel.MeasurementCharacteristic.Name == "None") { continue; } measurementType = "D"; phasename = theseries.SeriesInfo.Channel.Description; } if (DataType != null) { if (measurementType != DataType) { continue; } } if (theseries.SeriesInfo.SeriesType.Name.Substring(0, 3) == "Min") { continue; } if (theseries.SeriesInfo.SeriesType.Name.Substring(0, 3) == "Max") { continue; } theset.Yaxis0name = "Current"; if (measurementType == "V") { theset.Yaxis0name = "Voltage"; } if (measurementType == "D") { theset.Yaxis0name = "Breakers"; } //theitem.name = theseries.SeriesInfo.SeriesType.Name.Substring(0, 3) + " " + measurementType + theseries.SeriesInfo.Channel.Phase.Name; theitem.name = measurementType + phasename; theitem.data = new double[datacount]; theitem.type = "line"; theitem.yAxis = 0; if (theitem.name.Contains("IRES")) { theitem.showInTooltip = false; theitem.visible = false; } int j = 0; DateTime beginticks = eventDataGroup.DataSeries[i].DataPoints[0].Time; foreach (FaultData.DataAnalysis.DataPoint thepoint in eventDataGroup.DataSeries[i].DataPoints) { double elapsed = thepoint.Time.Subtract(beginticks).TotalSeconds; theset.xAxis[j] = elapsed.ToString(); theitem.data[j] = thepoint.Value; j++; } theset.data.Add(theitem); } break; } } //theset = FetchFaultSegmentDetails(EventInstanceID, theset); eventSet thereturnset = FetchMeterEventCycleData(EventInstanceID, theset.Yaxis0name, theset); return(thereturnset); }
private Dictionary <string, Meter> GetMeterLookup(List <XElement> deviceElements, MeterInfoDataContext meterInfo) { List <string> deviceIDs = deviceElements .Select(deviceElement => (string)deviceElement.Attribute("id")) .Where(id => (object)id != null) .Distinct() .ToList(); return(meterInfo.Meters .Where(meter => deviceIDs.Contains(meter.AssetKey)) .ToDictionary(meter => meter.AssetKey, StringComparer.OrdinalIgnoreCase)); }
private Dictionary <string, MeterLocation> GetMeterLocationLookup(List <XElement> deviceElements, List <XElement> lineElements, MeterInfoDataContext meterInfo) { List <string> meterLocationIDs = deviceElements .Select(deviceElement => deviceElement.Element("attributes") ?? new XElement("attributes")) .Select(deviceAttributes => (string)deviceAttributes.Element("stationID")) .Concat(lineElements.Select(lineElement => (string)lineElement.Element("endStationID"))) .Distinct() .ToList(); return(meterInfo.MeterLocations .Where(meterLocation => meterLocationIDs.Contains(meterLocation.AssetKey)) .ToDictionary(meterLocation => meterLocation.AssetKey, StringComparer.OrdinalIgnoreCase)); }
public LookupTables(MeterInfoDataContext meterInfo, FaultLocationInfoDataContext faultLocationInfo) { m_meterInfo = meterInfo; m_faultLocationInfo = faultLocationInfo; }
public override void Prepare(DbAdapterContainer dbAdapterContainer) { m_meterInfo = dbAdapterContainer.GetAdapter <MeterInfoDataContext>(); }