Need a unique gift idea?
A Pastebin account makes a great Christmas gift
SHARE
TWEET

Untitled

a guest Apr 28th, 2015 212 Never
Upgrade to PRO!
ENDING IN00days00hours00mins00secs
 
  1. import csv
  2. import collections
  3. import sys
  4.  
  5. #csvfilename = "SHL2.csv"
  6. csvfilename = "OCTGN_stats_anonymized-2015-02-20.csv"
  7.  
  8. csvfile = open(csvfilename, "rb")
  9. csvreader = csv.reader(csvfile, delimiter=',', quotechar='"')
  10. csvrows = list(csvreader)
  11. csvfile.close()
  12.  
  13.  
  14. # To handle both SHL2 and main data set, first determine which indices map to
  15. # which fields.
  16. corp_player_index = csvrows[0].index('Corp_Player')
  17. runner_player_index = csvrows[0].index('Runner_Player')
  18. corp_faction_index = csvrows[0].index('Corp_Faction')
  19. runner_faction_index = csvrows[0].index('Runner_Faction')
  20. result_index = csvrows[0].index('Result')
  21. version_index = csvrows[0].index('Version')
  22.  
  23. corp_win_conditions = frozenset(['Flatlined', 'ConcedeVictory', 'AgendaVictory', 'FlatlineVictory'])
  24. runner_win_conditions = frozenset(['AgendaDefeat', 'DeckDefeat', 'Conceded'])
  25.  
  26. csvrows = csvrows[1:]
  27.  
  28. # Elo calculation.
  29. elo_ratings = collections.defaultdict(lambda: 1600)
  30. K = 16.0
  31. for row in csvrows:
  32.     result = row[result_index]
  33.     if result in corp_win_conditions:
  34.         actual0 = 1
  35.         actual2 = 0
  36.     elif result in runner_win_conditions:
  37.         actual0 = 0
  38.         actual2 = 1
  39.     else:
  40.         print "Error - unexpected result: " + result
  41.         continue
  42.     corp_player = row[corp_player_index]
  43.     runner_player = row[runner_player_index]
  44.     rating0 = elo_ratings[corp_player]
  45.     rating2 = elo_ratings[runner_player]
  46.     Q0 = 10.0**(rating0/400.0)
  47.     Q2 = 10.0**(rating2/400.0)
  48.     Q_sum = Q0 + Q2
  49.     E0 = Q0 / Q_sum
  50.     E2 = Q2 / Q_sum
  51.     elo_ratings[corp_player] = rating0 + K*(actual0 - E0)
  52.     elo_ratings[runner_player] = rating2 + K*(actual2 - E2)
  53.  
  54.  
  55.  
  56. # top players by elo
  57. #top_elo = [(player, elo_ratings[player]) for player in wins]
  58. top_elo = elo_ratings.items()
  59. cutoff_elos = int(len(top_elo)*.90)
  60. best_players = [x[0] for x in sorted(top_elo, key = lambda b: b[1])[cutoff_elos:]]
  61. best_players = frozenset(best_players)
  62.  
  63.  
  64. # Further filter identities to matches played where both players are in this set, and OCGN version == 3.16
  65. csvrows = [row for row in csvrows if row[runner_player_index] in best_players and row[corp_player_index] in best_players and row[version_index].find("3.16") != -1]
  66.  
  67. # Redo elo calculation with deck identities.
  68. # TODO - this seems over fancy in retrospect. Why not just treat the identities
  69. # themselves as players and compute elo for them over all time.
  70. # Either with or without restricting to good players.
  71.  
  72. # Elo calculation.
  73. elo_ratings2 = collections.defaultdict(lambda: 1600)
  74. K = 16.0
  75. for row in csvrows:
  76.     result = row[result_index]
  77.     if result in corp_win_conditions:
  78.         actual0 = 1
  79.         actual2 = 0
  80.     elif result in runner_win_conditions:
  81.         actual0 = 0
  82.         actual2 = 1
  83.     else:
  84.         print "Error - unexpected result: " + result
  85.         continue
  86.     corp_faction = row[corp_faction_index]
  87.     runner_faction = row[runner_faction_index]
  88.     rating0 = elo_ratings2[corp_faction]
  89.     rating2 = elo_ratings2[runner_faction]
  90.     Q0 = 10.0**(rating0/400.0)
  91.     Q2 = 10.0**(rating2/400.0)
  92.     Q_sum = Q0 + Q2
  93.     E0 = Q0 / Q_sum
  94.     E2 = Q2 / Q_sum
  95.     elo_ratings2[corp_faction] = rating0 + K*(actual0 - E0)
  96.     elo_ratings2[runner_faction] = rating2 + K*(actual2 - E2)
  97.  
  98. factions = [(faction, elo_ratings2[faction]) for faction in elo_ratings2]
  99. factions.sort(key = lambda b: b[1])
  100. for i in factions:
  101.     print i
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top