sportdb 1.9.5 → 1.9.6
Sign up to get free protection for your applications and to get access to all the features.
- data/Manifest.txt +2 -17
- data/Rakefile +6 -0
- data/lib/sportdb.rb +9 -68
- data/lib/sportdb/calc.rb +6 -0
- data/lib/sportdb/cli/main.rb +13 -7
- data/lib/sportdb/finders/date.rb +2 -2
- data/lib/sportdb/matcher.rb +0 -8
- data/lib/sportdb/models/game.rb +5 -0
- data/lib/sportdb/models/team.rb +3 -0
- data/lib/sportdb/reader.rb +7 -84
- data/lib/sportdb/schema.rb +2 -0
- data/lib/sportdb/standings.rb +178 -0
- data/lib/sportdb/utils_map.rb +0 -9
- data/lib/sportdb/utils_teams.rb +0 -6
- data/lib/sportdb/version.rb +16 -5
- data/test/test_standings_ii.rb +46 -0
- metadata +74 -44
- data/lib/sportdb/console.rb +0 -112
- data/lib/sportdb/data/keys.rb +0 -53
- data/lib/sportdb/data/models.rb +0 -35
- data/lib/sportdb/models/event_comp.rb +0 -21
- data/lib/sportdb/models/game_comp.rb +0 -157
- data/lib/sportdb/models/group_comp.rb +0 -23
- data/lib/sportdb/service.rb +0 -30
- data/lib/sportdb/service/public/style.css +0 -21
- data/lib/sportdb/service/public/style.css.scss +0 -37
- data/lib/sportdb/service/server.rb +0 -184
- data/lib/sportdb/service/views/_debug.erb +0 -17
- data/lib/sportdb/service/views/_version.erb +0 -7
- data/lib/sportdb/service/views/debug.erb +0 -2
- data/lib/sportdb/service/views/index.erb +0 -6
- data/lib/sportdb/service/views/layout.erb +0 -15
- data/lib/sportdb/updater.rb +0 -152
- data/lib/sportdb/utils_record.rb +0 -91
data/lib/sportdb/console.rb
DELETED
@@ -1,112 +0,0 @@
|
|
1
|
-
## for use to run with interactive ruby (irb)
|
2
|
-
## e.g. irb -r sportdb/console
|
3
|
-
|
4
|
-
require 'sportdb'
|
5
|
-
|
6
|
-
# some ruby stdlibs
|
7
|
-
|
8
|
-
require 'logger'
|
9
|
-
require 'pp' # pretty printer
|
10
|
-
require 'uri'
|
11
|
-
require 'json'
|
12
|
-
require 'yaml'
|
13
|
-
|
14
|
-
|
15
|
-
## shortcuts for models
|
16
|
-
|
17
|
-
##
|
18
|
-
## todo/fix: just use include SportDb::Models - why? why not? is it possible/working?
|
19
|
-
|
20
|
-
Badge = SportDb::Model::Badge
|
21
|
-
Event = SportDb::Model::Event
|
22
|
-
Game = SportDb::Model::Game
|
23
|
-
Goal = SportDb::Model::Goal
|
24
|
-
Group = SportDb::Model::Group
|
25
|
-
League = SportDb::Model::League
|
26
|
-
Person = SportDb::Model::Person
|
27
|
-
Race = SportDb::Model::Race
|
28
|
-
Record = SportDb::Model::Record
|
29
|
-
Roster = SportDb::Model::Roster
|
30
|
-
Round = SportDb::Model::Round
|
31
|
-
Run = SportDb::Model::Run
|
32
|
-
Season = SportDb::Model::Season
|
33
|
-
Team = SportDb::Model::Team
|
34
|
-
Track = SportDb::Model::Track
|
35
|
-
|
36
|
-
|
37
|
-
Tag = WorldDb::Model::Tag
|
38
|
-
Tagging = WorldDb::Model::Tagging
|
39
|
-
Continent = WorldDb::Model::Continent
|
40
|
-
Country = WorldDb::Model::Country
|
41
|
-
Region = WorldDb::Model::Region
|
42
|
-
City = WorldDb::Model::City
|
43
|
-
Prop = WorldDb::Model::Prop
|
44
|
-
|
45
|
-
|
46
|
-
## connect to db
|
47
|
-
|
48
|
-
DB_CONFIG = {
|
49
|
-
adapter: 'sqlite3',
|
50
|
-
database: 'sport.db'
|
51
|
-
}
|
52
|
-
|
53
|
-
pp DB_CONFIG
|
54
|
-
ActiveRecord::Base.establish_connection( DB_CONFIG )
|
55
|
-
|
56
|
-
## test drive
|
57
|
-
|
58
|
-
puts "Welcome to sport.db, version #{SportDb::VERSION} (world.db, version #{WorldDb::VERSION})!"
|
59
|
-
|
60
|
-
## print tables stats (e.g. no of records)
|
61
|
-
puts 'sport.db'
|
62
|
-
puts '--------'
|
63
|
-
SportDb.tables
|
64
|
-
|
65
|
-
puts 'world.db'
|
66
|
-
puts '--------'
|
67
|
-
WorldDb.tables
|
68
|
-
|
69
|
-
puts 'Ready.'
|
70
|
-
|
71
|
-
|
72
|
-
## add some predefined shortcuts
|
73
|
-
|
74
|
-
##### some countries
|
75
|
-
|
76
|
-
AT = Country.find_by_key( 'at' )
|
77
|
-
DE = Country.find_by_key( 'de' )
|
78
|
-
EN = Country.find_by_key( 'en' )
|
79
|
-
|
80
|
-
US = Country.find_by_key( 'us' )
|
81
|
-
CA = Country.find_by_key( 'ca' )
|
82
|
-
MX = Country.find_by_key( 'mx' )
|
83
|
-
|
84
|
-
#### some events
|
85
|
-
|
86
|
-
EURO2008 = Event.find_by_key( 'euro.2008' )
|
87
|
-
EURO2012 = Event.find_by_key( 'euro.2012' )
|
88
|
-
EURO = EURO2012 # add alias
|
89
|
-
|
90
|
-
BL = Event.find_by_key( 'de.2013/14' )
|
91
|
-
PL = Event.find_by_key( 'en.2013/14' )
|
92
|
-
|
93
|
-
### some club teams
|
94
|
-
|
95
|
-
BARCA = Team.find_by_key( 'barcelona' )
|
96
|
-
MANU = Team.find_by_key( 'manunited' )
|
97
|
-
MUN = MANUNITED = MANU # add alias
|
98
|
-
BAYERN = Team.find_by_key( 'bayern' )
|
99
|
-
AUSTRIA = Team.find_by_key( 'austria' )
|
100
|
-
|
101
|
-
### some national teams (three letter fifa codes)
|
102
|
-
|
103
|
-
ESP = Team.find_by_key( 'esp' )
|
104
|
-
GER = Team.find_by_key( 'ger' )
|
105
|
-
AUT = Team.find_by_key( 'aut' )
|
106
|
-
|
107
|
-
MEX = Team.find_by_key( 'mex' )
|
108
|
-
ARG = Team.find_by_key( 'arg' )
|
109
|
-
|
110
|
-
## turn on activerecord logging to console
|
111
|
-
|
112
|
-
ActiveRecord::Base.logger = Logger.new( STDOUT )
|
data/lib/sportdb/data/keys.rb
DELETED
@@ -1,53 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
|
4
|
-
### todo/fix: move to sportdb-data gem/plugin/addon ??
|
5
|
-
##
|
6
|
-
### move to sportdb/data ?? or sportdb/const ?? sportdb/
|
7
|
-
## or let use sportdb/keys addon ??
|
8
|
-
|
9
|
-
###
|
10
|
-
## add all known repos settings from build scripts ???
|
11
|
-
##
|
12
|
-
#
|
13
|
-
|
14
|
-
## or sportdb/data ??
|
15
|
-
|
16
|
-
### fix: rename to ::Key (singular) - why? why not??
|
17
|
-
|
18
|
-
|
19
|
-
module SportDb
|
20
|
-
|
21
|
-
module EventKeys
|
22
|
-
# use constants for known keys; lets us define aliases (if things change)
|
23
|
-
AT_2011_12 = 'at.2011/12'
|
24
|
-
AT_2012_13 = 'at.2012/13'
|
25
|
-
AT_2013_14 = 'at.2013/14'
|
26
|
-
|
27
|
-
AT_CUP_2012_13 = 'at.cup.2012/13'
|
28
|
-
AT_CUP_2013_14 = 'at.cup.2013/14'
|
29
|
-
|
30
|
-
CL_2012_13 = 'cl.2012/13'
|
31
|
-
CL_2013_14 = 'cl.2013/14'
|
32
|
-
|
33
|
-
EURO_2008 = 'euro.2008'
|
34
|
-
EURO_2012 = 'euro.2012'
|
35
|
-
|
36
|
-
WORLD_2010 = 'world.2010'
|
37
|
-
WORLD_2014 = 'world.2014'
|
38
|
-
|
39
|
-
WORLD_QUALI_EUROPE_2014 = 'world.quali.europe.2014'
|
40
|
-
WORLD_QUALI_AMERICA_2014 = 'world.quali.america.2014'
|
41
|
-
|
42
|
-
##################################################################
|
43
|
-
# NB: see github/openfootball (leagues.txt) for keys in use
|
44
|
-
end # module EventKeys
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
module Keys
|
49
|
-
## all keys - used by anybody? really needed? check back later
|
50
|
-
include EventKeys
|
51
|
-
end
|
52
|
-
|
53
|
-
end # module SportDb
|
data/lib/sportdb/data/models.rb
DELETED
@@ -1,35 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
module SportDb
|
4
|
-
module Model
|
5
|
-
|
6
|
-
|
7
|
-
## add convenience finders to some model classes
|
8
|
-
|
9
|
-
class Event
|
10
|
-
|
11
|
-
include SportDb::EventKeys
|
12
|
-
|
13
|
-
def self.find_at_2012_13!() self.find_by_key!( AT_2012_13 ) end
|
14
|
-
def self.find_at_2013_14!() self.find_by_key!( AT_2013_14 ) end
|
15
|
-
|
16
|
-
def self.find_at_cup_2012_13!() self.find_by_key!( AT_CUP_2012_13 ) end
|
17
|
-
def self.find_at_cup_2013_14!() self.find_by_key!( AT_CUP_2013_14 ) end
|
18
|
-
|
19
|
-
def self.find_cl_2012_13!() self.find_by_key!( CL_2012_13 ) end
|
20
|
-
def self.find_cl_2013_14!() self.find_by_key!( CL_2013_14 ) end
|
21
|
-
|
22
|
-
def self.find_euro_2008!() self.find_by_key!( EURO_2008 ) end
|
23
|
-
def self.find_euro_2012!() self.find_by_key!( EURO_2012 ) end
|
24
|
-
|
25
|
-
def self.find_world_2010!() self.find_by_key!( WORLD_2010 ) end
|
26
|
-
def self.find_world_2014!() self.find_by_key!( WORLD_2014 ) end
|
27
|
-
|
28
|
-
def self.find_world_quali_europe_2014!() self.find_by_key!( WORLD_QUALI_EUROPE_2014 ) end
|
29
|
-
def self.find_world_quali_america_2014!() self.find_by_key!( WORLD_QUALI_AMERICA_2014 ) end
|
30
|
-
|
31
|
-
end # class Event
|
32
|
-
|
33
|
-
|
34
|
-
end # module Model
|
35
|
-
end # module SportDb
|
@@ -1,21 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
module SportDb
|
4
|
-
module Model
|
5
|
-
|
6
|
-
#############################################################
|
7
|
-
# collect depreciated or methods for future removal here
|
8
|
-
# - keep for now for compatibility (for old code)
|
9
|
-
|
10
|
-
class Event
|
11
|
-
|
12
|
-
def full_title # includes season (e.g. year)
|
13
|
-
puts "*** depreciated API call Event#full_title; use Event#title instead; full_title will get removed"
|
14
|
-
"#{league.title} #{season.title}"
|
15
|
-
end
|
16
|
-
|
17
|
-
end # class Event
|
18
|
-
|
19
|
-
|
20
|
-
end # module Model
|
21
|
-
end # module SportDb
|
@@ -1,157 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
module SportDb
|
4
|
-
module Model
|
5
|
-
|
6
|
-
#############################################################
|
7
|
-
# collect depreciated or methods for future removal here
|
8
|
-
# - keep for now for compatibility (for old code)
|
9
|
-
|
10
|
-
class Game
|
11
|
-
|
12
|
-
### getter/setters for deprecated attribs (score3,4,5,6) n national
|
13
|
-
def score3() score1et end
|
14
|
-
def score4() score2et end
|
15
|
-
def score5() score1p end
|
16
|
-
def score6() score2p end
|
17
|
-
|
18
|
-
def score3=(value) self.score1et = value end
|
19
|
-
def score4=(value) self.score2et = value end
|
20
|
-
def score5=(value) self.score1p = value end
|
21
|
-
def score6=(value) self.score2p = value end
|
22
|
-
|
23
|
-
def self.create_knockouts_from_ary!( games, round )
|
24
|
-
Game.create_from_ary!( games, round, true )
|
25
|
-
end
|
26
|
-
|
27
|
-
def self.create_from_ary!( games, round, knockout=false )
|
28
|
-
|
29
|
-
### fix:
|
30
|
-
# replace knockout=false with more attribs
|
31
|
-
# see create teams and than merge attribs
|
32
|
-
|
33
|
-
games.each_with_index do |values,index|
|
34
|
-
|
35
|
-
value_pos = index+1
|
36
|
-
value_scores = []
|
37
|
-
value_teams = []
|
38
|
-
value_knockout = knockout
|
39
|
-
value_play_at = round.start_at # if no date present use it from round
|
40
|
-
value_group = nil
|
41
|
-
|
42
|
-
### lets you use arguments in any order
|
43
|
-
## makes pos optional (if not present counting from 1 to n)
|
44
|
-
|
45
|
-
values.each do |value|
|
46
|
-
if value.kind_of? Numeric
|
47
|
-
value_pos = value
|
48
|
-
elsif value.kind_of?( TrueClass ) || value.kind_of?( FalseClass )
|
49
|
-
value_knockout = value
|
50
|
-
elsif value.kind_of? Array
|
51
|
-
value_scores = value
|
52
|
-
elsif value.kind_of? Team
|
53
|
-
value_teams << value
|
54
|
-
elsif value.kind_of? Group
|
55
|
-
value_group = value
|
56
|
-
elsif value.kind_of?( Date ) || value.kind_of?( Time ) || value.kind_of?( DateTime )
|
57
|
-
value_play_at = value
|
58
|
-
else
|
59
|
-
# issue an error/warning here
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
Game.create!(
|
64
|
-
:round => round,
|
65
|
-
:pos => value_pos,
|
66
|
-
:team1 => value_teams[0],
|
67
|
-
:score1 => value_scores[0],
|
68
|
-
:score2 => value_scores[1],
|
69
|
-
:score1et => value_scores[2],
|
70
|
-
:score2et => value_scores[3],
|
71
|
-
:score1p => value_scores[4],
|
72
|
-
:score2p => value_scores[5],
|
73
|
-
:team2 => value_teams[1],
|
74
|
-
:play_at => value_play_at,
|
75
|
-
:group => value_group, # Note: group is optional (may be null/nil)
|
76
|
-
:knockout => value_knockout )
|
77
|
-
end # each games
|
78
|
-
end
|
79
|
-
|
80
|
-
def self.create_pairs_from_ary_for_group!( pairs, group )
|
81
|
-
|
82
|
-
pairs.each do |pair|
|
83
|
-
game1_attribs = {
|
84
|
-
:round =>pair[0][5],
|
85
|
-
:pos =>pair[0][0],
|
86
|
-
:team1 =>pair[0][1],
|
87
|
-
:score1 =>pair[0][2][0],
|
88
|
-
:score2 =>pair[0][2][1],
|
89
|
-
:team2 =>pair[0][3],
|
90
|
-
:play_at =>pair[0][4],
|
91
|
-
:group =>group }
|
92
|
-
|
93
|
-
game2_attribs = {
|
94
|
-
:round =>pair[1][5],
|
95
|
-
:pos =>pair[1][0],
|
96
|
-
:team1 =>pair[1][1],
|
97
|
-
:score1 =>pair[1][2][0],
|
98
|
-
:score2 =>pair[1][2][1],
|
99
|
-
:team2 =>pair[1][3],
|
100
|
-
:play_at =>pair[1][4],
|
101
|
-
:group =>group }
|
102
|
-
|
103
|
-
game1 = Game.create!( game1_attribs )
|
104
|
-
game2 = Game.create!( game2_attribs )
|
105
|
-
|
106
|
-
# linkup games
|
107
|
-
game1.next_game_id = game2.id
|
108
|
-
game1.save!
|
109
|
-
|
110
|
-
game2.prev_game_id = game1.id
|
111
|
-
game2.save!
|
112
|
-
end # each pair
|
113
|
-
end
|
114
|
-
|
115
|
-
def self.create_knockout_pairs_from_ary!( pairs, round1, round2 )
|
116
|
-
|
117
|
-
pairs.each do |pair|
|
118
|
-
game1_attribs = {
|
119
|
-
:round =>round1,
|
120
|
-
:pos =>pair[0][0],
|
121
|
-
:team1 =>pair[0][1],
|
122
|
-
:score1 =>pair[0][2][0],
|
123
|
-
:score2 =>pair[0][2][1],
|
124
|
-
:team2 =>pair[0][3],
|
125
|
-
:play_at =>pair[0][4] }
|
126
|
-
|
127
|
-
game2_attribs = {
|
128
|
-
:round =>round2,
|
129
|
-
:pos =>pair[1][0],
|
130
|
-
:team1 =>pair[1][1],
|
131
|
-
:score1 =>pair[1][2][0],
|
132
|
-
:score2 =>pair[1][2][1],
|
133
|
-
:score1et =>pair[1][2][2],
|
134
|
-
:score2et =>pair[1][2][3],
|
135
|
-
:score1p =>pair[1][2][4],
|
136
|
-
:score1p =>pair[1][2][5],
|
137
|
-
:team2 =>pair[1][3],
|
138
|
-
:play_at =>pair[1][4],
|
139
|
-
:knockout =>true }
|
140
|
-
|
141
|
-
game1 = Game.create!( game1_attribs )
|
142
|
-
game2 = Game.create!( game2_attribs )
|
143
|
-
|
144
|
-
# linkup games
|
145
|
-
game1.next_game_id = game2.id
|
146
|
-
game1.save!
|
147
|
-
|
148
|
-
game2.prev_game_id = game1.id
|
149
|
-
game2.save!
|
150
|
-
end # each pair
|
151
|
-
end
|
152
|
-
|
153
|
-
end # class Game
|
154
|
-
|
155
|
-
|
156
|
-
end # module Model
|
157
|
-
end # module SportDb
|
@@ -1,23 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
module SportDb
|
4
|
-
module Model
|
5
|
-
|
6
|
-
#############################################################
|
7
|
-
# collect depreciated or methods for future removal here
|
8
|
-
# - keep for now for compatibility (for old code)
|
9
|
-
|
10
|
-
class Group
|
11
|
-
|
12
|
-
def add_teams_from_ary!( team_keys )
|
13
|
-
team_keys.each do |team_key|
|
14
|
-
team = Team.find_by_key!( team_key )
|
15
|
-
self.teams << team
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
end # class Group
|
20
|
-
|
21
|
-
|
22
|
-
end # module Model
|
23
|
-
end # module SportDb
|
data/lib/sportdb/service.rb
DELETED
@@ -1,30 +0,0 @@
|
|
1
|
-
######
|
2
|
-
# NB: use rackup to startup Sinatra service (see config.ru)
|
3
|
-
#
|
4
|
-
# e.g. config.ru:
|
5
|
-
# require './boot'
|
6
|
-
# run SportDb::Server
|
7
|
-
|
8
|
-
|
9
|
-
# 3rd party libs/gems
|
10
|
-
|
11
|
-
require 'sinatra/base'
|
12
|
-
|
13
|
-
|
14
|
-
# our own code
|
15
|
-
|
16
|
-
|
17
|
-
require 'sportdb/service/server'
|
18
|
-
|
19
|
-
|
20
|
-
### for legacy old code e.g. SportDb::Service::Server - remove later - do NOT use
|
21
|
-
## remove module Service (obsolete)
|
22
|
-
module SportDb
|
23
|
-
module Service
|
24
|
-
Server = SportDb::Server
|
25
|
-
end # module Service
|
26
|
-
end # module SportDb
|
27
|
-
|
28
|
-
|
29
|
-
# say hello
|
30
|
-
puts SportDb::Server.banner
|
@@ -1,21 +0,0 @@
|
|
1
|
-
body {
|
2
|
-
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; }
|
3
|
-
|
4
|
-
a {
|
5
|
-
color: black;
|
6
|
-
text-decoration: none; }
|
7
|
-
a:hover {
|
8
|
-
color: black;
|
9
|
-
background-color: aqua;
|
10
|
-
text-decoration: underline; }
|
11
|
-
a:visited {
|
12
|
-
color: black; }
|
13
|
-
|
14
|
-
|
15
|
-
.version {
|
16
|
-
text-align: center;
|
17
|
-
margin-top: 10px;
|
18
|
-
color: grey; }
|
19
|
-
.version a, .version span {
|
20
|
-
font-size: 12px;
|
21
|
-
color: grey; }
|