Created
September 2, 2021 07:49
-
-
Save Xevion/ec8dfeec299087348924585883a19167 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from typing import Dict, Union | |
def balance_distribution(dist: Dict[int, Union[int, float]]) -> float: | |
sum_known: float = sum(filter(lambda v : v != None, dist.values())) | |
unknown_spaces: int = len(list(filter(lambda v : v == None, dist.values()))) | |
# Average "unknown distribution" to place among all unfilled spots | |
unknown_replace_avg: float = (1.0 - sum_known) / unknown_spaces | |
for key, value in dist.items(): | |
if value == None: | |
dist[key] = unknown_replace_avg | |
return dist | |
patrons = 12032 | |
distribution = {1: None, 5: 0.1, 10: 0.05} | |
distribution = balance_distribution(distribution) | |
# Calculate subtotal for each subscription tier prior | |
subtotals = [] | |
for subscription, base in distribution.items(): | |
subtotal = patrons * subscription * base | |
subtotals.append(subtotal) | |
total = sum(subtotals) | |
# Print it out, with total in mind for percentages | |
for population, subscription, subtotal in zip(distribution.values(), distribution.keys(), subtotals): | |
percent = (subtotal / total) * 100 | |
print(f"${subscription} Tier: ${subtotal:,.2f} ({population * 100:.1f}% for {percent:.2f}%)") | |
print(f"Total: ${total:,.2f}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment