Class: Mmana2nec::MmanaProcessor
- Inherits:
-
Object
- Object
- Mmana2nec::MmanaProcessor
- Defined in:
- lib/mmana2nec/mmana_processor.rb
Instance Attribute Summary collapse
-
#intermediate_format ⇒ Object
readonly
Returns the value of attribute intermediate_format.
-
#lines ⇒ Object
readonly
Returns the value of attribute lines.
Instance Method Summary collapse
- #extract_data ⇒ Object
- #new_section? ⇒ Boolean
- #process_file(file_name) ⇒ Object
- #process_g_h_m_r_azel_x ⇒ Object
- #process_list ⇒ Object
- #process_load ⇒ Object
- #process_segmentation ⇒ Object
- #process_source ⇒ Object
- #process_wires ⇒ Object
Instance Attribute Details
#intermediate_format ⇒ Object (readonly)
Returns the value of attribute intermediate_format.
107 108 109 |
# File 'lib/mmana2nec/mmana_processor.rb', line 107 def intermediate_format @intermediate_format end |
#lines ⇒ Object (readonly)
Returns the value of attribute lines.
107 108 109 |
# File 'lib/mmana2nec/mmana_processor.rb', line 107 def lines @lines end |
Instance Method Details
#extract_data ⇒ Object
8 9 10 |
# File 'lib/mmana2nec/mmana_processor.rb', line 8 def extract_data lines.pop.split(",\t").map {|x| x.include?("w") ? x : x.to_f} end |
#new_section? ⇒ Boolean
4 5 6 |
# File 'lib/mmana2nec/mmana_processor.rb', line 4 def new_section? (lines.empty? || lines[-1].start_with?("***")) end |
#process_file(file_name) ⇒ Object
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/mmana2nec/mmana_processor.rb', line 108 def process_file file_name file = File.open(file_name) @lines = file.readlines.map { |x| x.gsub("\r","").gsub("\n", "") }.reverse @intermediate_format = IntermediateFormat.new #header name = lines.pop unknown_header_1 = lines.pop unknown_header_2 = lines.pop while !lines.empty? current_section = lines.pop if !current_section.start_with?("***") raise "BAD FILE FORMAT" end current_section = current_section[3..-4] section_method = "process_" + current_section.downcase.gsub("/","_") send(section_method) end @intermediate_format end |
#process_g_h_m_r_azel_x ⇒ Object
102 103 104 105 |
# File 'lib/mmana2nec/mmana_processor.rb', line 102 def process_g_h_m_r_azel_x ground_type, h, m, impedance, azimuth, elevation, x = extract_data # Figure this out later! end |
#process_list ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/mmana2nec/mmana_processor.rb', line 12 def process_list list_contents = [] list_count = lines.pop.to_i until new_section? list_contents << extract_data end if list_contents.length != list_count raise "Length check failed" end list_contents end |
#process_load ⇒ Object
89 90 91 92 93 94 95 |
# File 'lib/mmana2nec/mmana_processor.rb', line 89 def process_load intermediate_format.loads = process_list if intermediate_format.loads.length > 0 raise "Didn't deal with loads yet!" end end |
#process_segmentation ⇒ Object
97 98 99 100 |
# File 'lib/mmana2nec/mmana_processor.rb', line 97 def process_segmentation dm1, dm2, sc, ec = extract_data intermediate_format.segmentation = {dm1: dm1, dm2: dm2, sc: sc, ec: ec} end |
#process_source ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/mmana2nec/mmana_processor.rb', line 73 def process_source intermediate_format.sources = process_list.map { |data| connection, phase, voltage = data raise "Unexpected connection value #{connection.inspect}" if !connection.start_with?("w") wire = connection[1..-2].to_i segment = connection[-1] # TODO: Figure out center and end once we have real segments raise "Don't know how to handle segment type #{segment}" if segment != "b" segment = 1 {wire: wire, segment: segment, phase: phase, voltage: voltage} } end |
#process_wires ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/mmana2nec/mmana_processor.rb', line 27 def process_wires wire_lengths = {} wires = [] process_list.each_with_index do |data, index| x1, y1, z1, x2, y2, z2, diameter, segments = data wire_length = Math.sqrt( (x2-x1) ** 2 + (y2 - y1) ** 2 + (z2 - z1) ** 2) wire_lengths[index] = wire_length if segments < -1 raise "Can't process segment type #{segments}" end wires << {end_one: {x: x1, y: y1, z: z1}, end_two: {x: x2, y: y2, z: z2}, diameter: diameter, segments: segments } end wire_lengths = wire_lengths.values.sort shortest_wire = wire_lengths[0] longest_wire = wire_lengths[-1] if longest_wire >= (shortest_wire * 5) #must use shortest wire or smaller as segment size segment_length = shortest_wire else # can use any segment size wavelength = 300.0 / intermediate_format.frequency segment_length = wavelength / (2 * 20) # Half wavelength / 20. What is correct fudge factor? end wires.each_with_index do |wire, index| if wire[:segments] == -1 wire_length = wire_lengths[index] segments = (wire_length / segment_length).to_i segments += 1 if (segments * segment_length) != wire_length wire[:segments] = segments end end intermediate_format.wires = wires end |