supercontest.util.math
Mathematic utilities.
Functions
Bins/discretizes a number based on range. |
|
Simply converts a float or int to an int if it's a whole number or leaves it as float if it's a float. |
|
Many pieces of the results indicate percentage (like pick accuracy). |
|
Takes a total amount and divides it discretely among the top ranks. |
|
Simply rounds a number down to the nearest 10 (used for payouts). |
- supercontest.util.math.bucket_number(num: int | float, step: int, stop: int) str
Bins/discretizes a number based on range. Automatically creates signed buckets (for the negative increments of
stepdown to-stop). Each bin is inclusive on the lower/left val.- Parameters:
num – The value to place in a bin.
step – The width of the bins.
stop – The last bin. It will also create bookend bins from
stoptoinfand-stopto-inf.
- Returns:
The bin.
- supercontest.util.math.convert_num_to_int_if_whole(num: float | int) float | int
Simply converts a float or int to an int if it’s a whole number or leaves it as float if it’s a float.
- Parameters:
num – The number.
- Returns:
The converted number.
- supercontest.util.math.get_percentage(num: int | float, den: int | float, round_to: int = 1) int | float
Many pieces of the results indicate percentage (like pick accuracy). This function handles the divide by zero case, and the formatting into percentage, and the round to tenth decimal place.
- Parameters:
num – The numerator.
den – The denominator.
round_to – Decimal places to round to (0 is integer).
- Returns:
The resultant percentage, or inf if divide-by-zero. (0/0 is treated as 0).
- supercontest.util.math.log_rank_distribution(total: int | float, floor: int | float, max_distributions: int = 100, shape: float = 0.9) tuple[list[int], int]
Takes a total amount and divides it discretely among the top ranks. Uses a logarithmic distribution. The floor is where the distribution stops, with the tail of the logser (to infinity) just going to the first rank.
Ranks 2-n are then rounded down to the nearest 10, with remainders going to 1st rank. The final round-down from 1st place is returned to the caller.
- Parameters:
total – The quantity to be distributed.
floor – The cutoff for the minimum distribution.
max_distributions – If you want to only distribute to top n ranks. Otherwise, set it arbitrarily high, and it will use the specified “floor” as the final rank to receive distribution.
shape – The shape of the discrete logarithmic series (
p). Numbers closer to 1 flatten the distribution. Numbers closer to zero have heavier distributions to the top ranks.
- Returns:
The quantities distributed to the top ranks.
- Returns:
Remainder from 1st rank round-down.
- supercontest.util.math.round_down_to_nearest_10(num: int | float) int
Simply rounds a number down to the nearest 10 (used for payouts).
- Parameters:
num – The number.
- Returns:
The rounded number.