Class: OpenTx::Log::Session

Inherits:
Object
  • Object
show all
Defined in:
lib/opentx/log/session.rb

Class Method Summary collapse

Instance Method Summary collapse

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…

Returns:

  • (Boolean)


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

#a1Object



53
54
55
# File 'lib/opentx/log/session.rb', line 53

def a1
  @a1 ||= float_field('A1')
end

#a1?Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/opentx/log/session.rb', line 49

def a1?
  a1.any? { |v| v > 0.0 }
end

#a2Object



61
62
63
# File 'lib/opentx/log/session.rb', line 61

def a2
  @a2 ||= float_field('A2')
end

#a2?Boolean

Returns:

  • (Boolean)


57
58
59
# File 'lib/opentx/log/session.rb', line 57

def a2?
  a2.any? { |v| v > 0.0 }
end

#cell(index) ⇒ Object

Parameters:

  • index (1..6)


105
106
107
# File 'lib/opentx/log/session.rb', line 105

def cell(index)
  float_field("Cell #{index}")
end

#cell?(index) ⇒ Boolean

Parameters:

  • index (1..6)

Returns:

  • (Boolean)


100
101
102
# File 'lib/opentx/log/session.rb', line 100

def cell?(index)
  cell(index).any? { |v| v > 0.0 }
end

#cell_voltsObject



95
96
97
# File 'lib/opentx/log/session.rb', line 95

def cell_volts
  @cell_volts ||= float_field('Cell volts')
end

#cell_volts?Boolean

Returns:

  • (Boolean)


91
92
93
# File 'lib/opentx/log/session.rb', line 91

def cell_volts?
  cell_volts.any? { |v| v > 0.0 }
end

#durationObject



18
19
20
21
# File 'lib/opentx/log/session.rb', line 18

def duration
  milliseconds
  times.last - times.first
end

#fuelObject



87
88
89
# File 'lib/opentx/log/session.rb', line 87

def fuel
  @fuel ||= int_field('Fuel')
end

#fuel?Boolean

Returns:

  • (Boolean)


83
84
85
# File 'lib/opentx/log/session.rb', line 83

def fuel?
  fuel.any? { |f| f != 0 }
end

#millisecondsArray<Float>

Returns millisecond time stamps for all entries, 0-based.

Returns:

  • (Array<Float>)

    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

#rssiObject



45
46
47
# File 'lib/opentx/log/session.rb', line 45

def rssi
  @rssi ||= int_field('RSSI')
end

#rssi?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/opentx/log/session.rb', line 41

def rssi?
  rssi.any?
end

#swrObject



37
38
39
# File 'lib/opentx/log/session.rb', line 37

def swr
  @swr ||= int_field('SWR')
end

#swr?Boolean

Returns:

  • (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

Returns:

  • (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

Returns:

  • (Boolean)


74
75
76
# File 'lib/opentx/log/session.rb', line 74

def temp2?
  int_field('Temp2').any? { |t| t != 0 }
end

#timesArray<Time>

Returns all date-times in the session.

Returns:

  • (Array<Time>)

    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