Пример #1
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);
    }
Пример #2
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);
    }
Пример #3
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 FetchMeterEventDataByID(string EventInstanceID)
    {
        eventSet theset = new eventSet();
        theset.data = new List<signalDetail>();
        MeterData.EventDataTable events;
        DataGroup eventDataGroup = new DataGroup();
        using (MeterInfoDataContext meterInfo = new MeterInfoDataContext(ConnectionString))
        using (EventTableAdapter eventAdapter = new EventTableAdapter())
        using (EventDataTableAdapter eventDataAdapter = new EventDataTableAdapter())
        {
            eventAdapter.Connection.ConnectionString = ConnectionString;
            eventDataAdapter.Connection.ConnectionString = ConnectionString;

            events = eventAdapter.GetDataByID(Convert.ToInt32(EventInstanceID));
            theset.Yaxis0name = "Voltage";
            theset.Yaxis1name = "Current";

            foreach (MeterData.EventRow evt in events)
            {
                Meter meter = meterInfo.Meters.Single(m => m.ID == evt.MeterID);

                FaultData.Database.Line line = meterInfo.Lines.Single(l => l.ID == evt.LineID);

                //eventDataAdapter.GetTimeDomainData(evt.EventDataID);

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

                int i = 0;

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

                    signalDetail theitem = new signalDetail();

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

                    if (theseries.SeriesInfo.Channel.MeasurementType.Name.Equals("Voltage"))
                    {
                        measurementType = "V";
                    }

                    if (theseries.SeriesInfo.Channel.MeasurementType.Name.Equals("Power"))
                    {
                        measurementType = "P";
                    }

                    if (theseries.SeriesInfo.Channel.MeasurementType.Name.Equals("Energy"))
                    {
                        measurementType = "E";
                    }

                    if (theseries.SeriesInfo.SeriesType.Name.Substring(0, 3) == "Min") continue;
                    if (theseries.SeriesInfo.SeriesType.Name.Substring(0, 3) == "Max") continue;

                    //theitem.name = theseries.SeriesInfo.SeriesType.Name.Substring(0, 3) + " " + measurementType + theseries.SeriesInfo.Channel.Phase.Name;
                    theitem.name = measurementType + theseries.SeriesInfo.Channel.Phase.Name;
                    theitem.data = new double[datacount];
                    theitem.type = "line";
                    theitem.yAxis = 0;

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

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

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

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

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

                    int j = 0;
                    DateTime beginticks = eventDataGroup.DataSeries[i].DataPoints[0].Time;
                    foreach (FaultData.DataAnalysis.DataPoint thepoint in eventDataGroup.DataSeries[i].DataPoints)
                    {
                        double elapsed = thepoint.Time.Subtract(beginticks).TotalSeconds;
                        theset.xAxis[j] = elapsed.ToString();
                        theitem.data[j] = thepoint.Value;
                        j++;
                    }
                    i++;

                    theset.data.Add(theitem);
                }
                break;
            }
        }
        return (theset);
    }
    /// <summary>
    /// FetchMeterEventCycleData
    /// </summary>
    /// <param name="EventInstanceID"></param>
    /// <param name="MeasurementName"></param>
    /// <param name="theset"></param>
    /// <returns></returns>
    private eventSet FetchMeterEventCycleData(string EventInstanceID, string MeasurementName, eventSet theset)
    {
        DataGroup eventDataGroup = new DataGroup();
        List<DataGroup> cycleCurves;
        List<MeterData.EventDataRow> cycleDataRows;

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

        using (MeterInfoDataContext meterInfo = new MeterInfoDataContext(ConnectionString))
        using (EventTableAdapter eventAdapter = new EventTableAdapter())
        using (EventDataTableAdapter cycleDataAdapter = new EventDataTableAdapter())
        {
            cycleDataAdapter.Connection.ConnectionString = ConnectionString;
            eventAdapter.Connection.ConnectionString = ConnectionString;

            theset.Yaxis0name = MeasurementName;
            theset.Yaxis1name = "";

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

            cycleDataRows = cycleDataAdapter.GetDataBy(Convert.ToInt32(EventInstanceID)).ToList();
            cycleCurves = cycleDataRows.Select(ToDataSeries).ToList();

            //RMS, Phase angle, Peak, and Error
            //VAN, VBN, VCN, IAN, IBN, ICN, IR

            char typeChar = MeasurementName == "Voltage" ? 'V' : 'I';

            // Defines the names of the series that will be added to theset in the order that they will appear
            string[] seriesOrder = new string[] { "RMS", "Peak", "Angle" }
                .SelectMany(category => new string[] { "AN", "BN", "CN" }.Select(phase => string.Format("{0} {1}{2}", category, typeChar, phase)))
                .ToArray();

            // Defines the names of the series as they appear in cycleCurves
            string[] seriesNames =
            {
                "RMS VAN", "Angle VAN", "Peak VAN", "Error VAN",
                "RMS VBN", "Angle VBN", "Peak VBN", "Error VBN",
                "RMS VCN", "Angle VCN", "Peak VCN", "Error VCN",
                "RMS IAN", "Angle IAN", "Peak IAN", "Error IAN",
                "RMS IBN", "Angle IBN", "Peak IBN", "Error IBN",
                "RMS ICN", "Angle ICN", "Peak ICN", "Error ICN",
                "RMS IR", "Angle IR", "Peak IR", "Error IR"
            };

            // Lookup table to find a DataSeries by name
            Dictionary<string, DataSeries> seriesNameLookup = cycleCurves[0].DataSeries
                .Select((series, index) => new { Name = seriesNames[index], Series = series })
                .ToDictionary(obj => obj.Name, obj => obj.Series);

            int i = 0;
            if (cycleCurves.Count > 0)
            {
                foreach (string seriesName in seriesOrder)
                {
                    DataSeries theseries = seriesNameLookup[seriesName];

                    int datacount = theseries.DataPoints.Count();
                    signalDetail theitem = new signalDetail();

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

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

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

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

                    int j = 0;
                    DateTime beginticks = theseries.DataPoints[0].Time;
                    foreach (FaultData.DataAnalysis.DataPoint thepoint in theseries.DataPoints)
                    {
                        double elapsed = thepoint.Time.Subtract(beginticks).TotalSeconds;
                        //theset.xAxis[j] = elapsed.ToString();
                        theitem.data[j] = thepoint.Value;
                        j++;
                    }

                    theset.data.Add(theitem);
                }
            }
        }
        return (theset);
    }
    public eventSet getSignalDataByIDAndType(string EventInstanceID, String DataType)
    {
        eventSet theset = new eventSet();
        theset.data = new List<signalDetail>();
        MeterData.EventDataTable events;
        DataGroup eventDataGroup = new DataGroup();
        using (MeterInfoDataContext meterInfo = new MeterInfoDataContext(ConnectionString))
        using (EventTableAdapter eventAdapter = new EventTableAdapter())
        using (EventDataTableAdapter eventDataAdapter = new EventDataTableAdapter())

        {
            eventAdapter.Connection.ConnectionString = ConnectionString;
            eventDataAdapter.Connection.ConnectionString = ConnectionString;

            events = eventAdapter.GetDataByID(Convert.ToInt32(EventInstanceID));

            foreach (MeterData.EventRow evt in events)
            {
                Meter meter = meterInfo.Meters.Single(m => m.ID == evt.MeterID);

                FaultData.Database.Line line = meterInfo.Lines.Single(l => l.ID == evt.LineID);

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

                //eventDataGroup.FromData(meter, evt.Data);

                int i = -1;

                int datacount = eventDataGroup.DataSeries[0].DataPoints.Count();
                theset.xAxis = new string[datacount];

                foreach (DataSeries theseries in eventDataGroup.DataSeries)
                {
                    i++;

                    signalDetail theitem = new signalDetail();

                    string measurementType = "I"; // Assume Current, sorry this is ugly
                    string phasename = theseries.SeriesInfo.Channel.Phase.Name;

                    if (theseries.SeriesInfo.Channel.MeasurementType.Name.Equals("Voltage"))
                    {
                        measurementType = "V";
                    }

                    if (theseries.SeriesInfo.Channel.MeasurementType.Name.Equals("Power"))
                    {
                        measurementType = "P";
                    }

                    if (theseries.SeriesInfo.Channel.MeasurementType.Name.Equals("Energy"))
                    {
                        measurementType = "E";
                    }

                    if (theseries.SeriesInfo.Channel.MeasurementType.Name.Equals("Digital"))
                    {
                        if (theseries.SeriesInfo.Channel.MeasurementCharacteristic.Name == "None")
                            continue;

                        measurementType = "D";
                        phasename = theseries.SeriesInfo.Channel.Description;
                    }

                    if (DataType != null)
                    {
                        if (measurementType != DataType)
                        {
                            continue;
                        }
                    }

                    if (theseries.SeriesInfo.SeriesType.Name.Substring(0, 3) == "Min") continue;
                    if (theseries.SeriesInfo.SeriesType.Name.Substring(0, 3) == "Max") continue;

                    theset.Yaxis0name = "Current";

                    if (measurementType == "V")
                    {
                        theset.Yaxis0name = "Voltage";
                    }

                    if (measurementType == "D")
                    {
                        theset.Yaxis0name = "Breakers";
                    }

                    //theitem.name = theseries.SeriesInfo.SeriesType.Name.Substring(0, 3) + " " + measurementType + theseries.SeriesInfo.Channel.Phase.Name;
                    theitem.name = measurementType + phasename;
                    theitem.data = new double[datacount];
                    theitem.type = "line";
                    theitem.yAxis = 0;

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

                    int j = 0;
                    DateTime beginticks = eventDataGroup.DataSeries[i].DataPoints[0].Time;
                    foreach (FaultData.DataAnalysis.DataPoint thepoint in eventDataGroup.DataSeries[i].DataPoints)
                    {
                        double elapsed = thepoint.Time.Subtract(beginticks).TotalSeconds;
                        theset.xAxis[j] = elapsed.ToString();
                        theitem.data[j] = thepoint.Value;
                        j++;
                    }
                    theset.data.Add(theitem);
                }
                break;
            }
        }

        //theset = FetchFaultSegmentDetails(EventInstanceID, theset);

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

        return (thereturnset);
    }
Пример #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 <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);
    }