-
Notifications
You must be signed in to change notification settings - Fork 52
/
Copy pathbase.py
279 lines (221 loc) · 9.75 KB
/
base.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
import copy
from enum import Enum
class Shard(Enum):
PC_AS = 'pc-as' # Asia
PC_EU = 'pc-eu' # Europe
PC_KAKAO = 'pc-kakao' # Kakaogames server (Korea only)
PC_KRJP = 'pc-krjp' # Korea
PC_NA = 'pc-na' # North America
PC_OC = 'pc-oc' # Oceania
PC_SA = 'pc-sa' # South and Central America
PC_SEA = 'pc-sea' # South East Asia
PC_JP = 'pc-jp' # Japan
PC_RU = 'pc-ru' # Russia
PC_TOURNAMENT = 'pc-tournament' # PC Tournaments Shard
XBOX_AS = 'xbox-as' # Asia
XBOX_EU = 'xbox-eu' # Europe
XBOX_NA = 'xbox-na' # North America
XBOX_OC = 'xbox-oc' # Oceania
XBOX_SA = 'xbox-sa' # South America
KAKAO = 'kakao' # Kakao
PSN = 'psn' # PSN (Deprecated)
STEAM = 'steam' # Steam
TOURNAMENT = 'tournament' # Tournaments
XBOX = 'xbox' # Xbox (Deprecated)
CONSOLE = 'console' # Xbox/Psn
class Filter(Enum):
CREATED_AT_START = 'createdAt-start'
CREATED_AT_END = 'createdAt-end'
PLAYER_IDS = 'playerIds'
GAME_MODE = 'gameMode'
class Domain:
def __init__(self, data, meta=None):
self._raw_data = copy.deepcopy(data)
raw_data = copy.deepcopy(data)
self._meta = meta or Meta(raw_data)
self._data = raw_data.pop('data', {})
self.from_dict()
self.process_relationships()
def __repr__(self):
return '<{0} {1}>'.format(self.__class__.__name__, self.id)
def __str__(self):
return str(self.id)
@staticmethod
def instance(data, meta=None):
return globals()[data['data']['type'].title()](data, meta)
def from_dict(self):
self.description = self._data.get('description')
self.id = self._data.get('id')
self.type = self._data.get('type')
self.attributes = self._data.pop('attributes', {})
self.relationships = self._data.pop('relationships', {})
def to_dict(self):
return self._raw_data
def process_relationships(self):
if not self.relationships:
return
for name, relationship in self.relationships.items():
if not relationship['data']:
continue
if isinstance(relationship['data'], list):
setattr(self, name, [])
rel = getattr(self, name)
for data in relationship['data']:
item = self._meta.retrieve(data)
rel.append(
Domain.instance({'data': item}, meta=self._meta))
elif isinstance(relationship['data'], dict):
relationship_instance = Domain.instance(
relationship, meta=self._meta)
setattr(self, name, relationship_instance)
class Meta:
def __init__(self, data):
self._meta = data.pop('meta', {})
self._links = data.pop('links', {})
self._included = data.pop('included', {})
def retrieve(self, data):
if not self._included:
return data
return next(
filter(lambda x: x['id'] == data['id'], self._included), data)
class Sample(Domain):
def from_dict(self):
super().from_dict()
self.created_at = self.attributes.get('createdAt')
self.shard_id = self.attributes.get('shardId')
self.title_id = self.attributes.get('titleId')
class Match(Domain):
def from_dict(self):
super().from_dict()
self.created_at = self.attributes.get('createdAt')
self.duration = self.attributes.get('duration')
self.game_mode = self.attributes.get('gameMode')
self.is_custom_match = self.attributes.get('isCustomMatch')
self.map_name = self.attributes.get('mapName')
self.patch_version = self.attributes.get('patchVersion')
self.shard_id = self.attributes.get('shardId')
self.stats = self.attributes.get('stats')
self.tags = self.attributes.get('tags')
self.title_id = self.attributes.get('titleId')
self.season_state = self.attributes.get('seasonState')
self.match_type = self.attributes.get('matchType')
class Roster(Domain):
def from_dict(self):
super().from_dict()
self.shard_id = self.attributes.get('shardId')
self.stats = self.attributes.get('stats')
self.won = self.attributes.get('won')
class Participant(Domain):
def from_dict(self):
super().from_dict()
self.actor = self.attributes.get('actor')
self.shard_id = self.attributes.get('shardId')
self.stats = self.attributes.get('stats')
self.unpack_stats()
def unpack_stats(self):
self.dbnos = self.stats.get('DBNOs')
self.assists = self.stats.get('assists')
self.boosts = self.stats.get('boosts')
self.damage_dealt = self.stats.get('damageDealt')
self.death_type = self.stats.get('deathType')
self.headshot_kills = self.stats.get('headshotKills')
self.heals = self.stats.get('heals')
self.kill_place = self.stats.get('killPlace')
self.kill_streaks = self.stats.get('killStreaks')
self.kills = self.stats.get('kills')
self.longest_kill = self.stats.get('longestKill')
self.name = self.stats.get('name')
self.player_id = self.stats.get('playerId')
self.revives = self.stats.get('revives')
self.ride_distance = self.stats.get('rideDistance')
self.road_kills = self.stats.get('roadKills')
self.swim_distance = self.stats.get('swimDistance')
self.team_kills = self.stats.get('teamKills')
self.time_survived = self.stats.get('timeSurvived')
self.vehicle_destroys = self.stats.get('vehicleDestroys')
self.walk_distance = self.stats.get('walkDistance')
self.weapons_acquired = self.stats.get('weaponsAcquired')
self.win_place = self.stats.get('winPlace')
class Asset(Domain):
def from_dict(self):
super().from_dict()
self.created_at = self.attributes.get('createdAt')
self.description = self.attributes.get('description')
self.name = self.attributes.get('name')
self.url = self.attributes.get('URL')
class Player(Domain):
def from_dict(self):
super().from_dict()
self.name = self.attributes.get('name')
self.patch_version = self.attributes.get('patchVersion')
self.shard_id = self.attributes.get('shardId')
self.stats = self.attributes.get('stats')
self.title_id = self.attributes.get('titleId')
self.rank = self.attributes.get('rank')
class Tournament(Domain):
pass
class Season(Domain):
def from_dict(self):
super().from_dict()
self.is_current_season = self.attributes.get('isCurrentSeason')
self.is_off_season = self.attributes.get('isOffseason')
class Playerseason(Domain):
def from_dict(self):
super().from_dict()
self.best_rank_point = self.attributes.get('bestRankPoint')
game_mode_stats = self.attributes.get('gameModeStats')
self.solo = Stats({'data': game_mode_stats.get('solo', {})})
self.solo_fpp = Stats({'data': game_mode_stats.get('solo-fpp', {})})
self.duo = Stats({'data': game_mode_stats.get('duo', {})})
self.duo_fpp = Stats({'data': game_mode_stats.get('duo-fpp', {})})
self.squad = Stats({'data': game_mode_stats.get('squad', {})})
self.squad_fpp = Stats({'data': game_mode_stats.get('squad-fpp', {})})
class Stats(Domain):
# TODO: i don't think stats is really a domain
# but just a collection of statuses
def from_dict(self):
super().from_dict()
self.assists = self._data.get('assists')
self.boosts = self._data.get('boosts')
self.dbnos = self._data.get('dBNOs')
self.daily_kills = self._data.get('dailyKills')
self.damage_dealt = self._data.get('damageDealt')
self.days = self._data.get('days')
self.daily_wins = self._data.get('dailyWins')
self.headshot_kills = self._data.get('headshotKills')
self.heals = self._data.get('heals')
self.kills = self._data.get('kills')
self.longest_kill = self._data.get('longestKill')
self.longest_time_survived = self._data.get('longestTimeSurvived')
self.losses = self._data.get('losses')
self.max_kill_streaks = self._data.get('maxKillStreaks')
self.most_survival_time = self._data.get('mostSurvivalTime')
self.rank_points = self._data.get('rankPoints')
self.rank_points_title = self._data.get('rankPointsTitle')
self.revives = self._data.get('revives')
self.ride_distance = self._data.get('rideDistance')
self.road_kills = self._data.get('roadKills')
self.round_most_kills = self._data.get('roundMostKills')
self.rounds_played = self._data.get('roundsPlayed')
self.suicides = self._data.get('suicides')
self.swim_distance = self._data.get('swimDistance')
self.team_kills = self._data.get('teamKills')
self.time_survived = self._data.get('timeSurvived')
self.top10s = self._data.get('top10s')
self.vehicle_destroys = self._data.get('vehicleDestroys')
self.walk_distance = self._data.get('walkDistance')
self.weapons_acquired = self._data.get('weaponsAcquired')
self.weekly_kills = self._data.get('weeklyKills')
self.weekly_wins = self._data.get('weeklyWins')
self.wins = self._data.get('wins')
class Leaderboard(Domain):
def from_dict(self):
super().from_dict()
self.shard_id = self.attributes.get('shardId')
self.game_mode = self.attributes.get('gameMode')
class Weaponmasterysummary(Domain):
def from_dict(self):
super().from_dict()
self.platform = self.attributes.get('platform')
self.weapon_summaries = self.attributes.get('weaponSummaries')
self.latest_match_id = self.attributes.get('latestMatchId')