Hello,
I've updated the hands-on getting started guide for the sportdb
text library / gem.
Let's build the standings table for the English Premier League (EPL)
for the 2019/20 season from all 40 matches (as of Sept/2) in the
comma-separated values (.csv) format.
In a nutshell:
require 'sportdb/text'
matches = CsvMatchReader.read( 'england/2010s/2019-20/eng.1.csv' )
standings = SportDb::Struct::Standings.new
standings.update( matches )
standings.to_a.each do |l|
print '%2d. ' % l.rank
print '%-28s ' % l.team
print '%2d ' % l.played
print '%3d ' % l.won
print '%3d ' % l.drawn
print '%3d ' % l.lost
print '%3d:%-3d ' % [l.goals_for,l.goals_against]
print '%3d' % l.pts
print "\n"
end
resulting in:
1. Liverpool FC 4 4 0 0 12:3 12
2. Manchester City FC 4 3 1 0 14:3 10
3. Leicester City FC 4 2 2 0 6:3 8
4. Crystal Palace FC 4 2 1 1 3:2 7
5. Arsenal FC 4 2 1 1 6:6 7
6. Everton FC 4 2 1 1 4:4 7
7. West Ham United FC 4 2 1 1 6:7 7
8. Manchester United FC 4 1 2 1 7:4 5
9. Tottenham Hotspur FC 4 1 2 1 7:6 5
10. Sheffield United FC 4 1 2 1 5:5 5
11. Chelsea FC 4 1 2 1 6:9 5
12. Burnley FC 4 1 1 2 5:6 4
13. Southampton FC 4 1 1 2 4:6 4
14. Newcastle United FC 4 1 1 2 3:5 4
15. AFC Bournemouth 4 1 1 2 5:8 4
16. Brighton & Hove Albion FC 4 1 1 2 4:7 4
17. Wolverhampton Wanderers FC 4 0 3 1 4:5 3
18. Aston Villa FC 4 1 0 3 4:6 3
19. Norwich City FC 4 1 0 3 6:10 3
20. Watford FC 4 0 1 3 2:8 1
To wrap up let's break out the standings for home and away matches
for a deluxe version:
- Home - - Away - - Total -
Pld W D L F:A W D L F:A F:A +/- Pts
1. Liverpool FC 4 2 0 0 7:2 2 0 0 5:1
12:3 +9 12
2. Manchester City FC 4 1 1 0 6:2 2 0 0 8:1
14:3 +11 10
3. Leicester City FC 4 1 1 0 3:1 1 1 0 3:2
6:3 +3 8
4. Crystal Palace FC 4 1 1 0 1:0 1 0 1 2:2
3:2 +1 7
5. Arsenal FC 4 1 1 0 4:3 1 0 1 2:3
6:6 7
6. Everton FC 4 2 0 0 4:2 0 1 1 0:2
4:4 7
7. West Ham United FC 4 1 0 1 2:5 1 1 0 4:2
6:7 -1 7
8. Manchester United FC 4 1 0 1 5:2 0 2 0 2:2
7:4 +3 5
9. Tottenham Hotspur FC 4 1 0 1 3:2 0 2 0 4:4
7:6 +1 5
10. Sheffield United FC 4 1 0 1 2:2 0 2 0 3:3
5:5 5
11. Chelsea FC 4 0 2 0 3:3 1 0 1 3:6
6:9 -3 5
12. Burnley FC 4 1 0 1 3:3 0 1 1 2:3
5:6 -1 4
13. Southampton FC 4 0 1 1 2:3 1 0 1 2:3
4:6 -2 4
14. Newcastle United FC 4 0 1 1 1:2 1 0 1 2:3
3:5 -2 4
15. AFC Bournemouth 4 0 1 1 2:4 1 0 1 3:4
5:8 -3 4
16. Brighton & Hove Albion FC 4 0 1 1 1:3 1 0 1 3:4
4:7 -3 4
17. Wolverhampton Wanderers FC 4 0 2 0 2:2 0 1 1 2:3
4:5 -1 3
18. Aston Villa FC 4 1 0 1 3:2 0 0 2 1:4
4:6 -2 3
19. Norwich City FC 4 1 0 1 5:4 0 0 2 1:6
6:10 -4 3
20. Watford FC 4 0 0 2 1:6 0 1 1 1:2
2:8 -6 1
Anyone? Or Bonus: Why not build a standings table for the
Bundesliga, La Liga, Ligue 1, Seria A, or your very own league? Yes,
you can.
Full article titled "Working with CSV Files". [1]
Enjoy the beautiful game with ruby.
[1]: https://github.com/sportdb/docs/blob/master/working-with-csv-files.md