Last active
December 22, 2015 20:19
-
-
Save robert-nix/6525701 to your computer and use it in GitHub Desktop.
IPython GGtracker Hello, world! plot (hackiness warning)
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
%pylab inline | |
import urllib2 | |
import json | |
json_api_test = urllib2.urlopen("http://api.ggtracker.com/api/v1/matches?game_type=1v1&map_name=Derelict%20Watcher%20TE&race=terran&replay=true&vs_race=zerg&paginate=true&average_league=4&limit=100").read() | |
json_api_result = json.loads(json_api_test) | |
json_api_results = json_api_result['collection'] | |
json_result_ids = [res['id'] for res in json_api_results] | |
json_match_data = [json.loads(urllib2.urlopen("http://gg2-matchblobs-prod.s3.amazonaws.com/" + str(id)).read()) for id in json_result_ids] | |
import matplotlib.pyplot as plt | |
import matplotlib.cm as cm | |
active_workers = [] | |
active_mules = [] | |
mineral_incomes = [] | |
gas_incomes = [] | |
match_times = [] | |
base_counts = [] | |
for match in json_match_data: | |
for pair in match['WorkersActiveCount']: | |
workers = match['WorkersActiveCount'][pair] | |
min_incomes = np.array(match['MineralsCollectionRate'][pair]) | |
ves_incomes = np.array(match['VespeneCollectionRate'][pair]) | |
active_workers.extend(workers) | |
mules = np.zeros_like(workers) | |
tmacro_json = match['tmacro'][pair] | |
if len(tmacro_json) > 0: | |
tmacro = np.array(tmacro_json) | |
mule_ticks = np.hstack(tmacro[:,0]) | |
ticks = 0 | |
for i in range(len(mules)): | |
mules[i] = len([t for t in mule_ticks if t < ticks - 16*1 and t > ticks - 16*90]) | |
active_workers[i] -= mules[i] | |
ticks += 16*10 | |
base_ticks = [p[1] for p in match['num_bases'] if p[0] == int(pair)][0] | |
base_nums = np.zeros_like(workers) | |
for i in range(len(base_nums)): | |
base_nums[i] = len([1 for t in base_ticks if t[0] < 16*10*i and t[1] > 16*10*i]) | |
active_mules.extend(mules) | |
mineral_incomes.extend(min_incomes) | |
gas_incomes.extend(ves_incomes) | |
match_times.extend([16*10*n for n in range(len(workers))]) # unused | |
base_counts.extend(base_nums) | |
figure(figsize=(32,18)) | |
axes(axisbg='0.1') | |
xlim(0, 100) | |
ylim(0, 3500) | |
xlabel("Worker count") | |
ylabel("Resources / min") | |
scatter(np.array(active_workers) + 3 * np.array(active_mules), np.array(mineral_incomes) + np.array(gas_incomes), | |
alpha=0.25, s=75, c=base_counts, cmap=cm.get_cmap('Set1'), edgecolors='none') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment