Esempio n. 1
0
        private Dictionary <string, DataSeries> GetFaultCurveLookup()
        {
            FaultCurveTableAdapter faultCurveAdapter = m_dbAdapterContainer.GetAdapter <FaultCurveTableAdapter>();

            FaultLocationData.FaultCurveDataTable faultCurveTable = faultCurveAdapter.GetDataBy(m_eventID);

            Func <FaultLocationData.FaultCurveRow, DataSeries> toDataSeries = faultCurve =>
            {
                DataGroup dataGroup = new DataGroup();
                dataGroup.FromData(faultCurve.Data);
                return(dataGroup[0]);
            };

            return(faultCurveTable
                   .GroupBy(faultCurve => faultCurve.Algorithm)
                   .ToDictionary(grouping => grouping.Key, grouping =>
            {
                if (grouping.Count() > 1)
                {
                    Log.Warn($"Duplicate fault curve ({grouping.Key}) found for event {grouping.First().EventID}");
                }

                return toDataSeries(grouping.First());
            }));
        }
Esempio n. 2
0
        private Dictionary <string, DataSeries> GetFaultCurveLookup()
        {
            FaultCurveTableAdapter faultCurveAdapter = m_dbAdapterContainer.GetAdapter <FaultCurveTableAdapter>();

            FaultLocationData.FaultCurveDataTable faultCurveTable = faultCurveAdapter.GetDataBy(m_eventID);

            Func <FaultLocationData.FaultCurveRow, DataSeries> toDataSeries = faultCurve =>
            {
                DataGroup dataGroup = new DataGroup();
                dataGroup.FromData(faultCurve.Data);
                return(dataGroup[0]);
            };

            return(faultCurveTable.ToDictionary(faultCurve => faultCurve.Algorithm, toDataSeries));
        }
Esempio n. 3
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);
        }
        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);
        }
Esempio n. 5
0
        private eventSet FetchMeterEventFaultCurveByID(string EventInstanceID)
        {
            eventSet theset = new eventSet();

            theset.data       = new List <signalDetail>();
            theset.Yaxis0name = "Miles";
            theset.Yaxis1name = "";

            if (EventInstanceID == "0")
            {
                return(theset);
            }

            DataGroup         eventDataGroup = new DataGroup();
            List <DataSeries> faultCurves;
            List <FaultLocationData.FaultCurveRow> FaultCurves;

            using (MeterInfoDataContext meterInfo = new MeterInfoDataContext(ConnectionString))
                using (FaultSummaryTableAdapter summaryInfo = new FaultSummaryTableAdapter())
                    using (EventTableAdapter eventAdapter = new EventTableAdapter())
                        using (FaultCurveTableAdapter faultCurveAdapter = new FaultCurveTableAdapter())
                        {
                            faultCurveAdapter.Connection.ConnectionString = ConnectionString;
                            eventAdapter.Connection.ConnectionString      = ConnectionString;
                            summaryInfo.Connection.ConnectionString       = ConnectionString;

                            theset.Yaxis0name = "Miles";
                            theset.Yaxis1name = "";

                            MeterData.EventRow theevent = eventAdapter.GetDataByID(Convert.ToInt32(EventInstanceID)).First();
                            Meter themeter = meterInfo.Meters.Single(m => theevent.MeterID == m.ID);
                            Line  theline  = meterInfo.Lines.Single(l => theevent.LineID == l.ID);

                            FaultLocationData.FaultSummaryRow thesummary = (FaultLocationData.FaultSummaryRow)summaryInfo.GetDataBy(Convert.ToInt32(EventInstanceID)).Select("IsSelectedAlgorithm = 1").FirstOrDefault();

                            if ((object)thesummary == null)
                            {
                                return(theset);
                            }

                            FaultCurves = faultCurveAdapter.GetDataBy(Convert.ToInt32(EventInstanceID)).ToList();

                            if (FaultCurves.Count == 0)
                            {
                                return(theset);
                            }

                            faultCurves = FaultCurves.Select(ToDataSeries).ToList();

                            foreach (DataSeries faultCurve in faultCurves)
                            {
                                FixFaultCurve(faultCurve, theline);
                            }

                            double CyclesPerSecond = thesummary.DurationCycles / thesummary.DurationSeconds;
                            List <faultSegmentDetail> thedetails = new List <faultSegmentDetail>();
                            theset.detail = thedetails;

                            faultSegmentDetail thedetail = new faultSegmentDetail();

                            thedetail.type        = "" + thesummary.Inception.TimeOfDay.ToString();//; + "-" + new TimeSpan(thesummary.Inception.TimeOfDay.Ticks + thesummary.DurationSeconds).ToString();
                            thedetail.StartSample = thesummary.CalculationCycle;
                            thedetail.EndSample   = thesummary.CalculationCycle + 8;
                            thedetails.Add(thedetail);

                            //faultSegmentDetail thedetail2 = new faultSegmentDetail();

                            //thedetail2.type = "";
                            //thedetail2.StartSample = thesummary.CalculationCycle + (int)(Math.Round((faultCurves.First().SampleRate) / CyclesPerSecond));
                            //thedetail2.EndSample = thedetail2.StartSample - 4;
                            //thedetails.Add(thedetail2);

                            int i = 0;

                            foreach (DataSeries theseries in faultCurves)
                            {
                                int datacount = theseries.DataPoints.Count();

                                if (theset.xAxis == null)
                                {
                                    theset.xAxis = new string[datacount];
                                }

                                //theset.data[i] = new signalDetail();
                                signalDetail theitem = new signalDetail();

                                theitem.name  = FaultCurves[i].Algorithm;
                                theitem.data  = new double[datacount];
                                theitem.type  = "line";
                                theitem.yAxis = 0;

                                int      j          = 0;
                                DateTime beginticks = theseries.DataPoints[0].Time;

                                foreach (DataPoint thepoint in theseries.DataPoints)
                                {
                                    double elapsed = thepoint.Time.Subtract(beginticks).TotalSeconds;

                                    if (theset.xAxis[j] == null)
                                    {
                                        theset.xAxis[j] = elapsed.ToString();
                                    }

                                    theitem.data[j] = thepoint.Value;
                                    j++;
                                }

                                i++;
                                theset.data.Add(theitem);
                            }
                        }
            return(theset);
        }
Esempio n. 6
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);
        }
Esempio n. 7
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);
    }
    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);
    }