Ejemplo n.º 1
0
        // Fields

        #endregion

        #region [ Properties ]


        #endregion

        #region [ Static ]

        // Static Methods

        public static Dictionary <string, string> Parse(string[] lines, ref int index)
        {
            EventFile.SkipBlanks(lines, ref index);

            Dictionary <string, string> dictionary = new Dictionary <string, string>();

            while (index < lines.Length && lines[index] != "")
            {
                if (lines[index].Contains("="))
                {
                    string line  = new string(lines[index].ToCharArray());
                    int    count = line.Count(s => s == '=');

                    for (int x = 0; x < count; ++x)
                    {
                        string key = line.Split(new[] { '=' }, 2)[0].Trim();
                        line = line.Split(new[] { '=' }, 2)[1].TrimStart();
                        string value = line.Split(new[] { ' ' }, 2)[0];
                        line = line.Split(new[] { ' ' }, 2)[line.Split(new[] { ' ' }, 2).Length - 1].TrimStart();
                        dictionary.Add(key, value);
                    }
                }
                ++index;
            }


            return(dictionary);
        }
Ejemplo n.º 2
0
Archivo: Header.cs Proyecto: xj0229/gsf
        // Static Methods

        public static Header Parse(string[] lines, ref int index)
        {
            const string HeaderLine1 = @"(\S.*)\s+Date:\s+(\S+)\s+Time:\s+(\S+)";
            const string HeaderLine2 = @"(\S.*)(?:\s+Serial Number: (\d+))?";

            Header header = new Header();

            Match    regexMatch;
            DateTime eventTime;
            string   eventTimeString;
            int      serialNumber;

            if (index < lines.Length)
            {
                // Apply regex match to get information contained on first line of header
                regexMatch = Regex.Match(lines[index], HeaderLine1);

                if (regexMatch.Success)
                {
                    // Get relay ID from line 1
                    header.RelayID = regexMatch.Groups[1].Value.Trim();

                    // Build date/time string for parsing
                    eventTimeString = string.Format("{0} {1}", regexMatch.Groups[2].Value, regexMatch.Groups[3].Value);

                    // Get event time from line 1
                    if (EventFile.TryParseDateTime(eventTimeString, out eventTime))
                    {
                        header.EventTime = eventTime;
                    }

                    // Advance to the next line
                    index++;

                    if (index < lines.Length)
                    {
                        // Apply regex match to get information contained on second line of header
                        regexMatch = Regex.Match(lines[index], HeaderLine2);

                        if (regexMatch.Success)
                        {
                            // Get station ID and serial number from line 2
                            header.StationID = regexMatch.Groups[1].Value.Trim();

                            if (int.TryParse(regexMatch.Groups[2].Value, out serialNumber))
                            {
                                header.SerialNumber = serialNumber;
                            }

                            // Advance to the next line
                            index++;
                        }
                    }
                }
            }

            return(header);
        }
Ejemplo n.º 3
0
        public static EventFile Parse(string filename, double systemFrequency)
        {
            string[] lineSeparators = { "\r\n", "\n\r", "\r", "\n" };

            EventFile parsedFile = new EventFile();
            string    fileText   = File.ReadAllText(filename);

            int    firstLineSeparatorIndex = lineSeparators.Select(separator => fileText.IndexOf(separator)).Where(index => index >= 0).Min();
            string lineSeparator           = lineSeparators.First(separator => fileText.IndexOf(separator) == firstLineSeparatorIndex);

            string[] lines = fileText
                             .Split(new string[] { lineSeparator }, StringSplitOptions.None)
                             .Select(line => line.RemoveControlCharacters())
                             .ToArray();

            int lineIndex = 0;

            string       command;
            EventReport  parsedEventReport;
            EventHistory parsedEventHistory;
            CommaSeparatedEventReport parsedCommaSeparatedEventReport;

            while (lineIndex < lines.Length)
            {
                // Parse next command from the file
                command = ParseCommand(lines, ref lineIndex);

                // Skip to the next nonblank line
                SkipBlanks(lines, ref lineIndex);

                if (command.ToUpper().Contains("EVE"))
                {
                    parsedEventReport         = EventReport.Parse(systemFrequency, lines, ref lineIndex);
                    parsedEventReport.Command = command;
                    parsedFile.Add(parsedEventReport);
                }
                else if (command.ToUpper().Contains("CEV"))
                {
                    parsedCommaSeparatedEventReport         = CommaSeparatedEventReport.Parse(lines, ref lineIndex);
                    parsedCommaSeparatedEventReport.Command = (command.ToUpper().Contains("FID") ? command.Split('\"')[0] : command);
                    parsedFile.Add(parsedCommaSeparatedEventReport);
                }
                else if (command.ToUpper().Contains("HIS"))
                {
                    parsedEventHistory         = EventHistory.Parse(lines, ref lineIndex);
                    parsedEventHistory.Command = command;
                    parsedFile.Add(parsedEventHistory);
                }

                // Skip to the next nonblank line
                SkipBlanks(lines, ref lineIndex);
            }

            return(parsedFile);
        }
Ejemplo n.º 4
0
        public static EventReport Parse(double systemFrequency, string[] lines, ref int index)
        {
            EventReport eventReport = new EventReport();
            int         firmwareIndex;

            // Parse the report header
            eventReport.Header = Header.Parse(lines, ref index);

            // Skip to the next nonblank line
            EventFile.SkipBlanks(lines, ref index);

            // Get the index of the line where
            // the firmware information is located
            firmwareIndex = index;

            // Parse the firmware and event number
            eventReport.Firmware    = Firmware.Parse(lines, ref firmwareIndex);
            eventReport.EventNumber = ParseEventNumber(lines, ref index);
            index = Math.Max(firmwareIndex, index);

            // Skip to the next nonblank line
            EventFile.SkipBlanks(lines, ref index);

            // Parse the analog section of the report
            eventReport.AnalogSection = AnalogSection.Parse(eventReport.Header.EventTime, systemFrequency, lines, ref index);

            if (lines.Length < index)
            {
                // skip digitals for now
                while (!lines[index].ToLower().Contains("group settings") && index < lines.Length)
                {
                    ++index;
                }
                ++index;
                // Parse Group settings
                eventReport.GroupSetting = Settings.Parse(lines, ref index);
                EventFile.SkipBlanks(lines, ref index);

                // Parse Logic control equations
                ++index;
                EventFile.SkipBlanks(lines, ref index);
                eventReport.ControlEquations = ControlEquation.Parse(lines, ref index);
                EventFile.SkipBlanks(lines, ref index);

                // Parse Global Settings
                eventReport.GlobalSetting = Settings.Parse(lines, ref index);
            }
            return(eventReport);
        }
Ejemplo n.º 5
0
        // Static Methods

        public static EventHistory Parse(string[] lines, ref int index)
        {
            EventHistory eventHistory = new EventHistory();

            // Parse the report header
            eventHistory.Header = Header.Parse(lines, ref index);

            // Skip to the next nonblank line
            EventFile.SkipBlanks(lines, ref index);

            // Parse event histories
            eventHistory.Histories = EventHistoryRecord.ParseRecords(lines, ref index);

            return(eventHistory);
        }
Ejemplo n.º 6
0
        // Fields

        #endregion

        #region [ Properties ]


        #endregion

        #region [ Static ]

        // Static Methods

        public static Dictionary <string, string> Parse(string[] lines, ref int index)
        {
            EventFile.SkipBlanks(lines, ref index);

            Dictionary <string, string> dictionary = new Dictionary <string, string>();

            while (index < lines.Length && lines[index] != "")
            {
                if (lines[index].Contains("="))
                {
                    string line = lines[index];
                    dictionary.Add(line.Split('=')[0].Trim(), line.Split('=')[1].Trim());
                }
                ++index;
            }
            return(dictionary);
        }
Ejemplo n.º 7
0
        // Static Methods

        public static EventFile Parse(string filename)
        {
            string[] lineSeparators = { "\r\n", "\n\r", "\r", "\n" };

            EventFile parsedFile = new EventFile();
            string fileText = File.ReadAllText(filename);

            int firstLineSeparatorIndex = lineSeparators.Select(separator => fileText.IndexOf(separator)).Where(index => index >= 0).Min();
            string lineSeparator = lineSeparators.First(separator => fileText.IndexOf(separator) == firstLineSeparatorIndex);

            string[] lines = fileText
                .Split(new string[] { lineSeparator }, StringSplitOptions.None)
                .Select(line => line.RemoveControlCharacters())
                .ToArray();

            int lineIndex = 0;

            string command;
            EventReport parsedEventReport;
            EventHistory parsedEventHistory;

            while (lineIndex < lines.Length)
            {
                // Parse next command from the file
                command = ParseCommand(lines, ref lineIndex);

                // Skip to the next nonblank line
                SkipBlanks(lines, ref lineIndex);

                if (command.ToUpper().Contains("EVE"))
                {
                    parsedEventReport = ParseEventReport(lines, ref lineIndex);
                    parsedEventReport.Command = command;
                    parsedFile.Add(parsedEventReport);
                }
                else if (command.ToUpper().Contains("HIS"))
                {
                    parsedEventHistory = ParseEventHistory(lines, ref lineIndex);
                    parsedEventHistory.Command = command;
                    parsedFile.Add(parsedEventHistory);
                }

                // Skip to the next nonblank line
                SkipBlanks(lines, ref lineIndex);
            }

            return parsedFile;
        }
Ejemplo n.º 8
0
        // Static Methods

        public static CommaSeparatedEventReport Parse(string[] lines, ref int index)
        {
            CommaSeparatedEventReport commaSeparatedEventReport = new CommaSeparatedEventReport();

            commaSeparatedEventReport.Firmware = new Firmware();
            commaSeparatedEventReport.Header   = new Header();

            int triggerIndex = 0;

            foreach (string line in lines)
            {
                if (line.Split(',').Length > 11 && line.Split(',')[11].Contains(">"))
                {
                    commaSeparatedEventReport.TriggerIndex = triggerIndex;
                }

                ++triggerIndex;
            }

            while (!lines[index].ToUpper().Contains("SEL"))
            {
                ++index;
            }

            // Parse the report firmware id and checksum
            commaSeparatedEventReport.Firmware.ID       = lines[index].Split(',')[0].Split('=')[1].Split('"')[0];
            commaSeparatedEventReport.Firmware.Checksum = Convert.ToInt32(lines[index].Split(',')[1].Replace("\"", ""), 16);

            while (!lines[index].ToUpper().Contains("MONTH"))
            {
                ++index;
            }

            // Parse the date
            commaSeparatedEventReport.Header.EventTime = new DateTime(Convert.ToInt32(lines[++index].Split(',')[2]), Convert.ToInt32(lines[index].Split(',')[0]), Convert.ToInt32(lines[index].Split(',')[1]), Convert.ToInt32(lines[index].Split(',')[3]), Convert.ToInt32(lines[index].Split(',')[4]), Convert.ToInt32(lines[index].Split(',')[5]));

            // Set rest of header
            commaSeparatedEventReport.Header.SerialNumber = 0;
            commaSeparatedEventReport.Header.RelayID      = "";
            commaSeparatedEventReport.Header.StationID    = "";

            while (!lines[index].ToUpper().Contains("FREQ"))
            {
                ++index;
            }

            List <string> sampleStatHeader = lines[index].Split(',').ToList();
            List <string> sampleStats      = lines[++index].Split(',').ToList();

            commaSeparatedEventReport.AverageFrequency       = Convert.ToDouble(sampleStats[sampleStatHeader.FindIndex(x => x.ToUpper().Contains("FREQ"))]);
            commaSeparatedEventReport.SamplesPerCycleAnalog  = Convert.ToInt32(sampleStats[sampleStatHeader.FindIndex(x => x.ToUpper().Contains("SAM/CYC_A"))]);
            commaSeparatedEventReport.SamplesPerCycleDigital = Convert.ToInt32(sampleStats[sampleStatHeader.FindIndex(x => x.ToUpper().Contains("SAM/CYC_D"))]);
            commaSeparatedEventReport.NumberOfCycles         = Convert.ToInt32(sampleStats[sampleStatHeader.FindIndex(x => x.ToUpper().Contains("NUM_OF_CYC"))]);
            commaSeparatedEventReport.Event = sampleStats[sampleStatHeader.FindIndex(x => x.ToUpper().Contains("EVENT"))].Replace("/", "");

            while (!lines[index].ToUpper().Contains("IA"))
            {
                ++index;
            }

            commaSeparatedEventReport.AnalogSection = new AnalogSection();

            string[] fields = lines[index].Split(',');

            foreach (string name in fields)
            {
                if (name.Length < 10 && (
                        name.ToUpper().Contains("IA") ||
                        name.ToUpper().Contains("IB") ||
                        name.ToUpper().Contains("IC") ||
                        name.ToUpper().Contains("IN") ||
                        (!name.ToUpper().Contains("TRIG") && name.ToUpper().Contains("IG")) ||
                        name.ToUpper().Contains("VA") ||
                        name.ToUpper().Contains("VB") ||
                        name.ToUpper().Contains("VC") ||
                        name.ToUpper().Contains("VS") ||
                        name.ToUpper().Contains("VDC") ||
                        name.ToUpper().Contains("FREQ")
                        ))
                {
                    commaSeparatedEventReport.AnalogSection.AnalogChannels.Add(new Channel <double>());
                    commaSeparatedEventReport.AnalogSection.AnalogChannels[commaSeparatedEventReport.AnalogSection.AnalogChannels.Count - 1].Name = name.Split('(')[0].Trim('"');
                }
            }

            foreach (string channel in fields[12].Split(' '))
            {
                if (channel != "\"")
                {
                    commaSeparatedEventReport.AnalogSection.DigitalChannels.Add(new Channel <bool>());
                    commaSeparatedEventReport.AnalogSection.DigitalChannels[commaSeparatedEventReport.AnalogSection.DigitalChannels.Count - 1].Name = channel.Trim('"');
                }
            }

            commaSeparatedEventReport.InitialReadingIndex = ++index;
            int timeStepTicks = Convert.ToInt32(Math.Round(10000000.0 / commaSeparatedEventReport.AverageFrequency / commaSeparatedEventReport.SamplesPerCycleAnalog));

            while (!lines[index].ToUpper().Contains("SETTINGS"))
            {
                int diff = commaSeparatedEventReport.TriggerIndex - index - commaSeparatedEventReport.InitialReadingIndex;

                commaSeparatedEventReport.AnalogSection.TimeChannel.Samples.Add(commaSeparatedEventReport.Header.EventTime.AddTicks(-1 * timeStepTicks * diff));
                commaSeparatedEventReport.AnalogSection.AnalogChannels[0].Samples.Add(Convert.ToDouble(lines[index].Split(',')[0]) * (fields[0].ToUpper().Contains("KV")? 1000 : 1));
                commaSeparatedEventReport.AnalogSection.AnalogChannels[1].Samples.Add(Convert.ToDouble(lines[index].Split(',')[1]) * (fields[1].ToUpper().Contains("KV")? 1000 : 1));
                commaSeparatedEventReport.AnalogSection.AnalogChannels[2].Samples.Add(Convert.ToDouble(lines[index].Split(',')[2]) * (fields[2].ToUpper().Contains("KV")? 1000 : 1));
                commaSeparatedEventReport.AnalogSection.AnalogChannels[3].Samples.Add(Convert.ToDouble(lines[index].Split(',')[3]) * (fields[3].ToUpper().Contains("KV")? 1000 : 1));
                commaSeparatedEventReport.AnalogSection.AnalogChannels[4].Samples.Add(Convert.ToDouble(lines[index].Split(',')[4]) * (fields[4].ToUpper().Contains("KV")? 1000 : 1));
                commaSeparatedEventReport.AnalogSection.AnalogChannels[5].Samples.Add(Convert.ToDouble(lines[index].Split(',')[5]) * (fields[5].ToUpper().Contains("KV")? 1000 : 1));
                commaSeparatedEventReport.AnalogSection.AnalogChannels[6].Samples.Add(Convert.ToDouble(lines[index].Split(',')[6]) * (fields[6].ToUpper().Contains("KV")? 1000 : 1));
                commaSeparatedEventReport.AnalogSection.AnalogChannels[7].Samples.Add(Convert.ToDouble(lines[index].Split(',')[7]) * (fields[7].ToUpper().Contains("KV")? 1000 : 1));
                commaSeparatedEventReport.AnalogSection.AnalogChannels[8].Samples.Add(Convert.ToDouble(lines[index].Split(',')[8]) * (fields[8].ToUpper().Contains("KV")? 1000 : 1));
                commaSeparatedEventReport.AnalogSection.AnalogChannels[9].Samples.Add(Convert.ToDouble(lines[index].Split(',')[9]) * (fields[9].ToUpper().Contains("KV")? 1000 : 1));
                commaSeparatedEventReport.AnalogSection.AnalogChannels[10].Samples.Add(Convert.ToDouble(lines[index].Split(',')[10]));

                string digitals     = lines[index].Split(',')[12].Replace("\"", "");
                int    forEachIndex = 0;

                foreach (Channel <bool> channel in commaSeparatedEventReport.AnalogSection.DigitalChannels)
                {
                    channel.Samples.Add(Convert.ToString(Convert.ToInt32(digitals[forEachIndex / 4].ToString(), 16), 2).PadLeft(4, '0')[forEachIndex % 4] == '1');
                    ++forEachIndex;
                }

                ++index;
            }

            //skip "SETTINGS" AND " LINES
            if (lines[index].ToUpper() == "SETTINGS")
            {
                ++index;
            }
            if (lines[index] == "\"")
            {
                ++index;
            }

            EventFile.SkipBlanks(lines, ref index);
            // SKIP GROUP 1 AND GROUP SETTINGS lINES
            if (lines[index].ToUpper() == "GROUP 1")
            {
                ++index;
            }
            if (lines[index].ToUpper() == "GROUP SETTINGS:")
            {
                ++index;
            }

            commaSeparatedEventReport.GroupSetting = Settings.Parse(lines, ref index);
            EventFile.SkipBlanks(lines, ref index);
            ++index;
            commaSeparatedEventReport.ControlEquations = ControlEquation.Parse(lines, ref index);
            EventFile.SkipBlanks(lines, ref index);
            commaSeparatedEventReport.GlobalSetting = Settings.Parse(lines, ref index);

            return(commaSeparatedEventReport);
        }
Ejemplo n.º 9
0
        public static EventFile Parse(string filename, double systemFrequency)
        {
            string[] lineSeparators = { "\r\n", "\n\r", "\r", "\n" };

            EventFile parsedFile = new EventFile();
            string    fileText   = File.ReadAllText(filename);

            int    firstLineSeparatorIndex = lineSeparators.Select(separator => fileText.IndexOf(separator)).Where(index => index >= 0).Min();
            string lineSeparator           = lineSeparators.First(separator => fileText.IndexOf(separator) == firstLineSeparatorIndex);

            string[] lines = fileText
                             .Split(new string[] { lineSeparator }, StringSplitOptions.None)
                             .Select(line => line.RemoveControlCharacters())
                             .ToArray();

            int lineIndex = 0;

            string       command;
            EventReport  parsedEventReport;
            EventHistory parsedEventHistory;
            CommaSeparatedEventReport parsedCommaSeparatedEventReport;
            bool parsed = false;

            while (lineIndex < lines.Length && !parsed)
            {
                // Parse next command from the file
                command = ParseCommand(lines, ref lineIndex);

                // Skip to the next nonblank line
                SkipBlanks(lines, ref lineIndex);

                if (command.ToUpper().Contains("EVE"))
                {
                    parsedEventReport         = EventReport.Parse(systemFrequency, lines, ref lineIndex);
                    parsedEventReport.Command = command;
                    parsedFile.Add(parsedEventReport);
                    parsed = true;
                }
                else if (command.ToUpper().Contains("CEV") || filename.ToUpper().Contains(".CEV"))
                {
                    parsedCommaSeparatedEventReport         = CommaSeparatedEventReport.Parse(lines, ref lineIndex);
                    parsedCommaSeparatedEventReport.Command = (command.ToUpper().Contains("FID") ? command.Split('\"')[0] : command);
                    parsedFile.Add(parsedCommaSeparatedEventReport);
                    parsed = true;
                }
                else if (command.ToUpper().Contains("HIS"))
                {
                    parsedEventHistory         = EventHistory.Parse(lines, ref lineIndex);
                    parsedEventHistory.Command = command;
                    parsedFile.Add(parsedEventHistory);
                    parsed = true;
                }
                else
                {
                    // We do not know what type of file we are reading because the console command may be missing from the top of the file.
                    // We can attempt to glean if it is a cev by checking if the 3rd line can be split by commas.
                    if (lines[2].Split(',').Count() > 1)
                    {
                        parsedCommaSeparatedEventReport         = CommaSeparatedEventReport.Parse(lines, ref lineIndex);
                        parsedCommaSeparatedEventReport.Command = (command.ToUpper().Contains("FID") ? command.Split('\"')[0] : command);
                        parsedFile.Add(parsedCommaSeparatedEventReport);
                        parsed = true;
                    }
                    else if (!lines.Where(x => x.Contains("FID")).Contains(","))
                    {
                        parsedEventReport         = EventReport.Parse(systemFrequency, lines, ref lineIndex);
                        parsedEventReport.Command = command;
                        parsedFile.Add(parsedEventReport);
                        parsed = true;
                    }
                }

                // Skip to the next nonblank line
                SkipBlanks(lines, ref lineIndex);
            }

            return(parsedFile);
        }
Ejemplo n.º 10
0
        public static CommaSeparatedEventReport Parse(double systemFrequency, string[] lines, ref int index)
        {
            CommaSeparatedEventReport commaSeparatedEventReport = new CommaSeparatedEventReport();

            commaSeparatedEventReport.Firmware = new Firmware();
            commaSeparatedEventReport.Header   = new Header();

            int triggerIndex = 0;

            foreach (string line in lines)
            {
                if (line.Split(',').Length > 11 && line.Split(',')[11].Contains(">"))
                {
                    commaSeparatedEventReport.TriggerIndex = triggerIndex;
                }

                ++triggerIndex;
            }

            while (!lines[index].ToUpper().Contains("SEL"))
            {
                ++index;
            }

            // Parse the report firmware id and checksum
            commaSeparatedEventReport.Firmware.ID = lines[index].Split(',')[0].Split('=')[1].Split('"')[0];
            //commaSeparatedEventReport.Firmware.Checksum = Convert.ToInt32(lines[index].Split(',')[1].Replace("\"", ""), 16);

            while (!lines[index].ToUpper().Contains("MONTH"))
            {
                ++index;
            }

            // Parse the date
            commaSeparatedEventReport.Header.EventTime = new DateTime(Convert.ToInt32(lines[++index].Split(',')[2]), Convert.ToInt32(lines[index].Split(',')[0]), Convert.ToInt32(lines[index].Split(',')[1]), Convert.ToInt32(lines[index].Split(',')[3]), Convert.ToInt32(lines[index].Split(',')[4]), Convert.ToInt32(lines[index].Split(',')[5]));

            // Set rest of header
            commaSeparatedEventReport.Header.SerialNumber = 0;
            commaSeparatedEventReport.Header.RelayID      = "";
            commaSeparatedEventReport.Header.StationID    = "";

            while (!lines[index].ToUpper().Contains("FREQ"))
            {
                ++index;
            }

            List <string> sampleStatHeader = lines[index].Split(',').ToList();
            List <string> sampleStats      = lines[++index].Split(',').ToList();

            commaSeparatedEventReport.AverageFrequency       = Convert.ToDouble(sampleStats[sampleStatHeader.FindIndex(x => x.ToUpper().Contains("FREQ"))]);
            commaSeparatedEventReport.SamplesPerCycleAnalog  = Convert.ToDouble(sampleStats[sampleStatHeader.FindIndex(x => x.ToUpper().Contains("SAM/CYC_A"))]);
            commaSeparatedEventReport.SamplesPerCycleDigital = Convert.ToDouble(sampleStats[sampleStatHeader.FindIndex(x => x.ToUpper().Contains("SAM/CYC_D"))]);
            commaSeparatedEventReport.NumberOfCycles         = Convert.ToDouble(sampleStats[sampleStatHeader.FindIndex(x => x.ToUpper().Contains("NUM_OF_CYC"))]);
            commaSeparatedEventReport.Event = sampleStats[sampleStatHeader.FindIndex(x => x.ToUpper().Contains("EVENT"))].Replace("/", "");

            while (!lines[index].ToUpper().Contains("IA"))
            {
                ++index;
            }

            commaSeparatedEventReport.AnalogSection = new AnalogSection();

            string[] fields = lines[index].Split(',');

            int fieldIndex = 0;

            while (fields[fieldIndex].Trim('"').ToUpper() != "TRIG")
            {
                commaSeparatedEventReport.AnalogSection.AnalogChannels.Add(new Channel <double>());
                commaSeparatedEventReport.AnalogSection.AnalogChannels[commaSeparatedEventReport.AnalogSection.AnalogChannels.Count - 1].Name = fields[fieldIndex++].Split('(')[0].Trim('"');
            }

            foreach (string channel in fields[++fieldIndex].Split(' '))
            {
                if (channel != "\"")
                {
                    commaSeparatedEventReport.AnalogSection.DigitalChannels.Add(new Channel <bool?>());
                    commaSeparatedEventReport.AnalogSection.DigitalChannels[commaSeparatedEventReport.AnalogSection.DigitalChannels.Count - 1].Name = channel.Trim('"');
                }
            }

            commaSeparatedEventReport.InitialReadingIndex = ++index;
            int timeStepTicks = Convert.ToInt32(Math.Round(10000000.0 / systemFrequency / commaSeparatedEventReport.SamplesPerCycleAnalog));

            while (!lines[index].ToUpper().Contains("SETTINGS") && lines[index].ToUpper() != string.Empty)
            {
                int diff = commaSeparatedEventReport.TriggerIndex - index - commaSeparatedEventReport.InitialReadingIndex;
                commaSeparatedEventReport.AnalogSection.TimeChannel.Samples.Add(commaSeparatedEventReport.Header.EventTime.AddTicks(-1 * timeStepTicks * diff));

                int channelIndex = 0;
                foreach (var analogChannel in commaSeparatedEventReport.AnalogSection.AnalogChannels)
                {
                    analogChannel.Samples.Add(Convert.ToDouble(lines[index].Split(',')[channelIndex]) * (fields[channelIndex++].ToUpper().Contains("KV") ? 1000 : 1));
                }

                string digitals = lines[index].Split(',')[++channelIndex].Replace("\"", "");

                int forEachIndex = 0;
                foreach (Channel <bool?> channel in commaSeparatedEventReport.AnalogSection.DigitalChannels)
                {
                    if (digitals == "" || !Regex.IsMatch(digitals, @"\A\b[0-9a-fA-F]+\b\Z"))
                    {
                        channel.Samples.Add(null);
                    }
                    else
                    {
                        channel.Samples.Add(Convert.ToString(Convert.ToInt32(digitals[forEachIndex / 4].ToString(), 16), 2).PadLeft(4, '0')[forEachIndex % 4] == '1');
                    }
                    ++forEachIndex;
                }
                ++index;
            }

            try
            {
                //skip "SETTINGS" AND " LINES
                if (lines[index].ToUpper() == "SETTINGS")
                {
                    ++index;
                }
                if (lines[index] == "\"")
                {
                    ++index;
                }

                EventFile.SkipBlanks(lines, ref index);
                // SKIP GROUP 1 AND GROUP SETTINGS lINES
                if (lines[index].ToUpper() == "GROUP 1")
                {
                    ++index;
                }
                if (lines[index].ToUpper() == "GROUP SETTINGS:")
                {
                    ++index;
                }

                commaSeparatedEventReport.GroupSetting = Settings.Parse(lines, ref index);
                EventFile.SkipBlanks(lines, ref index);
                ++index;
                commaSeparatedEventReport.ControlEquations = ControlEquation.Parse(lines, ref index);
                EventFile.SkipBlanks(lines, ref index);
                commaSeparatedEventReport.GlobalSetting = Settings.Parse(lines, ref index);
            }
            catch (IndexOutOfRangeException)
            {
                if (index < lines.Length)
                {
                    throw;
                }
            }

            return(commaSeparatedEventReport);
        }
Ejemplo n.º 11
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);
         return true;
     }
     catch (IOException)
     {
         return false;
     }
 }
Ejemplo n.º 12
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)
        {
            Header header;
            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() && !m_eventFile.CommaSeparatedEventReports.Any())
                return;

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

            m_meterDataSet.Meter = new Meter();
            m_meterDataSet.Meter.AssetKey = header.RelayID;
            m_meterDataSet.Meter.Name = header.RelayID;
            m_meterDataSet.Meter.ShortName = new string(header.RelayID.ToNonNullString().Take(50).ToArray());

            m_meterDataSet.Meter.MeterLocation = new MeterLocation();
            m_meterDataSet.Meter.MeterLocation.AssetKey = header.StationID;
            m_meterDataSet.Meter.MeterLocation.Name = header.StationID;
            m_meterDataSet.Meter.MeterLocation.ShortName = new string(header.StationID.ToNonNullString().Take(50).ToArray());
            m_meterDataSet.Meter.MeterLocation.Description = header.StationID;

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

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

                    series.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))
                        series = series.Multiply(1000.0D);

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

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

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

                    timeSamples = report.AnalogSection.TimeChannel.Samples;
                    valueSamples = report.AnalogSection.DigitalChannels[i].Samples.Select(Convert.ToDouble).ToList();

                    series.SeriesInfo = channel.Series[0];

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

                    m_meterDataSet.Digitals.Add(series);
                }

                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 = groupSetting;

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

                if (double.TryParse(report.GetGroupSettings("Z0ANG"), out groupSetting))
                    z0.Angle = 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 = MakeParsedAnalog(report, i);
                    series = new DataSeries();

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

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

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

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

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

                    timeSamples = report.AnalogSection.TimeChannel.Samples;
                    valueSamples = report.AnalogSection.DigitalChannels[i].Samples.Select(Convert.ToDouble).ToList();

                    series.SeriesInfo = channel.Series[0];

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

                    m_meterDataSet.Digitals.Add(series);
                }
            }
        }
Ejemplo n.º 13
0
        // Static Methods

        public static List <EventHistoryRecord> ParseRecords(string[] lines, ref int index)
        {
            List <EventHistoryRecord> histories = new List <EventHistoryRecord>();
            EventHistoryRecord        eventHistory;
            string currentLine;

            List <Token> tokens;
            List <Token> headers;
            Dictionary <Token, Token> fields;
            Token fieldHeader;
            Token field;

            int      eventNumber;
            DateTime dateTime;
            double   faultLocation;
            double   current;
            double   frequency;
            int      group;
            int      shot;

            string date;
            string time;

            // Parse header
            headers = Split(lines[index++]);

            // Skip to the next nonblank line
            EventFile.SkipBlanks(lines, ref index);

            while (index < lines.Length)
            {
                currentLine = lines[index];

                // Empty line indicates end of event histories
                if (string.IsNullOrWhiteSpace(currentLine))
                {
                    break;
                }

                // Create a new event history record
                eventHistory = new EventHistoryRecord();

                // Parse fields
                tokens = Split(currentLine);

                // Initialize date and time variables
                date = null;
                time = null;

                fields = new Dictionary <Token, Token>();

                foreach (Token token in tokens)
                {
                    fieldHeader = headers.MinBy(header => token.Distance(header));
                    fields.AddOrUpdate(fieldHeader, token, (key, value) => value.JoinWith(token));
                }

                foreach (Token header in headers)
                {
                    if (fields.TryGetValue(header, out field))
                    {
                        switch (header.Text.ToUpper())
                        {
                        case "#":
                        case "REC_NUM":
                            // Parse the field as an event number
                            if (int.TryParse(field.Text, out eventNumber))
                            {
                                eventHistory.EventNumber = eventNumber;
                            }

                            break;

                        case "DATE":
                            // Parse the field as a date value
                            date = field.Text;

                            // If both date and time have been provided, parse them as a DateTime
                            if ((object)time != null && EventFile.TryParseDateTime(string.Format("{0} {1}", date, time), out dateTime))
                            {
                                eventHistory.Time = dateTime;
                            }

                            break;

                        case "TIME":
                            // Parse the field as a time value
                            time = field.Text;

                            // If both date and time have been provided, parse them as a DateTime
                            if ((object)date != null && EventFile.TryParseDateTime(string.Format("{0} {1}", date, time), out dateTime))
                            {
                                eventHistory.Time = dateTime;
                            }

                            break;

                        case "EVENT":
                            // Parse the field as an event type
                            eventHistory.EventType = field.Text;
                            break;

                        case "LOCAT":
                        case "LOCATION":
                            // Parse the field as a fault location value
                            if (double.TryParse(field.Text, out faultLocation))
                            {
                                eventHistory.FaultLocation = faultLocation;
                            }

                            break;

                        case "CURR":
                            // Parse the field as a current magnitude
                            if (double.TryParse(field.Text, out current))
                            {
                                eventHistory.Current = current;
                            }

                            break;

                        case "FREQ":
                            // Parse the field as a frequency value
                            if (double.TryParse(field.Text, out frequency))
                            {
                                eventHistory.Frequency = frequency;
                            }

                            break;

                        case "GRP":
                        case "GROUP":
                            // Parse the field as a group number
                            if (int.TryParse(field.Text, out group))
                            {
                                eventHistory.Group = group;
                            }

                            break;

                        case "SHOT":
                            // Parse the field as a shot number
                            if (int.TryParse(field.Text, out shot))
                            {
                                eventHistory.Shot = shot;
                            }

                            break;

                        case "TARGETS":
                            // Parse the field as targets
                            eventHistory.Targets = field.Text;
                            break;
                        }
                    }
                }

                // Add history record to the list of histories
                histories.Add(eventHistory);

                // Advance to the next line
                index++;
            }

            return(histories);
        }