live_f1-core 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (109) hide show
  1. data/.autotest +23 -0
  2. data/.gitignore +6 -0
  3. data/.rspec +1 -0
  4. data/Gemfile +3 -0
  5. data/Gemfile.lock +65 -0
  6. data/Guardfile +11 -0
  7. data/README.rdoc +62 -0
  8. data/Rakefile +11 -0
  9. data/bin/live_f1_example +74 -0
  10. data/features/fixtures/sessions/2012.03.china.qualifying/7136/keyframes.yaml +32722 -0
  11. data/features/fixtures/sessions/2012.03.china.qualifying/7136/session.key +1 -0
  12. data/features/fixtures/sessions/2012.03.china.qualifying/session.bin +0 -0
  13. data/features/fixtures/sessions/2012.04.bahrain.practice.2/7164/keyframes.yaml +22403 -0
  14. data/features/fixtures/sessions/2012.04.bahrain.practice.2/7164/session.key +1 -0
  15. data/features/fixtures/sessions/2012.04.bahrain.practice.2/session.bin +0 -0
  16. data/features/fixtures/sessions/2012.05.bahrain.race.post/7167/keyframes.yaml +1204 -0
  17. data/features/fixtures/sessions/2012.05.bahrain.race.post/7167/session.key +1 -0
  18. data/features/fixtures/sessions/2012.05.bahrain.race.post/session.bin +0 -0
  19. data/features/live_f1.feature +14 -0
  20. data/features/step_definitions/live_f1_steps.rb +69 -0
  21. data/features/support/env.rb +9 -0
  22. data/lib/live_f1/debug.rb +6 -0
  23. data/lib/live_f1/enum.rb +9 -0
  24. data/lib/live_f1/event.rb +23 -0
  25. data/lib/live_f1/packet/car/best_lap_time.rb +10 -0
  26. data/lib/live_f1/packet/car/driver.rb +14 -0
  27. data/lib/live_f1/packet/car/gap.rb +10 -0
  28. data/lib/live_f1/packet/car/interval.rb +10 -0
  29. data/lib/live_f1/packet/car/lap_count.rb +10 -0
  30. data/lib/live_f1/packet/car/lap_time.rb +10 -0
  31. data/lib/live_f1/packet/car/num_pits.rb +10 -0
  32. data/lib/live_f1/packet/car/number.rb +14 -0
  33. data/lib/live_f1/packet/car/period_1.rb +11 -0
  34. data/lib/live_f1/packet/car/period_2.rb +11 -0
  35. data/lib/live_f1/packet/car/period_3.rb +11 -0
  36. data/lib/live_f1/packet/car/pit_count.rb +18 -0
  37. data/lib/live_f1/packet/car/pit_lap_1.rb +10 -0
  38. data/lib/live_f1/packet/car/pit_lap_2.rb +10 -0
  39. data/lib/live_f1/packet/car/pit_lap_3.rb +10 -0
  40. data/lib/live_f1/packet/car/position.rb +14 -0
  41. data/lib/live_f1/packet/car/position_history.rb +14 -0
  42. data/lib/live_f1/packet/car/position_update.rb +13 -0
  43. data/lib/live_f1/packet/car/sector_1.rb +11 -0
  44. data/lib/live_f1/packet/car/sector_2.rb +11 -0
  45. data/lib/live_f1/packet/car/sector_3.rb +11 -0
  46. data/lib/live_f1/packet/car.rb +13 -0
  47. data/lib/live_f1/packet/decryptable.rb +22 -0
  48. data/lib/live_f1/packet/header.rb +127 -0
  49. data/lib/live_f1/packet/sector_time.rb +28 -0
  50. data/lib/live_f1/packet/sys/commentary.rb +33 -0
  51. data/lib/live_f1/packet/sys/copyright.rb +9 -0
  52. data/lib/live_f1/packet/sys/key_frame.rb +17 -0
  53. data/lib/live_f1/packet/sys/notice.rb +10 -0
  54. data/lib/live_f1/packet/sys/reset.rb +9 -0
  55. data/lib/live_f1/packet/sys/session_start.rb +25 -0
  56. data/lib/live_f1/packet/sys/speed.rb +29 -0
  57. data/lib/live_f1/packet/sys/timestamp.rb +23 -0
  58. data/lib/live_f1/packet/sys/track_status.rb +18 -0
  59. data/lib/live_f1/packet/sys/weather.rb +33 -0
  60. data/lib/live_f1/packet/sys.rb +10 -0
  61. data/lib/live_f1/packet.rb +129 -0
  62. data/lib/live_f1/source/keyframe.rb +30 -0
  63. data/lib/live_f1/source/live.rb +163 -0
  64. data/lib/live_f1/source/log.rb +29 -0
  65. data/lib/live_f1/source/session.rb +41 -0
  66. data/lib/live_f1/source.rb +83 -0
  67. data/lib/live_f1/version.rb +3 -0
  68. data/lib/live_f1.rb +32 -0
  69. data/live_f1-core.gemspec +26 -0
  70. data/spec/live_f1/event_spec.rb +5 -0
  71. data/spec/live_f1/packet/car/best_lap_time_spec.rb +19 -0
  72. data/spec/live_f1/packet/car/driver_spec.rb +20 -0
  73. data/spec/live_f1/packet/car/gap_spec.rb +20 -0
  74. data/spec/live_f1/packet/car/interval_spec.rb +20 -0
  75. data/spec/live_f1/packet/car/lap_count_spec.rb +20 -0
  76. data/spec/live_f1/packet/car/lap_time_spec.rb +20 -0
  77. data/spec/live_f1/packet/car/number_spec.rb +20 -0
  78. data/spec/live_f1/packet/car/period_1_spec.rb +21 -0
  79. data/spec/live_f1/packet/car/period_2_spec.rb +21 -0
  80. data/spec/live_f1/packet/car/period_3_spec.rb +21 -0
  81. data/spec/live_f1/packet/car/pit_count_spec.rb +20 -0
  82. data/spec/live_f1/packet/car/pit_lap_1_spec.rb +20 -0
  83. data/spec/live_f1/packet/car/pit_lap_2_spec.rb +20 -0
  84. data/spec/live_f1/packet/car/pit_lap_3_spec.rb +20 -0
  85. data/spec/live_f1/packet/car/position_history_spec.rb +20 -0
  86. data/spec/live_f1/packet/car/position_spec.rb +20 -0
  87. data/spec/live_f1/packet/car/position_update_spec.rb +19 -0
  88. data/spec/live_f1/packet/car/sector_1_spec.rb +21 -0
  89. data/spec/live_f1/packet/car/sector_2_spec.rb +21 -0
  90. data/spec/live_f1/packet/car/sector_3_spec.rb +21 -0
  91. data/spec/live_f1/packet/header_spec.rb +148 -0
  92. data/spec/live_f1/packet/sys/commentary_spec.rb +45 -0
  93. data/spec/live_f1/packet/sys/copyright_spec.rb +19 -0
  94. data/spec/live_f1/packet/sys/key_frame_spec.rb +39 -0
  95. data/spec/live_f1/packet/sys/notice_spec.rb +20 -0
  96. data/spec/live_f1/packet/sys/reset_spec.rb +26 -0
  97. data/spec/live_f1/packet/sys/session_start_spec.rb +31 -0
  98. data/spec/live_f1/packet/sys/speed_spec.rb +20 -0
  99. data/spec/live_f1/packet/sys/timestamp_spec.rb +34 -0
  100. data/spec/live_f1/packet/sys/track_status_spec.rb +20 -0
  101. data/spec/live_f1/packet/sys/weather_spec.rb +20 -0
  102. data/spec/live_f1/packet_spec.rb +112 -0
  103. data/spec/live_f1/source/keyframe_spec.rb +56 -0
  104. data/spec/live_f1/source/live_spec.rb +106 -0
  105. data/spec/live_f1/source/session_spec.rb +39 -0
  106. data/spec/live_f1/source_spec.rb +140 -0
  107. data/spec/spec_helper.rb +10 -0
  108. data/spec/support/packet_type_examples.rb +122 -0
  109. metadata +337 -0
data/.autotest ADDED
@@ -0,0 +1,23 @@
1
+ # -*- ruby -*-
2
+
3
+ require 'autotest/restart'
4
+
5
+ # Autotest.add_hook :initialize do |at|
6
+ # at.extra_files << "../some/external/dependency.rb"
7
+ #
8
+ # at.libs << ":../some/external"
9
+ #
10
+ # at.add_exception 'vendor'
11
+ #
12
+ # at.add_mapping(/dependency.rb/) do |f, _|
13
+ # at.files_matching(/test_.*rb$/)
14
+ # end
15
+ #
16
+ # %w(TestA TestB).each do |klass|
17
+ # at.extra_class_map[klass] = "test/test_misc.rb"
18
+ # end
19
+ # end
20
+
21
+ # Autotest.add_hook :run_command do |at|
22
+ # system "rake build"
23
+ # end
data/.gitignore ADDED
@@ -0,0 +1,6 @@
1
+ .DS_Store
2
+ .idea/
3
+ .yardoc/
4
+ doc/
5
+ data/
6
+ *.gem
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source :gemcutter
2
+
3
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,65 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ live_f1-core (0.0.1)
5
+
6
+ GEM
7
+ remote: http://rubygems.org/
8
+ specs:
9
+ builder (3.1.4)
10
+ coderay (1.0.8)
11
+ cucumber (1.2.1)
12
+ builder (>= 2.1.2)
13
+ diff-lcs (>= 1.1.3)
14
+ gherkin (~> 2.11.0)
15
+ json (>= 1.4.6)
16
+ diff-lcs (1.1.3)
17
+ fakeweb (1.3.0)
18
+ gherkin (2.11.5)
19
+ json (>= 1.4.6)
20
+ growl (1.0.3)
21
+ guard (1.5.0)
22
+ listen (>= 0.4.2)
23
+ lumberjack (>= 1.0.2)
24
+ pry (>= 0.9.10)
25
+ thor (>= 0.14.6)
26
+ guard-cucumber (1.2.0)
27
+ cucumber (>= 1.2.0)
28
+ guard (>= 1.1.0)
29
+ guard-rspec (2.1.0)
30
+ guard (>= 1.1)
31
+ rspec (~> 2.11)
32
+ hpricot (0.8.6)
33
+ json (1.7.5)
34
+ listen (0.5.3)
35
+ lumberjack (1.0.2)
36
+ method_source (0.8.1)
37
+ pry (0.9.10)
38
+ coderay (~> 1.0.5)
39
+ method_source (~> 0.8)
40
+ slop (~> 3.3.1)
41
+ rb-fsevent (0.9.2)
42
+ rspec (2.11.0)
43
+ rspec-core (~> 2.11.0)
44
+ rspec-expectations (~> 2.11.0)
45
+ rspec-mocks (~> 2.11.0)
46
+ rspec-core (2.11.1)
47
+ rspec-expectations (2.11.3)
48
+ diff-lcs (~> 1.1.3)
49
+ rspec-mocks (2.11.3)
50
+ slop (3.3.3)
51
+ thor (0.16.0)
52
+
53
+ PLATFORMS
54
+ ruby
55
+
56
+ DEPENDENCIES
57
+ cucumber
58
+ fakeweb
59
+ growl
60
+ guard-cucumber
61
+ guard-rspec
62
+ hpricot
63
+ live_f1-core!
64
+ rb-fsevent
65
+ rspec
data/Guardfile ADDED
@@ -0,0 +1,11 @@
1
+ guard 'rspec', :run_all => {:cli => "-f documentation -t focus"} do
2
+ watch(%r{^spec/.+_spec\.rb$})
3
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
4
+ watch('spec/spec_helper.rb') { "spec" }
5
+ end
6
+
7
+ guard 'cucumber', :change_format => "pretty" do
8
+ watch(%r{^features/.+\.feature$})
9
+ watch(%r{^features/support/.+$}) { 'features' }
10
+ watch(%r{^features/step_definitions/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'features' }
11
+ end
data/README.rdoc ADDED
@@ -0,0 +1,62 @@
1
+ = LiveF1
2
+
3
+ * TODO: URL
4
+
5
+ == DESCRIPTION
6
+
7
+ LiveF1 provides an API to receive data from the official live timing servers. It uses the same data that's streamed to the live timing applet at www.formula1.com/live_timing - and needs you to have a corresponding account to decrypt the stream - but enables you to have a more fine-grained access to the numbers.
8
+
9
+ == FEATURES
10
+
11
+ * Connects to the live timing stream and reports timing events which are detected
12
+
13
+ == SYNOPSIS
14
+
15
+ At this stage of development there isn't much of an external API. Take a look at the features or dig into the code to find out more.
16
+
17
+ == REQUIREMENTS
18
+
19
+ * Ruby 1.9.x
20
+
21
+ == INSTALL
22
+
23
+ The project uses Bundler, so get all the development dependencies with a simple
24
+
25
+ $ bundle install
26
+
27
+ == KNOWN ISSUES
28
+
29
+ * Currently live binary data is not being logged for playback
30
+
31
+ == LICENSE
32
+
33
+ (The MIT License)
34
+
35
+ Copyright (c) 2012
36
+
37
+ Permission is hereby granted, free of charge, to any person obtaining
38
+ a copy of this software and associated documentation files (the
39
+ 'Software'), to deal in the Software without restriction, including
40
+ without limitation the rights to use, copy, modify, merge, publish,
41
+ distribute, sublicense, and/or sell copies of the Software, and to
42
+ permit persons to whom the Software is furnished to do so, subject to
43
+ the following conditions
44
+
45
+ The above copyright notice and this permission notice shall be
46
+ included in all copies or substantial portions of the Software.
47
+
48
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
49
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
50
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
51
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
52
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
53
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
54
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
55
+
56
+ == DATA LICENSE
57
+
58
+ Data consumed using this library is and remains property of Formula One
59
+ Management Limited ('FOM'). It would be a VERY BAD IDEA to use it for anything
60
+ other than personal, non-commercial use.
61
+
62
+ http://www.formula1.com/termsandconditions.html
data/Rakefile ADDED
@@ -0,0 +1,11 @@
1
+ require 'cucumber/rake/task'
2
+ require 'rspec/core/rake_task'
3
+
4
+ Cucumber::Rake::Task.new(:features) do |t|
5
+ t.cucumber_opts = "--format progress"
6
+ end
7
+
8
+ RSpec::Core::RakeTask.new(:spec)
9
+
10
+ desc "Run the entire test suite"
11
+ task :default => [:spec, :features]
@@ -0,0 +1,74 @@
1
+ #!/usr/bin/env ruby
2
+ require 'rubygems'
3
+ require 'optparse'
4
+ require 'highline'
5
+
6
+ $: << File.join(File.dirname(__FILE__), '..', 'lib')
7
+ require 'live_f1'
8
+
9
+ options = {}
10
+ OptionParser.new do |opts|
11
+ opts.separator ""
12
+ opts.separator "Specific options:"
13
+
14
+ opts.on("-f LOGFILE", "--file", "Replays the given previously recorded .f1 data file (if not specified, will attempt to connect to the live timing server)") do |logfile|
15
+ options[:logfile] = logfile
16
+ end
17
+ opts.on("-u USERNAME", "--username", "For live connections, specify the formula1.com live timing username") do |username|
18
+ options[:username] = username
19
+ end
20
+ opts.on("-p [PASSWORD]", "--password", "For live connections, specify the formula1.com live timing password. Omitting the password will cause live-f1 to prompt for it.") do |password|
21
+ unless password
22
+ prompt = HighLine.new
23
+ password = prompt.ask("Password: ") { |q| q.echo = false }
24
+ end
25
+ options[:password] = password
26
+ end
27
+ opts.on("-d", "--debug", "Display bit data from each data packet's header") do
28
+ LiveF1.debug = true
29
+ end
30
+
31
+ opts.on_tail("-h", "--help", "Show this message") do
32
+ puts opts
33
+ exit
34
+ end
35
+
36
+ end.parse!
37
+
38
+ if options[:logfile]
39
+
40
+ timestamp = nil
41
+ packets = []
42
+
43
+ source = LiveF1::Source::Log.new(File.open(options[:logfile]))
44
+ source.run do |packet|
45
+ packets << packet
46
+ case packet
47
+ when LiveF1::Packet::Sys::Timestamp
48
+ t_start = timestamp || packet.number
49
+ t_end = packet.number
50
+ t_diff = t_end - t_start
51
+
52
+ # The interval is the difference in time between the last 2 timestamps, divided
53
+ # by the number of packets between the timestamps. This is then divided by 4 to
54
+ # speed up the replay
55
+ interval = t_diff.to_f / (packets.length) / 8
56
+ packets.pop # Remove the timestamp packet from the output queue
57
+ while p = packets.shift
58
+ puts p.inspect
59
+ sleep interval
60
+ end
61
+ timestamp = packet.number
62
+ end
63
+ end
64
+
65
+ else
66
+
67
+ source = LiveF1::Source::Live.new(options[:username], options[:password])
68
+ source.log_dir = "./data"
69
+ source.run do |packet|
70
+ puts packet.inspect
71
+ end
72
+
73
+ end
74
+