eagletree-log 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -19,19 +19,25 @@ module EagleTree
19
19
  attr_reader :version
20
20
 
21
21
  def initialize uri
22
+ @sessions = []
22
23
 
23
24
  open(uri, 'rb') do |file|
24
25
  @name = file.gets.chomp
25
26
  @meta = file.gets.chomp.split
27
+ session_count = @meta[27].to_i
26
28
 
27
29
  if 'All Sessions' != file.gets.chomp
28
30
  raise RuntimeError, "No 'All Sessions' marker found"
29
31
  end
30
32
 
31
- all_range = file.gets.chomp.split.map(&:to_i).map { |v| v * @meta[22].to_i }
33
+ # empty files are still valid, just have no sessions
34
+ if session_count.zero?
35
+ break
36
+ end
37
+
38
+ # read off the full file range
39
+ all_sessions_range = file.gets.chomp.split.map(&:to_i)
32
40
 
33
- @sessions = []
34
- session_count = @meta[27].to_i
35
41
  session_count.times do |expected|
36
42
  num = /Session (?<num>\d)/.match(file.gets)[:num].to_i
37
43
  if (expected + 1) != num
@@ -42,15 +48,11 @@ module EagleTree
42
48
  @sessions << Session.new(num, range)
43
49
  end
44
50
 
45
- if all_range != [@sessions.first.range[0], @sessions.last.range[1]]
46
- raise RuntimeError, 'File did not appear to contain all sessions'
47
- end
48
-
49
51
  session_index = 0
50
52
  session = @sessions[session_index]
51
53
  session_rows = []
52
54
  CSV.new(file, { :col_sep => ' ', :headers => true }).each do |csv|
53
- if !((session.range[0]..session.range[1]).include? csv[0].to_i)
55
+ if !((session.range[0]..(session.range[1]-1)).include? csv[0].to_i)
54
56
  session.rows = session_rows
55
57
  session_index += 1
56
58
  session = @sessions[session_index]
@@ -59,15 +61,15 @@ module EagleTree
59
61
 
60
62
  session_rows << csv
61
63
  end
62
- session.rows = session_rows
64
+ session.rows = session_rows unless session.nil?
63
65
 
64
66
  end
65
67
 
66
68
  @hardware = @meta[23] # TODO interpret correctly
67
69
  @version = @meta[25].to_f
68
70
 
69
- rescue
70
- raise ArgumentError, 'File does not appear to be an Eagle Tree log'
71
+ #rescue
72
+ # raise ArgumentError, 'File does not appear to be an Eagle Tree log'
71
73
  end
72
74
 
73
75
  end
@@ -1,5 +1,5 @@
1
1
  module EagleTree
2
2
  module Log
3
- VERSION = "0.0.2"
3
+ VERSION = "0.0.3"
4
4
  end
5
5
  end
data/spec/file_spec.rb CHANGED
@@ -2,12 +2,84 @@ require 'spec_helper'
2
2
 
3
3
  describe EagleTree::Log::File do
4
4
 
5
- context 'data file trex_600.fdr' do
5
+ context 'data file empty.fdr' do
6
6
 
7
- subject { EagleTree::Log::File.new(data_file('trex_600.fdr')) }
7
+ subject { EagleTree::Log::File.new(data_file('empty.fdr')) }
8
+
9
+ it { should have(0).sessions }
10
+
11
+ its(:name) { should eql('Skywalker') }
12
+
13
+ its(:hardware) { should eql('74') }
14
+
15
+ its(:version) { should eql(10.04) }
16
+
17
+ end
18
+
19
+ context 'data file funjet-gps.fdr' do
20
+
21
+ subject { EagleTree::Log::File.new(data_file('funjet-gps.fdr')) }
22
+
23
+ it { should have(1).sessions }
24
+
25
+ its(:name) { should eql('FunJet') }
26
+
27
+ its(:hardware) { should eql('73') }
28
+
29
+ its(:version) { should eql(8.03) }
30
+
31
+ end
32
+
33
+ context 'data file multi-session-1.fdr' do
34
+
35
+ subject { EagleTree::Log::File.new(data_file('multi-session-1.fdr')) }
36
+
37
+ it { should have(3).sessions }
38
+
39
+ its(:name) { should eql('Helis') }
40
+
41
+ its(:hardware) { should eql('73') }
42
+
43
+ its(:version) { should eql(6.93) }
44
+
45
+ end
46
+
47
+ context 'data file multi-session-2.fdr' do
48
+
49
+ subject { EagleTree::Log::File.new(data_file('multi-session-2.fdr')) }
50
+
51
+ it { should have(3).sessions }
52
+
53
+ its(:name) { should eql('Losi XXX4') }
54
+
55
+ its(:hardware) { should eql('71') }
56
+
57
+ its(:version) { should eql(6.02) }
58
+
59
+ end
60
+
61
+ context 'data file t600-1.fdr' do
62
+
63
+ subject { EagleTree::Log::File.new(data_file('t600-1.fdr')) }
8
64
 
9
65
  it { should have(1).sessions }
10
66
 
67
+ its(:name) { should eql('T-Rex 600') }
68
+
69
+ its(:hardware) { should eql('73') }
70
+
71
+ its(:version) { should eql(6.93) }
72
+
73
+ end
74
+
75
+ context 'data file t600-2.fdr' do
76
+
77
+ subject { EagleTree::Log::File.new(data_file('t600-2.fdr')) }
78
+
79
+ it { should have(1).sessions }
80
+
81
+ its(:name) { should eql('T-Rex 600') }
82
+
11
83
  its(:hardware) { should eql('73') }
12
84
 
13
85
  its(:version) { should eql(6.93) }
data/spec/session_spec.rb CHANGED
@@ -2,13 +2,93 @@ require 'spec_helper'
2
2
 
3
3
  describe EagleTree::Log::Session do
4
4
 
5
- context 'data file trex_600.fdr' do
5
+ context 'data file multi-session-1.fdr' do
6
6
 
7
- subject { EagleTree::Log::File.new(data_file('trex_600.fdr')).sessions[0] }
7
+ let(:file) { EagleTree::Log::File.new(data_file('multi-session-1.fdr')) }
8
+
9
+ subject { file }
10
+
11
+ it { should have(3).sessions }
12
+
13
+ context 'session 1' do
14
+
15
+ subject { file.sessions[0] }
16
+
17
+ it { should have(3555).rows }
18
+
19
+ its(:duration) { should be_within(0.1).of(355.5) }
20
+
21
+ end
22
+
23
+ context 'session 2' do
24
+
25
+ subject { file.sessions[1] }
26
+
27
+ it { should have(3699).rows }
28
+
29
+ its(:duration) { should be_within(0.1).of(369.9) }
30
+
31
+ end
32
+
33
+ context 'session 3' do
34
+
35
+ subject { file.sessions[2] }
36
+
37
+ it { should have(4241).rows }
38
+
39
+ its(:duration) { should be_within(0.1).of(424.0) }
40
+
41
+ end
42
+
43
+ end
44
+
45
+ context 'data file multi-session-2.fdr' do
46
+
47
+ let(:file) { EagleTree::Log::File.new(data_file('multi-session-2.fdr')) }
48
+
49
+ subject { file }
50
+
51
+ it { should have(3).sessions }
52
+
53
+ context 'session 1' do
54
+
55
+ subject { file.sessions[0] }
56
+
57
+ it { should have(226).rows }
58
+
59
+ its(:duration) { should be_within(0.1).of(22.6) }
60
+
61
+ end
62
+
63
+ context 'session 2' do
64
+
65
+ subject { file.sessions[1] }
66
+
67
+ it { should have(124).rows }
68
+
69
+ its(:duration) { should be_within(0.1).of(12.4) }
70
+
71
+ end
72
+
73
+ context 'session 3' do
74
+
75
+ subject { file.sessions[2] }
76
+
77
+ it { should have(6336).rows }
78
+
79
+ its(:duration) { should be_within(0.1).of(633.5) }
80
+
81
+ end
82
+
83
+ end
84
+
85
+ context 'data file t600-1.fdr' do
86
+
87
+ subject { EagleTree::Log::File.new(data_file('t600-1.fdr')).sessions[0] }
8
88
 
9
89
  it { should have(692).rows }
10
90
 
11
- its(:duration) { should eql(69.2) }
91
+ its(:duration) { should be_within(0.1).of(69.2) }
12
92
 
13
93
  its(:altitudes?) { should be_false }
14
94
 
@@ -48,4 +128,50 @@ describe EagleTree::Log::Session do
48
128
 
49
129
  end
50
130
 
131
+ context 'data file t600-2.fdr' do
132
+
133
+ subject { EagleTree::Log::File.new(data_file('t600-2.fdr')).sessions[0] }
134
+
135
+ it { should have(865).rows }
136
+
137
+ its(:duration) { should be_within(0.1).of(86.5) }
138
+
139
+ its(:altitudes?) { should be_false }
140
+
141
+ its(:airspeeds?) { should be_false }
142
+
143
+ its(:servo_currents?) { should be_false }
144
+
145
+ its(:throttles?) { should be_false }
146
+
147
+ its(:pack_voltages?) { should be_true }
148
+
149
+ it 'should have a few select pack voltages' do
150
+ subject.pack_voltages[0].should be_within(0.1).of(46.6)
151
+ subject.pack_voltages[100].should be_within(0.1).of(46.6)
152
+ subject.pack_voltages[250].should be_within(0.1).of(46.6)
153
+ subject.pack_voltages[500].should be_within(0.1).of(42.3)
154
+ end
155
+
156
+ its(:amps?) { should be_true }
157
+
158
+ it 'should have a few select amps' do
159
+ subject.amps[0].should be_within(0.01).of(0.18)
160
+ subject.amps[100].should be_within(0.01).of(0.0)
161
+ subject.amps[250].should be_within(0.01).of(0.0)
162
+ subject.amps[500].should be_within(0.01).of(19.9)
163
+ end
164
+
165
+ its(:temps1?) { should be_false }
166
+
167
+ its(:temps2?) { should be_false }
168
+
169
+ its(:temps3?) { should be_false }
170
+
171
+ its(:rpms?) { should be_true }
172
+
173
+ its(:rpms2?) { should be_false }
174
+
175
+ end
176
+
51
177
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: eagletree-log
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -88,7 +88,15 @@ files:
88
88
  - LICENSE.txt
89
89
  - README.md
90
90
  - Rakefile
91
- - data/trex_600.fdr
91
+ - data/empty.fdr
92
+ - data/funjet-gps.fdr
93
+ - data/multi-session-1.fdr
94
+ - data/multi-session-2.fdr
95
+ - data/old-1.fdr
96
+ - data/old-2.fdr
97
+ - data/old-3.fdr
98
+ - data/t600-1.fdr
99
+ - data/t600-2.fdr
92
100
  - eagletree-log.gemspec
93
101
  - lib/eagletree/log.rb
94
102
  - lib/eagletree/log/file.rb