Class: Jeti::Log::File
- Inherits:
-
Object
- Object
- Jeti::Log::File
- Defined in:
- lib/jeti/log/file.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Class Method Summary collapse
-
.jeti?(uri) ⇒ Jeti::Log::File
Determines if the file at the given URI is a Jeti telemetry log file.
Instance Method Summary collapse
-
#duration ⇒ Float
Gets the duration of the session, in seconds.
-
#initialize(uri) ⇒ File
constructor
A new instance of File.
- #mezon_data ⇒ Object
- #mezon_data? ⇒ Boolean
- #mgps_data ⇒ Object
- #mgps_data? ⇒ Boolean
- #mui_data ⇒ Object
- #mui_data? ⇒ Boolean
- #rx_data ⇒ Object
- #rx_data? ⇒ Boolean
-
#to_kml(file_options = {}, placemark_options = {}) ⇒ String
Converts the session into a KML document containing a placemark.
-
#to_kml? ⇒ Boolean
Determines if KML methods can be called for this session.
-
#to_kml_file(file_options = {}, placemark_options = {}) ⇒ KMLFile
Converts the session into a KMLFile containing a placemark.
-
#to_kml_placemark(options = {}) ⇒ KML::Placemark
Converts the session into a KML::Placemark containing GPS coordinates.
- #tx_data ⇒ Object
- #tx_data? ⇒ Boolean
- #value_dataset(device, sensor, modifier = ->(val) { val }) ⇒ Object
Constructor Details
#initialize(uri) ⇒ File
Returns a new instance of File.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/jeti/log/file.rb', line 18 def initialize(uri) open(uri, 'rb') do |file| lines = file.readlines.map(&:strip).group_by do |line| line.start_with?('#') ? :comments : :rows end @name = lines.fetch(:comments, ['Unknown']).first.gsub(/#/, '').strip @headers = [] @entries = [] lines[:rows].each_with_object(';').map(&:split).each do |line| if '000000000' == line.first if line.length == 4 line << '' elsif line.length == 5 # do nothing else raise RuntimeError, "Unexpected header length (#{line.length})" end @headers << Header.new(line[0], line[1], line[2..4]) else @entries << Entry.new(line[0], line[1], line[2..-1]) end end raise RuntimeError, 'No headers found in log file' if @headers.empty? raise RuntimeError, 'No entries found in log file' if @entries.empty? end rescue => e raise ArgumentError, "File does not appear to be a Jeti log (#{e})" end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
8 9 10 |
# File 'lib/jeti/log/file.rb', line 8 def name @name end |
Class Method Details
.jeti?(uri) ⇒ Jeti::Log::File
Determines if the file at the given URI is a Jeti telemetry log file.
14 15 16 |
# File 'lib/jeti/log/file.rb', line 14 def self.jeti?(uri) File.new(uri) rescue nil end |
Instance Method Details
#duration ⇒ Float
Gets the duration of the session, in seconds.
54 55 56 |
# File 'lib/jeti/log/file.rb', line 54 def duration (@entries.last.time - @entries.first.time) / 1000.0 end |
#mezon_data ⇒ Object
70 71 72 |
# File 'lib/jeti/log/file.rb', line 70 def mezon_data @mezon_data ||= Data::MezonDataBuilder.build(self) end |
#mezon_data? ⇒ Boolean
66 67 68 |
# File 'lib/jeti/log/file.rb', line 66 def mezon_data? device_present?(/Mezon/i) end |
#mgps_data ⇒ Object
62 63 64 |
# File 'lib/jeti/log/file.rb', line 62 def mgps_data @mgps_data ||= Data::MGPSDataBuilder.build(self) end |
#mgps_data? ⇒ Boolean
58 59 60 |
# File 'lib/jeti/log/file.rb', line 58 def mgps_data? device_present?(/MGPS/) end |
#mui_data ⇒ Object
78 79 80 |
# File 'lib/jeti/log/file.rb', line 78 def mui_data @mui_data ||= Data::MuiDataBuilder.build(self) end |
#mui_data? ⇒ Boolean
74 75 76 |
# File 'lib/jeti/log/file.rb', line 74 def mui_data? device_present?(/MUI/) end |
#rx_data ⇒ Object
86 87 88 |
# File 'lib/jeti/log/file.rb', line 86 def rx_data @rx_data ||= Data::RxDataBuilder.build(self) end |
#rx_data? ⇒ Boolean
82 83 84 |
# File 'lib/jeti/log/file.rb', line 82 def rx_data? device_present?(/Rx/) end |
#to_kml(file_options = {}, placemark_options = {}) ⇒ String
Converts the session into a KML document containing a placemark.
112 113 114 115 |
# File 'lib/jeti/log/file.rb', line 112 def to_kml( = {}, = {}) raise RuntimeError, 'No coordinates available for KML generation' unless to_kml? to_kml_file(, ).render end |
#to_kml? ⇒ Boolean
Determines if KML methods can be called for this session.
101 102 103 |
# File 'lib/jeti/log/file.rb', line 101 def to_kml? mgps_data? end |
#to_kml_file(file_options = {}, placemark_options = {}) ⇒ KMLFile
Converts the session into a KMLFile containing a placemark.
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
# File 'lib/jeti/log/file.rb', line 126 def to_kml_file( = {}, = {}) raise RuntimeError, 'No coordinates available for KML generation' unless to_kml? = () kml = KMLFile.new kml.objects << KML::Document.new( :name => [:name], :description => [:description], :styles => [ KML::Style.new( :id => [:style_id], :line_style => KML::LineStyle.new(:color => '7F00FFFF', :width => 4), :poly_style => KML::PolyStyle.new(:color => '7F00FF00') ) ], :features => [ to_kml_placemark() ] ) kml end |
#to_kml_placemark(options = {}) ⇒ KML::Placemark
Converts the session into a KML::Placemark containing GPS coordinates.
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 |
# File 'lib/jeti/log/file.rb', line 155 def to_kml_placemark( = {}) raise RuntimeError, 'No coordinates available for KML generation' unless to_kml? = () coords = mgps_data.map { |l| [l.longitude, l.latitude, l.altitude] } KML::Placemark.new( :name => [:name], :style_url => [:style_url], :geometry => KML::LineString.new( :altitude_mode => [:altitude_mode], :extrude => [:extrude], :tessellate => [:tessellate], :coordinates => coords.map { |c| c.join(',') }.join(' ') ) ) end |
#tx_data ⇒ Object
94 95 96 |
# File 'lib/jeti/log/file.rb', line 94 def tx_data @tx_data ||= Data::TxDataBuilder.build(self) end |
#tx_data? ⇒ Boolean
90 91 92 |
# File 'lib/jeti/log/file.rb', line 90 def tx_data? device_present?(/Tx/) end |
#value_dataset(device, sensor, modifier = ->(val) { val }) ⇒ Object
172 173 174 175 176 177 |
# File 'lib/jeti/log/file.rb', line 172 def value_dataset(device, sensor, modifier = ->(val) { val }) headers, entries = headers_and_entries_for_device(device) sensor_id = (headers.select { |h| sensor =~ h.name })[0].sensor_id entries.reject! { |e| e.detail(sensor_id).nil? } entries.map { |e| [e.time, modifier.call(e.value(sensor_id))] } end |