public MappingNode(FaultSummary fault) { Fault = fault; DistanceCurve = new Fault.Curve(); AngleCurve = new Fault.Curve(); if (!Enum.TryParse(fault.FaultType, out FaultType)) { FaultType = FaultType.None; } }
public Mapping(FaultSummary left, FaultSummary right) { Left = new MappingNode(left); Right = new MappingNode(right); }
protected void Page_Load(object sender, EventArgs e) { SqlConnection conn = null; SqlDataReader rdr = null; if (!IsPostBack) { if (Request["eventId"] != null) { postedEventId = Request["eventId"]; using (AdoDataConnection connection = new AdoDataConnection("systemSettings")) { try { Event theevent = (new TableOperations <Event>(connection)).QueryRecordWhere("ID = {0}", Convert.ToInt32(postedEventId)); FaultSummary thesummary = (new TableOperations <FaultSummary>(connection)).QueryRecordWhere("EventID = {0} AND IsSelectedAlgorithm = 1", Convert.ToInt32(postedEventId)); 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(); postedMeterName = connection.ExecuteScalar <string>("SELECT Name From Meter WHERE ID = {0}", theevent.MeterID); 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(); } } } } } }
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 <FaultCurve> FaultCurves; using (AdoDataConnection connection = new AdoDataConnection("SystemSettings")) { theset.Yaxis0name = "Miles"; theset.Yaxis1name = ""; Event evt = (new TableOperations <Event>(connection)).QueryRecordWhere("ID = {0}", Convert.ToInt32(EventInstanceID)); Meter meter = (new TableOperations <Meter>(connection)).QueryRecordWhere("ID = {0}", evt.MeterID); Line line = (new TableOperations <Line>(connection)).QueryRecordWhere("ID = {0}", evt.LineID); EventData eventData = (new TableOperations <EventData>(connection)).QueryRecordWhere("ID = {0}", evt.EventDataID); FaultSummary thesummary = (new TableOperations <FaultSummary>(connection)).QueryRecordWhere("EventID = {0} AND IsSelectedAlgorithm = 1", Convert.ToInt32(EventInstanceID)); if ((object)thesummary == null) { return(theset); } FaultCurves = (new TableOperations <FaultCurve>(connection)).QueryRecordsWhere("EventID = {0]", Convert.ToInt32(EventInstanceID)).ToList(); if (!FaultCurves.Any()) { return(theset); } faultCurves = FaultCurves.Select(ToDataSeries).ToList(); foreach (DataSeries faultCurve in faultCurves) { FixFaultCurve(faultCurve, line); } 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 Dictionary <string, dynamic> GetHeaderData() { Dictionary <string, string> query = Request.QueryParameters(); int eventId = int.Parse(query["eventId"]); string breakerOperationID = (query.ContainsKey("breakeroperation") ? query["breakeroperation"] : "-1"); const string NextBackForSystem = "GetPreviousAndNextEventIdsForSystem"; const string NextBackForStation = "GetPreviousAndNextEventIdsForMeterLocation"; const string NextBackForMeter = "GetPreviousAndNextEventIdsForMeter"; const string NextBackForLine = "GetPreviousAndNextEventIdsForLine"; Dictionary <string, Tuple <EventView, EventView> > nextBackLookup = new Dictionary <string, Tuple <EventView, EventView> >() { { NextBackForSystem, Tuple.Create((EventView)null, (EventView)null) }, { NextBackForStation, Tuple.Create((EventView)null, (EventView)null) }, { NextBackForMeter, Tuple.Create((EventView)null, (EventView)null) }, { NextBackForLine, Tuple.Create((EventView)null, (EventView)null) } }; Dictionary <string, dynamic> returnDict = new Dictionary <string, dynamic>(); EventView theEvent = m_dataContext.Table <EventView>().QueryRecordWhere("ID = {0}", eventId); returnDict.Add("postedSystemFrequency", m_dataContext.Connection.ExecuteScalar <string>("SELECT Value FROM Setting WHERE Name = 'SystemFrequency'") ?? "60.0"); returnDict.Add("postedStationName", theEvent.StationName); returnDict.Add("postedMeterId", theEvent.MeterID.ToString()); returnDict.Add("postedMeterName", theEvent.MeterName); returnDict.Add("postedLineName", theEvent.LineName); returnDict.Add("postedLineLength", theEvent.Length.ToString()); returnDict.Add("postedEventName", theEvent.EventTypeName); returnDict.Add("postedEventDate", theEvent.StartTime.ToString("yyyy-MM-dd HH:mm:ss.fffffff")); returnDict.Add("postedDate", theEvent.StartTime.ToShortDateString()); returnDict.Add("postedEventMilliseconds", theEvent.StartTime.Subtract(new DateTime(1970, 1, 1)).TotalMilliseconds.ToString()); returnDict.Add("xdaInstance", m_dataContext.Connection.ExecuteScalar <string>("SELECT Value FROM DashSettings WHERE Name = 'System.XDAInstance'")); using (IDbCommand cmd = m_dataContext.Connection.Connection.CreateCommand()) { cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add(new SqlParameter("@EventID", eventId)); cmd.CommandTimeout = 300; foreach (string procedure in nextBackLookup.Keys.ToList()) { EventView back = null; EventView next = null; int backID = -1; int nextID = -1; cmd.CommandText = procedure; using (IDataReader rdr = cmd.ExecuteReader()) { rdr.Read(); if (!rdr.IsDBNull(0)) { backID = rdr.GetInt32(0); } if (!rdr.IsDBNull(1)) { nextID = rdr.GetInt32(1); } } back = m_dataContext.Table <EventView>().QueryRecordWhere("ID = {0}", backID); next = m_dataContext.Table <EventView>().QueryRecordWhere("ID = {0}", nextID); nextBackLookup[procedure] = Tuple.Create(back, next); } } returnDict.Add("nextBackLookup", nextBackLookup); if (new List <string>() { "Fault", "RecloseIntoFault" }.Contains(returnDict["postedEventName"])) { const string SagDepthQuery = "SELECT TOP 1 " + " (1 - PerUnitMagnitude) * 100 " + "FROM " + " FaultSummary JOIN " + " Disturbance ON " + " Disturbance.EventID = FaultSummary.EventID AND " + " Disturbance.StartTime <= dbo.AdjustDateTime2(FaultSummary.Inception, FaultSummary.DurationSeconds) AND " + " Disturbance.EndTime >= FaultSummary.Inception JOIN " + " EventType ON " + " Disturbance.EventTypeID = EventType.ID AND " + " EventType.Name = 'Sag' JOIN " + " Phase ON " + " Disturbance.PhaseID = Phase.ID AND " + " Phase.Name = 'Worst' " + "WHERE FaultSummary.ID = {0} " + "ORDER BY PerUnitMagnitude"; FaultSummary thesummary = m_dataContext.Table <FaultSummary>().QueryRecordsWhere("EventID = {0} AND IsSelectedAlgorithm = 1", theEvent.ID).OrderBy(row => row.IsSuppressed).ThenBy(row => row.Inception).FirstOrDefault(); double sagDepth = m_dataContext.Connection.ExecuteScalar <double>(SagDepthQuery, thesummary.ID); if ((object)thesummary != null) { returnDict.Add("postedStartTime", thesummary.Inception.TimeOfDay.ToString()); returnDict.Add("postedPhase", thesummary.FaultType); returnDict.Add("postedDurationPeriod", thesummary.DurationCycles.ToString("##.##", CultureInfo.InvariantCulture) + " cycles"); returnDict.Add("postedMagnitude", thesummary.CurrentMagnitude.ToString("####.#", CultureInfo.InvariantCulture) + " Amps (RMS)"); returnDict.Add("postedSagDepth", sagDepth.ToString("####.#", CultureInfo.InvariantCulture) + "%"); returnDict.Add("postedCalculationCycle", thesummary.CalculationCycle.ToString()); } } else if (new List <string>() { "Sag", "Swell" }.Contains(returnDict["postedEventName"])) { openXDA.Model.Disturbance disturbance = m_dataContext.Table <openXDA.Model.Disturbance>().QueryRecordsWhere("EventID = {0}", theEvent.ID).Where(row => row.EventTypeID == theEvent.EventTypeID).OrderBy(row => row.StartTime).FirstOrDefault(); if ((object)disturbance != null) { returnDict.Add("postedStartTime", disturbance.StartTime.TimeOfDay.ToString()); returnDict.Add("postedPhase", m_dataContext.Table <Phase>().QueryRecordWhere("ID = {0}", disturbance.PhaseID).Name); returnDict.Add("postedDurationPeriod", disturbance.DurationCycles.ToString("##.##", CultureInfo.InvariantCulture) + " cycles"); if (disturbance.PerUnitMagnitude != -1.0e308) { returnDict.Add("postedMagnitude", disturbance.PerUnitMagnitude.ToString("N3", CultureInfo.InvariantCulture) + " pu (RMS)"); } } } if (breakerOperationID != "") { int id; if (int.TryParse(breakerOperationID, out id)) { BreakerOperation breakerRow = m_dataContext.Table <BreakerOperation>().QueryRecordWhere("ID = {0}", id); if ((object)breakerRow != null) { returnDict.Add("postedBreakerNumber", breakerRow.BreakerNumber); returnDict.Add("postedBreakerPhase", m_dataContext.Table <Phase>().QueryRecordWhere("ID = {0}", breakerRow.PhaseID).Name); returnDict.Add("postedBreakerTiming", breakerRow.BreakerTiming.ToString()); returnDict.Add("postedBreakerSpeed", breakerRow.BreakerSpeed.ToString()); returnDict.Add("postedBreakerOperation", m_dataContext.Connection.ExecuteScalar("SELECT Name FROM BreakerOperationType WHERE ID = {0}", breakerRow.BreakerOperationTypeID).ToString()); } } } return(returnDict); }