示例#1
0
        private List <D3Series> QueryCurrentData(Meter meter, Event evt)
        {
            DataGroup dataGroup = OpenSEEController.QueryDataGroup(evt.ID, meter);

            List <D3Series> WaveForm = dataGroup.DataSeries.Where(ds => ds.SeriesInfo.Channel.MeasurementType.Name == "Current"
                                                                  ).Select(
                ds => new D3Series()
            {
                ChannelID   = ds.SeriesInfo.Channel.ID,
                ChartLabel  = OpenSEEController.GetChartLabel(ds.SeriesInfo.Channel),
                LegendGroup = ds.SeriesInfo.Channel.Asset.AssetName,
                DataPoints  = ds.DataPoints.Select(dataPoint => new double[] { dataPoint.Time.Subtract(m_epoch).TotalMilliseconds, dataPoint.Value }).ToList(),
            }).ToList();

            WaveForm.Sort((a, b) => {
                if (a.LegendGroup == b.LegendGroup)
                {
                    return(a.ChartLabel.CompareTo(b.ChartLabel));
                }
                return(a.LegendGroup.CompareTo(b.LegendGroup));
            });

            VICycleDataGroup viCycleDataGroup = OpenSEEController.QueryVICycleDataGroup(evt.ID, meter);

            List <D3Series> result = new List <D3Series>();

            foreach (D3Series w in WaveForm)
            {
                result.Add(w);
                int index = viCycleDataGroup.CycleDataGroups.FindIndex(item => item.RMS.SeriesInfo.ChannelID == w.ChannelID);
                if (index > -1)
                {
                    result.Add(new D3Series
                    {
                        ChannelID   = w.ChannelID,
                        DataPoints  = viCycleDataGroup.CycleDataGroups[index].RMS.DataPoints.Select(dataPoint => new double[] { dataPoint.Time.Subtract(m_epoch).TotalMilliseconds, dataPoint.Value }).ToList(),
                        ChartLabel  = w.ChartLabel + " RMS",
                        LegendGroup = w.LegendGroup,
                    });

                    result.Add(new D3Series
                    {
                        ChannelID   = w.ChannelID,
                        DataPoints  = viCycleDataGroup.CycleDataGroups[index].Phase.Multiply(180.0D / Math.PI).DataPoints.Select(dataPoint => new double[] { dataPoint.Time.Subtract(m_epoch).TotalMilliseconds, dataPoint.Value }).ToList(),
                        ChartLabel  = w.ChartLabel + " Phase",
                        LegendGroup = w.LegendGroup,
                    });
                }
            }


            return(result);
        }
示例#2
0
        private List <D3Series> QueryDigitalData(Meter meter, Event evt)
        {
            DataGroup dataGroup = OpenSEEController.QueryDataGroup(evt.ID, meter);

            List <D3Series> result = dataGroup.DataSeries.Where(ds => ds.SeriesInfo.Channel.MeasurementType.Name == "Digital"
                                                                ).Select(
                ds => new D3Series()
            {
                ChannelID   = ds.SeriesInfo.Channel.ID,
                ChartLabel  = OpenSEEController.GetChartLabel(ds.SeriesInfo.Channel),
                LegendGroup = ds.SeriesInfo.Channel.Asset.AssetName,
                DataPoints  = ds.DataPoints.Select(dataPoint => new double[] { dataPoint.Time.Subtract(m_epoch).TotalMilliseconds, dataPoint.Value }).ToList(),
            }).ToList();

            return(result);
        }
示例#3
0
        public void ExportFFTToCSV(Stream returnStream, NameValueCollection requestParameters)
        {
            int eventId = int.Parse(requestParameters["eventID"]);

            using (AdoDataConnection connection = new AdoDataConnection("dbOpenXDA"))
                using (StreamWriter writer = new StreamWriter(returnStream))
                {
                    double startTime = requestParameters["startDate"] == null ? 0.0 : double.Parse(requestParameters["startDate"]);
                    int    cycles    = requestParameters["cycles"] == null ? 0 : int.Parse(requestParameters["cycles"]);

                    Event evt   = (new TableOperations <Event>(connection)).QueryRecordWhere("ID = {0}", eventId);
                    Meter meter = new TableOperations <Meter>(connection).QueryRecordWhere("ID = {0}", evt.MeterID);
                    meter.ConnectionFactory = () => new AdoDataConnection("dbOpenXDA");

                    AnalyticController ctrl      = new AnalyticController();
                    DataGroup          dataGroup = OpenSEEController.QueryDataGroup(evt.ID, meter);

                    List <D3Series> harmonics = ctrl.GetFFTLookup(dataGroup, startTime, cycles); // AnalyticController.GetFFTLookup(dataGroup, startTime, cycles);

                    List <string> headers = new List <string>()
                    {
                        "Harmonic"
                    };

                    headers = headers.Concat(harmonics.Select(item => item.LegendGroup + " " + item.LegendVertical + " " + item.LegendHorizontal)).ToList();

                    if (headers.Count == 1)
                    {
                        return;
                    }

                    // Write the CSV header to the file
                    writer.WriteLine(string.Join(",", headers));

                    for (int i = 0; i < harmonics.First().DataPoints.Count(); ++i)
                    {
                        List <string> line = new List <string>()
                        {
                            harmonics.First().DataPoints[i][0].ToString()
                        };

                        line = line.Concat(harmonics.Select(item => item.DataPoints[i][1].ToString())).ToList();

                        writer.WriteLine(string.Join(",", line));
                    }
                }
        }
示例#4
0
        private List <D3Series> QueryAnalogData(Meter meter, Event evt)
        {
            DataGroup dataGroup = OpenSEEController.QueryDataGroup(evt.ID, meter);

            List <D3Series> dataLookup = dataGroup.DataSeries.Where(ds =>
                                                                    ds.SeriesInfo.Channel.MeasurementType.Name != "Digital" &&
                                                                    ds.SeriesInfo.Channel.MeasurementType.Name != "Voltage" &&
                                                                    ds.SeriesInfo.Channel.MeasurementType.Name != "Current" &&
                                                                    ds.SeriesInfo.Channel.MeasurementType.Name != "TripCoilCurrent").Select(ds =>
                                                                                                                                            new D3Series()
            {
                ChannelID   = ds.SeriesInfo.Channel.ID,
                ChartLabel  = ds.SeriesInfo.Channel.Description ?? OpenSEEController.GetChartLabel(ds.SeriesInfo.Channel),
                LegendGroup = ds.SeriesInfo.Channel.Asset.AssetName,
                DataPoints  = ds.DataPoints.Select(dataPoint => new double[] { dataPoint.Time.Subtract(m_epoch).TotalMilliseconds, dataPoint.Value }).ToList(),
            }).ToList();


            return(dataLookup);
        }
示例#5
0
        private List <D3Series> QueryVoltageData(Meter meter, Event evt)
        {
            bool useLL;

            using (AdoDataConnection connection = new AdoDataConnection("systemSettings"))
            {
                useLL = connection.ExecuteScalar <bool?>("SELECT Value FROM Settings WHERE Name = 'useLLVoltage'") ?? false;
            }

            DataGroup dataGroup = OpenSEEController.QueryDataGroup(evt.ID, meter);

            List <D3Series> WaveForm = dataGroup.DataSeries.Where(ds => ds.SeriesInfo.Channel.MeasurementType.Name == "Voltage" && (
                                                                      (useLL && !(ds.SeriesInfo.Channel.Phase.Name == "AB" || ds.SeriesInfo.Channel.Phase.Name == "BC" || ds.SeriesInfo.Channel.Phase.Name == "CA")) ||
                                                                      (!useLL && (ds.SeriesInfo.Channel.Phase.Name == "AB" || ds.SeriesInfo.Channel.Phase.Name == "BC" || ds.SeriesInfo.Channel.Phase.Name == "CA")))
                                                                  ).Select(
                ds => new D3Series()
            {
                ChannelID   = ds.SeriesInfo.Channel.ID,
                ChartLabel  = OpenSEEController.GetChartLabel(ds.SeriesInfo.Channel),
                LegendGroup = ds.SeriesInfo.Channel.Asset.AssetName,
                DataPoints  = ds.DataPoints.Select(dataPoint => new double[] { dataPoint.Time.Subtract(m_epoch).TotalMilliseconds, dataPoint.Value }).ToList(),
            }).ToList();

            WaveForm.Sort((a, b) => {
                if (a.LegendGroup == b.LegendGroup)
                {
                    return(a.ChartLabel.CompareTo(b.ChartLabel));
                }
                return(a.LegendGroup.CompareTo(b.LegendGroup));
            });

            VICycleDataGroup viCycleDataGroup = OpenSEEController.QueryVICycleDataGroup(evt.ID, meter);

            List <D3Series> result = new List <D3Series>();

            foreach (D3Series w in WaveForm)
            {
                result.Add(w);
                int index = viCycleDataGroup.CycleDataGroups.FindIndex(item => item.RMS.SeriesInfo.ChannelID == w.ChannelID);
                if (index > -1)
                {
                    result.Add(new D3Series
                    {
                        ChannelID   = w.ChannelID,
                        DataPoints  = viCycleDataGroup.CycleDataGroups[index].RMS.DataPoints.Select(dataPoint => new double[] { dataPoint.Time.Subtract(m_epoch).TotalMilliseconds, dataPoint.Value }).ToList(),
                        ChartLabel  = w.ChartLabel + " RMS",
                        LegendGroup = w.LegendGroup,
                    });

                    result.Add(new D3Series
                    {
                        ChannelID   = w.ChannelID,
                        DataPoints  = viCycleDataGroup.CycleDataGroups[index].Phase.Multiply(180.0D / Math.PI).DataPoints.Select(dataPoint => new double[] { dataPoint.Time.Subtract(m_epoch).TotalMilliseconds, dataPoint.Value }).ToList(),
                        ChartLabel  = w.ChartLabel + " Phase",
                        LegendGroup = w.LegendGroup,
                    });
                }
            }


            return(result);
        }
示例#6
0
        public void ExportToPQDS(Stream returnStream, NameValueCollection requestParameters)
        {
            int eventID = int.Parse(requestParameters["eventID"]);

            using (AdoDataConnection connection = new AdoDataConnection("dbOpenXDA"))
            {
                Event evt   = (new TableOperations <Event>(connection)).QueryRecordWhere("ID = {0}", eventID);
                Meter meter = new TableOperations <Meter>(connection).QueryRecordWhere("ID = {0}", evt.MeterID);
                meter.ConnectionFactory = () => new AdoDataConnection("dbOpenXDA");



                // only get Single Voltage and Single Current Data for This....
                List <PQDS.DataSeries>  data     = new List <PQDS.DataSeries>();
                List <PQDS.MetaDataTag> metaData = new List <PQDS.MetaDataTag>();

                VIDataGroup dataGroup = new VIDataGroup(OpenSEEController.QueryDataGroup(evt.ID, meter));

                if (dataGroup.VA != null)
                {
                    data.Add(PQDSSeries(dataGroup.VA, "va"));
                }
                if (dataGroup.VB != null)
                {
                    data.Add(PQDSSeries(dataGroup.VB, "vb"));
                }
                if (dataGroup.VC != null)
                {
                    data.Add(PQDSSeries(dataGroup.VC, "vc"));
                }

                if (dataGroup.IA != null)
                {
                    data.Add(PQDSSeries(dataGroup.IA, "ia"));
                }
                if (dataGroup.IB != null)
                {
                    data.Add(PQDSSeries(dataGroup.IB, "ib"));
                }
                if (dataGroup.IC != null)
                {
                    data.Add(PQDSSeries(dataGroup.IC, "ic"));
                }
                if (dataGroup.IR != null)
                {
                    data.Add(PQDSSeries(dataGroup.IR, "in"));
                }


                if (data.Count() == 0)
                {
                    return;
                }

                // Add MetaData Information
                metaData = PQDSMetaData(evt, meter);

                PQDS.PQDSFile file = new PQDS.PQDSFile(metaData, data, evt.StartTime);

                using (StreamWriter writer = new StreamWriter(returnStream))
                {
                    file.WriteToStream(writer);
                }
            }
        }