Class: OpenTx::Log::Session
- Inherits:
-
Object
- Object
- OpenTx::Log::Session
- Defined in:
- lib/opentx/log/session.rb
Class Method Summary collapse
-
.known_rows?(headers) ⇒ Boolean
XXX currently just know Taranis X9D files…
Instance Method Summary collapse
- #a1 ⇒ Object
- #a1? ⇒ Boolean
- #a2 ⇒ Object
- #a2? ⇒ Boolean
- #cell(index) ⇒ Object
- #cell?(index) ⇒ Boolean
- #cell_volts ⇒ Object
- #cell_volts? ⇒ Boolean
- #duration ⇒ Object
- #fuel ⇒ Object
- #fuel? ⇒ Boolean
-
#initialize(csv_rows) ⇒ Session
constructor
A new instance of Session.
-
#milliseconds ⇒ Array<Float>
Millisecond time stamps for all entries, 0-based.
- #rssi ⇒ Object
- #rssi? ⇒ Boolean
- #swr ⇒ Object
- #swr? ⇒ Boolean
- #temp1(unit = :c) ⇒ Object
- #temp1? ⇒ Boolean
- #temp2(unit = :c) ⇒ Object
- #temp2? ⇒ Boolean
-
#times ⇒ Array<Time>
All date-times in the session.
Constructor Details
#initialize(csv_rows) ⇒ Session
Returns a new instance of Session.
14 15 16 |
# File 'lib/opentx/log/session.rb', line 14 def initialize(csv_rows) @rows = csv_rows end |
Class Method Details
.known_rows?(headers) ⇒ Boolean
XXX currently just know Taranis X9D files…
7 8 9 10 11 12 |
# File 'lib/opentx/log/session.rb', line 7 def self.known_rows?(headers) return false unless [48].include?(headers.length) # check for a few known headers (%w(Date Time SWR RSSI A1 A2 Long Lat Temp1 Temp2 RPM Fuel) - headers).empty? end |
Instance Method Details
#a1 ⇒ Object
53 54 55 |
# File 'lib/opentx/log/session.rb', line 53 def a1 @a1 ||= float_field('A1') end |
#a1? ⇒ Boolean
49 50 51 |
# File 'lib/opentx/log/session.rb', line 49 def a1? a1.any? { |v| v > 0.0 } end |
#a2 ⇒ Object
61 62 63 |
# File 'lib/opentx/log/session.rb', line 61 def a2 @a2 ||= float_field('A2') end |
#a2? ⇒ Boolean
57 58 59 |
# File 'lib/opentx/log/session.rb', line 57 def a2? a2.any? { |v| v > 0.0 } end |
#cell(index) ⇒ Object
105 106 107 |
# File 'lib/opentx/log/session.rb', line 105 def cell(index) float_field("Cell #{index}") end |
#cell?(index) ⇒ Boolean
100 101 102 |
# File 'lib/opentx/log/session.rb', line 100 def cell?(index) cell(index).any? { |v| v > 0.0 } end |
#cell_volts ⇒ Object
95 96 97 |
# File 'lib/opentx/log/session.rb', line 95 def cell_volts @cell_volts ||= float_field('Cell volts') end |
#cell_volts? ⇒ Boolean
91 92 93 |
# File 'lib/opentx/log/session.rb', line 91 def cell_volts? cell_volts.any? { |v| v > 0.0 } end |
#duration ⇒ Object
18 19 20 21 |
# File 'lib/opentx/log/session.rb', line 18 def duration milliseconds times.last - times.first end |
#fuel ⇒ Object
87 88 89 |
# File 'lib/opentx/log/session.rb', line 87 def fuel @fuel ||= int_field('Fuel') end |
#fuel? ⇒ Boolean
83 84 85 |
# File 'lib/opentx/log/session.rb', line 83 def fuel? fuel.any? { |f| f != 0 } end |
#milliseconds ⇒ Array<Float>
Returns millisecond time stamps for all entries, 0-based.
24 25 26 |
# File 'lib/opentx/log/session.rb', line 24 def milliseconds @milliseconds ||= times.map { |time| ((time - times.first) * 1000).round(2) } end |
#rssi ⇒ Object
45 46 47 |
# File 'lib/opentx/log/session.rb', line 45 def rssi @rssi ||= int_field('RSSI') end |
#rssi? ⇒ Boolean
41 42 43 |
# File 'lib/opentx/log/session.rb', line 41 def rssi? rssi.any? end |
#swr ⇒ Object
37 38 39 |
# File 'lib/opentx/log/session.rb', line 37 def swr @swr ||= int_field('SWR') end |
#swr? ⇒ Boolean
33 34 35 |
# File 'lib/opentx/log/session.rb', line 33 def swr? swr.any? end |
#temp1(unit = :c) ⇒ Object
69 70 71 72 |
# File 'lib/opentx/log/session.rb', line 69 def temp1(unit = :c) @temp1 ||= int_field('Temp1') @temp1.map { |t| convert_temperature(t, unit) } end |
#temp1? ⇒ Boolean
65 66 67 |
# File 'lib/opentx/log/session.rb', line 65 def temp1? int_field('Temp1').any? { |t| t != 0 } end |
#temp2(unit = :c) ⇒ Object
78 79 80 81 |
# File 'lib/opentx/log/session.rb', line 78 def temp2(unit = :c) @temp2 ||= int_field('Temp2') @temp2.map { |t| convert_temperature(t, unit) } end |
#temp2? ⇒ Boolean
74 75 76 |
# File 'lib/opentx/log/session.rb', line 74 def temp2? int_field('Temp2').any? { |t| t != 0 } end |
#times ⇒ Array<Time>
Returns all date-times in the session.
29 30 31 |
# File 'lib/opentx/log/session.rb', line 29 def times @times ||= @rows.map { |row| Time.strptime("#{row['Date']} #{row['Time']}", '%Y-%m-%d %H:%M:%S.%N') } end |