test222
Ruby
code posted
created at 07 Sep 06:11
Edit
|
Back
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
require 'csv' require 'mysql2' require 'dbi' require 'date' require 'json' class Team attr_accessor(:accounts, :teamId) def initialize @accounts = Array.new() end def pushAccount(a) @accounts = @accounts.push(a) end end class Game attr_accessor(:teams, :gameId) def initialize @teams = Array.new() end def pushTeam(t) @teams = @teams.push(t) end end dbh = DBI.connect("DBI:Mysql:riot:localhost", "root", "") sql = "select account_id, game_id, premade_team_id from games where premade_team_id is not null group by account_id, game_id, premade_team_id order by game_id, premade_team_id, account_id" sth = dbh.prepare(sql) sth.execute() previousGame = nil previousTeam = nil game = Game.new() team = Team.new() games = Array.new() sth.fetch() do |row| account = row[0] gameId = row[1] teamId = row[2] if previousGame.nil? previousGame = gameId previousTeam = teamId end if previousTeam != teamId team.teamId= previousTeam game.pushTeam(team) team = Team.new() previousTeam = teamId if previousGame != gameId game.gameId = previousGame games = games.push(game) game = Game.new() previousGame = gameId end end team.pushAccount(account) end team.teamId= previousTeam game.pushTeam(team) game.gameId = previousGame games = games.push(game) puts "game_id\tpremade_team_id\taccount_id" games.each() do |game| c = 0 game.teams().each() do |team| t = 0 team.accounts().each() do |account| if t == 0 puts "\t#{team.teamId}\t#{account}" else puts "\t\t#{account}" end t = t + 1 end if c == 0 puts game.gameId end c = c + 1 end puts "----------------------------" end |
1.81 KB in 4 ms with coderay