示例#1
0
        /// <summary>
        /// FetchFaultSegmentDetails
        /// </summary>
        /// <param name="EventInstanceID"></param>
        /// <param name="theset"></param>
        /// <returns></returns>
        private eventSet FetchFaultSegmentDetails(string EventInstanceID, eventSet theset)
        {
            List <faultSegmentDetail> thedetails = new List <faultSegmentDetail>();

            FaultLocationData.FaultSegmentDataTable segments;

            theset.detail = thedetails;

            using (FaultSegmentTableAdapter faultSegmentTableAdapter = new FaultSegmentTableAdapter())
            {
                faultSegmentTableAdapter.Connection.ConnectionString = ConnectionString;

                segments = faultSegmentTableAdapter.GetDataBy(Convert.ToInt32(EventInstanceID));

                foreach (FaultLocationData.FaultSegmentRow seg in segments)
                {
                    faultSegmentDetail thedetail = new faultSegmentDetail();

                    thedetail.type        = "Start";
                    thedetail.StartSample = seg.StartSample;
                    thedetail.EndSample   = seg.StartSample + 8;
                    thedetails.Add(thedetail);

                    faultSegmentDetail thedetail2 = new faultSegmentDetail();

                    thedetail2.type        = "End";
                    thedetail2.StartSample = seg.EndSample - 8;
                    thedetail2.EndSample   = seg.EndSample;
                    thedetails.Add(thedetail2);
                }
            }

            return(theset);
        }
    public eventSet getTrends(string siteID, string targetDate, string MeasurementType, string MeasurementCharacteristic, string Phase, string Period )
    {
        SqlConnection conn = null;
        SqlDataReader rdr = null;
        eventSet theset = new eventSet();
        String theSproc = "dbo.selectTrendingData";

        List<string> thedates = new List<string>();
        List<double> minimum = new List<double>();
        List<double> maximum = new List<double>();
        List<double> average = new List<double>();

        List<double> alarmlimithigh = new List<double>();
        List<double> alarmlimitlow = new List<double>();
        List<double> offlimithigh = new List<double>();
        List<double> offlimitlow = new List<double>();

        if (Period == "Month")
        {
            theSproc = "dbo.selectTrendingDataMonthly";
        }

        if (Period == "Week")
        {
            theSproc = "dbo.selectTrendingDataWeekly";
        }

        try
        {
            conn = new SqlConnection(connectionstring);
            conn.Open();
            SqlCommand cmd = new SqlCommand(theSproc, conn);
            cmd.CommandType = CommandType.StoredProcedure;

            cmd.Parameters.Add(new SqlParameter("@EventDate", targetDate));
            cmd.Parameters.Add(new SqlParameter("@MeterID", siteID));
            cmd.Parameters.Add(new SqlParameter("@MeasurementCharacteristicID", MeasurementCharacteristic));
            cmd.Parameters.Add(new SqlParameter("@MeasurementTypeID", MeasurementType));
            cmd.Parameters.Add(new SqlParameter("@PhaseID", Phase));
            cmd.CommandTimeout = 300;

            rdr = cmd.ExecuteReader();

            while (rdr.Read())
            {
                DateTime thetime = Round((DateTime)rdr["thedate"], new TimeSpan(0, 0, 1));
                String thetimestring = thetime.ToShortTimeString();

                if (Period == "Month")
                {
                    thetimestring = thetime.ToShortDateString();
                }

                if (Period == "Week")
                {
                    thetimestring = thetime.ToShortDateString();
                }

                thedates.Add(thetimestring);
                minimum.Add((double)rdr["theminimum"]);
                maximum.Add((double)rdr["themaximum"]);
                average.Add((double)rdr["theaverage"]);
                alarmlimithigh.Add((double)rdr["alarmlimithigh"]);

                if (rdr["alarmlimitlow"] == DBNull.Value)
                {
                    int i = 0;
                }
                else
                {
                    alarmlimitlow.Add((double)rdr["alarmlimitlow"]);
                }

                offlimithigh.Add((double)rdr["offlimithigh"]);
                offlimitlow.Add((double)rdr["offlimitlow"]);
            }

        }
        finally
        {
            if (conn != null)
            {
                conn.Close();
            }
            if (rdr != null)
            {
                rdr.Close();
            }
        }

        theset.xAxis = thedates.ToArray();

        theset.data = new eventDetail[7];

        theset.data[0] = new eventDetail();
        theset.data[0].name = "Alarm Limit High";
        theset.data[0].type = "line";
        theset.data[0].data = alarmlimithigh.ToArray();

        theset.data[1] = new eventDetail();
        theset.data[1].name = "Off Normal High";
        theset.data[1].type = "line";
        theset.data[1].data = offlimithigh.ToArray();

        theset.data[2] = new eventDetail();
        theset.data[2].name = "Max";
        theset.data[2].type = "errorbar";
        theset.data[2].data = maximum.ToArray();

        theset.data[3] = new eventDetail();
        theset.data[3].name = "Average";
        theset.data[3].type = "line";
        theset.data[3].data = average.ToArray();

        theset.data[4] = new eventDetail();
        theset.data[4].name = "Min";
        theset.data[4].type = "line";
        theset.data[4].data = minimum.ToArray();

        theset.data[5] = new eventDetail();
        theset.data[5].name = "Off Normal Low";
        theset.data[5].type = "line";
        theset.data[5].data = offlimitlow.ToArray();

        theset.data[6] = new eventDetail();
        theset.data[6].name = "Alarm Limit Low";
        theset.data[6].type = "line";
        theset.data[6].data = alarmlimitlow.ToArray();

        return (theset);
    }
    public eventSet getFaultsForPeriod(string siteID, string targetDateFrom, string targetDateTo, string userName)
    {
        SqlConnection conn = null;
        SqlDataReader rdr = null;
        eventSet theset = new eventSet();
        DateTime thedatefrom = DateTime.Parse(targetDateFrom);
        DateTime thedateto = DateTime.Parse(targetDateTo);

        int duration = thedateto.Subtract(thedatefrom).Days + 1;
        List<String> powerlineclasslist = new List<string>();

        try
        {
            conn = new SqlConnection(connectionstring);
            conn.Open();

            // Get Power Line Class Count
            SqlCommand cmd2 = new SqlCommand("dbo.selectPowerLineClasses", conn);
            cmd2.CommandType = CommandType.StoredProcedure;
            cmd2.Parameters.Add(new SqlParameter("@username", userName));
            cmd2.CommandTimeout = 300;
            rdr = cmd2.ExecuteReader();
            if (rdr.HasRows)
            {
                while (rdr.Read())
                {
                    powerlineclasslist.Add (Convert.ToString(rdr["class"]));
                }

            }

            rdr.Close();
            rdr = null;

            SqlCommand cmd = new SqlCommand("dbo.selectFaultsForMeterIDByDateRange", conn);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add(new SqlParameter("@EventDateFrom", thedatefrom));
            cmd.Parameters.Add(new SqlParameter("@EventDateTo", thedateto));
            cmd.Parameters.Add(new SqlParameter("@MeterID", siteID));
            cmd.Parameters.Add(new SqlParameter("@username", userName));
            cmd.CommandTimeout = 300;

            rdr = cmd.ExecuteReader();
            if (rdr.HasRows)
            {

                theset.data = new eventDetail[powerlineclasslist.Count];
                ////theset.xAxis = new string[duration];
                int i = 0;

                foreach (var temp in powerlineclasslist)
                {

                    theset.data[i] = new eventDetail();
                    theset.data[i].name = temp + " kV";
                    theset.data[i].data = new double[duration];
                    i++;
                }

                int j = 0;

                while (rdr.Read())
                {
                    //DateTime thedate = (DateTime)rdr["thedate"];
                    //theset.xAxis[j] = thedate.ToString("d");

                    for ( i = 0; i < powerlineclasslist.Count; i++)
                    {
                        theset.data[i].data[j] = Convert.ToDouble(rdr["thecount"]);
                        if ( i < (powerlineclasslist.Count - 1) ) rdr.Read();
                    }

                    j++;
                }
            }

        }
        finally
        {
            if (conn != null)
            {
                conn.Close();
            }
            if (rdr != null)
            {
                rdr.Close();
            }
        }

        return (theset);
    }
示例#4
0
        /// <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);
        }
示例#5
0
        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);
        }
示例#6
0
        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 eventSet FetchMeterEventDataByID(string EventInstanceID)
    {
        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));
            theset.Yaxis0name = "Voltage";
            theset.Yaxis1name = "Current";

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

                //eventDataAdapter.GetTimeDomainData(evt.EventDataID);

                eventDataGroup.FromData(meter, eventDataAdapter.GetTimeDomainData(evt.EventDataID));

                int i = 0;

                foreach (DataSeries theseries in eventDataGroup.DataSeries)
                {
                    int datacount = eventDataGroup.DataSeries[i].DataPoints.Count();
                    theset.xAxis = new string[datacount];

                    signalDetail theitem = new signalDetail();

                    string measurementType = "I"; // Assume Current, sorry this is ugly

                    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.SeriesType.Name.Substring(0, 3) == "Min") continue;
                    if (theseries.SeriesInfo.SeriesType.Name.Substring(0, 3) == "Max") continue;

                    //theitem.name = theseries.SeriesInfo.SeriesType.Name.Substring(0, 3) + " " + measurementType + theseries.SeriesInfo.Channel.Phase.Name;
                    theitem.name = measurementType + theseries.SeriesInfo.Channel.Phase.Name;
                    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("RES"))
                    {
                        theitem.showInTooltip = false;
                        theitem.visible = false;
                    }

                    if (theitem.name.Contains("Peak"))
                    {
                        theitem.showInTooltip = false;
                        theitem.visible = false;
                    }

                    if (theseries.SeriesInfo.Channel.MeasurementType.Name.Equals("Current"))
                    {
                        theitem.yAxis = 1;
                    }

                    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++;
                    }
                    i++;

                    theset.data.Add(theitem);
                }
                break;
            }
        }
        return (theset);
    }
示例#8
0
        private eventSet FetchMeterEventDataByID(string EventInstanceID)
        {
            eventSet theset = new eventSet();

            theset.data = new List <signalDetail>();
            DataGroup eventDataGroup = new DataGroup();

            using (AdoDataConnection connection = new AdoDataConnection("SystemSettings"))
            {
                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);
                theset.Yaxis0name = "Voltage";
                theset.Yaxis1name = "Current";


                //eventDataAdapter.GetTimeDomainData(evt.EventDataID);

                eventDataGroup.FromData(meter, eventData.TimeDomainData);

                int i = 0;

                foreach (DataSeries theseries in eventDataGroup.DataSeries)
                {
                    int datacount = eventDataGroup.DataSeries[i].DataPoints.Count();
                    theset.xAxis = new string[datacount];

                    signalDetail theitem = new signalDetail();

                    string measurementType = "I"; // Assume Current, sorry this is ugly

                    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.SeriesType.Name.Substring(0, 3) == "Min")
                    {
                        continue;
                    }
                    if (theseries.SeriesInfo.SeriesType.Name.Substring(0, 3) == "Max")
                    {
                        continue;
                    }

                    //theitem.name = theseries.SeriesInfo.SeriesType.Name.Substring(0, 3) + " " + measurementType + theseries.SeriesInfo.Channel.Phase.Name;
                    theitem.name  = measurementType + theseries.SeriesInfo.Channel.Phase.Name;
                    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("RES"))
                    {
                        theitem.showInTooltip = false;
                        theitem.visible       = false;
                    }

                    if (theitem.name.Contains("Peak"))
                    {
                        theitem.showInTooltip = false;
                        theitem.visible       = false;
                    }

                    if (theseries.SeriesInfo.Channel.MeasurementType.Name.Equals("Current"))
                    {
                        theitem.yAxis = 1;
                    }

                    int      j          = 0;
                    DateTime beginticks = eventDataGroup.DataSeries[i].DataPoints[0].Time;
                    foreach (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++;
                    }
                    i++;

                    theset.data.Add(theitem);
                }
            }
            return(theset);
        }
    /// <summary>
    /// FetchFaultSegmentDetails
    /// </summary>
    /// <param name="EventInstanceID"></param>
    /// <param name="theset"></param>
    /// <returns></returns>
    private eventSet FetchFaultSegmentDetails(string EventInstanceID, eventSet theset)
    {
        List<faultSegmentDetail> thedetails = new List<faultSegmentDetail>();
        FaultLocationData.FaultSegmentDataTable segments;

        theset.detail = thedetails;

        using (FaultSegmentTableAdapter faultSegmentTableAdapter = new FaultSegmentTableAdapter())
        {
            faultSegmentTableAdapter.Connection.ConnectionString = ConnectionString;

            segments = faultSegmentTableAdapter.GetDataBy(Convert.ToInt32(EventInstanceID));

            foreach (FaultLocationData.FaultSegmentRow seg in segments)
            {
            faultSegmentDetail thedetail = new faultSegmentDetail();

            thedetail.type = "Start";
            thedetail.StartSample = seg.StartSample;
            thedetail.EndSample = seg.StartSample + 8;
            thedetails.Add(thedetail);

            faultSegmentDetail thedetail2 = new faultSegmentDetail();

            thedetail2.type = "End";
            thedetail2.StartSample = seg.EndSample - 8;
            thedetail2.EndSample = seg.EndSample;
            thedetails.Add(thedetail2);
            }
        }

        return (theset);
    }
    /// <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);
    }
    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);
    }
示例#12
0
        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);
        }
示例#13
0
        public eventSet getSignalDataByIDAndType(string EventInstanceID, String DataType)
        {
            eventSet theset = new eventSet();

            theset.data = new List <signalDetail>();
            DataGroup eventDataGroup = new DataGroup();

            using (AdoDataConnection connection = new AdoDataConnection("SystemSettings"))
            {
                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);


                eventDataGroup.FromData(meter, eventData.TimeDomainData);

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

            //theset = FetchFaultSegmentDetails(EventInstanceID, theset);

            eventSet thereturnset = FetchMeterEventCycleData(EventInstanceID, theset.Yaxis0name, theset);

            return(thereturnset);
        }
    public eventSet getCorrectnessForPeriod(string siteID, string targetDateFrom, string targetDateTo, string userName)
    {
        SqlConnection conn = null;
        SqlDataReader rdr = null;
        eventSet theset = new eventSet();
        DateTime thedatefrom = DateTime.Parse(targetDateFrom);
        DateTime thedateto = DateTime.Parse(targetDateTo);
        int metercount = siteID.Split(',').Length - 1;

        int duration = thedateto.Subtract(thedatefrom).Days + 1;

        try
        {
            conn = new SqlConnection(connectionstring);
            conn.Open();
            SqlCommand cmd = new SqlCommand("dbo.selectCorrectnessForMeterIDByDateRange", conn);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add(new SqlParameter("@EventDateFrom", thedatefrom));
            cmd.Parameters.Add(new SqlParameter("@EventDateTo", thedateto));
            cmd.Parameters.Add(new SqlParameter("@MeterID", siteID));
            cmd.Parameters.Add(new SqlParameter("@username", userName));
            cmd.CommandTimeout = 300;

            rdr = cmd.ExecuteReader();
            if (rdr.HasRows)
            {

                theset.data = new eventDetail[7];

                theset.data[0] = new eventDetail();
                theset.data[0].name = "> 100%";
                theset.data[0].data = new double[duration];

                theset.data[1] = new eventDetail();
                theset.data[1].name = "98% - 100%";
                theset.data[1].data = new double[duration];

                theset.data[2] = new eventDetail();
                theset.data[2].name = "90% - 97%";
                theset.data[2].data = new double[duration];

                theset.data[3] = new eventDetail();
                theset.data[3].name = "70% - 89%";
                theset.data[3].data = new double[duration];

                theset.data[4] = new eventDetail();
                theset.data[4].name = "50% - 69%";
                theset.data[4].data = new double[duration];

                theset.data[5] = new eventDetail();
                theset.data[5].name = ">0% - 49%";
                theset.data[5].data = new double[duration];

                theset.data[6] = new eventDetail();
                theset.data[6].name = "0%";
                theset.data[6].data = new double[duration];

                int i = 0;

                while (rdr.Read())
                {
                    theset.data[0].data[i] = Convert.ToDouble(rdr["First"]);
                    theset.data[1].data[i] = Convert.ToDouble(rdr["Second"]);
                    theset.data[2].data[i] = Convert.ToDouble(rdr["Third"]);
                    theset.data[3].data[i] = Convert.ToDouble(rdr["Fourth"]);
                    theset.data[4].data[i] = Convert.ToDouble(rdr["Fifth"]);
                    theset.data[5].data[i] = Convert.ToDouble(rdr["Sixth"]);

                    Double composite = theset.data[0].data[i] + theset.data[1].data[i] + theset.data[2].data[i] + theset.data[3].data[i] + theset.data[4].data[i] + theset.data[5].data[i];

                    theset.data[6].data[i] = metercount - composite;
                    i++;
                }
            }
        }
        finally
        {
            if (conn != null)
            {
                conn.Close();
            }
            if (rdr != null)
            {
                rdr.Close();
            }
        }

        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 getCorrectnessForPeriod2(string siteID, string targetDateFrom, string targetDateTo, string userName)
    {
        SqlConnection conn = null;
        SqlDataReader rdr = null;
        eventSet theset = new eventSet();
        DateTime thedatefrom = DateTime.Parse(targetDateFrom);
        DateTime thedateto = DateTime.Parse(targetDateTo);

        int duration = thedateto.Subtract(thedatefrom).Days + 1;

        try
        {
            conn = new SqlConnection(connectionstring);
            conn.Open();
            SqlCommand cmd = new SqlCommand("dbo.selectCorrectnessForMeterIDByDateRange", conn);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add(new SqlParameter("@EventDateFrom", thedatefrom));
            cmd.Parameters.Add(new SqlParameter("@EventDateTo", thedateto));
            cmd.Parameters.Add(new SqlParameter("@MeterID", siteID));
            cmd.Parameters.Add(new SqlParameter("@username", userName));
            cmd.CommandTimeout = 300;

            rdr = cmd.ExecuteReader();
            if (rdr.HasRows)
            {

                theset.data = new eventDetail[3];
                //theset.xAxis = new string[duration];

                theset.data[0] = new eventDetail();
                theset.data[0].name = "Latched";
                theset.data[0].data = new double[duration];

                theset.data[1] = new eventDetail();
                theset.data[1].name = "Unreasonable";
                theset.data[1].data = new double[duration];

                theset.data[2] = new eventDetail();
                theset.data[2].name = "Noncongruent";
                theset.data[2].data = new double[duration];

                int i = 0;

                while (rdr.Read())
                {
                    //thedate, thecount, thename
                    //DateTime thedate = (DateTime)rdr["thedate"];
                    //theset.xAxis[i] = thedate.ToString("d");
                    theset.data[0].data[i] = Convert.ToDouble(rdr["Latched"]);
                    theset.data[1].data[i] = Convert.ToDouble(rdr["Unreasonable"]);
                    theset.data[2].data[i] = Convert.ToDouble(rdr["Noncongruent"]);
                    i++;
                }
            }

        }
        finally
        {
            if (conn != null)
            {
                conn.Close();
            }
            if (rdr != null)
            {
                rdr.Close();
            }
        }

        return (theset);
    }
示例#17
0
        /// <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();
            DataGroup          cycleCurves;
            List <ChannelData> cycleDataRows;

            if (MeasurementName != "Voltage" && MeasurementName != "Current")
            {
                return(theset);
            }

            using (AdoDataConnection connection = new AdoDataConnection("SystemSettings"))
            {
                theset.Yaxis0name = MeasurementName;
                theset.Yaxis1name = "";

                Event theevent = (new TableOperations <Event>(connection)).QueryRecordWhere("ID = {0}", Convert.ToInt32(EventInstanceID));
                Meter themeter = (new TableOperations <Meter>(connection)).QueryRecordWhere("ID = {0}", theevent.MeterID);
                Line  line     = (new TableOperations <Line>(connection)).QueryRecordWhere("ID = {0}", theevent.AssetID);

                cycleDataRows = (new TableOperations <ChannelData>(connection)).QueryRecordsWhere("EventID = {0}", theevent.ID).ToList();
                cycleCurves   = ToDataSeries(themeter, cycleDataRows);

                //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.DataSeries
                                                                   .Select((series, index) => new { Name = seriesNames[index], Series = series })
                                                                   .ToDictionary(obj => obj.Name, obj => obj.Series);

                int i = 0;
                if (cycleCurves != null)
                {
                    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);
        }