Example #1
0
        private List <MeterDataSet> LoadMeterDataSets(DbAdapterContainer dbAdapterContainer, FileGroup fileGroup)
        {
            List <MeterDataSet> meterDataSets = new List <MeterDataSet>();

            MeterInfoDataContext  meterInfo        = dbAdapterContainer.GetAdapter <MeterInfoDataContext>();
            EventTableAdapter     eventAdapter     = dbAdapterContainer.GetAdapter <EventTableAdapter>();
            EventDataTableAdapter eventDataAdapter = dbAdapterContainer.GetAdapter <EventDataTableAdapter>();

            MeterData.EventDataTable eventTable = eventAdapter.GetDataByFileGroup(fileGroup.ID);

            MeterDataSet meterDataSet;
            DataGroup    dataGroup;

            foreach (IGrouping <int, MeterData.EventRow> eventGroup in eventTable.GroupBy(evt => evt.MeterID))
            {
                meterDataSet       = new MeterDataSet();
                meterDataSet.Meter = meterInfo.Meters.SingleOrDefault(meter => meter.ID == eventGroup.Key);

                foreach (MeterData.EventRow evt in eventGroup)
                {
                    dataGroup = new DataGroup();
                    dataGroup.FromData(meterDataSet.Meter, eventDataAdapter.GetTimeDomainData(evt.EventDataID));

                    foreach (DataSeries dataSeries in dataGroup.DataSeries)
                    {
                        meterDataSet.DataSeries.Add(dataSeries);
                    }
                }

                meterDataSets.Add(meterDataSet);
            }

            return(meterDataSets);
        }
Example #2
0
        /// <summary>
        /// Loads new events from a file if the file has changed.
        /// </summary>
        private void RefreshEvents(EventTable eventTable)
        {
            if (string.IsNullOrEmpty(eventTable.FileName))
            {
                eventTable.FileName = Path.Combine(archivePath,
                                                   EventTableAdapter.GetTableFileName(Code, eventTable.TableDate));
            }

            DateTime fileAge = File.Exists(eventTable.FileName) ?
                               File.GetLastWriteTimeUtc(eventTable.FileName) : DateTime.MinValue;

            if (fileAge > DateTime.MinValue && fileAge != eventTable.FileAge)
            {
                stopwatch.Restart();
                adapter.FileName = eventTable.FileName;
                adapter.Fill(eventTable);
                eventTable.FileAge = fileAge;

                stopwatch.Stop();
                arcLog?.WriteAction(Locale.IsRussian ?
                                    "Чтение таблицы событий длины {0} успешно завершено за {1} мс" :
                                    "Reading an event table of length {0} completed successfully in {1} ms",
                                    eventTable.Events.Count, stopwatch.ElapsedMilliseconds);
            }
        }
Example #3
0
        private static void LoadEmail(int eventID, List <Recipient> recipients, string subject, string body)
        {
            EventTableAdapter eventAdapter = s_dbAdapterContainer.GetAdapter <EventTableAdapter>();

            MeterData.EventRow       eventRow    = eventAdapter.GetDataByID(eventID)[0];
            MeterData.EventDataTable systemEvent = eventAdapter.GetSystemEvent(eventRow.StartTime, eventRow.EndTime, s_timeTolerance);

            FaultEmailTableAdapter faultEmailAdapter = s_dbAdapterContainer.GetAdapter <FaultEmailTableAdapter>();

            FaultLocationData.FaultEmailDataTable      faultEmailTable      = new FaultLocationData.FaultEmailDataTable();
            FaultLocationData.EventFaultEmailDataTable eventFaultEmailTable = new FaultLocationData.EventFaultEmailDataTable();

            DateTime now    = TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow, s_timeZone);
            string   toLine = string.Join("; ", recipients.Select(recipient => recipient.Email));

            BulkLoader bulkLoader;

            faultEmailTable.AddFaultEmailRow(now, toLine, subject, body);
            faultEmailAdapter.Update(faultEmailTable);

            foreach (MeterData.EventRow evt in systemEvent)
            {
                if (eventRow.LineID == evt.LineID)
                {
                    eventFaultEmailTable.AddEventFaultEmailRow(evt.ID, faultEmailTable[0].ID);
                }
            }

            bulkLoader                = new BulkLoader();
            bulkLoader.Connection     = s_dbAdapterContainer.Connection;
            bulkLoader.CommandTimeout = s_dbAdapterContainer.CommandTimeout;
            bulkLoader.Load(eventFaultEmailTable);
        }
Example #4
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Request["eventid"] != null)
            {
                postedEventId = Request["eventid"];
                using (EventTableAdapter eventAdapter = new EventTableAdapter())
                    using (MeterInfoDataContext meterInfo = new MeterInfoDataContext(connectionstring))
                    {
                        try
                        {
                            eventAdapter.Connection.ConnectionString = connectionstring;
                            MeterData.EventRow theevent = eventAdapter.GetDataByID(Convert.ToInt32(postedEventId)).First();
                            Meter themeter = meterInfo.Meters.Single(m => m.ID == theevent.MeterID);

                            postedDate      = theevent.StartTime.ToShortDateString() + " " + theevent.StartTime.TimeOfDay.ToString();
                            postedMeterId   = theevent.MeterID.ToString();
                            postedMeterName = themeter.Name;
                        }

                        catch (Exception ex)
                        {
                            postedDate      = "";
                            postedEventId   = "";
                            postedMeterId   = "";
                            postedMeterName = "";
                        }
                        finally
                        {
                        }
                    }
            }
        }
    }
Example #5
0
        private EventTable lastTable;                                   // the last accessed event table


        /// <summary>
        /// Initializes a new instance of the class.
        /// </summary>
        public BasicEAL(IArchiveContext archiveContext, ArchiveConfig archiveConfig, int[] cnlNums)
            : base(archiveContext, archiveConfig, cnlNums)
        {
            options     = new BasicEAO(archiveConfig.CustomOptions);
            appLog      = archiveContext.Log;
            arcLog      = options.LogEnabled ? CreateLog(ModuleUtils.ModuleCode) : null;
            stopwatch   = new Stopwatch();
            adapter     = new EventTableAdapter();
            archivePath = Path.Combine(archiveContext.AppConfig.PathOptions.GetArcDir(options.IsCopy), Code);
            tableCache  = new MemoryCache <DateTime, EventTable>(ModuleUtils.CacheExpiration, ModuleUtils.CacheCapacity);

            currentTable = null;
            lastTable    = null;
        }
Example #6
0
        private EventTable lastTable;                                   // the last accessed event table


        /// <summary>
        /// Initializes a new instance of the class.
        /// </summary>
        public BasicEAL(IArchiveContext archiveContext, ArchiveConfig archiveConfig, int[] cnlNums,
                        ModuleConfig moduleConfig) : base(archiveContext, archiveConfig, cnlNums)
        {
            this.moduleConfig = moduleConfig ?? throw new ArgumentNullException(nameof(moduleConfig));
            options           = new BasicEAO(archiveConfig.CustomOptions);
            appLog            = archiveContext.Log;
            arcLog            = options.LogEnabled ? CreateLog(ModuleUtils.ModuleCode) : null;
            stopwatch         = new Stopwatch();
            adapter           = new EventTableAdapter();
            tableCache        = new MemoryCache <DateTime, EventTable>(ModuleUtils.CacheExpiration, ModuleUtils.CacheCapacity);

            archivePath  = "";
            currentTable = null;
            lastTable    = null;
        }
Example #7
0
        private VICycleDataGroup GetVICycleDataGroup()
        {
            MeterInfoDataContext  meterInfo        = m_dbAdapterContainer.GetAdapter <MeterInfoDataContext>();
            EventTableAdapter     eventAdapter     = m_dbAdapterContainer.GetAdapter <EventTableAdapter>();
            EventDataTableAdapter eventDataAdapter = m_dbAdapterContainer.GetAdapter <EventDataTableAdapter>();

            MeterData.EventRow     eventRow     = eventAdapter.GetDataByID(m_eventID)[0];
            MeterData.EventDataRow eventDataRow = eventDataAdapter.GetDataBy(m_eventID)[0];
            Meter meter = meterInfo.Meters.Single(m => m.ID == eventRow.MeterID);

            DataGroup dataGroup = new DataGroup();

            dataGroup.FromData(meter, eventDataRow.FrequencyDomainData);
            return(new VICycleDataGroup(dataGroup));
        }
Example #8
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);
        }
Example #9
0
        /// <summary>
        /// Deletes the outdated data from the archive.
        /// </summary>
        public override void DeleteOutdatedData()
        {
            DirectoryInfo arcDirInfo = new DirectoryInfo(archivePath);

            if (arcDirInfo.Exists)
            {
                DateTime minDT       = DateTime.UtcNow.AddDays(-options.StoragePeriod);
                string   minFileName = EventTableAdapter.GetTableFileName(Code, minDT);
                appLog.WriteAction(ServerPhrases.DeleteOutdatedData, Code, minDT.ToLocalizedDateString());

                foreach (FileInfo fileInfo in
                         arcDirInfo.EnumerateFiles(Code + "*", SearchOption.TopDirectoryOnly))
                {
                    if (string.CompareOrdinal(fileInfo.Name, minFileName) < 0)
                    {
                        fileInfo.Delete();
                    }
                }
            }
        }
        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);
        }
Example #11
0
    public static List <FlotSeries> GetFlotInfo(int eventID)
    {
        using (DbAdapterContainer dbAdapterContainer = new DbAdapterContainer(ConnectionString))
            using (AdoDataConnection connection = new AdoDataConnection(dbAdapterContainer.Connection, typeof(SqlDataAdapter), false))
            {
                EventTableAdapter            eventAdapter = dbAdapterContainer.GetAdapter <EventTableAdapter>();
                MeterInfoDataContext         meterInfo    = dbAdapterContainer.GetAdapter <MeterInfoDataContext>();
                FaultLocationInfoDataContext faultInfo    = dbAdapterContainer.GetAdapter <FaultLocationInfoDataContext>();

                MeterData.EventRow eventRow = eventAdapter.GetDataByID(eventID).FirstOrDefault();

                if ((object)eventRow == null)
                {
                    return(new List <FlotSeries>());
                }

                return(GetWaveformInfo(meterInfo.Series, eventRow.MeterID, eventRow.LineID)
                       .Select(ToFlotSeries)
                       .Concat(CycleDataInfo)
                       .Concat(GetFaultCurveInfo(connection, eventID).Select(ToFlotSeries))
                       .ToList());
            }
    }
Example #12
0
        public static List <FlotSeries> GetFlotInfo(int eventID)
        {
            using (DbAdapterContainer dbAdapterContainer = new DbAdapterContainer(ConnectionString))
                using (AdoDataConnection connection = new AdoDataConnection(dbAdapterContainer.Connection, typeof(SqlDataAdapter), false))
                {
                    EventTableAdapter            eventAdapter = dbAdapterContainer.GetAdapter <EventTableAdapter>();
                    MeterInfoDataContext         meterInfo    = dbAdapterContainer.GetAdapter <MeterInfoDataContext>();
                    FaultLocationInfoDataContext faultInfo    = dbAdapterContainer.GetAdapter <FaultLocationInfoDataContext>();

                    MeterData.EventRow eventRow = eventAdapter.GetDataByID(eventID).FirstOrDefault();

                    if ((object)eventRow == null)
                    {
                        return(new List <FlotSeries>());
                    }

                    List <Series> waveformInfo = GetWaveformInfo(meterInfo.Series, eventRow.MeterID, eventRow.LineID);

                    var lookup = waveformInfo
                                 .Where(info => info.Channel.MeasurementCharacteristic.Name == "Instantaneous")
                                 .Where(info => new string[] { "Instantaneous", "Values" }.Contains(info.SeriesType.Name))
                                 .Select(info => new { MeasurementType = info.Channel.MeasurementType.Name, Phase = info.Channel.Phase.Name })
                                 .Distinct()
                                 .ToDictionary(info => info);

                    IEnumerable <FlotSeries> cycleDataInfo = CycleDataInfo
                                                             .Where(info => lookup.ContainsKey(new { info.MeasurementType, info.Phase }))
                                                             .Select(info => info.Clone());

                    return(GetWaveformInfo(meterInfo.Series, eventRow.MeterID, eventRow.LineID)
                           .Select(ToFlotSeries)
                           .Concat(cycleDataInfo)
                           .Concat(GetFaultCurveInfo(connection, eventID).Select(ToFlotSeries))
                           .ToList());
                }
        }
    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
                    {

                    }
                }
            }
        }
    }
    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);
    }
    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);
    }
    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();
                                    }
                                }
                            }
            }
        }
    }
Example #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();
            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);
        }
Example #18
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);
        }
Example #19
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);
        }
    /// <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);
    }
Example #21
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Request["eventId"] != null)
            {
                if (Request["faultcurves"] != null)
                {
                    postedShowFaultCurves = Request["faultcurves"];
                }

                if (Request["breakerdigitals"] != null)
                {
                    postedShowBreakerDigitals = Request["breakerdigitals"];
                }

                postedURLQueryString = string.Concat(Request.QueryString.AllKeys
                                                     .Where(key => !key.Equals("eventId", StringComparison.OrdinalIgnoreCase))
                                                     .Select(key => "&" + HttpUtility.UrlEncode(key) + "=" + HttpUtility.UrlEncode(Request.QueryString[key])));

                postedEventId = Request["eventId"];

                using (DbAdapterContainer dbAdapterContainer = new DbAdapterContainer(connectionString))
                {
                    try
                    {
                        EventTypeTableAdapter    eventTypeAdapter   = dbAdapterContainer.GetAdapter <EventTypeTableAdapter>();
                        EventTableAdapter        eventAdapter       = dbAdapterContainer.GetAdapter <EventTableAdapter>();
                        MeterInfoDataContext     meterInfo          = dbAdapterContainer.GetAdapter <MeterInfoDataContext>();
                        FaultSummaryTableAdapter summaryInfo        = dbAdapterContainer.GetAdapter <FaultSummaryTableAdapter>();
                        DisturbanceTableAdapter  disturbanceAdapter = dbAdapterContainer.GetAdapter <DisturbanceTableAdapter>();

                        MeterData.EventRow theevent = eventAdapter.GetDataByID(Convert.ToInt32(postedEventId)).First();

                        JavaScriptSerializer serializer = new JavaScriptSerializer();

                        postedSeriesList = serializer.Serialize(signalService.GetFlotInfo(theevent.ID));

                        postedMeterId           = theevent.MeterID.ToString();
                        postedDate              = theevent.StartTime.ToShortDateString();
                        postedEventId           = theevent.ID.ToString();
                        postedEventDate         = theevent.StartTime.ToString("yyyy-MM-dd HH:mm:ss.fffffff");
                        postedEventMilliseconds = theevent.StartTime.Subtract(new DateTime(1970, 1, 1)).TotalMilliseconds.ToString();
                        postedMeterName         = meterInfo.Meters.Single(m => m.ID == theevent.MeterID).Name;

                        MeterData.EventTypeDataTable eventTypes = eventTypeAdapter.GetData();

                        postedAdjacentEventIds = GetPreviousAndNextEventIds(theevent.ID, dbAdapterContainer.Connection);

                        postedLineName = meterInfo.MeterLines.Where(row => row.LineID == theevent.LineID)
                                         .Where(row => row.MeterID == theevent.MeterID)
                                         .Select(row => row.LineName)
                                         .FirstOrDefault() ?? "";

                        postedLineLength = meterInfo.Lines
                                           .Where(row => row.ID == theevent.LineID)
                                           .Select(row => row.Length)
                                           .AsEnumerable()
                                           .Select(length => length.ToString())
                                           .FirstOrDefault() ?? "";

                        postedEventName = eventTypes
                                          .Where(row => row.ID == theevent.EventTypeID)
                                          .Select(row => row.Name)
                                          .DefaultIfEmpty("")
                                          .Single();

                        if (postedEventName.Equals("Fault"))
                        {
                            FaultLocationData.FaultSummaryDataTable thesummarydatatable = summaryInfo.GetDataBy(Convert.ToInt32(postedEventId));

                            FaultLocationData.FaultSummaryRow thesummary = thesummarydatatable
                                                                           .Where(row => row.IsSelectedAlgorithm == 1)
                                                                           .OrderBy(row => row.IsSuppressed)
                                                                           .ThenBy(row => row.Inception)
                                                                           .FirstOrDefault();

                            if ((object)thesummary != null)
                            {
                                postedStartTime      = thesummary.Inception.TimeOfDay.ToString();
                                postedDurationPeriod = thesummary.DurationCycles.ToString("##.##", CultureInfo.InvariantCulture) + " cycles";
                                postedMagnitude      = thesummary.CurrentMagnitude.ToString("####.#", CultureInfo.InvariantCulture) + " Amps (RMS)";
                            }
                        }
                        else if (new[] { "Sag", "Swell" }.Contains(postedEventName))
                        {
                            MeterData.DisturbanceDataTable disturbanceTable = disturbanceAdapter.GetDataBy(theevent.ID);

                            MeterData.DisturbanceRow disturbance = disturbanceTable
                                                                   .Where(row => row.EventTypeID == theevent.EventTypeID)
                                                                   .OrderBy(row => row.StartTime)
                                                                   .FirstOrDefault();

                            if ((object)disturbance != null)
                            {
                                postedStartTime      = disturbance.StartTime.TimeOfDay.ToString();
                                postedDurationPeriod = disturbance.DurationCycles.ToString("##.##", CultureInfo.InvariantCulture) + " cycles";

                                if (disturbance.PerUnitMagnitude != -1.0e308)
                                {
                                    postedMagnitude = disturbance.PerUnitMagnitude.ToString("N3", CultureInfo.InvariantCulture) + " pu (RMS)";
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        postedErrorMessage = ex.Message;
                    }
                }
            }
        }
    }
Example #22
0
    public List <FlotSeries> GetFlotData(int eventID, List <int> seriesIndexes)
    {
        List <FlotSeries> flotSeriesList = new List <FlotSeries>();

        using (DbAdapterContainer dbAdapterContainer = new DbAdapterContainer(ConnectionString))
            using (AdoDataConnection connection = new AdoDataConnection(dbAdapterContainer.Connection, typeof(SqlDataAdapter), false))
            {
                EventTableAdapter            eventAdapter      = dbAdapterContainer.GetAdapter <EventTableAdapter>();
                EventDataTableAdapter        eventDataAdapter  = dbAdapterContainer.GetAdapter <EventDataTableAdapter>();
                FaultCurveTableAdapter       faultCurveAdapter = dbAdapterContainer.GetAdapter <FaultCurveTableAdapter>();
                MeterInfoDataContext         meterInfo         = dbAdapterContainer.GetAdapter <MeterInfoDataContext>();
                FaultLocationInfoDataContext faultLocationInfo = dbAdapterContainer.GetAdapter <FaultLocationInfoDataContext>();

                MeterData.EventRow eventRow = eventAdapter.GetDataByID(eventID).FirstOrDefault();
                Meter meter = meterInfo.Meters.First(m => m.ID == eventRow.MeterID);

                List <Series> waveformInfo   = GetWaveformInfo(meterInfo.Series, eventRow.MeterID, eventRow.LineID);
                List <string> faultCurveInfo = GetFaultCurveInfo(connection, eventID);
                DateTime      epoch          = new DateTime(1970, 1, 1);

                Lazy <Dictionary <int, DataSeries> > waveformData = new Lazy <Dictionary <int, DataSeries> >(() =>
                {
                    return(ToDataGroup(meter, eventDataAdapter.GetTimeDomainData(eventRow.EventDataID)).DataSeries
                           .ToDictionary(dataSeries => dataSeries.SeriesInfo.ID));
                });

                Lazy <DataGroup> cycleData = new Lazy <DataGroup>(() => ToDataGroup(meter, eventDataAdapter.GetFrequencyDomainData(eventRow.EventDataID)));

                Lazy <Dictionary <string, DataSeries> > faultCurveData = new Lazy <Dictionary <string, DataSeries> >(() =>
                {
                    return(faultCurveAdapter
                           .GetDataBy(eventRow.ID)
                           .Select(faultCurve => new
                    {
                        Algorithm = faultCurve.Algorithm,
                        DataGroup = ToDataGroup(meter, faultCurve.Data)
                    })
                           .Where(obj => obj.DataGroup.DataSeries.Count > 0)
                           .ToDictionary(obj => obj.Algorithm, obj => obj.DataGroup[0]));
                });

                foreach (int index in seriesIndexes)
                {
                    DataSeries dataSeries = null;
                    FlotSeries flotSeries = null;

                    int waveformIndex   = index;
                    int cycleIndex      = waveformIndex - waveformInfo.Count;
                    int faultCurveIndex = cycleIndex - CycleDataInfo.Count;

                    if (waveformIndex < waveformInfo.Count)
                    {
                        if (!waveformData.Value.TryGetValue(waveformInfo[index].ID, out dataSeries))
                        {
                            continue;
                        }

                        flotSeries = ToFlotSeries(waveformInfo[index]);
                    }
                    else if (cycleIndex < CycleDataInfo.Count)
                    {
                        if (cycleIndex >= cycleData.Value.DataSeries.Count)
                        {
                            continue;
                        }

                        dataSeries = cycleData.Value[cycleIndex];

                        flotSeries = new FlotSeries()
                        {
                            MeasurementType           = CycleDataInfo[cycleIndex].MeasurementType,
                            MeasurementCharacteristic = CycleDataInfo[cycleIndex].MeasurementCharacteristic,
                            Phase      = CycleDataInfo[cycleIndex].Phase,
                            SeriesType = CycleDataInfo[cycleIndex].SeriesType
                        };
                    }
                    else if (faultCurveIndex < faultCurveInfo.Count)
                    {
                        string algorithm = faultCurveInfo[faultCurveIndex];

                        if (!faultCurveData.Value.TryGetValue(algorithm, out dataSeries))
                        {
                            continue;
                        }

                        flotSeries = ToFlotSeries(faultCurveInfo[faultCurveIndex]);
                    }
                    else
                    {
                        continue;
                    }

                    foreach (DataPoint dataPoint in dataSeries.DataPoints)
                    {
                        if (!double.IsNaN(dataPoint.Value))
                        {
                            flotSeries.DataPoints.Add(new double[] { dataPoint.Time.Subtract(epoch).TotalMilliseconds, dataPoint.Value });
                        }
                    }

                    flotSeriesList.Add(flotSeries);
                }
            }

        return(flotSeriesList);
    }
    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();
                    }
                }
            }
        }
    }
Example #24
0
        public List <FlotSeries> GetFlotData(int eventID, List <int> seriesIndexes)
        {
            List <FlotSeries> flotSeriesList = new List <FlotSeries>();

            using (DbAdapterContainer dbAdapterContainer = new DbAdapterContainer(ConnectionString))
                using (AdoDataConnection connection = new AdoDataConnection(dbAdapterContainer.Connection, typeof(SqlDataAdapter), false))
                {
                    EventTableAdapter            eventAdapter      = dbAdapterContainer.GetAdapter <EventTableAdapter>();
                    EventDataTableAdapter        eventDataAdapter  = dbAdapterContainer.GetAdapter <EventDataTableAdapter>();
                    FaultCurveTableAdapter       faultCurveAdapter = dbAdapterContainer.GetAdapter <FaultCurveTableAdapter>();
                    MeterInfoDataContext         meterInfo         = dbAdapterContainer.GetAdapter <MeterInfoDataContext>();
                    FaultLocationInfoDataContext faultLocationInfo = dbAdapterContainer.GetAdapter <FaultLocationInfoDataContext>();

                    MeterData.EventRow eventRow = eventAdapter.GetDataByID(eventID).FirstOrDefault();
                    Meter meter = meterInfo.Meters.First(m => m.ID == eventRow.MeterID);

                    List <FlotSeries> flotInfo = GetFlotInfo(eventID);
                    DateTime          epoch    = new DateTime(1970, 1, 1);

                    Lazy <Dictionary <int, DataSeries> > waveformData = new Lazy <Dictionary <int, DataSeries> >(() =>
                    {
                        return(ToDataGroup(meter, eventDataAdapter.GetTimeDomainData(eventRow.EventDataID)).DataSeries
                               .ToDictionary(dataSeries => dataSeries.SeriesInfo.ID));
                    });

                    Lazy <DataGroup> cycleData = new Lazy <DataGroup>(() => ToDataGroup(meter, eventDataAdapter.GetFrequencyDomainData(eventRow.EventDataID)));

                    Lazy <Dictionary <string, DataSeries> > faultCurveData = new Lazy <Dictionary <string, DataSeries> >(() =>
                    {
                        return(faultCurveAdapter
                               .GetDataBy(eventRow.ID)
                               .Select(faultCurve => new
                        {
                            Algorithm = faultCurve.Algorithm,
                            DataGroup = ToDataGroup(meter, faultCurve.Data)
                        })
                               .Where(obj => obj.DataGroup.DataSeries.Count > 0)
                               .ToDictionary(obj => obj.Algorithm, obj => obj.DataGroup[0]));
                    });

                    foreach (int index in seriesIndexes)
                    {
                        DataSeries dataSeries = null;
                        FlotSeries flotSeries;

                        if (index >= flotInfo.Count)
                        {
                            continue;
                        }

                        flotSeries = flotInfo[index];

                        if (flotSeries.FlotType == FlotSeriesType.Waveform)
                        {
                            if (!waveformData.Value.TryGetValue(flotSeries.SeriesID, out dataSeries))
                            {
                                continue;
                            }
                        }
                        else if (flotSeries.FlotType == FlotSeriesType.Cycle)
                        {
                            dataSeries = cycleData.Value.DataSeries
                                         .Where(series => series.SeriesInfo.Channel.MeasurementType.Name == flotSeries.MeasurementType)
                                         .Where(series => series.SeriesInfo.Channel.Phase.Name == flotSeries.Phase)
                                         .Skip(flotSeries.SeriesID)
                                         .FirstOrDefault();

                            if ((object)dataSeries == null)
                            {
                                continue;
                            }
                        }
                        else if (flotSeries.FlotType == FlotSeriesType.Fault)
                        {
                            string algorithm = flotSeries.ChannelName;

                            if (!faultCurveData.Value.TryGetValue(algorithm, out dataSeries))
                            {
                                continue;
                            }
                        }
                        else
                        {
                            continue;
                        }

                        foreach (DataPoint dataPoint in dataSeries.DataPoints)
                        {
                            if (!double.IsNaN(dataPoint.Value))
                            {
                                flotSeries.DataPoints.Add(new double[] { dataPoint.Time.Subtract(epoch).TotalMilliseconds, dataPoint.Value });
                            }
                        }

                        flotSeriesList.Add(flotSeries);
                    }
                }

            return(flotSeriesList);
        }
    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);
    }