sportdb 0.9.7 → 1.0.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.
- data/Manifest.txt +12 -55
- data/Rakefile +11 -10
- data/bin/sportdb +1 -2
- data/config/fixtures.de.yml +42 -0
- data/config/fixtures.en.yml +52 -0
- data/config/fixtures.es.yml +44 -0
- data/config/fixtures.pt.yml +44 -0
- data/lib/sportdb/cli/main.rb +189 -0
- data/lib/sportdb/cli/opts.rb +15 -69
- data/lib/sportdb/data/fixtures.rb +205 -0
- data/lib/sportdb/{keys.rb → data/keys.rb} +9 -2
- data/lib/sportdb/data/models.rb +43 -0
- data/lib/sportdb/deleter.rb +27 -0
- data/lib/sportdb/lang.rb +265 -0
- data/lib/sportdb/models/event.rb +0 -34
- data/lib/sportdb/reader.rb +322 -78
- data/lib/sportdb/stats.rb +28 -0
- data/lib/sportdb/utils.rb +90 -13
- data/lib/sportdb/version.rb +1 -1
- data/lib/sportdb.rb +49 -198
- data/tasks/test.rb +163 -0
- metadata +46 -71
- data/data/america/2011.rb +0 -36
- data/data/america/2011.txt +0 -110
- data/data/america/2011.yml +0 -30
- data/data/america/teams.txt +0 -26
- data/data/at/2011_12/bl.rb +0 -30
- data/data/at/2011_12/bl.txt +0 -79
- data/data/at/2011_12/cup.rb +0 -66
- data/data/at/2012_13/bl.rb +0 -33
- data/data/at/2012_13/bl.txt +0 -198
- data/data/at/2012_13/cup.rb +0 -111
- data/data/at/2012_13/cup.txt +0 -89
- data/data/at/badges.rb +0 -22
- data/data/at/teams.txt +0 -88
- data/data/cl/2011_12/cl.rb +0 -88
- data/data/cl/2011_12/el.rb +0 -65
- data/data/cl/2012_13/cl.rb +0 -324
- data/data/cl/badges.rb +0 -68
- data/data/cl/teams.txt +0 -46
- data/data/copa/sud_2012_13.rb +0 -38
- data/data/copa/sud_2012_13.txt +0 -49
- data/data/copa/teams.txt +0 -35
- data/data/de/2012_13/bl.rb +0 -38
- data/data/de/2012_13/bl.txt +0 -216
- data/data/de/teams.txt +0 -23
- data/data/en/2012_13/pl.rb +0 -39
- data/data/en/2012_13/pl.txt +0 -291
- data/data/en/teams.txt +0 -26
- data/data/es/teams.txt +0 -8
- data/data/euro/2008.rb +0 -30
- data/data/euro/2008.txt +0 -114
- data/data/euro/2012.rb +0 -25
- data/data/euro/2012.txt +0 -114
- data/data/euro/teams.txt +0 -36
- data/data/leagues.rb +0 -68
- data/data/mx/apertura_2012.rb +0 -35
- data/data/mx/apertura_2012.txt +0 -106
- data/data/mx/teams.txt +0 -20
- data/data/nfl/teams.txt +0 -46
- data/data/nhl/teams.txt +0 -40
- data/data/ro/l1_2012_13.rb +0 -137
- data/data/ro/teams.txt +0 -26
- data/data/seasons.rb +0 -22
- data/data/world/2010.rb +0 -93
- data/data/world/2010.txt +0 -215
- data/data/world/quali_2012_13_america.rb +0 -25
- data/data/world/quali_2012_13_america.txt +0 -41
- data/data/world/quali_2012_13_europe.rb +0 -32
- data/data/world/quali_2012_13_europe_c.txt +0 -85
- data/data/world/quali_2012_13_europe_i.txt +0 -74
- data/data/world/teams.txt +0 -25
- data/lib/sportdb/cli/runner.rb +0 -147
- data/lib/sportdb/loader.rb +0 -82
- data/lib/sportdb/templater.rb +0 -81
- data/templates/fixtures.rb.erb +0 -51
@@ -0,0 +1,205 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
def find_football_db_path_from_gemfile_gitref!
|
4
|
+
puts "[debug] find_football_db_path..."
|
5
|
+
puts "load path:"
|
6
|
+
pp $LOAD_PATH
|
7
|
+
|
8
|
+
candidates = []
|
9
|
+
$LOAD_PATH.each do |path|
|
10
|
+
if path =~ /\/(football\.db-[a-z0-9]+)|(football\.db)\//
|
11
|
+
candidates << path.dup
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
puts "found candidates:"
|
16
|
+
pp candidates
|
17
|
+
|
18
|
+
## cut-off everything after /football.db
|
19
|
+
# e.g. lib/ruby/gems/1.9.1/bundler/gems/football.db-38279c414449/lib becomes
|
20
|
+
# lib/ruby/gems/1.9.1/bundler/gems/football.db-38279c414449
|
21
|
+
|
22
|
+
cand = candidates[0]
|
23
|
+
|
24
|
+
puts "cand before: #{cand}"
|
25
|
+
|
26
|
+
## nb: *? is non-greedy many operator
|
27
|
+
|
28
|
+
## todo: why not just cut off trailing /lib - is it good enough??
|
29
|
+
# it's easier
|
30
|
+
|
31
|
+
regex = /(\/football\.db.*?)(\/.*)/
|
32
|
+
cand = cand.sub( regex ) do |_|
|
33
|
+
puts "cutting off >>#{$2}<<"
|
34
|
+
$1
|
35
|
+
end
|
36
|
+
|
37
|
+
puts "cand after: #{cand}"
|
38
|
+
|
39
|
+
## todo:exit with error if not found!!!
|
40
|
+
|
41
|
+
cand
|
42
|
+
end
|
43
|
+
|
44
|
+
|
45
|
+
|
46
|
+
module SportDB
|
47
|
+
|
48
|
+
module Fixtures # use shortcut/alias Fx?
|
49
|
+
|
50
|
+
## todo/ check: remove _FIXTURES and use module namespace instead?
|
51
|
+
|
52
|
+
|
53
|
+
SEASONS = [
|
54
|
+
'seasons'
|
55
|
+
]
|
56
|
+
|
57
|
+
LEAGUES = [
|
58
|
+
'leagues',
|
59
|
+
'leagues_club'
|
60
|
+
]
|
61
|
+
|
62
|
+
## todo/check: put teams into its own module/namespace (remove _TEAMS?)
|
63
|
+
EUROPE_TEAMS = [
|
64
|
+
'europe/teams'
|
65
|
+
]
|
66
|
+
|
67
|
+
## NB: copa america requires jpn as team invitee (from asia)
|
68
|
+
AMERICA_TEAMS = [
|
69
|
+
'world/teams',
|
70
|
+
'america/teams'
|
71
|
+
]
|
72
|
+
|
73
|
+
WORLD_TEAMS = [
|
74
|
+
'world/teams',
|
75
|
+
'america/teams',
|
76
|
+
'europe/teams'
|
77
|
+
]
|
78
|
+
|
79
|
+
AT_TEAMS = [ 'at/teams', 'at/teams2' ]
|
80
|
+
DE_TEAMS = [ 'de/teams' ]
|
81
|
+
EN_TEAMS = [ 'en/teams' ]
|
82
|
+
ES_TEAMS = [ 'es/teams' ]
|
83
|
+
FR_TEAMS = [ 'fr/teams' ]
|
84
|
+
IT_TEAMS = [ 'it/teams' ]
|
85
|
+
RO_TEAMS = [ 'ro/teams' ]
|
86
|
+
|
87
|
+
CLUB_EUROPE_TEAMS =
|
88
|
+
AT_TEAMS +
|
89
|
+
DE_TEAMS +
|
90
|
+
EN_TEAMS +
|
91
|
+
ES_TEAMS +
|
92
|
+
FR_TEAMS +
|
93
|
+
IT_TEAMS +
|
94
|
+
RO_TEAMS +
|
95
|
+
[
|
96
|
+
'club/europe/teams'
|
97
|
+
]
|
98
|
+
|
99
|
+
|
100
|
+
AR_TEAMS = [ 'ar/teams' ]
|
101
|
+
BR_TEAMS = [ 'br/teams' ]
|
102
|
+
MX_TEAMS = [ 'mx/teams' ]
|
103
|
+
|
104
|
+
CLUB_AMERICA_TEAMS =
|
105
|
+
AR_TEAMS +
|
106
|
+
BR_TEAMS +
|
107
|
+
MX_TEAMS +
|
108
|
+
[
|
109
|
+
'club/america/teams_c',
|
110
|
+
'club/america/teams_n',
|
111
|
+
'club/america/teams_s',
|
112
|
+
]
|
113
|
+
|
114
|
+
AR_FIXTURES = []
|
115
|
+
|
116
|
+
### todo: ? get event_key automatically from event_reader ?? why? why not??
|
117
|
+
BR_FIXTURES = [
|
118
|
+
['br.2013', 'br/2013/cb' ]
|
119
|
+
]
|
120
|
+
|
121
|
+
MX_FIXTURES = [
|
122
|
+
['mx.apertura.2012.2', 'mx/2012/apertura' ],
|
123
|
+
['mx.clausura.2013.1', 'mx/2013/clausura' ]
|
124
|
+
]
|
125
|
+
|
126
|
+
|
127
|
+
AT_FIXTURES = [
|
128
|
+
['at.2011/12', 'at/2011_12/bl' ],
|
129
|
+
['at.cup.2011/12', 'at/2011_12/cup' ],
|
130
|
+
['at.2012/13', 'at/2012_13/bl', 'at/2012_13/bl2'],
|
131
|
+
['at.cup.2012/13', 'at/2012_13/cup']
|
132
|
+
]
|
133
|
+
|
134
|
+
DE_FIXTURES = [
|
135
|
+
['de.2012/13', 'de/2012_13/bl' ]
|
136
|
+
]
|
137
|
+
|
138
|
+
EN_FIXTURES = [
|
139
|
+
['en.2012/13', 'en/2012_13/pl' ]
|
140
|
+
]
|
141
|
+
|
142
|
+
RO_FIXTURES = [
|
143
|
+
['ro.2012/13', 'ro/2012_13/l1' ]
|
144
|
+
]
|
145
|
+
|
146
|
+
|
147
|
+
EUROPE_FIXTURES = [
|
148
|
+
['euro.2008', 'europe/2008/euro'],
|
149
|
+
['euro.2012', 'europe/2012/euro'],
|
150
|
+
]
|
151
|
+
|
152
|
+
AMERICA_FIXTURES = [
|
153
|
+
['america.copa.2011', 'america/2011/copa'],
|
154
|
+
['america.gold.2011', 'america/2011/gold'],
|
155
|
+
['america.gold.2013', 'america/2013/gold'],
|
156
|
+
['america.copa.2015', 'america/2015/copa'],
|
157
|
+
]
|
158
|
+
|
159
|
+
WORLD_FIXTURES = [
|
160
|
+
['world.conf.2009', 'world/2009/conf'],
|
161
|
+
['world.2010', 'world/2010/cup'],
|
162
|
+
['world.quali.america.2014', 'world/2014/quali_america'],
|
163
|
+
['world.quali.europe.c.2014', 'world/2014/quali_europe_c'],
|
164
|
+
['world.quali.europe.2014', 'world/2014/quali_europe', 'world/2014/quali_europe_c', 'world/2014/quali_europe_i'],
|
165
|
+
['world.2014', 'world/2014/cup'],
|
166
|
+
]
|
167
|
+
|
168
|
+
CLUB_EUROPE_FIXTURES = [
|
169
|
+
['cl.2011/12', 'club/europe/2011_12/cl'],
|
170
|
+
['el.2011/12', 'club/europe/2011_12/el'],
|
171
|
+
['cl.2012/13', 'club/europe/2012_13/cl'],
|
172
|
+
['el.2012/13', 'club/europe/2012_13/el'],
|
173
|
+
]
|
174
|
+
|
175
|
+
CLUB_AMERICA_FIXTURES = [
|
176
|
+
['america.cl.2011/12', 'club/america/2011_12/cl'],
|
177
|
+
['copa.libertadores.2012', 'club/america/2012/libertadores' ],
|
178
|
+
['copa.sud.2012', 'club/america/2012/sud'],
|
179
|
+
['america.cl.2012/13', 'club/america/2012_13/cl'],
|
180
|
+
['copa.libertadores.2013', 'club/america/2013/libertadores' ]
|
181
|
+
]
|
182
|
+
|
183
|
+
def self.all
|
184
|
+
SEASONS +
|
185
|
+
LEAGUES +
|
186
|
+
CLUB_AMERICA_TEAMS +
|
187
|
+
AR_FIXTURES +
|
188
|
+
BR_FIXTURES +
|
189
|
+
MX_FIXTURES +
|
190
|
+
CLUB_AMERICA_FIXTURES +
|
191
|
+
CLUB_EUROPE_TEAMS +
|
192
|
+
AT_FIXTURES +
|
193
|
+
DE_FIXTURES +
|
194
|
+
EN_FIXTURES +
|
195
|
+
RO_FIXTURES +
|
196
|
+
CLUB_EUROPE_FIXTURES +
|
197
|
+
WORLD_TEAMS +
|
198
|
+
AMERICA_FIXTURES +
|
199
|
+
EUROPE_FIXTURES +
|
200
|
+
WORLD_FIXTURES
|
201
|
+
end # method all
|
202
|
+
|
203
|
+
end # module Fixtures
|
204
|
+
|
205
|
+
end # module SportDB
|
@@ -1,8 +1,15 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
### todo/fix: move to sportdb-data gem/plugin/addon ??
|
4
|
+
|
5
|
+
|
6
|
+
### fix: rename to ::Key (singular) - why? why not??
|
1
7
|
|
2
8
|
module SportDB::Keys
|
3
9
|
|
4
10
|
module EventKeys
|
5
11
|
# use constants for known keys; lets us define aliases (if things change)
|
12
|
+
|
6
13
|
|
7
14
|
AT_2011_12 = 'at.2011/12'
|
8
15
|
AT_2012_13 = 'at.2012/13'
|
@@ -15,8 +22,8 @@ module SportDB::Keys
|
|
15
22
|
|
16
23
|
WORLD_2010 = 'world.2010'
|
17
24
|
|
18
|
-
|
19
|
-
|
25
|
+
WORLD_QUALI_EUROPE_2014 = 'world.quali.europe.2014'
|
26
|
+
WORLD_QUALI_AMERICA_2014 = 'world.quali.america.2014'
|
20
27
|
|
21
28
|
############################
|
22
29
|
## NB: see db/leagues.rb for keys in use
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module SportDB::Models
|
4
|
+
|
5
|
+
## add convenience finders to some model classes
|
6
|
+
|
7
|
+
class Event
|
8
|
+
|
9
|
+
include SportDB::Keys::EventKeys
|
10
|
+
|
11
|
+
def self.find_at_2012_13!
|
12
|
+
self.find_by_key!( AT_2012_13 )
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.find_at_cup_2012_13!
|
16
|
+
self.find_by_key!( AT_CUP_2012_13 )
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.find_cl_2012_13!
|
20
|
+
self.find_by_key!( CL_2012_13 )
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.find_euro_2012!
|
24
|
+
self.find_by_key!( EURO_2012 )
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.find_world_2010!
|
28
|
+
self.find_by_key!( WORLD_2010 )
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.find_world_quali_europe_2014!
|
32
|
+
self.find_by_key!( WORLD_QUALI_EUROPE_2014 )
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.find_world_quali_america_2014!
|
36
|
+
self.find_by_key!( WORLD_QUALI_AMERICA_2014 )
|
37
|
+
end
|
38
|
+
|
39
|
+
end # class Event
|
40
|
+
|
41
|
+
end # module SportDB::Models
|
42
|
+
|
43
|
+
|
@@ -0,0 +1,27 @@
|
|
1
|
+
|
2
|
+
module SportDB
|
3
|
+
|
4
|
+
class Deleter
|
5
|
+
######
|
6
|
+
# NB: make models available in sportdb module by default with namespace
|
7
|
+
# e.g. lets you use Team instead of Models::Team
|
8
|
+
include SportDB::Models
|
9
|
+
|
10
|
+
def run
|
11
|
+
# for now delete all tables
|
12
|
+
|
13
|
+
Team.delete_all
|
14
|
+
Game.delete_all
|
15
|
+
Event.delete_all
|
16
|
+
EventTeam.delete_all
|
17
|
+
Group.delete_all
|
18
|
+
GroupTeam.delete_all
|
19
|
+
Round.delete_all
|
20
|
+
Badge.delete_all
|
21
|
+
League.delete_all
|
22
|
+
Season.delete_all
|
23
|
+
end
|
24
|
+
|
25
|
+
end # class Deleter
|
26
|
+
|
27
|
+
end # module SportDB
|
data/lib/sportdb/lang.rb
ADDED
@@ -0,0 +1,265 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module SportDB
|
4
|
+
|
5
|
+
class Lang
|
6
|
+
|
7
|
+
def initialize( logger=nil )
|
8
|
+
|
9
|
+
@lang = 'en' # make default lang english/en
|
10
|
+
|
11
|
+
# load word lists
|
12
|
+
|
13
|
+
@fixtures_en = YAML.load( File.read_utf8( "#{SportDB.config_path}/fixtures.en.yml" ))
|
14
|
+
@fixtures_de = YAML.load( File.read_utf8( "#{SportDB.config_path}/fixtures.de.yml" ))
|
15
|
+
@fixtures_es = YAML.load( File.read_utf8( "#{SportDB.config_path}/fixtures.es.yml" ))
|
16
|
+
|
17
|
+
@fixtures = {
|
18
|
+
'en' => @fixtures_en,
|
19
|
+
'de' => @fixtures_de,
|
20
|
+
'es' => @fixtures_es,
|
21
|
+
}
|
22
|
+
|
23
|
+
|
24
|
+
@words_en = fixtures_hash_to_words_ary( @fixtures_en )
|
25
|
+
@words_de = fixtures_hash_to_words_ary( @fixtures_de )
|
26
|
+
@words_es = fixtures_hash_to_words_ary( @fixtures_es )
|
27
|
+
|
28
|
+
puts "en - #{@words_en.size} words: #{@words_en}"
|
29
|
+
puts "de - #{@words_de.size} words: #{@words_de}"
|
30
|
+
puts "es - #{@words_es.size} words: #{@words_es}"
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
attr_reader :words_en
|
35
|
+
attr_reader :words_de
|
36
|
+
attr_reader :words_es
|
37
|
+
attr_reader :lang
|
38
|
+
|
39
|
+
def lang=(value)
|
40
|
+
puts "setting lang to #{value}"
|
41
|
+
|
42
|
+
if @lang != value
|
43
|
+
# reset cached values on language change
|
44
|
+
puts "reseting cached lang values (lang changed from #{@lang} to #{value})"
|
45
|
+
|
46
|
+
@group = nil
|
47
|
+
@round = nil
|
48
|
+
@knockout_round = nil
|
49
|
+
@leg1 = nil
|
50
|
+
@leg2 = nil
|
51
|
+
|
52
|
+
@regex_group = nil
|
53
|
+
@regex_round = nil
|
54
|
+
@regex_knockout_round = nil
|
55
|
+
@regex_leg1 = nil
|
56
|
+
@regex_leg2 = nil
|
57
|
+
end
|
58
|
+
|
59
|
+
@lang = value
|
60
|
+
|
61
|
+
end
|
62
|
+
|
63
|
+
|
64
|
+
def group
|
65
|
+
@group ||= group_getter
|
66
|
+
end
|
67
|
+
|
68
|
+
def round
|
69
|
+
@round ||= round_getter
|
70
|
+
end
|
71
|
+
|
72
|
+
def knockout_round
|
73
|
+
@knock_round ||= knockout_round_getter
|
74
|
+
end
|
75
|
+
|
76
|
+
def leg1
|
77
|
+
@leg1 ||= leg1_getter
|
78
|
+
end
|
79
|
+
|
80
|
+
def leg2
|
81
|
+
@leg2 ||= leg2_getter
|
82
|
+
end
|
83
|
+
|
84
|
+
|
85
|
+
def regex_group
|
86
|
+
@regex_group ||= regex_group_getter
|
87
|
+
end
|
88
|
+
|
89
|
+
def regex_round
|
90
|
+
@regex_round ||= regex_round_getter
|
91
|
+
end
|
92
|
+
|
93
|
+
def regex_knockout_round
|
94
|
+
@regex_knockout_round ||= regex_knockout_round_getter
|
95
|
+
end
|
96
|
+
|
97
|
+
def regex_leg1
|
98
|
+
@regex_leg1 ||= regex_leg1_getter
|
99
|
+
end
|
100
|
+
|
101
|
+
def regex_leg2
|
102
|
+
@regex_leg2 ||= regex_leg2_getter
|
103
|
+
end
|
104
|
+
|
105
|
+
|
106
|
+
|
107
|
+
private
|
108
|
+
def group_getter
|
109
|
+
h = @fixtures[ lang ]
|
110
|
+
values = h['group']
|
111
|
+
values
|
112
|
+
end
|
113
|
+
|
114
|
+
def round_getter
|
115
|
+
# e.g. Spieltag|Runde|Achtelfinale|Viertelfinale|Halbfinale|Finale
|
116
|
+
|
117
|
+
h = @fixtures[ lang ]
|
118
|
+
values = h['round']
|
119
|
+
values << "|" << h['matchday'] ## todo/check: fold round n matchday into one key? why? why not??
|
120
|
+
|
121
|
+
### add knockout rounds values too
|
122
|
+
values << "|" << h['round32']
|
123
|
+
values << "|" << h['round16']
|
124
|
+
values << "|" << h['quarterfinals']
|
125
|
+
values << "|" << h['semifinals']
|
126
|
+
values << "|" << h['thirdplace']
|
127
|
+
values << "|" << h['final']
|
128
|
+
values
|
129
|
+
end
|
130
|
+
|
131
|
+
def leg1_getter
|
132
|
+
h = @fixtures[ lang ]
|
133
|
+
values = h['leg1']
|
134
|
+
values
|
135
|
+
end
|
136
|
+
|
137
|
+
def leg2_getter
|
138
|
+
h = @fixtures[ lang ]
|
139
|
+
values = h['leg2']
|
140
|
+
values
|
141
|
+
end
|
142
|
+
|
143
|
+
def knockout_round_getter
|
144
|
+
h = @fixtures[ lang ]
|
145
|
+
values = h['round32']
|
146
|
+
values << "|" << h['round16']
|
147
|
+
values << "|" << h['quarterfinals']
|
148
|
+
values << "|" << h['semifinals']
|
149
|
+
values << "|" << h['thirdplace']
|
150
|
+
values << "|" << h['final']
|
151
|
+
values
|
152
|
+
end
|
153
|
+
|
154
|
+
def regex_group_getter
|
155
|
+
## todo: escape for regex?
|
156
|
+
/#{group}/
|
157
|
+
end
|
158
|
+
|
159
|
+
def regex_round_getter
|
160
|
+
## todo: escape for regex?
|
161
|
+
## todo: sort by length - biggest words go first? does regex match biggest word automatically?? - check
|
162
|
+
/#{round}/
|
163
|
+
end
|
164
|
+
|
165
|
+
def regex_knockout_round_getter
|
166
|
+
## todo: escape for regex?
|
167
|
+
/#{knockout_round}/
|
168
|
+
end
|
169
|
+
|
170
|
+
def regex_leg1_getter
|
171
|
+
## todo: escape for regex?
|
172
|
+
/#{leg1}/
|
173
|
+
end
|
174
|
+
|
175
|
+
def regex_leg2_getter
|
176
|
+
## todo: escape for regex?
|
177
|
+
/#{leg2}/
|
178
|
+
end
|
179
|
+
|
180
|
+
|
181
|
+
def fixtures_hash_to_words_ary( hash )
|
182
|
+
ary = []
|
183
|
+
hash.each do |key_wild, values_wild|
|
184
|
+
key = key_wild.to_s.strip
|
185
|
+
values = values_wild.to_s.strip
|
186
|
+
|
187
|
+
puts "processing key >>#{key}<< with words >>#{values}<<"
|
188
|
+
|
189
|
+
ary += values.split('|')
|
190
|
+
end
|
191
|
+
ary
|
192
|
+
end
|
193
|
+
|
194
|
+
end # class Lang
|
195
|
+
|
196
|
+
|
197
|
+
class LangChecker
|
198
|
+
|
199
|
+
def initialize( logger=nil )
|
200
|
+
## add logger here
|
201
|
+
end
|
202
|
+
|
203
|
+
def analyze( name, include_path )
|
204
|
+
# return lang code e.g. en, de, es
|
205
|
+
|
206
|
+
path = "#{include_path}/#{name}.txt"
|
207
|
+
|
208
|
+
puts "*** parsing data '#{name}' (#{path})..."
|
209
|
+
|
210
|
+
text = File.read_utf8( path )
|
211
|
+
|
212
|
+
### todo/fix:
|
213
|
+
# remove comment lines and end of line comments from text
|
214
|
+
|
215
|
+
en = count_words_in_text( SportDB.lang.words_en, text )
|
216
|
+
de = count_words_in_text( SportDB.lang.words_de, text )
|
217
|
+
es = count_words_in_text( SportDB.lang.words_es, text )
|
218
|
+
|
219
|
+
lang_counts = [
|
220
|
+
[ 'en', en ],
|
221
|
+
[ 'de', de ],
|
222
|
+
[ 'es', es ]
|
223
|
+
]
|
224
|
+
|
225
|
+
# sort by word count (reverse sort e.g. highest count goes first)
|
226
|
+
lang_counts = lang_counts.sort {|l,r| r[1] <=> l[1] }
|
227
|
+
|
228
|
+
# dump stats
|
229
|
+
|
230
|
+
puts "****************************************"
|
231
|
+
lang_counts.each_with_index do |item,index|
|
232
|
+
## e.g. 1. en: 20 words
|
233
|
+
## 2. de: 2 words
|
234
|
+
puts "#{index+1}. #{item[0]}: #{item[1]}"
|
235
|
+
end
|
236
|
+
|
237
|
+
## return lang code w/ highest count
|
238
|
+
lang_counts[0][0]
|
239
|
+
end
|
240
|
+
|
241
|
+
private
|
242
|
+
def count_word_in_text( word, text )
|
243
|
+
count = 0
|
244
|
+
pos = text.index( word )
|
245
|
+
while pos.nil? == false
|
246
|
+
count += 1
|
247
|
+
puts "bingo - found >>#{word}<< on pos #{pos}, count: #{count}"
|
248
|
+
### todo: check if pos+word.length/size needs +1 or similar
|
249
|
+
pos = text.index( word, pos+word.length)
|
250
|
+
end
|
251
|
+
count
|
252
|
+
end
|
253
|
+
|
254
|
+
def count_words_in_text( words, text )
|
255
|
+
count = 0
|
256
|
+
words.each do |word|
|
257
|
+
count += count_word_in_text( word, text )
|
258
|
+
end
|
259
|
+
count
|
260
|
+
end
|
261
|
+
|
262
|
+
end # class LangChecker
|
263
|
+
|
264
|
+
|
265
|
+
end # module SportDB
|
data/lib/sportdb/models/event.rb
CHANGED
@@ -73,40 +73,6 @@ class Event < ActiveRecord::Base
|
|
73
73
|
|
74
74
|
known_teams
|
75
75
|
end # method known_teams_table
|
76
|
-
|
77
|
-
###########################
|
78
|
-
## convenience helpers
|
79
|
-
|
80
|
-
include SportDB::Keys::EventKeys
|
81
|
-
|
82
|
-
def self.find_at_2012_13!
|
83
|
-
self.find_by_key!( AT_2012_13 )
|
84
|
-
end
|
85
|
-
|
86
|
-
def self.find_at_cup_2012_13!
|
87
|
-
self.find_by_key!( AT_CUP_2012_13 )
|
88
|
-
end
|
89
|
-
|
90
|
-
def self.find_cl_2012_13!
|
91
|
-
self.find_by_key!( CL_2012_13 )
|
92
|
-
end
|
93
|
-
|
94
|
-
def self.find_euro_2012!
|
95
|
-
self.find_by_key!( EURO_2012 )
|
96
|
-
end
|
97
|
-
|
98
|
-
def self.find_world_2010!
|
99
|
-
self.find_by_key!( WORLD_2010 )
|
100
|
-
end
|
101
|
-
|
102
|
-
def self.find_world_quali_euro_2012_13!
|
103
|
-
self.find_by_key!( WORLD_QUALI_EURO_2012_13 )
|
104
|
-
end
|
105
|
-
|
106
|
-
def self.find_world_quali_america_2012_13!
|
107
|
-
self.find_by_key!( WORLD_QUALI_AMERICA_2012_13 )
|
108
|
-
end
|
109
|
-
|
110
76
|
|
111
77
|
end # class Event
|
112
78
|
|