Skip to content

Instantly share code, notes, and snippets.

@Noxville
Created January 6, 2015 15:20
Show Gist options
  • Save Noxville/9f585976f54ac1dea2c2 to your computer and use it in GitHub Desktop.
Save Noxville/9f585976f54ac1dea2c2 to your computer and use it in GitHub Desktop.
Reduction and coversion of csv data to Reddit markdown tables for Notails Wisp.
import datetime
import operator
f = file("notail_wisp.csv", 'r')
m = [e.strip() for e in f.readlines()]
class MonthSummary:
def __init__(self, key, order):
self.key = key
self.order = order
self.wins = 0
self.loses = 0
def total(self):
return self.wins + self.loses
def gw(self):
return ( "%.1f" % ((100. * self.wins) / self.total())) if self.total else "-"
month_summaries = {}
for _m in m:
d = _m.split("\t")
date = datetime.datetime.strptime(d[1], "%m/%d/%y")
key = date.strftime("%B %Y")
order = (date.year * 100) + date.month
_mid = d[0]
_sum = month_summaries[key] if key in month_summaries else MonthSummary(key, order)
win = False
winner = d[3] if d[5] == "RADIANT" else d[4]
if winner in ["Secret", "Fnatic.EU"]:
win = True
if (d[0] == "1143519062"):
win = True
if win:
_sum.wins+=1
else:
_sum.loses+=1
month_summaries[key] = _sum
print "Month|Games Played|Games Won|Games Lost|Game Win %"
print ":---:|:----------:|:-------:|:--------:|:--------:"
for m in (sorted(month_summaries.values(), key=operator.attrgetter('order'))):
print "{month} | {gp} | {won} | {lost} | {gw}% ".format(month=m.key, gp=m.total(), won=m.wins, lost=m.loses, gw=m.gw())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment