sportdb 1.9.16 → 1.10.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/HISTORY.md +2 -19
- data/Manifest.txt +1 -137
- data/README.md +2 -21
- data/Rakefile +14 -25
- data/lib/sportdb.rb +9 -260
- data/lib/sportdb/cli/main.rb +5 -14
- data/lib/sportdb/cli/opts.rb +2 -0
- data/lib/sportdb/cli/version.rb +26 -0
- metadata +10 -278
- data/.gemtest +0 -0
- data/config/fixtures/de.yml +0 -46
- data/config/fixtures/en.yml +0 -54
- data/config/fixtures/es.yml +0 -48
- data/config/fixtures/fr.yml +0 -53
- data/config/fixtures/it.yml +0 -55
- data/config/fixtures/pt.yml +0 -46
- data/config/fixtures/ro.yml +0 -55
- data/data/seasons.txt +0 -74
- data/data/setups/all.txt +0 -5
- data/lib/sportdb/calc.rb +0 -279
- data/lib/sportdb/deleter.rb +0 -52
- data/lib/sportdb/finders/date.rb +0 -374
- data/lib/sportdb/finders/goals.rb +0 -260
- data/lib/sportdb/finders/scores.rb +0 -122
- data/lib/sportdb/lang.rb +0 -216
- data/lib/sportdb/matcher.rb +0 -31
- data/lib/sportdb/models/assoc.rb +0 -106
- data/lib/sportdb/models/assoc_assoc.rb +0 -15
- data/lib/sportdb/models/badge.rb +0 -14
- data/lib/sportdb/models/event.rb +0 -65
- data/lib/sportdb/models/event_ground.rb +0 -15
- data/lib/sportdb/models/event_team.rb +0 -16
- data/lib/sportdb/models/forward.rb +0 -55
- data/lib/sportdb/models/game.rb +0 -244
- data/lib/sportdb/models/goal.rb +0 -15
- data/lib/sportdb/models/ground.rb +0 -100
- data/lib/sportdb/models/group.rb +0 -23
- data/lib/sportdb/models/group_team.rb +0 -14
- data/lib/sportdb/models/league.rb +0 -83
- data/lib/sportdb/models/person.rb +0 -21
- data/lib/sportdb/models/roster.rb +0 -18
- data/lib/sportdb/models/round.rb +0 -22
- data/lib/sportdb/models/season.rb +0 -14
- data/lib/sportdb/models/stats/alltime_standing.rb +0 -44
- data/lib/sportdb/models/stats/alltime_standing_entry.rb +0 -23
- data/lib/sportdb/models/stats/event_standing.rb +0 -55
- data/lib/sportdb/models/stats/event_standing_entry.rb +0 -21
- data/lib/sportdb/models/stats/group_standing.rb +0 -50
- data/lib/sportdb/models/stats/group_standing_entry.rb +0 -22
- data/lib/sportdb/models/team.rb +0 -119
- data/lib/sportdb/models/team_comp.rb +0 -64
- data/lib/sportdb/models/utils.rb +0 -78
- data/lib/sportdb/models/world/city.rb +0 -21
- data/lib/sportdb/models/world/continent.rb +0 -20
- data/lib/sportdb/models/world/country.rb +0 -19
- data/lib/sportdb/models/world/region.rb +0 -19
- data/lib/sportdb/patterns.rb +0 -38
- data/lib/sportdb/reader.rb +0 -130
- data/lib/sportdb/reader_file.rb +0 -123
- data/lib/sportdb/reader_zip.rb +0 -165
- data/lib/sportdb/readers/assoc.rb +0 -54
- data/lib/sportdb/readers/event.rb +0 -200
- data/lib/sportdb/readers/game.rb +0 -877
- data/lib/sportdb/readers/ground.rb +0 -53
- data/lib/sportdb/readers/league.rb +0 -54
- data/lib/sportdb/readers/season.rb +0 -83
- data/lib/sportdb/readers/squad_club.rb +0 -201
- data/lib/sportdb/readers/squad_national_team.rb +0 -173
- data/lib/sportdb/readers/team.rb +0 -53
- data/lib/sportdb/schema.rb +0 -373
- data/lib/sportdb/standings.rb +0 -178
- data/lib/sportdb/stats.rb +0 -27
- data/lib/sportdb/utils.rb +0 -89
- data/lib/sportdb/utils_date.rb +0 -26
- data/lib/sportdb/utils_goals.rb +0 -20
- data/lib/sportdb/utils_group.rb +0 -63
- data/lib/sportdb/utils_map.rb +0 -44
- data/lib/sportdb/utils_round.rb +0 -165
- data/lib/sportdb/utils_scores.rb +0 -17
- data/lib/sportdb/utils_teams.rb +0 -43
- data/lib/sportdb/version.rb +0 -22
- data/test/data/at-austria/2013_14/bl.txt +0 -227
- data/test/data/at-austria/2013_14/bl.yml +0 -30
- data/test/data/at-austria/2013_14/bl_ii.txt +0 -154
- data/test/data/at-austria/2013_14/el.txt +0 -4
- data/test/data/at-austria/2013_14/el.yml +0 -25
- data/test/data/at-austria/2013_14/squads/austria.txt +0 -40
- data/test/data/at-austria/2013_14/squads/salzburg.txt +0 -35
- data/test/data/at-austria/leagues.txt +0 -11
- data/test/data/at-austria/teams.txt +0 -75
- data/test/data/at-austria/teams_2.txt +0 -34
- data/test/data/national-teams/assocs.txt +0 -231
- data/test/data/national-teams/europe/assocs.txt +0 -13
- data/test/data/national-teams/europe/teams.txt +0 -13
- data/test/data/national-teams/north-america/assocs.txt +0 -10
- data/test/data/national-teams/north-america/teams.txt +0 -7
- data/test/data/national-teams/teams.txt +0 -19
- data/test/data/players/europe/at-austria/players.txt +0 -45
- data/test/data/players/europe/de-deutschland/players.txt +0 -41
- data/test/data/players/south-america/br-brazil/players.txt +0 -51
- data/test/data/world-cup/1930/cup.txt +0 -71
- data/test/data/world-cup/1930/cup.yml +0 -23
- data/test/data/world-cup/1930/cup_goals.txt +0 -47
- data/test/data/world-cup/1930/cup_goals.yml +0 -23
- data/test/data/world-cup/1954/cup.txt +0 -90
- data/test/data/world-cup/1954/cup.yml +0 -30
- data/test/data/world-cup/1962/cup.txt +0 -86
- data/test/data/world-cup/1962/cup.yml +0 -32
- data/test/data/world-cup/1974/cup.yml +0 -35
- data/test/data/world-cup/1974/cup_finals.txt +0 -14
- data/test/data/world-cup/1974/cup_i.txt +0 -55
- data/test/data/world-cup/1974/cup_ii.txt +0 -34
- data/test/data/world-cup/2014/cup.txt +0 -5
- data/test/data/world-cup/2014/cup.yml +0 -54
- data/test/data/world-cup/2014/squads/br-brazil.txt +0 -46
- data/test/data/world-cup/2014/squads/de-deutschland.txt +0 -8
- data/test/data/world-cup/2014/squads/jp-japan.txt +0 -30
- data/test/data/world-cup/2014/squads/uy-uruguay.txt +0 -32
- data/test/data/world-cup/leagues.txt +0 -5
- data/test/data/world-cup/seasons_1930.txt +0 -4
- data/test/data/world-cup/seasons_1954.txt +0 -4
- data/test/data/world-cup/seasons_1962.txt +0 -4
- data/test/data/world-cup/seasons_1974.txt +0 -5
- data/test/data/world-cup/teams_1930.txt +0 -26
- data/test/data/world-cup/teams_1954.txt +0 -30
- data/test/data/world-cup/teams_1962.txt +0 -29
- data/test/data/world-cup/teams_1974.txt +0 -29
- data/test/helper.rb +0 -120
- data/test/test_assoc_reader.rb +0 -201
- data/test/test_changes.rb +0 -74
- data/test/test_cursor.rb +0 -50
- data/test/test_date.rb +0 -100
- data/test/test_goals.rb +0 -109
- data/test/test_lang.rb +0 -130
- data/test/test_load.rb +0 -61
- data/test/test_reader.rb +0 -88
- data/test/test_reader_from_string.rb +0 -65
- data/test/test_round_auto.rb +0 -370
- data/test/test_round_def.rb +0 -109
- data/test/test_round_header.rb +0 -183
- data/test/test_scores.rb +0 -70
- data/test/test_squad_club_reader.rb +0 -76
- data/test/test_squad_national_team_reader.rb +0 -116
- data/test/test_standings.rb +0 -279
- data/test/test_standings_ii.rb +0 -46
- data/test/test_utils.rb +0 -124
- data/test/test_winner.rb +0 -95
data/config/fixtures/en.yml
DELETED
@@ -1,54 +0,0 @@
|
|
1
|
-
###########################
|
2
|
-
# known keywords for fixtures
|
3
|
-
|
4
|
-
|
5
|
-
group: Group
|
6
|
-
|
7
|
-
round: Round|Matchday|Week
|
8
|
-
|
9
|
-
stage: Stage|Phase|Rounds
|
10
|
-
# e.g.
|
11
|
-
# Group stage
|
12
|
-
# Play off stage|Play-off stage
|
13
|
-
# Knockout stage|Knockout stages
|
14
|
-
# First stage
|
15
|
-
# Second stage
|
16
|
-
# Qualifying rounds
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
### Knockout rounds
|
21
|
-
|
22
|
-
playoffs: Playoff|Playoffs|Play-off|Play-offs|Play-off for quarter-finals
|
23
|
-
round32: Round of 32|Last 32
|
24
|
-
round16: Round of 16|Last 16|8th finals
|
25
|
-
quarterfinals: Quarterfinals|Quarter-finals|Quarters|Quarterfinal|Last 8
|
26
|
-
semifinals: Semifinals|Semi-finals|Semis|Last 4
|
27
|
-
fifthplace: Fifth place match|Fifth place|5th place match|5th place final|5th place|Match for fifth place|Match for 5th place
|
28
|
-
thirdplace: Third place match|Third-place match|Third place|3rd place match|3rd place final|3rd place|Match for third place|Match for 3rd place|Third-place play-off|Third place play-off
|
29
|
-
final: Final|Finals
|
30
|
-
|
31
|
-
|
32
|
-
### Pair matches/games if marked with leg1 n leg2
|
33
|
-
|
34
|
-
leg1: 1st leg|First leg
|
35
|
-
leg2: 2nd leg|Second leg
|
36
|
-
|
37
|
-
|
38
|
-
#######################
|
39
|
-
# months of year
|
40
|
-
|
41
|
-
january: January
|
42
|
-
february: February
|
43
|
-
march: March
|
44
|
-
april: April
|
45
|
-
may: May
|
46
|
-
june: June
|
47
|
-
july: July
|
48
|
-
august: August
|
49
|
-
september: September
|
50
|
-
october: October
|
51
|
-
november: November
|
52
|
-
december: December
|
53
|
-
|
54
|
-
|
data/config/fixtures/es.yml
DELETED
@@ -1,48 +0,0 @@
|
|
1
|
-
###########################
|
2
|
-
# known keywords for fixtures
|
3
|
-
|
4
|
-
|
5
|
-
group: Grupo
|
6
|
-
|
7
|
-
round: Fecha|Jornada
|
8
|
-
|
9
|
-
|
10
|
-
stage: Primera fase|Segunda fase|Fase de grupos|Fase final
|
11
|
-
|
12
|
-
|
13
|
-
### Knock out rounds
|
14
|
-
|
15
|
-
## fix: add playoffs + fifthplace
|
16
|
-
|
17
|
-
|
18
|
-
round32: Dieciseisavos de final|16vos de final
|
19
|
-
round16: Octavos|Octavos de final|8vos de final
|
20
|
-
quarterfinals: Cuartos|Cuartos de final|4tos de final
|
21
|
-
semifinals: Semifinales|Semifinal
|
22
|
-
thirdplace: Tercer lugar
|
23
|
-
final: Final
|
24
|
-
|
25
|
-
### Pair matches/games if marked with leg1 n leg2
|
26
|
-
|
27
|
-
leg1: Ida
|
28
|
-
leg2: Vuelta
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
#######################
|
33
|
-
# months of year
|
34
|
-
|
35
|
-
january: enero
|
36
|
-
february: febrero
|
37
|
-
march: marzo
|
38
|
-
april: abril
|
39
|
-
may: mayo
|
40
|
-
june: junio
|
41
|
-
july: julio
|
42
|
-
august: agosto
|
43
|
-
september: septiembre
|
44
|
-
october: octubre
|
45
|
-
november: noviembre
|
46
|
-
december: diciembre
|
47
|
-
|
48
|
-
|
data/config/fixtures/fr.yml
DELETED
@@ -1,53 +0,0 @@
|
|
1
|
-
###########################
|
2
|
-
# known keywords for fixtures
|
3
|
-
|
4
|
-
|
5
|
-
group: Groupe
|
6
|
-
|
7
|
-
round: Journée
|
8
|
-
|
9
|
-
stage: Phase de groupes|Phase à élimination directe|Phase finale
|
10
|
-
# e.g.
|
11
|
-
# Group stage
|
12
|
-
# Play off stage|Play-off stage
|
13
|
-
# Knockout stage|Knockout stages
|
14
|
-
# First stage
|
15
|
-
# Second stage
|
16
|
-
# Qualifying rounds
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
### Knockout rounds
|
22
|
-
|
23
|
-
## fix: add playoffs + fifthplace
|
24
|
-
|
25
|
-
|
26
|
-
round32: Seizièmes de finale
|
27
|
-
round16: Huitièmes de finale
|
28
|
-
quarterfinals: Quarts de finale
|
29
|
-
semifinals: Demi-finales
|
30
|
-
thirdplace: Match pour la troisième place
|
31
|
-
final: Finale
|
32
|
-
|
33
|
-
### Pair matches/games if marked with leg1 n leg2
|
34
|
-
|
35
|
-
leg1: Match aller
|
36
|
-
leg2: Match retour
|
37
|
-
|
38
|
-
|
39
|
-
#######################
|
40
|
-
# months of year
|
41
|
-
|
42
|
-
january: janvier
|
43
|
-
february: février
|
44
|
-
march: mars
|
45
|
-
april: avril
|
46
|
-
may: mai
|
47
|
-
june: juin
|
48
|
-
july: juillet
|
49
|
-
august: août
|
50
|
-
september: septembre
|
51
|
-
october: octobre
|
52
|
-
november: novembre
|
53
|
-
december: décembre
|
data/config/fixtures/it.yml
DELETED
@@ -1,55 +0,0 @@
|
|
1
|
-
###########################
|
2
|
-
# known keywords for fixtures
|
3
|
-
|
4
|
-
|
5
|
-
group: Gruppo
|
6
|
-
|
7
|
-
|
8
|
-
round: Giornata
|
9
|
-
|
10
|
-
stage: Fase a gironi|Fase a eliminazione diretta
|
11
|
-
# e.g.
|
12
|
-
# Group stage
|
13
|
-
# Play off stage|Play-off stage
|
14
|
-
# Knockout stage|Knockout stages
|
15
|
-
# First stage
|
16
|
-
# Second stage
|
17
|
-
# Qualifying rounds
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
### Knockout rounds
|
23
|
-
|
24
|
-
## fix: add playoffs + fifthplace
|
25
|
-
|
26
|
-
|
27
|
-
round32: Sedicesimi di finale
|
28
|
-
round16: Ottavi di finale
|
29
|
-
quarterfinals: Quarti di finale
|
30
|
-
semifinals: Semifinali
|
31
|
-
thirdplace: Finale 3º posto
|
32
|
-
final: Finale
|
33
|
-
|
34
|
-
### Pair matches/games if marked with leg1 n leg2
|
35
|
-
|
36
|
-
leg1: Andata
|
37
|
-
leg2: Ritorno
|
38
|
-
|
39
|
-
|
40
|
-
#######################
|
41
|
-
# months of year
|
42
|
-
|
43
|
-
january: gennaio
|
44
|
-
february: febbraio
|
45
|
-
march: marzo
|
46
|
-
april: aprile
|
47
|
-
may: maggio
|
48
|
-
june: giugno
|
49
|
-
july: luglio
|
50
|
-
august: agosto
|
51
|
-
september: settembre
|
52
|
-
october: ottobre
|
53
|
-
november: novembre
|
54
|
-
december: dicembre
|
55
|
-
|
data/config/fixtures/pt.yml
DELETED
@@ -1,46 +0,0 @@
|
|
1
|
-
###########################
|
2
|
-
# known keywords for fixtures
|
3
|
-
|
4
|
-
|
5
|
-
group: Grupo
|
6
|
-
|
7
|
-
round: Rodada
|
8
|
-
|
9
|
-
stage: Fase de grupos|Fase final|Primeira Fase|Segunda Fase
|
10
|
-
|
11
|
-
|
12
|
-
### Knock out rounds
|
13
|
-
|
14
|
-
## fix: add playoffs + fifthplace
|
15
|
-
|
16
|
-
round32: 16-avos de final
|
17
|
-
round16: Oitavos de final|Oitavas-de-final
|
18
|
-
quarterfinals: Quartos de final|Quartas-de-final
|
19
|
-
semifinals: Semifinais
|
20
|
-
thirdplace: Terceiro lugar
|
21
|
-
final: Final
|
22
|
-
|
23
|
-
|
24
|
-
### Pair matches/games if marked with leg1 n leg2
|
25
|
-
|
26
|
-
leg1: 1º jogo # Ida -- exists ??
|
27
|
-
leg2: 2º jogo # Volta -- exists ??
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
#######################
|
32
|
-
# months of year
|
33
|
-
|
34
|
-
january: janeiro
|
35
|
-
february: fevereiro
|
36
|
-
march: março
|
37
|
-
april: abril
|
38
|
-
may: maio
|
39
|
-
june: junho
|
40
|
-
july: julho
|
41
|
-
august: agosto
|
42
|
-
september: setembro
|
43
|
-
october: outubro
|
44
|
-
november: novembro
|
45
|
-
december: dezembro
|
46
|
-
|
data/config/fixtures/ro.yml
DELETED
@@ -1,55 +0,0 @@
|
|
1
|
-
###########################
|
2
|
-
# known keywords for fixtures
|
3
|
-
|
4
|
-
|
5
|
-
group: Grupa
|
6
|
-
|
7
|
-
round: Runda|Etapa
|
8
|
-
|
9
|
-
|
10
|
-
stage: Faza grupelor|Faza eliminatorie
|
11
|
-
# e.g.
|
12
|
-
# Group stage
|
13
|
-
# Play off stage|Play-off stage
|
14
|
-
# Knockout stage|Knockout stages
|
15
|
-
# First stage
|
16
|
-
# Second stage
|
17
|
-
# Qualifying rounds
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
### Knockout rounds
|
23
|
-
|
24
|
-
## fix: add playoffs + fifthplace
|
25
|
-
|
26
|
-
|
27
|
-
round32: 1/16 de finală
|
28
|
-
round16: Optimi de finală
|
29
|
-
quarterfinals: Sferturi de finală
|
30
|
-
semifinals: Semifinale
|
31
|
-
thirdplace: Meciul pentru locul 3
|
32
|
-
final: Finala
|
33
|
-
|
34
|
-
### Pair matches/games if marked with leg1 n leg2
|
35
|
-
|
36
|
-
leg1: Tur ## Prima manșă - use too ??
|
37
|
-
leg2: Retur ## Manșa secundă - use too ??
|
38
|
-
|
39
|
-
|
40
|
-
#######################
|
41
|
-
# months of year
|
42
|
-
|
43
|
-
january: ianuarie
|
44
|
-
february: februarie
|
45
|
-
march: martie
|
46
|
-
april: aprilie
|
47
|
-
may: mai
|
48
|
-
june: iunie
|
49
|
-
july: iulie
|
50
|
-
august: august
|
51
|
-
september: septembrie
|
52
|
-
october: octombrie
|
53
|
-
november: noiembrie
|
54
|
-
december: decembrie
|
55
|
-
|
data/data/seasons.txt
DELETED
@@ -1,74 +0,0 @@
|
|
1
|
-
###
|
2
|
-
# use period for season? why? why not?
|
3
|
-
# - semantic hairsplitting? make it an alias? why? why not? who cares?
|
4
|
-
|
5
|
-
|
6
|
-
###
|
7
|
-
# use 2012-13 or 2012_13 or 2012.13 or 2012+13 why? why not ???
|
8
|
-
|
9
|
-
2020/21
|
10
|
-
2019/20
|
11
|
-
2018/19
|
12
|
-
2017/18
|
13
|
-
2016/17
|
14
|
-
2015/16
|
15
|
-
2014/15
|
16
|
-
2013/14
|
17
|
-
2012/13
|
18
|
-
2011/12
|
19
|
-
2010/11
|
20
|
-
2009/10
|
21
|
-
2008/09
|
22
|
-
2007/08
|
23
|
-
2006/07
|
24
|
-
2005/06
|
25
|
-
2004/05
|
26
|
-
2003/04
|
27
|
-
2002/03
|
28
|
-
2001/02
|
29
|
-
2000/01
|
30
|
-
|
31
|
-
# -- years only --
|
32
|
-
|
33
|
-
2022
|
34
|
-
2021
|
35
|
-
2020
|
36
|
-
2019
|
37
|
-
2018
|
38
|
-
2017
|
39
|
-
2016
|
40
|
-
2015
|
41
|
-
2014
|
42
|
-
2013
|
43
|
-
2012
|
44
|
-
2011
|
45
|
-
2010
|
46
|
-
2009
|
47
|
-
2008
|
48
|
-
2007
|
49
|
-
2006
|
50
|
-
2005
|
51
|
-
2004
|
52
|
-
2003
|
53
|
-
2002
|
54
|
-
2001
|
55
|
-
2000
|
56
|
-
|
57
|
-
|
58
|
-
# e.g. Liga MX has two (complete) seasons in *one* year e.g. Clausura 2013 n Apertura 2013
|
59
|
-
### for 2013.1 use 2013_I 2013-I 2013.I n 2013-II 2013.II or 2013.A n 2013.B - why? why not??
|
60
|
-
|
61
|
-
2015.1
|
62
|
-
2015.2
|
63
|
-
2014.1
|
64
|
-
2014.2
|
65
|
-
2013.1
|
66
|
-
2013.2
|
67
|
-
2012.1
|
68
|
-
2012.2
|
69
|
-
2011.1
|
70
|
-
2011.2
|
71
|
-
2010.1
|
72
|
-
2010.2
|
73
|
-
|
74
|
-
|
data/data/setups/all.txt
DELETED
data/lib/sportdb/calc.rb
DELETED
@@ -1,279 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
module SportDb
|
4
|
-
|
5
|
-
############
|
6
|
-
##
|
7
|
-
## fix/todo: obsolete
|
8
|
-
## - use new Standings class
|
9
|
-
|
10
|
-
|
11
|
-
##############################################
|
12
|
-
# helper/ builds standings table in memory
|
13
|
-
# - find a better module name for StandingsHelper ?? why? why not?
|
14
|
-
|
15
|
-
|
16
|
-
module StandingsHelper
|
17
|
-
|
18
|
-
## todo:
|
19
|
-
## add team_id to struct - why? why not? - saves a db lookup?
|
20
|
-
class Stats
|
21
|
-
### fix/todo: change/rename :pos to :rank
|
22
|
-
attr_accessor :pos, :played, :won, :lost, :drawn,
|
23
|
-
:goals_for, :goals_against, :pts,
|
24
|
-
:recs
|
25
|
-
|
26
|
-
def initialize
|
27
|
-
@pos = nil # use 0? why? why not?
|
28
|
-
@played = 0
|
29
|
-
@won = 0
|
30
|
-
@lost = 0
|
31
|
-
@drawn = 0
|
32
|
-
@goals_for = 0
|
33
|
-
@goals_against = 0
|
34
|
-
@pts = 0
|
35
|
-
@recs = 0
|
36
|
-
# note: appearances (event) count or similar
|
37
|
-
# is recs counter (number of (stats) records)
|
38
|
-
end
|
39
|
-
|
40
|
-
def add( rec )
|
41
|
-
### fix: add plus + operator too!
|
42
|
-
|
43
|
-
# note: will NOT update/add pos (ranking)
|
44
|
-
self.played += rec.played
|
45
|
-
self.won += rec.won
|
46
|
-
self.lost += rec.lost
|
47
|
-
self.drawn += rec.drawn
|
48
|
-
self.goals_for += rec.goals_for
|
49
|
-
self.goals_against += rec.goals_against
|
50
|
-
self.pts += rec.pts
|
51
|
-
self.recs += rec.recs
|
52
|
-
|
53
|
-
self # return self stats rec
|
54
|
-
end # method add
|
55
|
-
end # class Stats
|
56
|
-
|
57
|
-
|
58
|
-
def self.calc( games, opts={} )
|
59
|
-
|
60
|
-
##
|
61
|
-
# possible opts include:
|
62
|
-
# pts_won: 3 or 2 or n (default 3)
|
63
|
-
# pts_exclude_scorep false or true (default false) -- exclude penalty shotout scores (e.g. count a draw/tie - no winner)
|
64
|
-
#
|
65
|
-
recs = calc_stats( games, opts )
|
66
|
-
|
67
|
-
## update pos (that is, ranking e.g. 1.,2., 3. etc.)
|
68
|
-
recs= update_ranking( recs )
|
69
|
-
|
70
|
-
pp recs
|
71
|
-
recs
|
72
|
-
end
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
def self.calc_for_events( events, opts={} )
|
77
|
-
|
78
|
-
## todo:
|
79
|
-
## - add tracker for appeareances (stats records counter)
|
80
|
-
|
81
|
-
alltime_recs = {} # stats recs indexed by team_key
|
82
|
-
|
83
|
-
events.each do |event|
|
84
|
-
puts " update standings for #{event.title}"
|
85
|
-
recs = calc_stats( event.games, opts )
|
86
|
-
|
87
|
-
recs.each do |team_key, rec|
|
88
|
-
alltime_rec = alltime_recs[ team_key ] || Stats.new
|
89
|
-
|
90
|
-
## add stats values
|
91
|
-
alltime_rec.add( rec )
|
92
|
-
|
93
|
-
alltime_recs[ team_key ] = alltime_rec
|
94
|
-
end
|
95
|
-
end
|
96
|
-
|
97
|
-
|
98
|
-
### fix:
|
99
|
-
# - make merge team into a helper method (for reuse)
|
100
|
-
|
101
|
-
## check for merging teams
|
102
|
-
# e.g. all time world cup
|
103
|
-
# Germany incl. West Germany
|
104
|
-
# Russia incl. Soviet Union etc.
|
105
|
-
|
106
|
-
# todo: change opts para to :includes instead of :merge ? why? why not??
|
107
|
-
|
108
|
-
merge = opts[:merge]
|
109
|
-
if merge
|
110
|
-
puts " merging teams (stats records):"
|
111
|
-
pp merge
|
112
|
-
|
113
|
-
merge.each do |k,v|
|
114
|
-
# note: assume key is destition team key and
|
115
|
-
# value is source team key e.g. 'GER' => 'FRG'
|
116
|
-
# or array (for mulitple teamss e.g. 'GER' => ['FRG','GDR']
|
117
|
-
team_key_dest = k.to_s
|
118
|
-
|
119
|
-
if v.kind_of? Array
|
120
|
-
team_keys_src = v
|
121
|
-
else
|
122
|
-
team_keys_src = [v] # turn single value arg into array w/ single item
|
123
|
-
end
|
124
|
-
team_keys_src = team_keys_src.map { |src| src.to_s } # turn all to string (might be symbol)
|
125
|
-
|
126
|
-
alltime_rec_dest = alltime_recs[ team_key_dest ] || Stats.new
|
127
|
-
|
128
|
-
team_keys_src.each do |team_key_src|
|
129
|
-
alltime_rec_src = alltime_recs[ team_key_src]
|
130
|
-
|
131
|
-
if alltime_rec_src # stats record found?
|
132
|
-
alltime_rec_dest.add( alltime_rec_src ) # add stats values
|
133
|
-
alltime_recs.delete( team_key_src ) # remove old src entry
|
134
|
-
end
|
135
|
-
end
|
136
|
-
|
137
|
-
alltime_recs[ team_key_dest ] = alltime_rec_dest
|
138
|
-
end
|
139
|
-
end
|
140
|
-
|
141
|
-
## update pos (that is, ranking e.g. 1.,2., 3. etc.)
|
142
|
-
alltime_recs= update_ranking( alltime_recs )
|
143
|
-
|
144
|
-
## pp alltime_recs
|
145
|
-
alltime_recs
|
146
|
-
end
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
def self.calc_stats( games, opts={} )
|
151
|
-
|
152
|
-
## fix:
|
153
|
-
# passing in e.g. pts for win (3? 2? etc.)
|
154
|
-
# default to 3 for now
|
155
|
-
|
156
|
-
# note:
|
157
|
-
# returns stats records w/ stats records counter always set to one (recs==1)
|
158
|
-
|
159
|
-
## todo/fix: find a better way to include logger (do NOT hardcode usage of root logger)!!!
|
160
|
-
logger = LogUtils::Logger.root
|
161
|
-
|
162
|
-
|
163
|
-
## lets you pass in 2 as an alterantive, for example
|
164
|
-
pts_won = opts[:pts_won] || 3
|
165
|
-
|
166
|
-
## lets you exclude penalty shootout (e.g. match gets scored as draw/tie 1 pt each)
|
167
|
-
# e.g. why? used for alltime standings formula in world cup, for example
|
168
|
-
# todo: check other standings - exclude penalty shootout too - e.g. championsleague ?? if yes - make it true as default??
|
169
|
-
pts_exclude_scorep = opts[:pts_exclude_scorep].present? ? opts[:pts_exclude_scorep] : false
|
170
|
-
|
171
|
-
|
172
|
-
recs = {}
|
173
|
-
|
174
|
-
games.each_with_index do |g,i| # note: index(i) starts w/ zero (0)
|
175
|
-
puts " [#{i+1}] #{g.team1.title} - #{g.team2.title} #{g.score_str}"
|
176
|
-
unless g.over?
|
177
|
-
puts " !!!! skipping match - not yet over (play_at date in the future)"
|
178
|
-
next
|
179
|
-
end
|
180
|
-
unless g.complete?
|
181
|
-
logger.error "[StandingsHelper.calc_stats] skipping match #{g.team1.title} - #{g.team2.title} - scores incomplete #{g.score_str}"
|
182
|
-
next
|
183
|
-
end
|
184
|
-
|
185
|
-
rec1 = recs[ g.team1.key ] || Stats.new
|
186
|
-
rec2 = recs[ g.team2.key ] || Stats.new
|
187
|
-
|
188
|
-
## set stats records counter to one if new (first) record update
|
189
|
-
rec1.recs = 1 if rec1.recs == 0
|
190
|
-
rec2.recs = 1 if rec2.recs == 0
|
191
|
-
|
192
|
-
rec1.played += 1
|
193
|
-
rec2.played += 1
|
194
|
-
|
195
|
-
## check - if winner (excludes penalty shootout scores in calc? start w/ extra time e.g winneret)
|
196
|
-
if pts_exclude_scorep
|
197
|
-
winner = g.winneret || g.winner90 ## if no extra time (et) score; try 90min (regular time score)
|
198
|
-
else
|
199
|
-
winner = g.winner ## note: might include penalty shoot scores
|
200
|
-
end
|
201
|
-
|
202
|
-
if winner == 1
|
203
|
-
rec1.won += 1
|
204
|
-
rec2.lost += 1
|
205
|
-
rec1.pts += pts_won
|
206
|
-
elsif winner == 2
|
207
|
-
rec1.lost += 1
|
208
|
-
rec2.won += 1
|
209
|
-
rec2.pts += pts_won
|
210
|
-
else ## assume drawn/tie (that is, 0)
|
211
|
-
rec1.drawn += 1
|
212
|
-
rec2.drawn += 1
|
213
|
-
rec1.pts += 1
|
214
|
-
rec2.pts += 1
|
215
|
-
end
|
216
|
-
|
217
|
-
rec1.goals_for += g.score1
|
218
|
-
rec1.goals_against += g.score2
|
219
|
-
|
220
|
-
rec2.goals_for += g.score2
|
221
|
-
rec2.goals_against += g.score1
|
222
|
-
|
223
|
-
## add overtime and penalty??
|
224
|
-
## - for now add only overtime if present
|
225
|
-
|
226
|
-
rec1.goals_for += (g.score1et-g.score1) if g.score1et.present?
|
227
|
-
rec1.goals_against += (g.score2et-g.score2) if g.score2et.present?
|
228
|
-
|
229
|
-
rec2.goals_for += (g.score2et-g.score2) if g.score2et.present?
|
230
|
-
rec2.goals_against += (g.score1et-g.score1) if g.score1et.present?
|
231
|
-
|
232
|
-
recs[ g.team1.key ] = rec1
|
233
|
-
recs[ g.team2.key ] = rec2
|
234
|
-
end # each game
|
235
|
-
|
236
|
-
recs # return records; hash indexed by team key
|
237
|
-
end # method calc
|
238
|
-
|
239
|
-
|
240
|
-
def self.update_ranking( recs )
|
241
|
-
#############################
|
242
|
-
### calc ranking / pos
|
243
|
-
##
|
244
|
-
## fix/allow sampe pos e.g. all 1 or more than one team 3rd etc.
|
245
|
-
## see sportbook for an example
|
246
|
-
|
247
|
-
# build array from hash
|
248
|
-
ary = []
|
249
|
-
recs.each do |k,v|
|
250
|
-
ary << [k,v]
|
251
|
-
end
|
252
|
-
|
253
|
-
ary.sort! do |l,r|
|
254
|
-
## note: reverse order (thus, change l,r to r,l)
|
255
|
-
value = r[1].pts <=> l[1].pts
|
256
|
-
if value == 0 # same pts try goal diff
|
257
|
-
value = (r[1].goals_for-r[1].goals_against) <=> (l[1].goals_for-l[1].goals_against)
|
258
|
-
if value == 0 # same goal diff too; try assume more goals better for now
|
259
|
-
value = r[1].goals_for <=> l[1].goals_for
|
260
|
-
end
|
261
|
-
end
|
262
|
-
value
|
263
|
-
end
|
264
|
-
|
265
|
-
## update pos using ordered array
|
266
|
-
ary.each_with_index do |rec,i|
|
267
|
-
k = rec[0]
|
268
|
-
v = rec[1]
|
269
|
-
v.pos = i+1 ## add ranking (e.g. 1,2,3 etc.) - note: i starts w/ zero (0)
|
270
|
-
recs[ k ] = v ## update recs
|
271
|
-
end
|
272
|
-
|
273
|
-
recs
|
274
|
-
end # method update_ranking
|
275
|
-
|
276
|
-
|
277
|
-
end # module StandingsHelper
|
278
|
-
|
279
|
-
end # module SportDb
|