/
item_set.py
98 lines (85 loc) · 2.79 KB
/
item_set.py
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
from analyze import BuildAnalyzer
from data import champion_keys
import json
from pathlib import Path
def rounded(num):
""" Round the number for item counts with weird logic """
if num < 1.1:
return 1
elif num < 2:
return 2
else:
return int(num)
class ItemSetBuilder:
__analyzer = None
def __init__(self, analyzer):
if type(analyzer) is BuildAnalyzer:
self.__analyzer = analyzer
else:
raise Exception("Analyzer is not valid")
def starting_items(self):
items = []
for item in self.__analyzer.starting_items:
if item["percentage"] > 50:
items.append({
"id": str(item["item_id"]),
"count": rounded(item["avg_count"])
})
return items
def items(self, l):
items = []
for item in sorted(l,
key=lambda x: x["percentage"],
reverse=True):
if item["percentage"] > 3:
items.append({
"id": str(item["item_id"]),
"count": rounded(item["avg_count"])
})
return items
def generate(self):
d = {
"title": "CB for {0} ({1} games)".format(
self.__analyzer.championKey,
self.__analyzer.gameCount),
"type": "custom",
"map": "SR",
"mode": "CLASSIC",
"blocks": [
{
"type": "Starting items",
"items": self.starting_items()
},
{
"type": "Offensive items",
"items": self.items(self.__analyzer.offensive_items)
},
{
"type": "Defensive items",
"items": self.items(self.__analyzer.defensive_items)
},
{
"type": "Other items",
"items": self.items(self.__analyzer.other_items)
},
{
"type": "Consumables",
"items": self.items(self.__analyzer.consumables)
}
]
}
return d
def create_directories():
for key in champion_keys():
path = Path.cwd().joinpath(Path("results/" + key + "/Recommended/"))
if path.exists() is False:
path.mkdir(parents=True)
def create_files():
for key in champion_keys():
path = Path.cwd().joinpath(
Path("results/" + key + "/Recommended/" + key + ".json"))
with path.open('w') as f:
json.dump(
ItemSetBuilder(BuildAnalyzer(key)).generate(),
f,
indent=2)