Created
May 8, 2014 07:08
-
-
Save CRamsan/2fbbadfeda7481779d7f 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
import urllib.request | |
import json | |
import time | |
import math | |
#Big outfits cannot be retrieved by one single calls so we will divide it in multiple calls | |
#Lets get the size of the outfit | |
request = urllib.request.urlopen("http://census.soe.com/count/ps2:v2/outfit_member/?outfit_id=37509488620628689") | |
outfit_size = json.loads(request.read().decode('utf8'))['count'] | |
#How many members will be retrieved by a single call | |
members_per_call = 50 | |
characters = [] | |
for x in range(math.ceil(outfit_size/members_per_call)): | |
print ("Downloading data " + str(x+1) + "/" + str(math.ceil(outfit_size/members_per_call))) | |
request = urllib.request.urlopen("http://census.soe.com/get/ps2:v2/outfit_member/?outfit_id=37509488620628689&"+ | |
"c:resolve=character&c:start=" + str(x*members_per_call) + "&c:limit=" + str(members_per_call) + "&"+ | |
"c:join=type:characters_stat_history^list:1^inject_at:stat_history^on:character_id&"+ | |
"c:join=type:characters_stat^list:1^inject_at:stat^on:character_id&"+ | |
"c:join=type:characters_stat_by_faction^list:1^inject_at:stat_by_faction^on:character_id&"+ | |
"c:join=type:characters_weapon_stat^list:1^inject_at:weapon_stat^on:character_id&"+ | |
"c:join=type:characters_weapon_stat_by_faction^list:1^inject_at:weapon_stat_by_faction^on:character_id") | |
characters.extend(json.loads(request.read().decode('utf8'))['outfit_member_list']) | |
print ("Done!") | |
with open("data.csv", "w") as data: | |
data.write("Name,Battle Rank,Score/Minute,K/D Ratio,Kills,Deaths,Headshots,Accuracy,Facilities Captured,Facilities Defended,Minutes Played,Infiltrator,Light Assault,Engineer,Combat Medic,Heavy Assault,MAX\n") | |
for character in characters: | |
if 'character' not in character: | |
continue | |
name = character['character']['name']['first'] | |
battleRank = character['character']['battle_rank']['value'] | |
minutesPlayed = character['character']['times']['minutes_played'] | |
sph = 0 | |
kdr = 0 | |
kills = 0 | |
deaths = 1 | |
facility_capture = 0 | |
facility_defend = 0 | |
stat_list = character['stat_history'] | |
for stat in stat_list: | |
if stat['stat_name'] == 'score': | |
sph = int(stat['all_time']) / int(minutesPlayed) | |
elif stat['stat_name'] == 'kills': | |
kills = stat['all_time'] | |
elif stat['stat_name'] == 'deaths': | |
deaths = stat['all_time'] | |
if deaths == '0': | |
deaths = 1 | |
elif stat['stat_name'] == 'facility_defend': | |
facility_defend = stat['all_time'] | |
elif stat['stat_name'] == 'facility_capture': | |
facility_capture = stat['all_time'] | |
kdr = int(kills)/int(deaths) | |
shots_fired = 0 | |
hit_count = 0 | |
infiltrator = 0 | |
light_assault = 0 | |
engineer = 0 | |
medic = 0 | |
heavy = 0 | |
mech = 0 | |
stats = character['stat'] | |
for stat in stats: | |
if stat['stat_name'] == 'fire_count': | |
shots_fired += int(stat['value_forever']) | |
if stat['stat_name'] == 'hit_count': | |
hit_count += int(stat['value_forever']) | |
if stat['stat_name'] == 'play_time': | |
if stat['profile_id'] == '1' or stat['profile_id'] == '17' or stat['profile_id'] == '10': | |
infiltrator += int(stat['value_forever'])/60 | |
elif stat['profile_id'] == '3' or stat['profile_id'] == '19' or stat['profile_id'] == '12': | |
light_assault += int(stat['value_forever'])/60 | |
elif stat['profile_id'] == '4' or stat['profile_id'] == '20' or stat['profile_id'] == '13': | |
medic += int(stat['value_forever'])/60 | |
elif stat['profile_id'] == '5' or stat['profile_id'] == '21' or stat['profile_id'] == '14': | |
engineer += int(stat['value_forever'])/60 | |
elif stat['profile_id'] == '6' or stat['profile_id'] == '22' or stat['profile_id'] == '15': | |
heavy += int(stat['value_forever'])/60 | |
elif stat['profile_id'] == '7' or stat['profile_id'] == '23' or stat['profile_id'] == '16': | |
mech += int(stat['value_forever'])/60 | |
headshots = 0 | |
weapon_stat_by_faction = character['weapon_stat_by_faction'] | |
for stat in weapon_stat_by_faction: | |
if stat['stat_name'] == 'weapon_headshots': | |
headshots += int(stat['value_nc']) | |
headshots += int(stat['value_tr']) | |
headshots += int(stat['value_vs']) | |
accuracy = int(hit_count)/int(shots_fired) | |
data.write(name + "," + str(battleRank) + "," + str(sph) + "," + str(kdr) + "," + str(kills) + "," + str(deaths) + "," + str(headshots) + "," + | |
str(accuracy) + "," + str(facility_capture) + "," + str(facility_defend)+ "," + str(minutesPlayed) + "," + str(infiltrator) + "," + | |
str(light_assault) + "," + str(engineer) + "," + str(medic) + "," + str(heavy) + "," + str(mech) + "\n") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment