-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelpers.py
72 lines (47 loc) · 2.21 KB
/
helpers.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import random
import numpy as np
import math
OPTIONS = ("Welcome Page", "CMO Lab: Nike Marketing",
"COO Lab: Starbucks Operation",
"CFO Lab: Corporate Valuation",
"CPO Lab: Product Portfolio")
def ad_calc_profit(price_item, cost_item, ad_budget):
profit_item = []
break_even_cnt = 0
# Calculate profit for each case
for i in range(len(price_item)):
# Get all key factors
unit_price = price_item[i]
unit_cost = cost_item[i]
sales_expense = 37000
unit_sold = ad_budget*1000*0.7
# Calculate total profit
profit = unit_sold * (unit_price - unit_cost) - sales_expense
print("------")
print(f"unit sold: {unit_sold}")
print(unit_price, unit_cost, profit)
profit_item.append(profit)
if profit >= 0.0:
break_even_cnt += 1
# Calculate probability of break-even
prob_profit = break_even_cnt / len(profit_item)
return profit_item, prob_profit
def get_items_ad_triangular(unit_price, unit_cost, N):
price_item = np.random.triangular(size=N, left=unit_price-25.0, right=unit_price+10.0, mode=unit_price)
cost_item = np.random.triangular(size=N, left=unit_cost-5.0, right=unit_cost+10.0, mode=unit_cost)
return price_item, cost_item
def get_items(value_range, N, shape):
if shape == "Normal":
return np.random.normal(size=N, loc= (value_range[0] + value_range[1])/2)
elif shape == "Triangle":
return np.random.triangular(size=N, left=value_range[0], right=value_range[1],
mode=(value_range[0] + value_range[1])/2)
elif shape == "Uniform":
return np.random.uniform(size=N, low=value_range[0], high=value_range[1])
def apply_function(input_items, distribution):
if distribution == 'Secret Formula 1':
return np.sqrt(input_items + 1) * 2 + np.random.uniform(size=len(input_items), low=1, high=5)
elif distribution == 'Secret Formula 2':
return np.sqrt(input_items+1)*2 + np.random.poisson(size=len(input_items))
elif distribution == 'Secret Formula 3':
return np.sqrt(input_items + 1) * 2 + np.random.triangular(size=len(input_items), left=1, right=5, mode=2.5)