Ejemplo n.º 1
0
        // Shamelessly copy pasted from the XDAWaveFormDataParser
        // Thanks other Stephen
        private void ParseSELEVE()
        {
            try
            {
                // Parse event file
                EventFile parsedFile = EventFile.Parse(m_currentFilePath);

                // Convert to common channel format
                if (parsedFile.EventReports.Count > 0)
                {
                    m_channels = parsedFile.EventReports
                                 .SelectMany(report => report.AnalogSection.AnalogChannels.Select(channel => MakeParsedChannel(report, channel)))
                                 .ToList();
                }
                else if (parsedFile.CommaSeparatedEventReports.Count > 0)
                {
                    m_channels = parsedFile.CommaSeparatedEventReports
                                 .SelectMany(report => report.AnalogSection.AnalogChannels.Select(channel => MakeParsedChannel(report, channel)))
                                 .ToList();
                }
            }
            catch (Exception e)
            {
                e.Source = m_currentFileRootName;
                ExceptionList.Add(e);
            }
        }
Ejemplo n.º 2
0
        private void SELEVEButton_Click(object sender, EventArgs e)
        {
            EventFile parsedFile;

            using (OpenFileDialog dialog = new OpenFileDialog())
            {
                dialog.Filter = "SEL Event Files|*.eve;*.sel;*.cev;|Text Files|*.txt|All Files|*.*";
                dialog.Title  = "Browse SEL Event Files";

                if (dialog.ShowDialog() == DialogResult.Cancel)
                {
                    return;
                }

                if (!File.Exists(dialog.FileName))
                {
                    return;
                }

                // Parse event file
                parsedFile = EventFile.Parse(dialog.FileName);

                // Convert to common channel format
                if (parsedFile.EventReports.Count > 0)
                {
                    m_channels = parsedFile.EventReports
                                 .SelectMany(report => report.AnalogSection.AnalogChannels.Select(channel => MakeParsedChannel(report, channel)))
                                 .ToList();
                }
                else if (parsedFile.CommaSeparatedEventReports.Count > 0)
                {
                    m_channels = parsedFile.CommaSeparatedEventReports
                                 .SelectMany(report => report.AnalogSection.AnalogChannels.Select(channel => MakeParsedChannel(report, channel)))
                                 .ToList();
                }
                else
                {
                    m_channels = null;
                }

                // Clear the list box and data chart
                ChannelListBox.Items.Clear();
                DataChart.Series.Clear();

                // Populate the list box with channel names
                ChannelListBox.Items.AddRange(m_channels
                                              .Select((channel, index) => string.Format("[{0}] {1}", index, channel.Name))
                                              .Cast <object>()
                                              .ToArray());

                // Select the first channel in the list
                ChannelListBox.SelectedIndex = 0;

                // Change the title text of the window to show what file the user has open
                m_fileName = dialog.SafeFileName;
                Text       = string.Format("SEL EVE - [{0}]", dialog.SafeFileName);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Parses the file into a meter data set per meter contained in the file.
        /// </summary>
        /// <param name="filePath">The path to the file to be parsed.</param>
        /// <returns>List of meter data sets, one per meter.</returns>
        public void Parse(string filePath)
        {
            Channel         channel;
            DataSeries      series;
            List <DateTime> timeSamples;
            List <double>   valueSamples;

            if ((object)m_eventFile == null)
            {
                m_eventFile = EventFile.Parse(filePath);
            }

            if (!m_eventFile.EventReports.Any())
            {
                return;
            }

            m_meterDataSet.Meter           = new Meter();
            m_meterDataSet.Meter.AssetKey  = m_eventFile.EventReports[0].Header.RelayID;
            m_meterDataSet.Meter.Name      = m_eventFile.EventReports[0].Header.RelayID;
            m_meterDataSet.Meter.ShortName = new string(m_eventFile.EventReports[0].Header.RelayID.ToNonNullString().Take(50).ToArray());

            m_meterDataSet.Meter.MeterLocation             = new MeterLocation();
            m_meterDataSet.Meter.MeterLocation.AssetKey    = m_eventFile.EventReports[0].Header.StationID;
            m_meterDataSet.Meter.MeterLocation.Name        = m_eventFile.EventReports[0].Header.StationID;
            m_meterDataSet.Meter.MeterLocation.ShortName   = new string(m_eventFile.EventReports[0].Header.StationID.ToNonNullString().Take(50).ToArray());
            m_meterDataSet.Meter.MeterLocation.Description = m_eventFile.EventReports[0].Header.StationID;

            foreach (EventReport report in m_eventFile.EventReports)
            {
                for (int i = 0; i < report.AnalogSection.AnalogChannels.Count; i++)
                {
                    channel = MakeParsedChannel(report, i);
                    series  = new DataSeries();

                    timeSamples  = report.AnalogSection.TimeChannel.Samples;
                    valueSamples = report.AnalogSection.AnalogChannels[i].Samples;

                    series.SeriesInfo = channel.Series[0];

                    series.DataPoints = timeSamples
                                        .Zip(valueSamples, (time, value) => new DataPoint()
                    {
                        Time = time, Value = value
                    })
                                        .ToList();

                    if (new string[] { "VA", "VB", "VC" }.Contains(report.AnalogSection.AnalogChannels[i].Name))
                    {
                        m_meterDataSet.DataSeries.Add(series.Multiply(1000.0));
                    }
                    else
                    {
                        m_meterDataSet.DataSeries.Add(series);
                    }
                }
            }
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Determines whether the file can be parsed at this time.
 /// </summary>
 /// <param name="filePath">The path to the file to be parsed.</param>
 /// <param name="fileCreationTime">The time the file was created.</param>
 /// <returns>True if the file can be parsed; false otherwise.</returns>
 public bool CanParse(string filePath, DateTime fileCreationTime)
 {
     try
     {
         m_eventFile = EventFile.Parse(filePath, SystemFrequency, MaxFileDuration);
         return(true);
     }
     catch (IOException)
     {
         return(false);
     }
 }
Ejemplo n.º 5
0
        /// <summary>
        /// Parses the file into a meter data set per meter contained in the file.
        /// </summary>
        /// <param name="filePath">The path to the file to be parsed.</param>
        /// <returns>List of meter data sets, one per meter.</returns>
        public void Parse(string filePath)
        {
            if ((object)m_eventFile == null)
            {
                m_eventFile = EventFile.Parse(filePath, SystemFrequency, MaxFileDuration);
            }

            if (!m_eventFile.EventReports.Any() && !m_eventFile.CommaSeparatedEventReports.Any())
            {
                return;
            }

            Header header = m_eventFile.EventReports.FirstOrDefault()?.Header
                            ?? m_eventFile.CommaSeparatedEventReports[0].Header;

            Meter meter = new Meter();

            meter.MeterLocation = new MeterLocation();
            meter.Channels      = new List <Channel>();
            meter.AssetKey      = header.RelayID;
            meter.Name          = header.RelayID;
            meter.ShortName     = new string(header.RelayID.ToNonNullString().Take(50).ToArray());

            MeterLocation meterLocation = meter.MeterLocation;

            meterLocation.Meters = new List <Meter>()
            {
                meter
            };
            meterLocation.AssetKey    = header.StationID;
            meterLocation.Name        = header.StationID;
            meterLocation.ShortName   = new string(header.StationID.ToNonNullString().Take(50).ToArray());
            meterLocation.Description = header.StationID;

            foreach (EventReport report in m_eventFile.EventReports)
            {
                for (int i = 0; i < report.AnalogSection.AnalogChannels.Count; i++)
                {
                    Channel channel = MakeParsedAnalog(report, i);
                    channel.Meter = meter;
                    meter.Channels.Add(channel);

                    List <DateTime> timeSamples  = report.AnalogSection.TimeChannel.Samples;
                    List <double>   valueSamples = report.AnalogSection.AnalogChannels[i].Samples;
                    DataSeries      dataSeries   = new DataSeries();

                    dataSeries.DataPoints = timeSamples
                                            .Zip(valueSamples, (time, value) => new DataPoint()
                    {
                        Time = time, Value = value
                    })
                                            .ToList();

                    if (new string[] { "VA", "VB", "VC", "VS" }.Contains(report.AnalogSection.AnalogChannels[i].Name))
                    {
                        dataSeries = dataSeries.Multiply(1000.0D);
                    }

                    dataSeries.SeriesInfo = channel.Series[0];
                    m_meterDataSet.DataSeries.Add(dataSeries);
                }

                for (int i = 0; i < report.AnalogSection.DigitalChannels.Count; i++)
                {
                    Channel channel = MakeParsedDigital(report, i);

                    if (channel.Name == "*")
                    {
                        continue;
                    }

                    channel.Meter = meter;
                    meter.Channels.Add(channel);

                    List <DateTime> timeSamples    = report.AnalogSection.TimeChannel.Samples;
                    List <bool?>    digitalSamples = report.AnalogSection.DigitalChannels[i].Samples;
                    DataSeries      dataSeries     = new DataSeries();

                    dataSeries.SeriesInfo = channel.Series[0];

                    dataSeries.DataPoints = timeSamples
                                            .Zip(digitalSamples, (time, value) => new { Time = time, Value = value })
                                            .Where(x => x.Value != null)
                                            .Select(x => new DataPoint {
                        Time = x.Time, Value = Convert.ToDouble(x.Value)
                    })
                                            .ToList();

                    m_meterDataSet.Digitals.Add(dataSeries);
                }

                ComplexNumber z1 = new ComplexNumber(0.0D, 0.0D);
                ComplexNumber z0 = new ComplexNumber(0.0D, 0.0D);
                double        groupSetting;

                if (double.TryParse(report.GetGroupSettings("Z1MAG"), out groupSetting))
                {
                    z1.Magnitude = groupSetting;
                }

                if (double.TryParse(report.GetGroupSettings("Z1ANG"), out groupSetting))
                {
                    z1.Angle = Angle.FromDegrees(groupSetting);
                }

                if (double.TryParse(report.GetGroupSettings("Z0MAG"), out groupSetting))
                {
                    z0.Magnitude = groupSetting;
                }

                if (double.TryParse(report.GetGroupSettings("Z0ANG"), out groupSetting))
                {
                    z0.Angle = Angle.FromDegrees(groupSetting);
                }

                if (z1 != z0)
                {
                    m_meterDataSet.Configuration.R1 = z1.Real;
                    m_meterDataSet.Configuration.X1 = z1.Imaginary;
                    m_meterDataSet.Configuration.R0 = z0.Real;
                    m_meterDataSet.Configuration.X0 = z0.Imaginary;

                    if (double.TryParse(report.GetGroupSettings("LL"), out groupSetting))
                    {
                        m_meterDataSet.Configuration.LineLength = groupSetting;
                    }
                }
            }

            foreach (CommaSeparatedEventReport report in m_eventFile.CommaSeparatedEventReports)
            {
                for (int i = 0; i < report.AnalogSection.AnalogChannels.Count; i++)
                {
                    Channel channel = MakeParsedAnalog(report, i);
                    channel.Meter = meter;
                    meter.Channels.Add(channel);

                    List <DateTime> timeSamples  = report.AnalogSection.TimeChannel.Samples;
                    List <double>   valueSamples = report.AnalogSection.AnalogChannels[i].Samples;
                    DataSeries      dataSeries   = new DataSeries();

                    dataSeries.DataPoints = timeSamples
                                            .Zip(valueSamples, (time, value) => new DataPoint()
                    {
                        Time = time, Value = value
                    })
                                            .ToList();

                    dataSeries.SeriesInfo = channel.Series[0];
                    m_meterDataSet.DataSeries.Add(dataSeries);
                }

                for (int i = 0; i < report.AnalogSection.DigitalChannels.Count; i++)
                {
                    Channel channel = MakeParsedDigital(report, i);

                    if (channel.Name == "*")
                    {
                        continue;
                    }

                    channel.Meter = meter;
                    meter.Channels.Add(channel);

                    List <DateTime> timeSamples    = report.AnalogSection.TimeChannel.Samples;
                    List <bool?>    digitalSamples = report.AnalogSection.DigitalChannels[i].Samples;
                    DataSeries      dataSeries     = new DataSeries();

                    dataSeries.SeriesInfo = channel.Series[0];

                    dataSeries.DataPoints = timeSamples
                                            .Zip(digitalSamples, (time, value) => new { Time = time, Value = value })
                                            .Where(x => x.Value != null)
                                            .Select(x => new DataPoint {
                        Time = x.Time, Value = Convert.ToDouble(x.Value)
                    })
                                            .ToList();

                    m_meterDataSet.Digitals.Add(dataSeries);
                }
            }

            m_meterDataSet.Meter = meter;
        }