sportdb-models 1.19.0 → 2.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (58) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +20 -20
  3. data/Manifest.txt +27 -38
  4. data/README.md +31 -31
  5. data/Rakefile +32 -32
  6. data/lib/sportdb/models.rb +212 -159
  7. data/lib/sportdb/{deleter.rb → models/deleter.rb} +3 -9
  8. data/lib/sportdb/models/formats.rb +23 -0
  9. data/lib/sportdb/models/models/assoc.rb +38 -0
  10. data/lib/sportdb/models/{badge.rb → models/badge.rb} +14 -14
  11. data/lib/sportdb/models/models/event.rb +55 -0
  12. data/lib/sportdb/models/{forward.rb → models/forward.rb} +55 -55
  13. data/lib/sportdb/models/{goal.rb → models/goal.rb} +15 -15
  14. data/lib/sportdb/models/models/ground.rb +16 -0
  15. data/lib/sportdb/models/{group.rb → models/group.rb} +10 -7
  16. data/lib/sportdb/models/models/league.rb +20 -0
  17. data/lib/sportdb/models/{roster.rb → models/lineup.rb} +17 -18
  18. data/lib/sportdb/models/{game.rb → models/match.rb} +18 -61
  19. data/lib/sportdb/models/{person.rb → models/person.rb} +21 -21
  20. data/lib/sportdb/models/{round.rb → models/round.rb} +1 -6
  21. data/lib/sportdb/models/{season.rb → models/season.rb} +15 -14
  22. data/lib/sportdb/models/{stage.rb → models/stage.rb} +9 -5
  23. data/lib/sportdb/models/{stats/alltime_standing_entry.rb → models/stats/alltime_standing.rb} +9 -1
  24. data/lib/sportdb/models/{stats/event_standing_entry.rb → models/stats/event_standing.rb} +31 -21
  25. data/lib/sportdb/models/{stats/group_standing_entry.rb → models/stats/group_standing.rb} +10 -1
  26. data/lib/sportdb/models/models/team.rb +56 -0
  27. data/lib/sportdb/models/{world → models/world}/city.rb +2 -2
  28. data/lib/sportdb/models/{world → models/world}/continent.rb +20 -20
  29. data/lib/sportdb/models/{world → models/world}/country.rb +0 -0
  30. data/lib/sportdb/models/{world → models/world}/state.rb +19 -19
  31. data/lib/sportdb/models/schema.rb +466 -0
  32. data/lib/sportdb/models/stats.rb +23 -0
  33. data/lib/sportdb/models/utils.rb +24 -24
  34. data/lib/sportdb/{version.rb → models/version.rb} +27 -22
  35. data/test/helper.rb +46 -42
  36. data/test/test_changes.rb +38 -38
  37. data/test/test_cursor.rb +15 -15
  38. data/test/test_winner.rb +75 -70
  39. metadata +39 -44
  40. data/lib/sportdb/calc.rb +0 -279
  41. data/lib/sportdb/models/assoc.rb +0 -106
  42. data/lib/sportdb/models/assoc_assoc.rb +0 -15
  43. data/lib/sportdb/models/event.rb +0 -66
  44. data/lib/sportdb/models/event_ground.rb +0 -15
  45. data/lib/sportdb/models/event_team.rb +0 -16
  46. data/lib/sportdb/models/ground.rb +0 -100
  47. data/lib/sportdb/models/group_team.rb +0 -14
  48. data/lib/sportdb/models/league.rb +0 -83
  49. data/lib/sportdb/models/stage_team.rb +0 -14
  50. data/lib/sportdb/models/stats/alltime_standing.rb +0 -44
  51. data/lib/sportdb/models/stats/event_standing.rb +0 -55
  52. data/lib/sportdb/models/stats/group_standing.rb +0 -50
  53. data/lib/sportdb/models/team.rb +0 -119
  54. data/lib/sportdb/models/team_compat.rb +0 -64
  55. data/lib/sportdb/patterns.rb +0 -37
  56. data/lib/sportdb/schema.rb +0 -397
  57. data/lib/sportdb/standings.rb +0 -178
  58. data/lib/sportdb/stats.rb +0 -27
@@ -0,0 +1,23 @@
1
+
2
+ module SportDb
3
+
4
+ class Stats
5
+ include Models
6
+
7
+ def tables
8
+ puts " #{League.count} leagues / #{Season.count} seasons"
9
+ puts " #{Event.count} events (league+season recs) / #{Round.count} rounds / #{Group.count} groups / #{Stage.count} stages"
10
+ puts " #{Team.count} teams"
11
+ puts " #{Match.count} matches"
12
+ puts " #{Badge.count} badges"
13
+
14
+ puts " #{Lineup.count} lineups (person+team+event recs)"
15
+ puts " #{Goal.count} goals (person+match recs)"
16
+
17
+ puts " #{Assoc.count} assocs|orgs"
18
+ puts " #{Ground.count} grounds|stadiums"
19
+ end
20
+
21
+ end # class Stats
22
+
23
+ end # module SportDb
@@ -2,27 +2,27 @@ module SportDb
2
2
  module Model
3
3
 
4
4
 
5
- class GameCursor
5
+ class MatchCursor
6
6
 
7
- def initialize( games )
8
- @games = games
7
+ def initialize( matches )
8
+ @matches = matches
9
9
  end
10
10
 
11
11
  def each
12
- state = GameCursorState.new
12
+ state = MatchCursorState.new
13
13
 
14
- @games.each do |game|
15
- state.next( game )
16
- yield( game, state ) # e.g. lets you use state.new_date? or state.new_week? or state.new_year? etc.
14
+ @matches.each do |match|
15
+ state.next( match )
16
+ yield( match, state ) # e.g. lets you use state.new_date? or state.new_week? or state.new_year? etc.
17
17
  end
18
18
  end # method each
19
- end # class GameCursor
19
+ end # class MatchCursor
20
20
 
21
21
 
22
- class GameCursorState
22
+ class MatchCursorState
23
23
 
24
24
  def initialize
25
- @last_play_at = DateTime.new( 1971, 1, 1 )
25
+ @last_date = DateTime.new( 1971, 1, 1 )
26
26
  @new_date = true
27
27
  @new_year = true
28
28
  @new_week = true
@@ -34,44 +34,44 @@ class GameCursorState
34
34
  def new_date?() @new_date; end
35
35
  def new_year?() @new_year; end
36
36
  def new_week?() @new_week; end
37
-
37
+
38
38
 
39
39
  ## add new league ?
40
40
  ## add new round ?
41
41
  ## add new time ?
42
-
43
- def next( game )
42
+
43
+ def next( match )
44
44
  @index += 1 # zero-based index; start off with -1 (undefined/uninitialized)
45
- game_play_at = game.play_at # cache play_at value ref
45
+ match_date = match.date # cache date value ref
46
46
 
47
- if @last_play_at.year == game_play_at.year &&
48
- @last_play_at.month == game_play_at.month &&
49
- @last_play_at.day == game_play_at.day
47
+ if @last_date.year == match_date.year &&
48
+ @last_date.month == match_date.month &&
49
+ @last_date.day == match_date.day
50
50
  @new_date = false
51
51
  else
52
52
  @new_date = true
53
-
53
+
54
54
  # check for new_year
55
- if @last_play_at.year == game_play_at.year
55
+ if @last_date.year == match_date.year
56
56
  @new_year = false
57
57
  else
58
58
  @new_year = true
59
59
  end
60
-
60
+
61
61
  # check for new_week
62
62
  # -- todo: find a method for week number; do NOT use strftime; there must be something easier
63
63
  # -- check if activesupport adds .week or similar ??? use it if it exists
64
- if @last_play_at.strftime('%V') == game_play_at.strftime('%V')
64
+ if @last_date.strftime('%V') == match_date.strftime('%V')
65
65
  @new_week = false
66
66
  else
67
67
  @new_week = true
68
68
  end
69
69
  end
70
70
 
71
- @last_play_at = game.play_at
71
+ @last_date = match.date
72
72
  end # method next
73
-
74
- end # class GameCursorState
73
+
74
+ end # class MatchCursorState
75
75
 
76
76
 
77
77
  end # module Model
@@ -1,22 +1,27 @@
1
- # encoding: utf-8
2
-
3
- module SportDb
4
-
5
- MAJOR = 1 ## todo: namespace inside version or something - why? why not??
6
- MINOR = 19
7
- PATCH = 0
8
- VERSION = [MAJOR,MINOR,PATCH].join('.')
9
-
10
- def self.version
11
- VERSION
12
- end
13
-
14
- def self.banner
15
- "sportdb-models/#{VERSION} on Ruby #{RUBY_VERSION} (#{RUBY_RELEASE_DATE}) [#{RUBY_PLATFORM}]"
16
- end
17
-
18
- def self.root
19
- "#{File.expand_path( File.dirname(File.dirname(File.dirname(__FILE__))) )}"
20
- end
21
-
22
- end # module SportDb
1
+ module SportDb
2
+ module Module
3
+ module Models
4
+ MAJOR = 2
5
+ MINOR = 0
6
+ PATCH = 3
7
+ VERSION = [MAJOR,MINOR,PATCH].join('.')
8
+
9
+ def self.version
10
+ VERSION
11
+ end
12
+
13
+ def self.banner
14
+ "sportdb-models/#{VERSION} on Ruby #{RUBY_VERSION} (#{RUBY_RELEASE_DATE}) [#{RUBY_PLATFORM}]"
15
+ end
16
+
17
+ def self.root
18
+ "#{File.expand_path( File.dirname(File.dirname(File.dirname(File.dirname(__FILE__)))) )}"
19
+ end
20
+
21
+ end # module Models
22
+ end # module Module
23
+
24
+ #################
25
+ ## add convenience shortcuts
26
+ VERSION = Module::Models::VERSION
27
+ end # module SportDb
@@ -1,42 +1,46 @@
1
- ## minitest setup
2
- require 'minitest/autorun'
3
-
4
-
5
- ## our own code
6
- require 'sportdb/models'
7
-
8
-
9
- #####################
10
- # Models shortcuts
11
-
12
- Country = WorldDb::Model::Country
13
-
14
- Person = PersonDb::Model::Person
15
-
16
- League = SportDb::Model::League
17
- Season = SportDb::Model::Season
18
- Event = SportDb::Model::Event
19
- Team = SportDb::Model::Team
20
- Roster = SportDb::Model::Roster
21
- Assoc = SportDb::Model::Assoc
22
- AssocAssoc = SportDb::Model::AssocAssoc
23
-
24
- Round = SportDb::Model::Round
25
- Group = SportDb::Model::Group
26
- Stage = SportDb::Model::Stage
27
- Game = SportDb::Model::Game
28
- GameCursor = SportDb::Model::GameCursor
29
-
30
-
31
- EventStanding = SportDb::Model::EventStanding
32
- EventStandingEntry = SportDb::Model::EventStandingEntry
33
- GroupStanding = SportDb::Model::GroupStanding
34
- GroupStandingEntry = SportDb::Model::GroupStandingEntry
35
- AlltimeStanding = SportDb::Model::AlltimeStanding
36
- AlltimeStandingEntry = SportDb::Model::AlltimeStandingEntry
37
-
38
-
39
- #################################
40
- # setup db -> schema / tables
41
-
42
- SportDb.setup_in_memory_db
1
+ ## minitest setup
2
+ require 'minitest/autorun'
3
+
4
+
5
+ ## our own code
6
+ require 'sportdb/models'
7
+
8
+
9
+ #####################
10
+ # Models shortcuts
11
+
12
+ Country = WorldDb::Model::Country
13
+
14
+ Person = PersonDb::Model::Person
15
+
16
+ League = SportDb::Model::League
17
+ Season = SportDb::Model::Season
18
+ Event = SportDb::Model::Event
19
+ Team = SportDb::Model::Team
20
+ Lineup = SportDb::Model::Lineup
21
+ Assoc = SportDb::Model::Assoc
22
+ AssocAssoc = SportDb::Model::AssocAssoc
23
+
24
+ Round = SportDb::Model::Round
25
+ Group = SportDb::Model::Group
26
+ Stage = SportDb::Model::Stage
27
+ Match = SportDb::Model::Match
28
+ MatchCursor = SportDb::Model::MatchCursor
29
+
30
+
31
+ EventStanding = SportDb::Model::EventStanding
32
+ EventStandingEntry = SportDb::Model::EventStandingEntry
33
+ GroupStanding = SportDb::Model::GroupStanding
34
+ GroupStandingEntry = SportDb::Model::GroupStandingEntry
35
+ AlltimeStanding = SportDb::Model::AlltimeStanding
36
+ AlltimeStandingEntry = SportDb::Model::AlltimeStandingEntry
37
+
38
+
39
+ #################################
40
+ # setup db -> schema / tables
41
+
42
+ SportDb.setup_in_memory_db
43
+
44
+ ## test helpers here
45
+ SportDb.delete!
46
+ SportDb.tables
@@ -8,18 +8,18 @@ require 'helper'
8
8
 
9
9
  class TestChanges < MiniTest::Test
10
10
 
11
- def test_scores
12
- game1 = Game.new
13
- game1.score1 = 1
14
- game1.score2 = 2
15
-
16
- game2 = Game.new
17
- game2.score1 = 1
18
- game2.score2 = 1
19
- game2.score1p = 5
20
- game2.score2p = 3
21
-
22
- game_attribs = {
11
+ def test_score
12
+ match1 = Match.new
13
+ match1.score1 = 1
14
+ match1.score2 = 2
15
+
16
+ match2 = Match.new
17
+ match2.score1 = 1
18
+ match2.score2 = 1
19
+ match2.score1p = 5
20
+ match2.score2p = 3
21
+
22
+ match_attribs = {
23
23
  score1: 1,
24
24
  score2: 2,
25
25
  score1et: nil,
@@ -28,50 +28,50 @@ class TestChanges < MiniTest::Test
28
28
  score2p: nil
29
29
  }
30
30
 
31
- assert_equal false, game1.check_for_changes( game_attribs )
32
- assert_equal true, game2.check_for_changes( game_attribs )
31
+ assert_equal false, match1.check_for_changes( match_attribs )
32
+ assert_equal true, match2.check_for_changes( match_attribs )
33
33
  end
34
34
 
35
- def test_play_at
36
- game1 = Game.new
37
- game1.score1 = 1
38
- game1.score2 = 2
39
- game1.play_at = DateTime.new( 2012, 11, 5 )
35
+ def test_date
36
+ match1 = Match.new
37
+ match1.score1 = 1
38
+ match1.score2 = 2
39
+ match1.date = Date.new( 2012, 11, 5 )
40
40
 
41
- game2 = Game.new
42
- game2.score1 = 1
43
- game2.score2 = 2
44
- game2.play_at = DateTime.new( 2012, 12, 24 )
41
+ match2 = Match.new
42
+ match2.score1 = 1
43
+ match2.score2 = 2
44
+ match2.date = DateTime.new( 2012, 12, 24 )
45
45
 
46
- game_attribs = {
46
+ match_attribs = {
47
47
  score1: 1,
48
48
  score2: 2,
49
- play_at: DateTime.new( 2012, 11, 5 )
49
+ date: DateTime.new( 2012, 11, 5 )
50
50
  }
51
51
 
52
- assert_equal false, game1.check_for_changes( game_attribs )
53
- assert_equal true, game2.check_for_changes( game_attribs )
52
+ assert_equal false, match1.check_for_changes( match_attribs )
53
+ assert_equal true, match2.check_for_changes( match_attribs )
54
54
  end
55
55
 
56
56
  def test_group_id
57
- game1 = Game.new
58
- game1.score1 = 1
59
- game1.score2 = 2
60
- game1.group_id = 1
57
+ match1 = Match.new
58
+ match1.score1 = 1
59
+ match1.score2 = 2
60
+ match1.group_id = 1
61
61
 
62
- game2 = Game.new
63
- game2.score1 = 1
64
- game2.score2 = 2
65
- game2.group_id = 2
62
+ match2 = Match.new
63
+ match2.score1 = 1
64
+ match2.score2 = 2
65
+ match2.group_id = 2
66
66
 
67
- game_attribs = {
67
+ match_attribs = {
68
68
  score1: 1,
69
69
  score2: 2,
70
70
  group_id: 1
71
71
  }
72
72
 
73
- assert_equal false, game1.check_for_changes( game_attribs )
74
- assert_equal true, game2.check_for_changes( game_attribs )
73
+ assert_equal false, match1.check_for_changes( match_attribs )
74
+ assert_equal true, match2.check_for_changes( match_attribs )
75
75
  end
76
76
 
77
77
 
@@ -9,42 +9,42 @@ require 'helper'
9
9
 
10
10
  class TestCursor < MiniTest::Test
11
11
 
12
- def test_games
13
- games = []
12
+ def test_matches
13
+ matches = []
14
14
 
15
- games << Game.new( score1: 3, score2: 1, play_at: DateTime.new(2013, 8, 9) )
16
- games << Game.new( score1: 1, score2: 3, play_at: DateTime.new(2013, 8, 10) )
17
- games << Game.new( score1: 2, score2: 0, play_at: DateTime.new(2013, 8, 10) )
18
- games << Game.new( score1: 3, score2: 2, play_at: DateTime.new(2013, 8, 12) ) # new_week
15
+ matches << Match.new( score1: 3, score2: 1, date: Date.new(2013, 8, 9) )
16
+ matches << Match.new( score1: 1, score2: 3, date: Date.new(2013, 8, 10) )
17
+ matches << Match.new( score1: 2, score2: 0, date: Date.new(2013, 8, 10) )
18
+ matches << Match.new( score1: 3, score2: 2, date: Date.new(2013, 8, 12) ) # new_week
19
19
 
20
- GameCursor.new( games ).each do |game,state|
20
+ MatchCursor.new( matches ).each do |match,state|
21
21
  if state.index == 0
22
- assert_equal 3, game.score1
23
- assert_equal 1, game.score2
22
+ assert_equal 3, match.score1
23
+ assert_equal 1, match.score2
24
24
  assert_equal true, state.new_date?
25
25
  assert_equal true, state.new_year?
26
26
  assert_equal true, state.new_week?
27
27
  end
28
28
 
29
29
  if state.index == 1
30
- assert_equal 1, game.score1
31
- assert_equal 3, game.score2
30
+ assert_equal 1, match.score1
31
+ assert_equal 3, match.score2
32
32
  assert_equal true, state.new_date?
33
33
  assert_equal false, state.new_year?
34
34
  assert_equal false, state.new_week?
35
35
  end
36
36
 
37
37
  if state.index == 2
38
- assert_equal 2, game.score1
39
- assert_equal 0, game.score2
38
+ assert_equal 2, match.score1
39
+ assert_equal 0, match.score2
40
40
  assert_equal false, state.new_date?
41
41
  assert_equal false, state.new_year?
42
42
  assert_equal false, state.new_week?
43
43
  end
44
44
 
45
45
  if state.index == 3
46
- assert_equal 3, game.score1
47
- assert_equal 2, game.score2
46
+ assert_equal 3, match.score1
47
+ assert_equal 2, match.score2
48
48
  assert_equal true, state.new_date?
49
49
  assert_equal true, state.new_week?
50
50
  assert_equal false, state.new_year?
@@ -1,95 +1,100 @@
1
1
  # encoding: utf-8
2
2
 
3
+ ###
4
+ # to run use
5
+ # ruby -I ./lib -I ./test test/test_winner.rb
6
+
7
+
3
8
  require 'helper'
4
9
 
5
10
  class TestWinner < MiniTest::Test
6
11
 
7
12
  def test_1_2
8
- game = Game.new
9
- game.score1 = 1
10
- game.score2 = 2
11
- game.calc_winner
12
-
13
- assert_equal 2, game.winner90
14
- assert_equal 2, game.winner
15
- assert_equal true, game.winner2?
16
- assert_equal false, game.winner1?
17
- assert_equal false, game.draw?
13
+ match = Match.new
14
+ match.score1 = 1
15
+ match.score2 = 2
16
+ match.calc_winner
17
+
18
+ assert_equal 2, match.winner90
19
+ assert_equal 2, match.winner
20
+ assert_equal true, match.winner2?
21
+ assert_equal false, match.winner1?
22
+ assert_equal false, match.draw?
18
23
  end
19
24
 
20
25
  def test_1_1
21
- game = Game.new
22
- game.score1 = 1
23
- game.score2 = 1
24
- game.calc_winner
25
-
26
- assert_equal 0, game.winner90
27
- assert_equal 0, game.winner
28
- assert_equal true, game.draw?
29
- assert_equal false, game.winner1?
30
- assert_equal false, game.winner2?
26
+ match = Match.new
27
+ match.score1 = 1
28
+ match.score2 = 1
29
+ match.calc_winner
30
+
31
+ assert_equal 0, match.winner90
32
+ assert_equal 0, match.winner
33
+ assert_equal true, match.draw?
34
+ assert_equal false, match.winner1?
35
+ assert_equal false, match.winner2?
31
36
  end
32
37
 
33
38
  def test_2_1
34
- game = Game.new
35
- game.score1 = 2
36
- game.score2 = 1
37
- game.calc_winner
38
-
39
- assert_equal 1, game.winner90
40
- assert_equal 1, game.winner
41
- assert_equal true, game.winner1?
42
- assert_equal false, game.winner2?
43
- assert_equal false, game.draw?
39
+ match = Match.new
40
+ match.score1 = 2
41
+ match.score2 = 1
42
+ match.calc_winner
43
+
44
+ assert_equal 1, match.winner90
45
+ assert_equal 1, match.winner
46
+ assert_equal true, match.winner1?
47
+ assert_equal false, match.winner2?
48
+ assert_equal false, match.draw?
44
49
  end
45
50
 
46
51
  def test_1_1__2_1
47
- game = Game.new
48
- game.score1 = 1
49
- game.score2 = 1
50
- game.score1et = 2
51
- game.score2et = 1
52
- game.calc_winner
53
-
54
- assert_equal 0, game.winner90
55
- assert_equal 1, game.winner
56
- assert_equal true, game.winner1?
57
- assert_equal false, game.winner2?
58
- assert_equal false, game.draw?
52
+ match = Match.new
53
+ match.score1 = 1
54
+ match.score2 = 1
55
+ match.score1et = 2
56
+ match.score2et = 1
57
+ match.calc_winner
58
+
59
+ assert_equal 0, match.winner90
60
+ assert_equal 1, match.winner
61
+ assert_equal true, match.winner1?
62
+ assert_equal false, match.winner2?
63
+ assert_equal false, match.draw?
59
64
  end
60
65
 
61
66
  def test_1_1__2_2__3_5
62
- game = Game.new
63
- game.score1 = 1
64
- game.score2 = 1
65
- game.score1et = 2
66
- game.score2et = 2
67
- game.score1p = 3
68
- game.score2p = 5
69
- game.calc_winner
70
-
71
- assert_equal 0, game.winner90
72
- assert_equal 2, game.winner
73
- assert_equal true, game.winner2?
74
- assert_equal false, game.winner1?
75
- assert_equal false, game.draw?
67
+ match = Match.new
68
+ match.score1 = 1
69
+ match.score2 = 1
70
+ match.score1et = 2
71
+ match.score2et = 2
72
+ match.score1p = 3
73
+ match.score2p = 5
74
+ match.calc_winner
75
+
76
+ assert_equal 0, match.winner90
77
+ assert_equal 2, match.winner
78
+ assert_equal true, match.winner2?
79
+ assert_equal false, match.winner1?
80
+ assert_equal false, match.draw?
76
81
  end
77
82
 
78
83
  def test_1_1_x_3_5
79
- game = Game.new
80
- game.score1 = 1
81
- game.score2 = 1
82
- game.score1et = nil
83
- game.score2et = nil
84
- game.score1p = 3
85
- game.score2p = 5
86
- game.calc_winner
87
-
88
- assert_equal 0, game.winner90
89
- assert_equal 2, game.winner
90
- assert_equal true, game.winner2?
91
- assert_equal false, game.winner1?
92
- assert_equal false, game.draw?
84
+ match = Match.new
85
+ match.score1 = 1
86
+ match.score2 = 1
87
+ match.score1et = nil
88
+ match.score2et = nil
89
+ match.score1p = 3
90
+ match.score2p = 5
91
+ match.calc_winner
92
+
93
+ assert_equal 0, match.winner90
94
+ assert_equal 2, match.winner
95
+ assert_equal true, match.winner2?
96
+ assert_equal false, match.winner1?
97
+ assert_equal false, match.draw?
93
98
  end
94
99
 
95
100
  end # class TestWinner