Last active
December 30, 2016 01:36
-
-
Save ScalaWilliam/4f38055d1d96589c7a7c7a4538d96e7d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"execution_count": 4, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [ | |
"import json\n", | |
"import os\n", | |
"import urllib" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 12, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [], | |
"source": [ | |
"main_path = 'all.json'\n", | |
"if not os.path.exists(main_path):\n", | |
" urllib.urlretrieve('http://actionfps.com/all/games.json', main_path)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 16, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [ | |
"with open(main_path) as f:\n", | |
" games = json.loads(f.read())" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 23, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [], | |
"source": [ | |
"from collections import Counter\n", | |
"def selected_players():\n", | |
" for game in games:\n", | |
" for team in game['teams']:\n", | |
" for player in team['players']:\n", | |
" if \"user\" not in player and \"clan\" in player:\n", | |
" yield player['name']\n", | |
"counter = Counter(selected_players())" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 26, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"[(u'Pi_Pomps', 1114),\n", | |
" (u'Pi_RKTnoob', 545),\n", | |
" (u'Pi_KGB', 492),\n", | |
" (u'Pi_MrPompey14', 474),\n", | |
" (u'Pi_Halo', 334)]" | |
] | |
}, | |
"execution_count": 26, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"counter.most_common(5)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 28, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [], | |
"source": [ | |
"ranks_path = 'playerranks.json'\n", | |
"ranks_file = 'https://actionfps.com/playerranks/?format=json'\n", | |
"if not os.path.exists(ranks_path):\n", | |
" urllib.urlretrieve(ranks_file, ranks_path)\n", | |
"with open(ranks_path) as f:\n", | |
" ranks = json.loads(f.read())" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 42, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"[(u'ketar', 733), (u'piton', 711), (u'fede', 732), 1]" | |
] | |
}, | |
"execution_count": 42, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"def near_winners():\n", | |
" for name, stats in ranks['players'].iteritems():\n", | |
" if 700 < stats['games'] < 800:\n", | |
" yield name, stats['games']\n", | |
" yield 1\n", | |
"list(near_winners())" | |
] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Python 2", | |
"language": "python", | |
"name": "python2" | |
}, | |
"language_info": { | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 2 | |
}, | |
"file_extension": ".py", | |
"mimetype": "text/x-python", | |
"name": "python", | |
"nbconvert_exporter": "python", | |
"pygments_lexer": "ipython2", | |
"version": "2.7.12" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 2 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment