import dota
import utils

def serialize_player(player):
  friend = dota.Friend.get_or_none(steam_id=player['account_id'])
  player_data = {
    'personaname': player['personaname'] if player['personaname'] else '',
    'nickname': friend.name if friend else '',
    'kills': player['kills'],
    'deaths': player['deaths'],
    'assists': player['assists'],
    'total_gold': player['total_gold'],
    'last_hits': player['last_hits'],
    'denies': player['denies'],
    'hero_damage': player['hero_damage'],
    'party_id': player['party_id'],
    'win': player['win'],
    'level': player['level'],
    'is_radiant': player['is_radiant'],
    'hero': dota.Hero.get(hero_id=player['hero_id']).localized_name,
    'hero_id': player['hero_id'],
    'rank_tier': player['rank_tier'],
    'rank': utils.get_ranking(player['rank_tier']),
  }
  return player_data
