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); }
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); }