ftc_event 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.idea/.gitignore +2 -0
- data/.idea/.rakeTasks +7 -0
- data/.idea/ftc_event.iml +32 -0
- data/.idea/inspectionProfiles/Project_Default.xml +6 -0
- data/.idea/inspectionProfiles/profiles_settings.xml +5 -0
- data/.idea/misc.xml +7 -0
- data/.idea/modules.xml +8 -0
- data/.idea/vcs.xml +6 -0
- data/.rspec +3 -0
- data/.rubocop.yml +17 -0
- data/.travis.yml +7 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +53 -0
- data/LICENSE.txt +21 -0
- data/README.md +54 -0
- data/Rakefile +8 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/ftc_event.gemspec +33 -0
- data/lib/ftc_event/alliance.rb +47 -0
- data/lib/ftc_event/elimination.rb +75 -0
- data/lib/ftc_event/eliminations.rb +33 -0
- data/lib/ftc_event/event.rb +75 -0
- data/lib/ftc_event/league.rb +36 -0
- data/lib/ftc_event/match.rb +161 -0
- data/lib/ftc_event/qualification.rb +63 -0
- data/lib/ftc_event/qualifications.rb +33 -0
- data/lib/ftc_event/team.rb +55 -0
- data/lib/ftc_event/version.rb +5 -0
- data/lib/ftc_event.rb +17 -0
- metadata +144 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: bc1e3cbb8a698c4fdc0f7d8bf55a14669b9c2f6dbae46db3ba38478bae0d5352
|
4
|
+
data.tar.gz: c54d67ec82119e7f32cd8dd1878d03dd71f05ef869c6c72af7107dce325f3aef
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 670b6da28f10e983adb64421811e266edbb976096ba0c2b6e04352b133e29832c69a524fd418e59ea3f9ee6feadb167c3ab9e87ef4d2031a6c88df01f239df21
|
7
|
+
data.tar.gz: 843e8f6813a102cb5096cf2a1bc726ed7d00674341c098d285b49e60c3c947adb4e7d265a9943e0b234185612955ae588895adaca0ce1f0e2f8da1a6421b28cb
|
data/.gitignore
ADDED
data/.idea/.gitignore
ADDED
data/.idea/.rakeTasks
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<Settings><!--This file was automatically generated by Ruby plugin.
|
3
|
+
You are allowed to:
|
4
|
+
1. Remove rake task
|
5
|
+
2. Add existing rake tasks
|
6
|
+
To add existing rake tasks automatically delete this file and reload the project.
|
7
|
+
--><RakeGroup description="" fullCmd="" taksId="rake"><RakeTask description="Build ftc_event-0.1.0.gem into the pkg directory" fullCmd="build" taksId="build" /><RakeTask description="Remove any temporary products" fullCmd="clean" taksId="clean" /><RakeTask description="Remove any generated files" fullCmd="clobber" taksId="clobber" /><RakeTask description="Build and install ftc_event-0.1.0.gem into system gems" fullCmd="install" taksId="install" /><RakeGroup description="" fullCmd="" taksId="install"><RakeTask description="Build and install ftc_event-0.1.0.gem into system gems without network access" fullCmd="install:local" taksId="local" /></RakeGroup><RakeTask description="Create tag v0.1.0 and build and push ftc_event-0.1.0.gem to rubygems.org" fullCmd="release[remote]" taksId="release[remote]" /><RakeTask description="Run RSpec code examples" fullCmd="spec" taksId="spec" /><RakeTask description="" fullCmd="default" taksId="default" /><RakeTask description="" fullCmd="release" taksId="release" /><RakeGroup description="" fullCmd="" taksId="release"><RakeTask description="" fullCmd="release:guard_clean" taksId="guard_clean" /><RakeTask description="" fullCmd="release:rubygem_push" taksId="rubygem_push" /><RakeTask description="" fullCmd="release:source_control_push" taksId="source_control_push" /></RakeGroup></RakeGroup></Settings>
|
data/.idea/ftc_event.iml
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<module type="RUBY_MODULE" version="4">
|
3
|
+
<component name="ModuleRunConfigurationManager">
|
4
|
+
<shared />
|
5
|
+
</component>
|
6
|
+
<component name="NewModuleRootManager">
|
7
|
+
<content url="file://$MODULE_DIR$">
|
8
|
+
<sourceFolder url="file://$MODULE_DIR$/features" isTestSource="true" />
|
9
|
+
<sourceFolder url="file://$MODULE_DIR$/spec" isTestSource="true" />
|
10
|
+
<sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" />
|
11
|
+
</content>
|
12
|
+
<orderEntry type="jdk" jdkName="rbenv: 2.6.3" jdkType="RUBY_SDK" />
|
13
|
+
<orderEntry type="sourceFolder" forTests="false" />
|
14
|
+
<orderEntry type="library" scope="PROVIDED" name="ast (v2.4.0, rbenv: 2.6.3) [gem]" level="application" />
|
15
|
+
<orderEntry type="library" scope="PROVIDED" name="bundler (v2.0.1, rbenv: 2.6.3) [gem]" level="application" />
|
16
|
+
<orderEntry type="library" scope="PROVIDED" name="diff-lcs (v1.3, rbenv: 2.6.3) [gem]" level="application" />
|
17
|
+
<orderEntry type="library" scope="PROVIDED" name="jaro_winkler (v1.5.4, rbenv: 2.6.3) [gem]" level="application" />
|
18
|
+
<orderEntry type="library" scope="PROVIDED" name="parallel (v1.19.1, rbenv: 2.6.3) [gem]" level="application" />
|
19
|
+
<orderEntry type="library" scope="PROVIDED" name="parser (v2.7.0.2, rbenv: 2.6.3) [gem]" level="application" />
|
20
|
+
<orderEntry type="library" scope="PROVIDED" name="rainbow (v3.0.0, rbenv: 2.6.3) [gem]" level="application" />
|
21
|
+
<orderEntry type="library" scope="PROVIDED" name="rake (v10.5.0, rbenv: 2.6.3) [gem]" level="application" />
|
22
|
+
<orderEntry type="library" scope="PROVIDED" name="rspec (v3.9.0, rbenv: 2.6.3) [gem]" level="application" />
|
23
|
+
<orderEntry type="library" scope="PROVIDED" name="rspec-core (v3.9.1, rbenv: 2.6.3) [gem]" level="application" />
|
24
|
+
<orderEntry type="library" scope="PROVIDED" name="rspec-expectations (v3.9.0, rbenv: 2.6.3) [gem]" level="application" />
|
25
|
+
<orderEntry type="library" scope="PROVIDED" name="rspec-mocks (v3.9.1, rbenv: 2.6.3) [gem]" level="application" />
|
26
|
+
<orderEntry type="library" scope="PROVIDED" name="rspec-support (v3.9.2, rbenv: 2.6.3) [gem]" level="application" />
|
27
|
+
<orderEntry type="library" scope="PROVIDED" name="rubocop (v0.79.0, rbenv: 2.6.3) [gem]" level="application" />
|
28
|
+
<orderEntry type="library" scope="PROVIDED" name="ruby-progressbar (v1.10.1, rbenv: 2.6.3) [gem]" level="application" />
|
29
|
+
<orderEntry type="library" scope="PROVIDED" name="sqlite3 (v1.4.2, rbenv: 2.6.3) [gem]" level="application" />
|
30
|
+
<orderEntry type="library" scope="PROVIDED" name="unicode-display_width (v1.6.1, rbenv: 2.6.3) [gem]" level="application" />
|
31
|
+
</component>
|
32
|
+
</module>
|
data/.idea/misc.xml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<project version="4">
|
3
|
+
<component name="JavaScriptSettings">
|
4
|
+
<option name="languageLevel" value="ES6" />
|
5
|
+
</component>
|
6
|
+
<component name="ProjectRootManager" version="2" project-jdk-name="ruby-2.4.2-p198" project-jdk-type="RUBY_SDK" />
|
7
|
+
</project>
|
data/.idea/modules.xml
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<project version="4">
|
3
|
+
<component name="ProjectModuleManager">
|
4
|
+
<modules>
|
5
|
+
<module fileurl="file://$PROJECT_DIR$/.idea/ftc_event.iml" filepath="$PROJECT_DIR$/.idea/ftc_event.iml" />
|
6
|
+
</modules>
|
7
|
+
</component>
|
8
|
+
</project>
|
data/.idea/vcs.xml
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
Style/Documentation:
|
2
|
+
Enabled: false
|
3
|
+
|
4
|
+
Style/TrailingCommaInHashLiteral:
|
5
|
+
Enabled: false
|
6
|
+
|
7
|
+
Style/TrailingCommaInArrayLiteral:
|
8
|
+
Enabled: false
|
9
|
+
|
10
|
+
Style/FormatString:
|
11
|
+
Enabled: false
|
12
|
+
|
13
|
+
Style/FormatStringToken:
|
14
|
+
Enabled: false
|
15
|
+
|
16
|
+
Layout/LineLength:
|
17
|
+
Max: 120
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
ftc_event (0.1.0)
|
5
|
+
sqlite3 (~> 1.4)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
ast (2.4.0)
|
11
|
+
diff-lcs (1.3)
|
12
|
+
jaro_winkler (1.5.4)
|
13
|
+
parallel (1.19.1)
|
14
|
+
parser (2.7.0.2)
|
15
|
+
ast (~> 2.4.0)
|
16
|
+
rainbow (3.0.0)
|
17
|
+
rake (10.5.0)
|
18
|
+
rspec (3.9.0)
|
19
|
+
rspec-core (~> 3.9.0)
|
20
|
+
rspec-expectations (~> 3.9.0)
|
21
|
+
rspec-mocks (~> 3.9.0)
|
22
|
+
rspec-core (3.9.1)
|
23
|
+
rspec-support (~> 3.9.1)
|
24
|
+
rspec-expectations (3.9.0)
|
25
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
26
|
+
rspec-support (~> 3.9.0)
|
27
|
+
rspec-mocks (3.9.1)
|
28
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
29
|
+
rspec-support (~> 3.9.0)
|
30
|
+
rspec-support (3.9.2)
|
31
|
+
rubocop (0.79.0)
|
32
|
+
jaro_winkler (~> 1.5.1)
|
33
|
+
parallel (~> 1.10)
|
34
|
+
parser (>= 2.7.0.1)
|
35
|
+
rainbow (>= 2.2.2, < 4.0)
|
36
|
+
ruby-progressbar (~> 1.7)
|
37
|
+
unicode-display_width (>= 1.4.0, < 1.7)
|
38
|
+
ruby-progressbar (1.10.1)
|
39
|
+
sqlite3 (1.4.2)
|
40
|
+
unicode-display_width (1.6.1)
|
41
|
+
|
42
|
+
PLATFORMS
|
43
|
+
ruby
|
44
|
+
|
45
|
+
DEPENDENCIES
|
46
|
+
bundler (~> 2.0)
|
47
|
+
ftc_event!
|
48
|
+
rake (~> 10.0)
|
49
|
+
rspec (~> 3.0)
|
50
|
+
rubocop (~> 0.79)
|
51
|
+
|
52
|
+
BUNDLED WITH
|
53
|
+
2.0.1
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2020 Jeremy Cole
|
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,54 @@
|
|
1
|
+
# FtcEvent
|
2
|
+
|
3
|
+
This is a Ruby gem for accessing the SQLite3 databases produced by the FIRST Tech Challenge scorekeeper software.
|
4
|
+
|
5
|
+
This gem was primarily developed in order to access the match start times to automatically extract per-match videos excerpts from an event video. See [jeremycole/ftc_video](https://github.com/jeremycole/ftc_video) for more about that.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'ftc_event'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install ftc_event
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
Get some basic information using IRB:
|
26
|
+
|
27
|
+
```
|
28
|
+
>> e = FtcEvent::Event.new("event.db")
|
29
|
+
|
30
|
+
>> e.name
|
31
|
+
=> "Northern Nevada FTC League Tournament"
|
32
|
+
|
33
|
+
>> e.qualifications.matches.count
|
34
|
+
=> 24
|
35
|
+
|
36
|
+
>> e.qualifications.match(1).result
|
37
|
+
=> "Red 63 points [no penalties] (win), Blue 37 points [no penalties] (loss)"
|
38
|
+
```
|
39
|
+
|
40
|
+
You'll probably want to explore with IRB.
|
41
|
+
|
42
|
+
## Development
|
43
|
+
|
44
|
+
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.
|
45
|
+
|
46
|
+
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).
|
47
|
+
|
48
|
+
## Contributing
|
49
|
+
|
50
|
+
Bug reports and pull requests are welcome on GitHub at [jeremycole/ftc_event](https://github.com/jeremycole/ftc_event).
|
51
|
+
|
52
|
+
## License
|
53
|
+
|
54
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'bundler/setup'
|
5
|
+
require 'ftc_event'
|
6
|
+
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
9
|
+
|
10
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
11
|
+
# require "pry"
|
12
|
+
# Pry.start
|
13
|
+
|
14
|
+
require 'irb'
|
15
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/ftc_event.gemspec
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
lib = File.expand_path('lib', __dir__)
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
+
require 'ftc_event/version'
|
6
|
+
|
7
|
+
Gem::Specification.new do |spec|
|
8
|
+
spec.name = 'ftc_event'
|
9
|
+
spec.version = FtcEvent::VERSION
|
10
|
+
spec.authors = ['Jeremy Cole']
|
11
|
+
spec.email = ['jeremy@jcole.us']
|
12
|
+
|
13
|
+
spec.summary = 'A library for accessing a FIRST Tech Challenge scorekeeper event database.'
|
14
|
+
spec.description = spec.summary
|
15
|
+
spec.homepage = 'http://github.com/jeremycole/ftc_event'
|
16
|
+
spec.license = 'MIT'
|
17
|
+
|
18
|
+
# Specify which files should be added to the gem when it is released.
|
19
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
20
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
21
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
22
|
+
end
|
23
|
+
spec.bindir = 'exe'
|
24
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
25
|
+
spec.require_paths = ['lib']
|
26
|
+
|
27
|
+
spec.add_development_dependency 'bundler', '~> 2.0'
|
28
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
29
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
30
|
+
spec.add_development_dependency 'rubocop', '~> 0.79'
|
31
|
+
|
32
|
+
spec.add_dependency 'sqlite3', '~> 1.4'
|
33
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module FtcEvent
|
4
|
+
class Alliance
|
5
|
+
attr_reader :event
|
6
|
+
attr_reader :rank
|
7
|
+
|
8
|
+
def initialize(event, rank)
|
9
|
+
@event = event
|
10
|
+
@rank = rank
|
11
|
+
end
|
12
|
+
|
13
|
+
def info
|
14
|
+
event.db.query('SELECT * FROM alliances WHERE rank = ?', [rank])&.first
|
15
|
+
end
|
16
|
+
|
17
|
+
def teams
|
18
|
+
[1, 2, 3].map { |n| info["team#{n}"] }.reject(&:zero?)
|
19
|
+
end
|
20
|
+
|
21
|
+
def each_team
|
22
|
+
return enum_for(:each_team) unless block_given?
|
23
|
+
|
24
|
+
teams.each do |team_number|
|
25
|
+
yield event.team(team_number)
|
26
|
+
end
|
27
|
+
|
28
|
+
nil
|
29
|
+
end
|
30
|
+
|
31
|
+
def short_team_list
|
32
|
+
each_team.map(&:number).join(' & ')
|
33
|
+
end
|
34
|
+
|
35
|
+
def long_team_list
|
36
|
+
each_team.map(&:description).join(' and ')
|
37
|
+
end
|
38
|
+
|
39
|
+
def short_description
|
40
|
+
"##{rank} #{short_team_list}"
|
41
|
+
end
|
42
|
+
|
43
|
+
def long_description
|
44
|
+
"##{rank} #{long_team_list}"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module FtcEvent
|
4
|
+
class Elimination < Match
|
5
|
+
attr_reader :event
|
6
|
+
attr_reader :match
|
7
|
+
|
8
|
+
def initialize(event, match)
|
9
|
+
@event = event
|
10
|
+
@match = match
|
11
|
+
end
|
12
|
+
|
13
|
+
def table_prefix
|
14
|
+
'elims'
|
15
|
+
end
|
16
|
+
|
17
|
+
def short_name
|
18
|
+
case match
|
19
|
+
when 1, 3, 5
|
20
|
+
'SF1-%i' % [(match + 1) / 2]
|
21
|
+
when 2, 4, 6
|
22
|
+
'SF2-%i' % [(match + 0) / 2]
|
23
|
+
when 7
|
24
|
+
'F-1'
|
25
|
+
when 9
|
26
|
+
'F-2'
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def short_identifier
|
31
|
+
short_name.gsub(/-/, '')
|
32
|
+
end
|
33
|
+
|
34
|
+
def long_name
|
35
|
+
case match
|
36
|
+
when 1, 3, 5
|
37
|
+
'Semifinal 1 Match %i' % [(match + 1) / 2]
|
38
|
+
when 2, 4, 6
|
39
|
+
'Semifinal 2 Match %i' % [(match + 0) / 2]
|
40
|
+
when 7
|
41
|
+
'Finals Match 1'
|
42
|
+
when 9
|
43
|
+
'Finals Match 2'
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def positions
|
48
|
+
FtcEvent::ALLIANCES
|
49
|
+
end
|
50
|
+
|
51
|
+
def alliances
|
52
|
+
positions.each_with_object({}) do |position, h|
|
53
|
+
h[position] = Alliance.new(event, info[position])
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def each_team(alliance)
|
58
|
+
return enum_for(:each_team, alliance) unless block_given?
|
59
|
+
|
60
|
+
alliances[alliance].each_team do |team|
|
61
|
+
yield team
|
62
|
+
end
|
63
|
+
|
64
|
+
nil
|
65
|
+
end
|
66
|
+
|
67
|
+
def short_alliance_description(color)
|
68
|
+
alliances[color].short_description
|
69
|
+
end
|
70
|
+
|
71
|
+
def long_alliance_description(color)
|
72
|
+
alliances[color].long_description
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module FtcEvent
|
4
|
+
class Eliminations
|
5
|
+
attr_reader :event
|
6
|
+
|
7
|
+
def initialize(event)
|
8
|
+
@event = event
|
9
|
+
end
|
10
|
+
|
11
|
+
def name
|
12
|
+
'Eliminations'
|
13
|
+
end
|
14
|
+
|
15
|
+
def match(match_number)
|
16
|
+
Elimination.new(event, match_number)
|
17
|
+
end
|
18
|
+
|
19
|
+
def matches
|
20
|
+
event.db.query('SELECT match FROM elims').map { |row| row['match'] }
|
21
|
+
end
|
22
|
+
|
23
|
+
def each_match
|
24
|
+
return enum_for(:each_match) unless block_given?
|
25
|
+
|
26
|
+
matches.each do |match_number|
|
27
|
+
yield match(match_number)
|
28
|
+
end
|
29
|
+
|
30
|
+
nil
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module FtcEvent
|
4
|
+
class Event
|
5
|
+
attr_reader :db
|
6
|
+
|
7
|
+
def initialize(filename)
|
8
|
+
@db = SQLite3::Database.new(filename, results_as_hash: true)
|
9
|
+
end
|
10
|
+
|
11
|
+
def config
|
12
|
+
db.execute('SELECT key, value FROM config').each_with_object({}) do |row, h|
|
13
|
+
h[row['key']] = row['value']
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def leagues
|
18
|
+
db.execute('SELECT code FROM leagueInfo').map { |row| row['code'] }
|
19
|
+
end
|
20
|
+
|
21
|
+
def code
|
22
|
+
config['code']
|
23
|
+
end
|
24
|
+
|
25
|
+
def name
|
26
|
+
config['name']
|
27
|
+
end
|
28
|
+
|
29
|
+
def short_name
|
30
|
+
code.upcase
|
31
|
+
end
|
32
|
+
|
33
|
+
def start
|
34
|
+
Time.at(config['start'].to_f / 1000.0)
|
35
|
+
end
|
36
|
+
|
37
|
+
def end
|
38
|
+
Time.at(config['end'].to_f / 1000.0)
|
39
|
+
end
|
40
|
+
|
41
|
+
def league(code = leagues.first)
|
42
|
+
League.new(self, code)
|
43
|
+
end
|
44
|
+
|
45
|
+
def team(number)
|
46
|
+
Team.new(self, number)
|
47
|
+
end
|
48
|
+
|
49
|
+
def qualifications
|
50
|
+
Qualifications.new(self)
|
51
|
+
end
|
52
|
+
|
53
|
+
def alliance(rank)
|
54
|
+
Alliance.new(self, rank)
|
55
|
+
end
|
56
|
+
|
57
|
+
def eliminations
|
58
|
+
Eliminations.new(self)
|
59
|
+
end
|
60
|
+
|
61
|
+
def phases
|
62
|
+
[qualifications, eliminations]
|
63
|
+
end
|
64
|
+
|
65
|
+
def each_phase
|
66
|
+
return enum_for(:each_phase) unless block_given?
|
67
|
+
|
68
|
+
phases.each do |phase|
|
69
|
+
yield phase unless phase.matches.empty?
|
70
|
+
end
|
71
|
+
|
72
|
+
nil
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module FtcEvent
|
4
|
+
class League
|
5
|
+
attr_reader :event
|
6
|
+
attr_reader :code
|
7
|
+
|
8
|
+
def initialize(event, code)
|
9
|
+
@event = event
|
10
|
+
@code = code
|
11
|
+
end
|
12
|
+
|
13
|
+
def info
|
14
|
+
event.db.query('SELECT * FROM leagueInfo WHERE code = ?', [code])&.first
|
15
|
+
end
|
16
|
+
|
17
|
+
def name
|
18
|
+
info['name']
|
19
|
+
end
|
20
|
+
|
21
|
+
def teams
|
22
|
+
result = event.db.query('SELECT team FROM leagueMembers WHERE code = ?', [code])
|
23
|
+
result&.map { |row| row['team'] }
|
24
|
+
end
|
25
|
+
|
26
|
+
def each_team
|
27
|
+
return enum_for(:each_team) unless block_given?
|
28
|
+
|
29
|
+
teams.each do |number|
|
30
|
+
yield event.team(number)
|
31
|
+
end
|
32
|
+
|
33
|
+
nil
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,161 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module FtcEvent
|
4
|
+
class Match
|
5
|
+
attr_reader :event
|
6
|
+
attr_reader :match
|
7
|
+
|
8
|
+
def initialize(event, match)
|
9
|
+
@event = event
|
10
|
+
@match = match
|
11
|
+
end
|
12
|
+
|
13
|
+
def table_prefix
|
14
|
+
raise 'Abstract method not implemented'
|
15
|
+
end
|
16
|
+
|
17
|
+
def one_row_from_table(table, match)
|
18
|
+
result = event.db.query("SELECT * FROM #{table_prefix}#{table} WHERE match = ?", [match])
|
19
|
+
result&.first
|
20
|
+
end
|
21
|
+
|
22
|
+
def info
|
23
|
+
one_row_from_table('', match)
|
24
|
+
end
|
25
|
+
|
26
|
+
def data
|
27
|
+
one_row_from_table('Data', match)
|
28
|
+
end
|
29
|
+
|
30
|
+
def results
|
31
|
+
one_row_from_table('Results', match)
|
32
|
+
end
|
33
|
+
|
34
|
+
def game_specific
|
35
|
+
one_row_from_table('GameSpecific', match)
|
36
|
+
end
|
37
|
+
|
38
|
+
def short_name
|
39
|
+
raise 'Abstract method not implemented'
|
40
|
+
end
|
41
|
+
|
42
|
+
def short_identifier
|
43
|
+
raise 'Abstract method not implemented'
|
44
|
+
end
|
45
|
+
|
46
|
+
def long_name
|
47
|
+
raise 'Abstract method not implemented'
|
48
|
+
end
|
49
|
+
|
50
|
+
def positions
|
51
|
+
raise 'Abstract method not implemented'
|
52
|
+
end
|
53
|
+
|
54
|
+
def teams
|
55
|
+
raise 'Abstract method not implemented'
|
56
|
+
end
|
57
|
+
|
58
|
+
def each_team(_alliance)
|
59
|
+
raise 'Abstract method not implemented'
|
60
|
+
end
|
61
|
+
|
62
|
+
def short_alliance_description(_color)
|
63
|
+
raise 'Abstract method not implemented'
|
64
|
+
end
|
65
|
+
|
66
|
+
def long_alliance_description(_color)
|
67
|
+
raise 'Abstract method not implemented'
|
68
|
+
end
|
69
|
+
|
70
|
+
def short_alliances_description
|
71
|
+
'%s vs. %s' % [
|
72
|
+
short_alliance_description('red'),
|
73
|
+
short_alliance_description('blue'),
|
74
|
+
]
|
75
|
+
end
|
76
|
+
|
77
|
+
def long_alliances_description
|
78
|
+
'%s vs. %s' % [
|
79
|
+
long_alliance_description('red'),
|
80
|
+
long_alliance_description('blue'),
|
81
|
+
]
|
82
|
+
end
|
83
|
+
|
84
|
+
def short_description
|
85
|
+
"#{short_name}: #{short_alliances_description}"
|
86
|
+
end
|
87
|
+
|
88
|
+
def long_description
|
89
|
+
"#{long_name}: #{long_alliances_description}"
|
90
|
+
end
|
91
|
+
|
92
|
+
def other_alliance(alliance)
|
93
|
+
return unless FtcEvent::ALLIANCES.include?(alliance)
|
94
|
+
|
95
|
+
FtcEvent::ALLIANCES.reject { |x| x == alliance }.first
|
96
|
+
end
|
97
|
+
|
98
|
+
def penalties_by(alliance)
|
99
|
+
results["#{alliance}PenaltyCommitted"]
|
100
|
+
end
|
101
|
+
|
102
|
+
def points_for(alliance)
|
103
|
+
results["#{alliance}Score"]
|
104
|
+
end
|
105
|
+
|
106
|
+
def score_for(alliance)
|
107
|
+
points_for(alliance) + penalties_by(other_alliance(alliance))
|
108
|
+
end
|
109
|
+
|
110
|
+
def winner
|
111
|
+
red = score_for('red')
|
112
|
+
blue = score_for('blue')
|
113
|
+
|
114
|
+
if red > blue
|
115
|
+
'red'
|
116
|
+
elsif blue > red
|
117
|
+
'blue'
|
118
|
+
else
|
119
|
+
'tie'
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
def win_for(alliance)
|
124
|
+
case winner
|
125
|
+
when 'tie'
|
126
|
+
'tie'
|
127
|
+
when alliance
|
128
|
+
'win'
|
129
|
+
when other_alliance(alliance)
|
130
|
+
'loss'
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
def result_for(alliance)
|
135
|
+
return unless ALLIANCES.include?(alliance)
|
136
|
+
|
137
|
+
from_penalties = penalties_by(other_alliance(alliance))
|
138
|
+
'%i points [%s penalties] (%s)' % [
|
139
|
+
score_for(alliance),
|
140
|
+
from_penalties.zero? ? 'no' : "#{from_penalties} from",
|
141
|
+
win_for(alliance),
|
142
|
+
]
|
143
|
+
end
|
144
|
+
|
145
|
+
def result
|
146
|
+
"Red #{result_for('red')}, Blue #{result_for('blue')}"
|
147
|
+
end
|
148
|
+
|
149
|
+
def started
|
150
|
+
Time.at(data['start'].to_f / 1000.0)
|
151
|
+
end
|
152
|
+
|
153
|
+
def scheduled
|
154
|
+
Time.at(data['scheduleStart'].to_f / 1000.0)
|
155
|
+
end
|
156
|
+
|
157
|
+
def posted
|
158
|
+
Time.at(data['postedTime'].to_f / 1000.0)
|
159
|
+
end
|
160
|
+
end
|
161
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module FtcEvent
|
4
|
+
class Qualification < Match
|
5
|
+
attr_reader :event
|
6
|
+
attr_reader :match
|
7
|
+
|
8
|
+
def initialize(event, match)
|
9
|
+
@event = event
|
10
|
+
@match = match
|
11
|
+
end
|
12
|
+
|
13
|
+
def table_prefix
|
14
|
+
'quals'
|
15
|
+
end
|
16
|
+
|
17
|
+
def short_name
|
18
|
+
'Q-%i' % [match]
|
19
|
+
end
|
20
|
+
|
21
|
+
def short_identifier
|
22
|
+
'Q%02i' % [match]
|
23
|
+
end
|
24
|
+
|
25
|
+
def long_name
|
26
|
+
'Qualification Match %i' % [match]
|
27
|
+
end
|
28
|
+
|
29
|
+
def positions
|
30
|
+
FtcEvent::ALLIANCES.product([1, 2]).map(&:join)
|
31
|
+
end
|
32
|
+
|
33
|
+
def teams
|
34
|
+
positions.each_with_object({}) do |position, h|
|
35
|
+
h[position] = Team.new(event, info[position])
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def each_team(alliance)
|
40
|
+
return enum_for(:each_team, alliance) unless block_given?
|
41
|
+
|
42
|
+
teams.each do |position, team|
|
43
|
+
yield team if position.start_with?(alliance)
|
44
|
+
end
|
45
|
+
|
46
|
+
nil
|
47
|
+
end
|
48
|
+
|
49
|
+
def short_alliance_description(color)
|
50
|
+
'%i & %i' % [
|
51
|
+
teams["#{color}1"]&.number || 0,
|
52
|
+
teams["#{color}2"]&.number || 0,
|
53
|
+
]
|
54
|
+
end
|
55
|
+
|
56
|
+
def long_alliance_description(color)
|
57
|
+
'%s and %s' % [
|
58
|
+
teams["#{color}1"].description,
|
59
|
+
teams["#{color}2"].description,
|
60
|
+
]
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module FtcEvent
|
4
|
+
class Qualifications
|
5
|
+
attr_reader :event
|
6
|
+
|
7
|
+
def initialize(event)
|
8
|
+
@event = event
|
9
|
+
end
|
10
|
+
|
11
|
+
def name
|
12
|
+
'Qualifications'
|
13
|
+
end
|
14
|
+
|
15
|
+
def match(match_number)
|
16
|
+
Qualification.new(event, match_number)
|
17
|
+
end
|
18
|
+
|
19
|
+
def matches
|
20
|
+
event.db.query('SELECT match FROM quals').map { |row| row['match'] }
|
21
|
+
end
|
22
|
+
|
23
|
+
def each_match
|
24
|
+
return enum_for(:each_match) unless block_given?
|
25
|
+
|
26
|
+
matches.each do |match_number|
|
27
|
+
yield match(match_number)
|
28
|
+
end
|
29
|
+
|
30
|
+
nil
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module FtcEvent
|
4
|
+
class Team
|
5
|
+
attr_reader :event
|
6
|
+
attr_reader :number
|
7
|
+
|
8
|
+
def initialize(event, number)
|
9
|
+
@event = event
|
10
|
+
@number = number
|
11
|
+
end
|
12
|
+
|
13
|
+
def info
|
14
|
+
event.db.query('SELECT * FROM teamInfo WHERE number = ?', [number])&.first
|
15
|
+
end
|
16
|
+
|
17
|
+
def name
|
18
|
+
info && info['name']
|
19
|
+
end
|
20
|
+
|
21
|
+
def school
|
22
|
+
info && info['school']
|
23
|
+
end
|
24
|
+
|
25
|
+
def city
|
26
|
+
info && info['city']
|
27
|
+
end
|
28
|
+
|
29
|
+
def state
|
30
|
+
info && info['state']
|
31
|
+
end
|
32
|
+
|
33
|
+
def country
|
34
|
+
info && info['country']
|
35
|
+
end
|
36
|
+
|
37
|
+
def location
|
38
|
+
return unless info
|
39
|
+
|
40
|
+
[
|
41
|
+
city,
|
42
|
+
state,
|
43
|
+
country != 'USA' ? country : nil
|
44
|
+
].reject(&:nil?).join(', ')
|
45
|
+
end
|
46
|
+
|
47
|
+
def description
|
48
|
+
"#{number} #{name}"
|
49
|
+
end
|
50
|
+
|
51
|
+
def full_description
|
52
|
+
"#{description} from #{location}"
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
data/lib/ftc_event.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module FtcEvent
|
4
|
+
ALLIANCES = %w[red blue].freeze
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'sqlite3'
|
8
|
+
|
9
|
+
require 'ftc_event/event'
|
10
|
+
require 'ftc_event/league'
|
11
|
+
require 'ftc_event/team'
|
12
|
+
require 'ftc_event/match'
|
13
|
+
require 'ftc_event/qualifications'
|
14
|
+
require 'ftc_event/qualification'
|
15
|
+
require 'ftc_event/alliance'
|
16
|
+
require 'ftc_event/eliminations'
|
17
|
+
require 'ftc_event/elimination'
|
metadata
ADDED
@@ -0,0 +1,144 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ftc_event
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jeremy Cole
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-02-17 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rubocop
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0.79'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0.79'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: sqlite3
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '1.4'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '1.4'
|
83
|
+
description: A library for accessing a FIRST Tech Challenge scorekeeper event database.
|
84
|
+
email:
|
85
|
+
- jeremy@jcole.us
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".gitignore"
|
91
|
+
- ".idea/.gitignore"
|
92
|
+
- ".idea/.rakeTasks"
|
93
|
+
- ".idea/ftc_event.iml"
|
94
|
+
- ".idea/inspectionProfiles/Project_Default.xml"
|
95
|
+
- ".idea/inspectionProfiles/profiles_settings.xml"
|
96
|
+
- ".idea/misc.xml"
|
97
|
+
- ".idea/modules.xml"
|
98
|
+
- ".idea/vcs.xml"
|
99
|
+
- ".rspec"
|
100
|
+
- ".rubocop.yml"
|
101
|
+
- ".travis.yml"
|
102
|
+
- Gemfile
|
103
|
+
- Gemfile.lock
|
104
|
+
- LICENSE.txt
|
105
|
+
- README.md
|
106
|
+
- Rakefile
|
107
|
+
- bin/console
|
108
|
+
- bin/setup
|
109
|
+
- ftc_event.gemspec
|
110
|
+
- lib/ftc_event.rb
|
111
|
+
- lib/ftc_event/alliance.rb
|
112
|
+
- lib/ftc_event/elimination.rb
|
113
|
+
- lib/ftc_event/eliminations.rb
|
114
|
+
- lib/ftc_event/event.rb
|
115
|
+
- lib/ftc_event/league.rb
|
116
|
+
- lib/ftc_event/match.rb
|
117
|
+
- lib/ftc_event/qualification.rb
|
118
|
+
- lib/ftc_event/qualifications.rb
|
119
|
+
- lib/ftc_event/team.rb
|
120
|
+
- lib/ftc_event/version.rb
|
121
|
+
homepage: http://github.com/jeremycole/ftc_event
|
122
|
+
licenses:
|
123
|
+
- MIT
|
124
|
+
metadata: {}
|
125
|
+
post_install_message:
|
126
|
+
rdoc_options: []
|
127
|
+
require_paths:
|
128
|
+
- lib
|
129
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
130
|
+
requirements:
|
131
|
+
- - ">="
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
version: '0'
|
134
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
requirements: []
|
140
|
+
rubygems_version: 3.0.3
|
141
|
+
signing_key:
|
142
|
+
specification_version: 4
|
143
|
+
summary: A library for accessing a FIRST Tech Challenge scorekeeper event database.
|
144
|
+
test_files: []
|