feat(players.py, matches.py, utils.py): 补充比赛序列化方法,增加 utils
补充比赛序列化方法,增加 utils Signed-off-by: Ching <loooching@gmail.com>
This commit is contained in:
parent
4b31d228c6
commit
e109649c95
23
matches.py
23
matches.py
@ -1,23 +1,18 @@
|
|||||||
import opendota
|
import opendota
|
||||||
|
import datetime
|
||||||
|
import players
|
||||||
|
import utils
|
||||||
|
|
||||||
match_client = opendota.MatchesApi()
|
match_client = opendota.MatchesApi()
|
||||||
|
|
||||||
def serialize_player(player):
|
|
||||||
player_data = {
|
|
||||||
'personaname': player.personaname,
|
|
||||||
'kills': player.kills,
|
|
||||||
'deaths': player.deaths,
|
|
||||||
'assists': player.assists,
|
|
||||||
'total_gold': player.total_gold,
|
|
||||||
'last_hits': player.last_hits,
|
|
||||||
'denies': player.denies,
|
|
||||||
}
|
|
||||||
return player_data
|
|
||||||
|
|
||||||
def serialize_match(match_id):
|
def serialize_match(match_id):
|
||||||
match = match_client.get_matches_by_match_id(match_id)
|
match = match_client.get_matches_by_match_id(match_id)
|
||||||
match_data = {
|
match_data = {
|
||||||
'players': [serialize_player(player) for player in match.players],
|
'players': [players.serialize_player(player) for player in match.players],
|
||||||
|
'dire_score': match.dire_score,
|
||||||
|
'radiant_score': match.radiant_score,
|
||||||
|
'start_time': datetime.datetime.fromtimestamp(match.start_time).strftime('%Y-%m-%d %H:%M:%S'),
|
||||||
|
'duration': '%d:%02d:%02d' % utils.convert_seconds_to_hms(match.duration),
|
||||||
|
'radiant_win': match.radiant_win,
|
||||||
}
|
}
|
||||||
return match_data
|
return match_data
|
||||||
|
|
||||||
|
|||||||
15
players.py
Normal file
15
players.py
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
def serialize_player(player):
|
||||||
|
player_data = {
|
||||||
|
'personaname': player.personaname,
|
||||||
|
'kills': player.kills,
|
||||||
|
'deaths': player.deaths,
|
||||||
|
'assists': player.assists,
|
||||||
|
'total_gold': player.total_gold,
|
||||||
|
'last_hits': player.last_hits,
|
||||||
|
'denies': player.denies,
|
||||||
|
'party_id': player.party_id,
|
||||||
|
'win': player.win,
|
||||||
|
'level': player.level,
|
||||||
|
'is_radiant': player.is_radiant,
|
||||||
|
}
|
||||||
|
return player_data
|
||||||
Loading…
x
Reference in New Issue
Block a user