def point_diff(self): try: home_scores = self.home_game.filter(season=current_season().year, week__gte=0).aggregate( team_score=Sum('homeScore'), opp_score=Sum('awayScore')) away_scores = self.away_game.filter(season=current_season().year, week__gte=0).aggregate( team_score=Sum('awayScore'), opp_score=Sum('homeScore')) if home_scores['team_score'] is None: home_scores['team_score'] = 0 if home_scores['opp_score'] is None: home_scores['opp_score'] = 0 if away_scores['team_score'] is None: away_scores['team_score'] = 0 if away_scores['opp_score'] is None: away_scores['opp_score'] = 0 return (home_scores['team_score'] + away_scores['team_score'] - home_scores['opp_score'] - away_scores[ 'opp_score']) / float(self.wins + self.losses) except ZeroDivisionError: return 0.0
def div_rank(self): agg = seed( list( Team.objects.filter(division=self.division).order_by("-wins")), current_season()) for i in range(len(agg)): if agg[i].id == self.id: return i + 1
def point_diff(self): try: home_scores = self.home_game.filter( season=current_season().year, week__gte=0).aggregate(team_score=Sum('homeScore'), opp_score=Sum('awayScore')) away_scores = self.away_game.filter( season=current_season().year, week__gte=0).aggregate(team_score=Sum('awayScore'), opp_score=Sum('homeScore')) if home_scores['team_score'] is None: home_scores['team_score'] = 0 if home_scores['opp_score'] is None: home_scores['opp_score'] = 0 if away_scores['team_score'] is None: away_scores['team_score'] = 0 if away_scores['opp_score'] is None: away_scores['opp_score'] = 0 return (home_scores['team_score'] + away_scores['team_score'] - home_scores['opp_score'] - away_scores['opp_score']) / float(self.wins + self.losses) except ZeroDivisionError: return 0.0
def apg_season(self): spg = self.playerstats_set.filter(game__season=current_season().year).aggregate(Avg('assists'))['assists__avg'] if spg is None: return 0.0 return spg
def rpg_season(self): rpg = self.playerstats_set.filter(game__season=current_season().year).aggregate(Avg('rebounds'))['rebounds__avg'] if rpg is None: return 0.0 return rpg
def ppg_season(self): fgpg = self.playerstats_set.filter(game__season=current_season().year).aggregate(Avg('field_goals'))['field_goals__avg'] if fgpg is None: return 0.0 return fgpg * 2
def regular_season_games(team): return Game.objects.filter(Q(away_team__id=team.id) | Q(home_team__id=team.id), week__gte=0, season=current_season().year).order_by('week')
def years_left(self, season=None): if season is None: season = current_season() return self.start - season.year + self.years
def div_rank(self): agg = seed(list(Team.objects.filter(division=self.division).order_by("-wins")), current_season()) for i in range(len(agg)): if agg[i].id == self.id: return i + 1