Наследование: System.Data.Linq.DataContext
    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
                    {

                    }

                }

            }
        }
    }
Пример #2
0
        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);
        }
    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
                    {

                    }
                }
            }
        }
    }
    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.Date.ToShortDateString();
                        postedMeterId = theevent.MeterID.ToString();
                        postedMeterName = themeter.Name;
                    }

                    catch (Exception ex)
                    {
                        postedDate = "";
                        postedEventId = "";
                        postedMeterId = "";
                        postedMeterName = "";
                    }
                    finally
                    {

                    }
                }
            }
        }
    }
 // Determines whether configuration exists for the meter with the given asset key.
 private static void ValidateMeterKey(string filePath, string meterKey, MeterInfoDataContext meterInfo)
 {
     // Determine whether there exists a meter whose asset key matches the given meterKey
     if (!meterInfo.Meters.Any(m => m.AssetKey == meterKey))
         throw new FileSkippedException($"Skipped file \"{filePath}\" because no meter configuration was found for meter {meterKey}.");
 }
    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 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);
    }
    /// <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);
    }
    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();
                    }
                }
            }
        }
    }
Пример #11
0
        // 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);

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

            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
                };
            });
        }
Пример #12
0
        /// <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", "General1");
                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", "General2");
                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", "General3");
                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;
        }