public static SkipBlanks ( string lines, int &index ) : void | ||
lines | string | |
index | int | |
return | void |
// 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); }
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); }
// 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); }
// 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); }
// 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); }
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); }
// 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); }