Created
February 7, 2019 04:25
-
-
Save siennathesane/0aa9ef4be8208e15d9ce06439a03d8ae 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
| import matplotlib.pyplot as plt | |
| import numpy as np | |
| PRICE_SHEET = { | |
| "scale_amount": 1000, | |
| "base_price": 1, | |
| "feature_x": 0.1, | |
| "feature_y": 0.15, | |
| "feature_z": 0.20, | |
| } | |
| def compute_price(feature_list, base_unit_price, scale_amount): | |
| # 5 units * 10 cost = 50 cost | |
| base_price_at_scale_amount = base_unit_price * scale_amount | |
| for idx, premium in enumerate(feature_list): | |
| # safety check. if there are no feature premiums, the base price is valid. | |
| if len(feature_list) == 0: | |
| base_price_at_scale_amount = base_unit_price * scale_amount | |
| else: | |
| # add the premium cost to the base price. | |
| base_price_at_scale_amount += base_price_at_scale_amount * premium | |
| return base_price_at_scale_amount | |
| def compute(local_price_sheet): | |
| results = { | |
| "no_features": [], | |
| "feature_x": [], | |
| "feature_y": [], | |
| "feature_z": [] | |
| } | |
| for scale_unit in range(0, local_price_sheet["scale_amount"]): | |
| no_features_results = compute_price([], local_price_sheet["base_price"], scale_unit) | |
| results["no_features"].append(no_features_results) | |
| feature_x_results = compute_price( | |
| [ | |
| local_price_sheet["feature_x"] | |
| ], | |
| local_price_sheet["base_price"], | |
| scale_unit | |
| ) | |
| results["feature_x"].append(feature_x_results) | |
| feature_y_results = compute_price( | |
| [ | |
| local_price_sheet["feature_x"], | |
| local_price_sheet["feature_y"] | |
| ], | |
| local_price_sheet["base_price"], | |
| scale_unit | |
| ) | |
| results["feature_y"].append(feature_y_results) | |
| feature_z_results = compute_price( | |
| [ | |
| local_price_sheet["feature_x"], | |
| local_price_sheet["feature_y"], | |
| local_price_sheet["feature_z"] | |
| ], | |
| local_price_sheet["base_price"], | |
| scale_unit | |
| ) | |
| results["feature_z"].append(feature_z_results) | |
| return results | |
| def main(): | |
| for i in range(1, 100, 25): | |
| print("computing loop {}".format(i)) | |
| local_price_sheet = PRICE_SHEET | |
| local_price_sheet["scale_amount"] = local_price_sheet["scale_amount"] * i | |
| feature_price_scale = compute(local_price_sheet) | |
| x = np.linspace(0, PRICE_SHEET["scale_amount"], PRICE_SHEET["scale_amount"]) | |
| plt.figure() | |
| plt.suptitle("Feature Premium at Scale") | |
| plt.title("Feature Premium Max Diff Per Billing Cycle: {:.2f}".format( | |
| feature_price_scale["feature_z"][-1] - feature_price_scale["no_features"][-1])) | |
| plt.ylabel("Price in Currency Units") | |
| plt.xlabel("Units in Circulation") | |
| plt.plot(x, feature_price_scale["no_features"], label="no features", linestyle="-") | |
| plt.plot(x, feature_price_scale["feature_x"], label="feature set x", linestyle="--") | |
| plt.plot(x, feature_price_scale["feature_y"], label="feature set y", linestyle="-.") | |
| plt.plot(x, feature_price_scale["feature_z"], label="feature set z", linestyle=":") | |
| plt.legend(loc="upper left") | |
| plt.savefig("data/scale-{}".format(local_price_sheet["scale_amount"]), dpi=300) | |
| plt.close() | |
| if __name__ == '__main__': | |
| main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment