Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: update stddev to be sample and top snr to be sorted reverse #6

Merged
merged 1 commit into from
Apr 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions models.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,24 @@ class DivisionTeam:
class Division:
name: str
teams: list[DivisionTeam]

def strength(self) -> float:
return numpy.average([team.district_points for team in self.teams]) # type: ignore

@staticmethod
def __snr(point_list: list[int]) -> float:
return 10 * numpy.log10(numpy.average(point_list)**2 / numpy.std(point_list)**2) # type: ignore

return 10 * numpy.log10(numpy.average(point_list) ** 2 / numpy.std(point_list, ddof=1) ** 2) # type: ignore

def stddev(self) -> float:
return numpy.std([team.district_points for team in self.teams], ddof=1)

def avg(self) -> float:
return numpy.average([team.district_points for team in self.teams])

def snr(self) -> float:
return Division.__snr([team.district_points for team in self.teams])

def top_snr(self) -> float:
'''Calculates the signal-to-noise ratio of the top 25% of teams'''
return Division.__snr([team.district_points for team in sorted(self.teams, key=lambda t: t.district_points)[:len(self.teams)//4]])
points = [team.district_points for team in sorted(self.teams, key=lambda t: t.district_points, reverse=True)[:len(self.teams)//4]]
return Division.__snr(points)