ergast_f1 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +12 -0
- data/.rspec +2 -0
- data/.travis.yml +5 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +7 -0
- data/LICENSE.txt +21 -0
- data/README.md +95 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/ergast_f1.gemspec +33 -0
- data/lib/ergast_f1.rb +22 -0
- data/lib/ergast_f1/ergast_client.rb +27 -0
- data/lib/ergast_f1/race.rb +81 -0
- data/lib/ergast_f1/season.rb +35 -0
- data/lib/ergast_f1/version.rb +3 -0
- data/lib/runner.rb +7 -0
- data/todo.txt +33 -0
- data/vcr_cassettes/collisions_hungary_2017.yml +36 -0
- data/vcr_cassettes/construction_standings.yml +49 -0
- data/vcr_cassettes/current_season_cassette.yml +227 -0
- data/vcr_cassettes/driver_standings.yml +334 -0
- data/vcr_cassettes/engine_failure_hungary_2017.yml +34 -0
- data/vcr_cassettes/fastest_lap_australia_2017.yml +36 -0
- data/vcr_cassettes/hungary_2017_finishers.yml +34 -0
- data/vcr_cassettes/jerez_1997.yml +51 -0
- data/vcr_cassettes/last_round_1997.yml +46 -0
- data/vcr_cassettes/latest_race_result.yml +310 -0
- data/vcr_cassettes/nonexistent_1989_circuit_name.yml +34 -0
- data/vcr_cassettes/nonexistent_grid_position.yml +34 -0
- data/vcr_cassettes/nonexistent_round.yml +65 -0
- data/vcr_cassettes/race_by_grid_position.yml +35 -0
- data/vcr_cassettes/race_filtered_on_constructor.yml +35 -0
- data/vcr_cassettes/race_filtered_on_nonexistent_constructor.yml +34 -0
- data/vcr_cassettes/season_cassette.yml +61 -0
- data/vcr_cassettes/second_fastest_lap.yml +36 -0
- data/vcr_cassettes/senna_monaco_1994.yml +34 -0
- data/vcr_cassettes/suzuka_1989_by_circuit_name.yml +50 -0
- data/vcr_cassettes/suzuka_1989_by_round.yml +338 -0
- data/vcr_cassettes/vettel_result_hungaroring_2017_by_circuit.yml +35 -0
- data/vcr_cassettes/vettel_result_hungaroring_2017_by_round_number.yml +51 -0
- metadata +197 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ba4fe8c5822d06158b23f315a94017a966e094c9
|
4
|
+
data.tar.gz: b64631ed4c894aad83de73737e87ab26920e49b7
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4c94b7f8563f1715255daf8ce40cddf8bc2f610b8a8c169aeb6807edaaf87f51f48e8f5a60eeb1541e250da20e83fd5834264e634a18145f2b9f4bf3a851b93d
|
7
|
+
data.tar.gz: ccf5dd98d99dbedd2f3d15c50bc65d00698dd228afac8eae5ab2f6380eaab0d2cd0d317385d1e292854bc3056fe10bce8bbb0f3fd7994aad918c3f9b4ce09868
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at nathan@3playmedia.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 Nathan Burgess
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
# ErgastF1-Ruby
|
2
|
+
ErgastF1-Ruby is a Ruby gem wrapper for using the [ErgastF1 API](http://ergast.com/mrd/).
|
3
|
+
It currently supports querying Formula 1 race results by season year and round number or circuit name. Additionally, it includes support for filtering a race result by driver, constructor, finishing position, grid position and finishing status/cause of retirement (ex. "Finished", "Gearbox", "Engine"). Future features will include schedules, qualifying results, standings, driver information and more.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'ergast_f1'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install ergast_f1
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
### Querying Race Results
|
24
|
+
To return all data for a specific race, initialize an instance of `ErgastF1::Race` with a season year and either a round number or a circuit name and call `.result`:
|
25
|
+
|
26
|
+
```ruby
|
27
|
+
ErgastF1::Race.new(year: 1989, round: 15).result
|
28
|
+
ErgastF1::Race.new(year: 1989, circuit: "Suzuka").result
|
29
|
+
|
30
|
+
```
|
31
|
+
Results from the ErgastF1 API are supplied as an array. If no results are found, an empty array is returned.
|
32
|
+
|
33
|
+
### Filtering results
|
34
|
+
Results can be filtered by a number of parameters:
|
35
|
+
|
36
|
+
```ruby
|
37
|
+
race = ErgastF1::Race.new(year: 2017, circuit: "Hungaroring")
|
38
|
+
|
39
|
+
#Constructor Name
|
40
|
+
race.constructor_result("Ferrari")
|
41
|
+
|
42
|
+
#Driver Family Name
|
43
|
+
race.driver_result("Vettel")
|
44
|
+
|
45
|
+
#Starting Grid Position
|
46
|
+
race.grid_position(6)
|
47
|
+
|
48
|
+
#Fastest Laptime Ranking - the driver with the supplied ranking for fastest laptime
|
49
|
+
race.laptime_ranking(1)
|
50
|
+
|
51
|
+
```
|
52
|
+
### Filtering by finishing status
|
53
|
+
ErgastF1-Ruby supports filtering race results by a scored "finishing status", i.e., if the driver finished or, if they retired, the reason why.
|
54
|
+
```ruby
|
55
|
+
race.finishing_status("Engine")
|
56
|
+
```
|
57
|
+
Valid ilters for finishing status:
|
58
|
+
|
59
|
+
* Finished
|
60
|
+
* Disqualified
|
61
|
+
* Accident
|
62
|
+
* Collision
|
63
|
+
* Engine
|
64
|
+
* Gearbox
|
65
|
+
* Transmission
|
66
|
+
* Clutch
|
67
|
+
* Hydraulics
|
68
|
+
* Electrical
|
69
|
+
* Spun
|
70
|
+
* Radiator
|
71
|
+
* Suspension
|
72
|
+
* Brakes
|
73
|
+
* Differential
|
74
|
+
* Overheating
|
75
|
+
* Mechanical
|
76
|
+
* Tyre
|
77
|
+
* Driver Seat
|
78
|
+
* Puncture
|
79
|
+
* Driveshaft
|
80
|
+
|
81
|
+
## Development
|
82
|
+
|
83
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
84
|
+
|
85
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
86
|
+
|
87
|
+
## Contributing
|
88
|
+
|
89
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/Nathan Burgess/ergast_f1. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
90
|
+
|
91
|
+
|
92
|
+
## License
|
93
|
+
|
94
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
95
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "ergast_f1"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/ergast_f1.gemspec
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'ergast_f1/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "ergast_f1"
|
8
|
+
spec.version = ErgastF1::VERSION
|
9
|
+
spec.authors = ["Nathan Burgess"]
|
10
|
+
spec.email = ["burgess.nathan28@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{A Ruby wrapper for the ergast F1 API}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
17
|
+
f.match(%r{^(test|spec|features)/})
|
18
|
+
end
|
19
|
+
spec.bindir = "exe"
|
20
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
21
|
+
spec.require_paths = ["lib"]
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.14"
|
24
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
25
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
26
|
+
spec.add_development_dependency "pry"
|
27
|
+
spec.add_development_dependency "vcr"
|
28
|
+
spec.add_development_dependency "webmock"
|
29
|
+
|
30
|
+
spec.add_runtime_dependency "json"
|
31
|
+
spec.add_runtime_dependency "curb"
|
32
|
+
|
33
|
+
end
|
data/lib/ergast_f1.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
require "ergast_f1/version"
|
2
|
+
require "ergast_f1/season"
|
3
|
+
require "ergast_f1/race"
|
4
|
+
require "ergast_f1/ergast_client"
|
5
|
+
|
6
|
+
require "json"
|
7
|
+
require "curb"
|
8
|
+
|
9
|
+
# TODO: INHERIT FROM MORE USEFUL ERROR TYPES
|
10
|
+
class BadQuery < StandardError; end
|
11
|
+
class ApiError < StandardError; end
|
12
|
+
|
13
|
+
class TestMe
|
14
|
+
def self.hello
|
15
|
+
puts "hello world"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
|
20
|
+
module ErgastF1
|
21
|
+
# Your code goes here...
|
22
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
class ErgastClient
|
2
|
+
BASE_URL = "http://ergast.com/api/f1/"
|
3
|
+
|
4
|
+
def initialize(endpoint_path)
|
5
|
+
# TODO: SUPPORT OTHER FORMATS BESIDES JSON
|
6
|
+
@endpoint = BASE_URL + endpoint_path + ".json"
|
7
|
+
end
|
8
|
+
|
9
|
+
def api_get_request
|
10
|
+
c = Curl::Easy.new(@endpoint)
|
11
|
+
c.connect_timeout = 60
|
12
|
+
c.timeout = 300
|
13
|
+
c.http_get()
|
14
|
+
# TODO: ADD CONNECTION ERROR HANDLING
|
15
|
+
return json_parse_response(c.body_str)
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def json_parse_response(response)
|
21
|
+
begin
|
22
|
+
return JSON.parse(response)
|
23
|
+
rescue JSON::ParserError
|
24
|
+
return ApiError, "Error: invalid JSON reponse from ErgastF1 server"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
module ErgastF1
|
2
|
+
class Race
|
3
|
+
STATUS_TABLE = {"Finished" => "1",
|
4
|
+
"Disqualified" => "2",
|
5
|
+
"Accident" => "3",
|
6
|
+
"Collision" => "4",
|
7
|
+
"Engine" => "5",
|
8
|
+
"Gearbox" => "6",
|
9
|
+
"Transmission" => "7",
|
10
|
+
"Clutch" => "8",
|
11
|
+
"Hydraulics" => "9",
|
12
|
+
"Electrical" => "10",
|
13
|
+
"Spun" => "20",
|
14
|
+
"Radiator" => "21",
|
15
|
+
"Suspension" => "22",
|
16
|
+
"Brakes" => "23",
|
17
|
+
"Differential" => "24",
|
18
|
+
"Overheating" => "25",
|
19
|
+
"Mechanical" => "26",
|
20
|
+
"Tyre" => "27",
|
21
|
+
"Driver Seat" => "28",
|
22
|
+
"Puncture" => "29",
|
23
|
+
"Driveshaft" => "30"
|
24
|
+
}
|
25
|
+
|
26
|
+
def initialize(year: nil, circuit: nil, round: nil)
|
27
|
+
@year = year || Time.now.year
|
28
|
+
@circuit = circuit
|
29
|
+
@round = round
|
30
|
+
end
|
31
|
+
|
32
|
+
def result
|
33
|
+
race_data(race_path + "/results")
|
34
|
+
end
|
35
|
+
|
36
|
+
def constructor_result(constructor_name)
|
37
|
+
race_data(race_path + "/constructors/#{constructor_name}/results")
|
38
|
+
end
|
39
|
+
|
40
|
+
def driver_result(driver_name)
|
41
|
+
race_data(race_path + "/drivers/#{driver_name}/results")
|
42
|
+
end
|
43
|
+
|
44
|
+
def grid_position(position)
|
45
|
+
race_data(race_path + "/grid/#{position}/results")
|
46
|
+
end
|
47
|
+
|
48
|
+
def finishing_status(status)
|
49
|
+
finishing_status = resolve_finishing_status(status)
|
50
|
+
race_data(race_path + "/status/#{finishing_status}/results")
|
51
|
+
end
|
52
|
+
|
53
|
+
def laptime_ranking(position=nil)
|
54
|
+
raise BadQuery, "Fastest lap data isn't available for races before 2004" if @year < 2004
|
55
|
+
race_data(race_path + "/fastest/#{position}/results")
|
56
|
+
end
|
57
|
+
|
58
|
+
private
|
59
|
+
|
60
|
+
def race_path
|
61
|
+
if @round
|
62
|
+
"#{@year}/#{@round}"
|
63
|
+
elsif @circuit
|
64
|
+
"#{@year}/circuits/#{@circuit}"
|
65
|
+
else
|
66
|
+
"#{@year}/last"
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def resolve_finishing_status(status)
|
71
|
+
STATUS_TABLE[status] || (raise BadQuery, "Invalid status supplied. Valid status arguments are: Finished, Disqualified, Accident, Collision, Engine, Gearbox, Transmission, Clutch, Hydraulics, Electrical, Spun, Radiator, Suspension, Brakes, Differential, Overheating, Mechanical, Tyre, Driver, Puncture, Driveshaft.")
|
72
|
+
end
|
73
|
+
|
74
|
+
def race_data(endpoint)
|
75
|
+
parsed_response = ErgastClient.new(endpoint).api_get_request
|
76
|
+
race_results = parsed_response.dig("MRData", "RaceTable", "Races")
|
77
|
+
return [] if race_results.empty?
|
78
|
+
race_results.first["Results"]
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module ErgastF1
|
2
|
+
class Season
|
3
|
+
def initialize(year=nil)
|
4
|
+
@year = year || Time.now.year
|
5
|
+
end
|
6
|
+
|
7
|
+
def races(round=nil)
|
8
|
+
season_data = get_season
|
9
|
+
|
10
|
+
if round
|
11
|
+
season_data.dig("MRData", "RaceTable", "Races").select{|r| r["round"] == round.to_s}.first || (raise ApiError, "Nonexistent Round Number Specified")
|
12
|
+
else
|
13
|
+
season_data.dig("MRData", "RaceTable", "Races")
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def driver_standings
|
18
|
+
parsed_response = ErgastClient.new("#{@year}/driverStandings").api_get_request
|
19
|
+
# Uh oh, array for standings lists
|
20
|
+
parsed_response.dig("MRData", "StandingsTable", "StandingsLists").first["DriverStandings"]
|
21
|
+
end
|
22
|
+
|
23
|
+
def constructor_standings
|
24
|
+
parsed_response = ErgastClient.new("#{@year}/constructorStandings").api_get_request
|
25
|
+
# Uh oh, array for standings lists
|
26
|
+
parsed_response.dig("MRData", "StandingsTable", "StandingsLists").first["ConstructorStandings"]
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def get_season
|
32
|
+
ErgastClient.new("#{@year}").api_get_request
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|