antw-dyno 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (38) hide show
  1. data/LICENSE +19 -0
  2. data/README.markdown +68 -0
  3. data/Rakefile +45 -0
  4. data/VERSION.yml +4 -0
  5. data/lib/dyno.rb +22 -0
  6. data/lib/dyno/competitor.rb +55 -0
  7. data/lib/dyno/event.rb +16 -0
  8. data/lib/dyno/parsers/gtr2_parser.rb +13 -0
  9. data/lib/dyno/parsers/race07_parser.rb +130 -0
  10. data/lib/dyno/parsers/rfactor_parser.rb +138 -0
  11. data/spec/competitor_spec.rb +129 -0
  12. data/spec/event_spec.rb +59 -0
  13. data/spec/fixtures/gtr2/full.ini +0 -0
  14. data/spec/fixtures/gtr2/header_no_track.ini +0 -0
  15. data/spec/fixtures/gtr2/header_only.ini +0 -0
  16. data/spec/fixtures/gtr2/no_header_section.ini +0 -0
  17. data/spec/fixtures/gtr2/single_driver.ini +0 -0
  18. data/spec/fixtures/race07/full.ini +131 -0
  19. data/spec/fixtures/race07/header_no_track.ini +11 -0
  20. data/spec/fixtures/race07/header_only.ini +12 -0
  21. data/spec/fixtures/race07/no_header_section.ini +6 -0
  22. data/spec/fixtures/race07/no_steam_id.ini +37 -0
  23. data/spec/fixtures/race07/single_driver.ini +37 -0
  24. data/spec/fixtures/race07/single_driver_dnf.ini +34 -0
  25. data/spec/fixtures/race07/single_driver_dsq.ini +34 -0
  26. data/spec/fixtures/readme.markdown +5 -0
  27. data/spec/fixtures/rfactor/arca.xml +187 -0
  28. data/spec/fixtures/rfactor/event_only.xml +43 -0
  29. data/spec/fixtures/rfactor/full.xml +1023 -0
  30. data/spec/fixtures/rfactor/missing_root.xml +6 -0
  31. data/spec/fixtures/rfactor/single_driver.xml +85 -0
  32. data/spec/fixtures/rfactor/single_driver_dnf.xml +80 -0
  33. data/spec/fixtures/rfactor/single_driver_dsq.xml +79 -0
  34. data/spec/parsers/gtr2_parser_spec.rb +199 -0
  35. data/spec/parsers/race07_parser_spec.rb +155 -0
  36. data/spec/parsers/rfactor_parser_spec.rb +158 -0
  37. data/spec/spec_helper.rb +3 -0
  38. metadata +107 -0
@@ -0,0 +1,155 @@
1
+ require File.join( File.dirname(__FILE__), '..', 'spec_helper' )
2
+
3
+ describe Dyno::Parsers::Race07Parser do
4
+
5
+ it 'should respond to .parse' do
6
+ Dyno::Parsers::Race07Parser.should respond_to(:parse)
7
+ end
8
+
9
+ it 'should respond to .parse_file' do
10
+ Dyno::Parsers::Race07Parser.should respond_to(:parse_file)
11
+ end
12
+
13
+ it 'should respond to #parse' do
14
+ Dyno::Parsers::Race07Parser.public_instance_methods.should include('parse')
15
+ end
16
+
17
+ # --------------
18
+ # Event parsing.
19
+
20
+ describe 'parse_event!' do
21
+ before(:all) do
22
+ @event = Dyno::Parsers::Race07Parser.parse_file(
23
+ 'spec/fixtures/race07/header_only.ini'
24
+ )
25
+ end
26
+
27
+ it 'should set the game' do
28
+ @event.game.should == 'RACE 07'
29
+ end
30
+
31
+ it 'should correctly set the game version' do
32
+ # 1.1.1.14
33
+ @event.game_version.should == '1.1.1.14'
34
+ end
35
+
36
+ it 'should correctly set the event time' do
37
+ # 2008/09/13 23:00:50
38
+ @event.time.should == Time.local(2008, 9, 13, 23, 00, 50)
39
+ end
40
+
41
+ it 'should correctly set the track' do
42
+ @event.track.should == 'Anderstorp 2007'
43
+ end
44
+
45
+ it 'should not set the track if one could not be discerned' do
46
+ event = Dyno::Parsers::Race07Parser.parse_file(
47
+ 'spec/fixtures/race07/header_no_track.ini'
48
+ )
49
+
50
+ event.track.should be_nil
51
+ end
52
+
53
+ it 'should whine loudly if there is no "Header" section' do
54
+ lambda {
55
+ Dyno::Parsers::Race07Parser.parse_file(
56
+ 'spec/fixtures/race07/no_header_section.ini'
57
+ )
58
+ }.should raise_error(Dyno::MalformedInputError)
59
+ end
60
+ end
61
+
62
+ # -------------------
63
+ # Competitor parsing.
64
+
65
+ describe 'parse_competitors!' do
66
+ before(:all) do
67
+ @event = Dyno::Parsers::Race07Parser.parse_file(
68
+ 'spec/fixtures/race07/single_driver.ini'
69
+ )
70
+ end
71
+
72
+ it 'should set the driver name correctly' do
73
+ @event.competitors.first.name.should == 'Gabriel Lloyd'
74
+ end
75
+
76
+ it 'should set the vehicle correctly' do
77
+ @event.competitors.first.vehicle.should == 'Chevrolet Lacetti 2007'
78
+ end
79
+
80
+ it 'should set the steam id (uid) correctly' do
81
+ @event.competitors.first.uid.should == 635
82
+ end
83
+
84
+ it 'should not set the steam id if one is not present' do
85
+ event = Dyno::Parsers::Race07Parser.parse_file(
86
+ 'spec/fixtures/race07/no_steam_id.ini'
87
+ )
88
+
89
+ event.competitors.first.uid.should be_nil
90
+ end
91
+
92
+ it 'should set the lap count correctly' do
93
+ @event.competitors.first.laps.should == 13
94
+ end
95
+
96
+ it 'should convert the race time to a float' do
97
+ @event.competitors.first.race_time.should == 1296.73
98
+ end
99
+
100
+ it 'should convert the best lap time to a float' do
101
+ @event.competitors.first.best_lap.should == 97.825
102
+ end
103
+
104
+ it "should correctly set the competitors lap times" do
105
+ @event.competitors.first.lap_times.should == [
106
+ 110.816, # Lap=(0, -1.000, 1:50.816)
107
+ 98.835, # Lap=(1, 89.397, 1:38.835)
108
+ 98.082, # Lap=(2, 200.213, 1:38.082)
109
+ 98.367, # Lap=(3, 299.048, 1:38.367)
110
+ 97.825, # Lap=(4, 397.131, 1:37.825)
111
+ 98.757, # Lap=(5, 495.497, 1:38.757)
112
+ 98.718, # Lap=(6, 593.322, 1:38.718)
113
+ 98.478, # Lap=(7, 692.080, 1:38.478)
114
+ 99.347, # Lap=(8, 790.797, 1:39.347)
115
+ 98.713, # Lap=(9, 889.275, 1:38.713)
116
+ 98.952, # Lap=(10, 988.622, 1:38.952)
117
+ 99.285, # Lap=(11, 1087.336, 1:39.285)
118
+ 100.555 # Lap=(12, 1186.288, 1:40.555)
119
+ ]
120
+ end
121
+
122
+ it 'should correctly sort drivers by their finishing time, and assign their position' do
123
+ event = Dyno::Parsers::Race07Parser.parse_file(
124
+ 'spec/fixtures/race07/full.ini'
125
+ )
126
+
127
+ event.competitors[0].name.should == 'Gabriel Lloyd'
128
+ event.competitors[0].position.should == 1
129
+
130
+ event.competitors[1].name.should == 'Jerry Lalich'
131
+ event.competitors[1].position.should == 2
132
+
133
+ event.competitors[2].name.should == 'Mark Voss'
134
+ event.competitors[2].position.should == 3
135
+
136
+ event.competitors[3].name.should == 'Corey Ball'
137
+ event.competitors[3].position.should == 4
138
+
139
+ event.competitors[4].name.should == 'Reino Lintula'
140
+ event.competitors[4].position.should == 5
141
+ end
142
+
143
+ it 'should set a competitor as "did not finish" when necessary' do
144
+ Dyno::Parsers::Race07Parser.parse_file(
145
+ 'spec/fixtures/race07/single_driver_dnf.ini'
146
+ ).competitors[0].should be_dnf
147
+ end
148
+
149
+ it 'should set a competitor as "disqualified" when necessary' do
150
+ Dyno::Parsers::Race07Parser.parse_file(
151
+ 'spec/fixtures/race07/single_driver_dsq.ini'
152
+ ).competitors[0].should be_dsq
153
+ end
154
+ end
155
+ end
@@ -0,0 +1,158 @@
1
+ require File.join( File.dirname(__FILE__), '..', 'spec_helper' )
2
+
3
+ describe Dyno::Parsers::RFactorParser do
4
+
5
+ it 'should respond to .parse' do
6
+ Dyno::Parsers::RFactorParser.should respond_to(:parse)
7
+ end
8
+
9
+ it 'should respond to .parse_file' do
10
+ Dyno::Parsers::RFactorParser.should respond_to(:parse_file)
11
+ end
12
+
13
+ it 'should respond to #parse' do
14
+ Dyno::Parsers::RFactorParser.public_instance_methods.should include('parse')
15
+ end
16
+
17
+ # --------------
18
+ # Event parsing.
19
+
20
+ describe 'parse_event!' do
21
+ before(:all) do
22
+ @event = Dyno::Parsers::RFactorParser.parse_file(
23
+ 'spec/fixtures/rfactor/event_only.xml'
24
+ )
25
+ end
26
+
27
+ it 'should set the game' do
28
+ @event.game.should == 'JF3 2007'
29
+ end
30
+
31
+ it 'should correctly set the game version' do
32
+ # 1.255
33
+ @event.game_version.should == '1.255'
34
+ end
35
+
36
+ it 'should correctly set the event time' do
37
+ # 2008/12/21 21:56:13
38
+ @event.time.should == Time.local(2008, 12, 21, 21, 56, 13)
39
+ end
40
+
41
+ it 'should correctly set the track' do
42
+ @event.track.should == 'Suzuka 2005'
43
+ end
44
+
45
+ it 'should whine loudly if there is no "RaceResults" node' do
46
+ lambda {
47
+ Dyno::Parsers::RFactorParser.parse_file(
48
+ 'spec/fixtures/rfactor/missing_root.xml'
49
+ )
50
+ }.should raise_error(Dyno::MalformedInputError)
51
+ end
52
+ end
53
+
54
+ # -------------------
55
+ # Competitor parsing.
56
+
57
+ describe 'parse_competitors!' do
58
+ before(:all) do
59
+ @event = Dyno::Parsers::RFactorParser.parse_file(
60
+ 'spec/fixtures/rfactor/single_driver.xml'
61
+ )
62
+ end
63
+
64
+ it 'should set the driver name correctly' do
65
+ @event.competitors.first.name.should == 'Zach Evans'
66
+ end
67
+
68
+ it 'should set the vehicle correctly' do
69
+ @event.competitors.first.vehicle.should == 'JF3 2007'
70
+ end
71
+
72
+ it 'should set the lap count correctly' do
73
+ @event.competitors.first.laps.should == 17
74
+ end
75
+
76
+ it 'should convert the race time to a float' do
77
+ @event.competitors.first.race_time.should == 2049.6411
78
+ end
79
+
80
+ it 'should convert the best lap time to a float' do
81
+ @event.competitors.first.best_lap.should == 119.3561
82
+ end
83
+
84
+ it "should correctly set the competitors lap times" do
85
+ @event.competitors.first.lap_times.should == [
86
+ 130.5218, # <Lap num="1" [...] >130.5218</Lap>
87
+ 119.7023, # <Lap num="2" [...] >119.7023</Lap>
88
+ 120.2195, # <Lap num="3" [...] >120.2195</Lap>
89
+ 119.6123, # <Lap num="4" [...] >119.6123</Lap>
90
+ 120.2735, # <Lap num="5" [...] >120.2735</Lap>
91
+ 119.6417, # <Lap num="6" [...] >119.6417</Lap>
92
+ 119.6810, # <Lap num="7" [...] >119.6810</Lap>
93
+ 119.9735, # <Lap num="8" [...] >119.9735</Lap>
94
+ 120.0426, # <Lap num="9" [...] >120.0426</Lap>
95
+ 120.0213, # <Lap num="10" [...] >120.0213</Lap>
96
+ 120.5605, # <Lap num="11" [...] >120.5605</Lap>
97
+ 119.3561, # <Lap num="12" [...] >119.3561</Lap>
98
+ 120.2949, # <Lap num="13" [...] >120.2949</Lap>
99
+ 120.5171, # <Lap num="14" [...] >120.5171</Lap>
100
+ 120.1576, # <Lap num="15" [...] >120.1576</Lap>
101
+ 119.3593, # <Lap num="16" [...] >119.3593</Lap>
102
+ 119.7063 # <Lap num="17" [...] >119.7063</Lap>
103
+ ]
104
+ end
105
+
106
+ it 'should correctly sort drivers by their finishing time, and assign their position' do
107
+ event = Dyno::Parsers::RFactorParser.parse_file(
108
+ 'spec/fixtures/rfactor/full.xml'
109
+ )
110
+
111
+ [ [ "Zach Evans", 1 ],
112
+ [ "Archie Gray", 2 ],
113
+ [ "Jonathan Mistry", 3 ],
114
+ [ "Sjef Petersen", 4 ],
115
+ [ "Topi Keskinen", 5 ],
116
+ [ "Evan Hanson", 6 ],
117
+ [ "Tom M. Hall", 7 ],
118
+ [ "Oliver Baker", 8 ],
119
+ [ "Jamie Norman", 9 ],
120
+ [ "Haruaki Gotou", 10 ],
121
+ [ "Hiromitsu Kishimoto", 11 ],
122
+ [ "Edgar Est\303\251vez Guajardo", 12 ],
123
+ [ "Sabahudin Smerkolj", 13 ]
124
+ ].each do |(name, position)|
125
+ event.competitors[position - 1].name.should == name
126
+ event.competitors[position - 1].position.should == position
127
+ end
128
+ end
129
+
130
+ it 'should set a competitor as "did not finish" when necessary' do
131
+ Dyno::Parsers::RFactorParser.parse_file(
132
+ 'spec/fixtures/rfactor/single_driver_dnf.xml'
133
+ ).competitors.first.should be_dnf
134
+ end
135
+
136
+ it 'should set a competitor as "disqualified" when necessary' do
137
+ Dyno::Parsers::RFactorParser.parse_file(
138
+ 'spec/fixtures/rfactor/single_driver_dsq.xml'
139
+ ).competitors.first.should be_dsq
140
+ end
141
+
142
+ describe 'when parsing ARCA results' do
143
+ it 'should not raise an error' do
144
+ lambda{
145
+ Dyno::Parsers::RFactorParser.parse_file(
146
+ 'spec/fixtures/rfactor/arca.xml'
147
+ )
148
+ }.should_not raise_error
149
+ end
150
+
151
+ it 'should have the correct number of competitors' do
152
+ Dyno::Parsers::RFactorParser.parse_file(
153
+ 'spec/fixtures/rfactor/arca.xml'
154
+ ).competitors.size.should == 3
155
+ end
156
+ end
157
+ end
158
+ end
@@ -0,0 +1,3 @@
1
+ $TESTING=true
2
+ $:.push File.join(File.dirname(__FILE__), '..', 'lib')
3
+ require 'dyno'
metadata ADDED
@@ -0,0 +1,107 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: antw-dyno
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.2
5
+ platform: ruby
6
+ authors:
7
+ - Anthony Williams
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-05-08 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: iniparse
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 0.2.0
24
+ version:
25
+ description: A rubygem for parsing sim-racing results files.
26
+ email: anthony@ninecraft.com
27
+ executables: []
28
+
29
+ extensions: []
30
+
31
+ extra_rdoc_files:
32
+ - README.markdown
33
+ - LICENSE
34
+ files:
35
+ - LICENSE
36
+ - README.markdown
37
+ - Rakefile
38
+ - VERSION.yml
39
+ - lib/dyno
40
+ - lib/dyno/competitor.rb
41
+ - lib/dyno/event.rb
42
+ - lib/dyno/parsers
43
+ - lib/dyno/parsers/gtr2_parser.rb
44
+ - lib/dyno/parsers/race07_parser.rb
45
+ - lib/dyno/parsers/rfactor_parser.rb
46
+ - lib/dyno.rb
47
+ - spec/competitor_spec.rb
48
+ - spec/event_spec.rb
49
+ - spec/fixtures
50
+ - spec/fixtures/gtr2
51
+ - spec/fixtures/gtr2/full.ini
52
+ - spec/fixtures/gtr2/header_no_track.ini
53
+ - spec/fixtures/gtr2/header_only.ini
54
+ - spec/fixtures/gtr2/no_header_section.ini
55
+ - spec/fixtures/gtr2/single_driver.ini
56
+ - spec/fixtures/race07
57
+ - spec/fixtures/race07/full.ini
58
+ - spec/fixtures/race07/header_no_track.ini
59
+ - spec/fixtures/race07/header_only.ini
60
+ - spec/fixtures/race07/no_header_section.ini
61
+ - spec/fixtures/race07/no_steam_id.ini
62
+ - spec/fixtures/race07/single_driver.ini
63
+ - spec/fixtures/race07/single_driver_dnf.ini
64
+ - spec/fixtures/race07/single_driver_dsq.ini
65
+ - spec/fixtures/readme.markdown
66
+ - spec/fixtures/rfactor
67
+ - spec/fixtures/rfactor/arca.xml
68
+ - spec/fixtures/rfactor/event_only.xml
69
+ - spec/fixtures/rfactor/full.xml
70
+ - spec/fixtures/rfactor/missing_root.xml
71
+ - spec/fixtures/rfactor/single_driver.xml
72
+ - spec/fixtures/rfactor/single_driver_dnf.xml
73
+ - spec/fixtures/rfactor/single_driver_dsq.xml
74
+ - spec/parsers
75
+ - spec/parsers/gtr2_parser_spec.rb
76
+ - spec/parsers/race07_parser_spec.rb
77
+ - spec/parsers/rfactor_parser_spec.rb
78
+ - spec/spec_helper.rb
79
+ has_rdoc: true
80
+ homepage: http://github.com/anthonyw/dyno
81
+ post_install_message:
82
+ rdoc_options:
83
+ - --inline-source
84
+ - --charset=UTF-8
85
+ require_paths:
86
+ - lib
87
+ required_ruby_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ version: "0"
92
+ version:
93
+ required_rubygems_version: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: "0"
98
+ version:
99
+ requirements: []
100
+
101
+ rubyforge_project:
102
+ rubygems_version: 1.2.0
103
+ signing_key:
104
+ specification_version: 2
105
+ summary: A rubygem for parsing sim-racing results files.
106
+ test_files: []
107
+