-
Notifications
You must be signed in to change notification settings - Fork 0
/
summoner_class.py
96 lines (83 loc) · 3.24 KB
/
summoner_class.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
import global_state as glb
from match_class import Match
class Summoner(object):
def __init__(self, summoner_dict):
self.__dict__ = summoner_dict
if "summonerId" not in summoner_dict:
try:
self._look_up()
except glb.api.SummonerNotFound:
raise
self.timestamp = 0
def __str__(self):
str_ = "{} [{}]".format(self.name, self.region)
return str_
def _look_up(self):
try:
(self.summonerId, self.name) = glb.api.get_summoner_id_and_name(self.__dict__)
except glb.api.SummonerNotFound:
print("Summoner {} doesn't exist".format(self))
raise
def _set_timestamp(self):
self.timestamp = glb.db.get_max("matches", "timestamp", self._as_param_dict())
if type(self.timestamp) is int:
self.timestamp += 1
else:
self.timestamp = 0
glb.db.update("summoners", [self.__dict__])
# def _get_timestamp(self):
# return glb.db.get_data("summoners", self._as_param_dict())[0]['timestamp']
def _as_param_dict(self):
return {"summonerId": [self.summonerId], "region": [self.region]}
def in_db(self):
sum_info = glb.db.get_data("summoners", self._as_param_dict())
if len(sum_info):
return True
else:
return False
def add_to_db(self):
glb.db.insert("summoners", [self.__dict__])
def update_matches(self):
params = self.__dict__.copy()
(params["seasons"], params["queues"]) = glb.db.get_seasons_and_queues()
raw_matches = glb.api.get_matches_list(params)
matches = []
print("New matches:", len(raw_matches))
if len(raw_matches):
not_found = []
cannot_analyse = []
offmeta = []
opp_error = []
for raw_match in raw_matches:
try:
match = Match(self, raw_match)
except Match.CannotAnalyse as err:
match = err.match
cannot_analyse.append(match)
continue
except Match.NotFound as err:
match = err.match
not_found.append(match)
continue
except Match.OffMeta as err:
match = err.match
offmeta.append(match)
except Match.OpponentError as err:
match = err.match
opp_error.append(match)
matches.append(match)
print("Processed:", len(matches))
print("Not found:", len(not_found))
print("Cannot analyse:", len(cannot_analyse))
print("Offmeta:", len(offmeta))
print("Opponent error:", len(opp_error))
glb.db.insert("matches", list(map(lambda m: m.__dict__, matches)))
self._set_timestamp()
# def get_stats(self, db, roles):
# params = self._as_param_dict()
# params["role"] = roles
# matches = db.get_data("matches", params)
# stats = FullStats(matches)
# print("ROLE(S):", reduce(lambda x, y: "{}, {}".format(x, y), roles))
# print("ROLE(S) STATS:")
# print(stats)