Skip to content

Instantly share code, notes, and snippets.

@havenwood
Created August 25, 2019 22:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save havenwood/434b0eab8573e6cd3bd61bf434620381 to your computer and use it in GitHub Desktop.
Save havenwood/434b0eab8573e6cd3bd61bf434620381 to your computer and use it in GitHub Desktop.
red = {player_7: {id: 7, team: 'r', name: 'Player_7', score: 27, ping: 3, cc: 'RU', osp: 'osp', rate: '50000', snaps: '20'}, player_8: {id: 8, team: 'r', name: 'Player_8', score: 24, ping: 10, cc: 'RU', osp: 'osp', rate: '15000', snaps: '20'}, player_9: {id: 9, team: 'r', name: 'Player_9', score: 12, ping: 29, cc: 'LV', osp: 'osp', rate: '15000', snaps: '20'}, player_6: {id: 6, team: 'r', name: 'Player_6', score: 12, ping: 8, cc: 'RU', osp: 'osp', rate: '50000', snaps: '20'}, player_10: {id: 10, team: 'r', name: 'Player_10', score: 0, ping: 40, cc: 'RU', osp: 'osp', rate: '25000', snaps: '20'}}.to_h
blue = {player_3: {id: 3, team: 'b', name: 'Player_3', score: 29, ping: 10, cc: 'BY', osp: 'osp', rate: '25000', snaps: '40'}, player_4: {id: 4, team: 'b', name: 'Player_4', score: 24, ping: 10, cc: 'RU', osp: 'osp', rate: '15000', snaps: '20'}, player_0: {id: 0, team: 'b', name: 'Player_0', score: 24, ping: 21, cc: 'RU', osp: 'osp', rate: '50000', snaps: '40'}, player_2: {id: 2, team: 'b', name: 'Player_2', score: 15, ping: 17, cc: 'RU', osp: 'osp', rate: '4000', snaps: '20'}, player_1: {id: 1, team: 'b', name: 'Player_1', score: 12, ping: 6, cc: 'BY', osp: 'osp', rate: '4000', snaps: '20'}, player_5: {id: 5, team: 'b', name: 'Player_5', score: 7, ping: 21, cc: 'RU', osp: 'osp', rate: '15000', snaps: '40'}}.to_h
[red, blue].reduce(:merge).group_by { |score:, **| score }.to_h { |k, v| [:"n_#{k}", v.to_h] }
#=> {:n_27=>
# {:player_7=>{:id=>7, :team=>"r", :name=>"Player_7", :score=>27, :ping=>3, :cc=>"RU", :osp=>"osp", :rate=>"50000", :snaps=>"20"}},
# :n_24=>
# {:player_8=>{:id=>8, :team=>"r", :name=>"Player_8", :score=>24, :ping=>10, :cc=>"RU", :osp=>"osp", :rate=>"15000", :snaps=>"20"},
# :player_4=>{:id=>4, :team=>"b", :name=>"Player_4", :score=>24, :ping=>10, :cc=>"RU", :osp=>"osp", :rate=>"15000", :snaps=>"20"},
# :player_0=>{:id=>0, :team=>"b", :name=>"Player_0", :score=>24, :ping=>21, :cc=>"RU", :osp=>"osp", :rate=>"50000", :snaps=>"40"}},
# :n_12=>
# {:player_9=>{:id=>9, :team=>"r", :name=>"Player_9", :score=>12, :ping=>29, :cc=>"LV", :osp=>"osp", :rate=>"15000", :snaps=>"20"},
# :player_6=>{:id=>6, :team=>"r", :name=>"Player_6", :score=>12, :ping=>8, :cc=>"RU", :osp=>"osp", :rate=>"50000", :snaps=>"20"},
# :player_1=>{:id=>1, :team=>"b", :name=>"Player_1", :score=>12, :ping=>6, :cc=>"BY", :osp=>"osp", :rate=>"4000", :snaps=>"20"}},
# :n_0=>
# {:player_10=>{:id=>10, :team=>"r", :name=>"Player_10", :score=>0, :ping=>40, :cc=>"RU", :osp=>"osp", :rate=>"25000", :snaps=>"20"}},
# :n_29=>
# {:player_3=>{:id=>3, :team=>"b", :name=>"Player_3", :score=>29, :ping=>10, :cc=>"BY", :osp=>"osp", :rate=>"25000", :snaps=>"40"}},
# :n_15=>
# {:player_2=>{:id=>2, :team=>"b", :name=>"Player_2", :score=>15, :ping=>17, :cc=>"RU", :osp=>"osp", :rate=>"4000", :snaps=>"20"}},
# :n_7=>
# {:player_5=>{:id=>5, :team=>"b", :name=>"Player_5", :score=>7, :ping=>21, :cc=>"RU", :osp=>"osp", :rate=>"15000", :snaps=>"40"}}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment