Title / Description
Code 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
Author
Highlight as C C++ CSS Clojure Delphi ERb Groovy (beta) HAML HTML JSON Java JavaScript PHP Plain text Python Ruby SQL XML YAML diff code