Skip to content

Instantly share code, notes, and snippets.

@int64ago
Created June 10, 2015 06:08
Show Gist options
  • Save int64ago/eb2b0c15440a9fdba4c4 to your computer and use it in GitHub Desktop.
Save int64ago/eb2b0c15440a9fdba4c4 to your computer and use it in GitHub Desktop.
Huawei PK rank statistics
#!/usr/bin/python
# -*- encoding: utf-8 -*-
import os, sys, tarfile, tempfile, re
try:
tar = tarfile.open(sys.argv[1], 'r:gz')
tar.extractall(tempfile.gettempdir())
dirname = os.path.join(tempfile.gettempdir(),
os.path.basename(sys.argv[1])[:-len('.tar.gz')])
champ = []
fight = []
for f in os.listdir(dirname):
if f.endswith(".csv"):
uid = f.split('_')[3]
csv = open(os.path.join(dirname, f), 'r')
res = re.search(uid + '[\s\S]+?\r', csv.read()).group(0)
csv.close()
if len(uid) == 5:
fight.append(int(res.split(', ')[6]))
else:
champ.append(int(res.split(', ')[6]))
print('Fight: %f' % (sum(fight) * 1.0 / len(fight)))
print('Champ: %f' % (sum(champ) * 1.0 / len(champ)))
except:
print('Usage: python pkrank.py <filename>.tar.gz')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment