Created
April 8, 2019 20:58
-
-
Save aarmora/9a632efd6565a054a7b6747f4d160d86 to your computer and use it in GitHub Desktop.
Returns indicative information of if a user is using the same account as another or not
This file contains hidden or 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 requests | |
import datetime as dt | |
import requests | |
first_user = '80623424' | |
second_user = '887227975' | |
def get_intervals(l): | |
return [(x['start_time'], x['start_time'] + x['duration'], x['match_id']) for x in l if x.get('start_time') is not None] | |
def n_days_ago_as_epoch(n): | |
today = int(dt.datetime.now().strftime('%s')) | |
return today - n * 24 * 60 * 60 | |
def x_during_y(x, y): | |
x_during_y = [] | |
for _x in x: | |
for _y in y: | |
if _y[0] <= _x[0] <= _y[1]: | |
x_during_y.append([_x, _y]) | |
return x_during_y | |
def x_within_one_hour_of_y(x, y): | |
x_during_y = [] | |
one_hour = 60 * 60 | |
for _x in x: | |
for _y in y: | |
if _y[0] <= _x[0] + one_hour <= _y[1] or _y[0] <= _x[0] - one_hour <= _y[1]: | |
x_during_y.append([_x, _y]) | |
return x_during_y | |
def x_within_mins_of_end(x, y, n): | |
x_during_y = [] | |
n_mins = 60 * n | |
for _x in x: | |
for _y in y: | |
if _y[0] <= _x[1] + n_mins <= _y[1] or _y[0] <= _x[1] - n_mins <= _y[1]: | |
x_during_y.append([_x, _y]) | |
return x_during_y | |
# In[168]: | |
ss = requests.get('https://api.opendota.com/api/players/' + first_user + '/matches?significant=0').json() | |
imp = requests.get('https://api.opendota.com/api/players/' + second_user + '/matches?significant=0').json() | |
ss_during_imp = x_during_y( | |
get_intervals(ss), | |
get_intervals(imp), | |
) | |
# In[175]: | |
print 'Number of times Impatient and Six-SeveN have played at the same time', len(ss_during_imp) | |
print '..with the most recent occurrence', dt.datetime.fromtimestamp(ss_during_imp[0][0][0]), ' MatchID ', ss_during_imp[0][0][-1] | |
# In[176]: | |
time_ago = n_days_ago_as_epoch(365 * 2) | |
a = [x for x in get_intervals(imp) if x[0] > time_ago ] | |
b = [x for x in get_intervals(ss) if x[0] > time_ago] | |
print 'Impatient has played', len(a), ' games in the past 2 years' | |
print 'Six-SeveN has played', len(b), ' games in the past 2 years' | |
# In[179]: | |
a_during_b = x_during_y(a, b) | |
print 'Since last coincident match, they have played simultaneously {} times'.format(len(a_during_b)) | |
# In[186]: | |
import pprint | |
a_within_b_one_hour = x_within_one_hour_of_y(a, b) | |
print 'Within the last 2 years, they have played within one hour of each other {} times: '.format(len(a_within_b_one_hour)) | |
print 'Date, MatchID, MatchID' | |
pprint.pprint([(dt.datetime.fromtimestamp(x[0][0]).strftime('%Y-%m-%d'), x[0][-1], x[1][-1]) for x in a_within_b_one_hour]) | |
# In[195]: | |
a_10_b = x_within_mins_of_end(b, a, 15) + x_within_mins_of_end(a, b, 15) | |
print 'Within the last 2 years, they have played within 15 minutes of a game\'s end {} times: '.format(len(a_10_b)) | |
print 'Date, MatchID, MatchID' | |
pprint.pprint([(dt.datetime.fromtimestamp(x[0][0]).strftime('%Y-%m-%d'), x[0][-1], x[1][-1]) for x in a_10_b]) | |
# In[196]: | |
a_3_b = x_within_mins_of_end(b, a, 3) + x_within_mins_of_end(a, b, 3) | |
print 'Within the last 2 years, they have played within 3 minutes of a game\'s end {} times: '.format(len(a_3_b)) | |
print 'Date, MatchID, MatchID' | |
pprint.pprint([(dt.datetime.fromtimestamp(x[0][0]).strftime('%Y-%m-%d'), x[0][-1], x[1][-1]) for x in a_3_b]) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment