-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
105 lines (91 loc) · 3.9 KB
/
Copy pathmain.py
File metadata and controls
105 lines (91 loc) · 3.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
import requests
import math
import configparser
config = configparser.ConfigParser()
config.read('config.ini')
battles = [
"10611",
]
cookies = {
"user_id": config.get('DEFAULT', 'user_id'),
"serial": config.get('DEFAULT', 'serial'),
"botbr_id": config.get('DEFAULT', 'botbr_id')
}
def load_battle_info(battle_id):
url = f"https://battleofthebits.com/api/v1/battle/load/{battle_id}"
json_data = requests.get(url, cookies=cookies).json()
return json_data['title'], int(json_data['entry_count']), int(json_data['type']), len(json_data['format_tokens'])
def get_botbr_scores(battle_id, botbr_id):
json_data = requests.get(f"https://battleofthebits.com/api/v1/entry/list/0/250?filters=battle_id~{battle_id}^botbr_id~{botbr_id}", cookies=cookies).json()
thearray = []
for entry in json_data:
if entry.get('score'):
thearray.append(entry['score'])
else:
thearray.append(0.0)
return thearray
def create_entry_array(entry_array, botbr_dict, url):
json_data = requests.get(url, cookies=cookies).json()
for entry in json_data:
if entry.get('score'):
entry_array.append(entry['score'])
else:
entry_array.append(0.0)
botbr_id = entry['botbr_id']
if botbr_id not in botbr_dict.keys():
botbr_dict[botbr_id] = {'entries': 0, 'has_collabs': False}
botbr_dict[botbr_id]['entries'] += 1
if entry.get('authors'):
if len(entry['authors']) > 1:
botbr_dict[botbr_id]['has_collabs'] = True
return entry_array, botbr_dict
def get_battle_entries(battle_id):
title, entry_count, battle_type, format_count = load_battle_info(battle_id)
iterations = math.ceil(entry_count / 250)
entry_array = []
botbr_dict = {}
for i in range(iterations):
entry_array, botbr_dict = create_entry_array(
entry_array,
botbr_dict,
f"https://battleofthebits.com/api/v1/entry/list/{i}/250?filters=battle_id~{battle_id}"
)
title = "OHB: " + title if battle_type == 3 else "Major: " + title
return title, entry_array, botbr_dict, format_count
def calc_average(score_array):
if not score_array:
return 0.0
score = 0.0
for entry_score in score_array:
try:
score = score + float(entry_score)
except ValueError:
pass
score_average = score / len(score_array)
return round(score_average, 3)
#try:
full_score_array = []
for battle_id in battles:
title, score_array, botbr_info, format_count = get_battle_entries(battle_id)
full_score_array += score_array
score_average = calc_average(score_array)
print(title + "\n" + str(len(score_array)) + " Entries" + "\n" + "Average Score: " + str(score_average) + "\nFormat Count: " + str(format_count) + "\n")
if format_count >= 6:
print('Complete BotBrs:')
for botbr, data_stuff in botbr_info.items():
if data_stuff['entries'] == format_count:
botbr_data = requests.get(f'https://battleofthebits.com/api/v1/botbr/load/{botbr}/', cookies=cookies).json()
xtra = ''
if data_stuff['has_collabs']:
xtra = '*collabs involved'
print(f"{botbr_data['name']}: {calc_average(get_botbr_scores(battle_id, botbr))} {xtra}")
# # Adventists
# if 12 <= data_stuff['entries'] <= 24:
# botbr_data = requests.get(f'https://battleofthebits.com/api/v1/botbr/load/{botbr}/').json()
# print(f"Adventist: {botbr_data['name']}: {calc_average(get_botbr_scores(battle_id, botbr))} - {data_stuff['entries']} entries")
if len(battles) > 1:
full_score_average = calc_average(full_score_array)
print("All Battles" + "\n" + str(len(full_score_array)) + " Entries" + "\n" + "Average Score: " + str(
full_score_average))
#except:
# print("Not a valid battle id.")