-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdrink.py
More file actions
124 lines (101 loc) · 4.2 KB
/
Copy pathdrink.py
File metadata and controls
124 lines (101 loc) · 4.2 KB
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
import time
class Drink:
total_alcohol_sold = 0 # Static variable to track total alcohol sold
def __init__(self, name, init_price, alcohol_content=0): # array with one price - the starting price
self.name = name
self.price = init_price
self.alcohol_content = alcohol_content
self.price_history = [init_price] # former allPrices
self.maxPrice = init_price * 1.5
self.minPrice = init_price * 0.5
self.orders = {} # gives every order a time; size of dict is equal to amount of orders
self.period_order_count = 0 # counter of orders in a period
self.price_was_changed = 0 # counts the times the price is changed
self.price_change_prob = 0.2
self.drinkWasPurchased = 0
def setPrice(self, price):
newPrice = 0
if price >= self.maxPrice:
newPrice = self.maxPrice
elif price <= self.minPrice:
newPrice = self.minPrice
else:
newPrice = price
self.price = round(newPrice, 1)
self.price_history.append(newPrice)
def update_recentlyChangedPrices(self):
for drink in recentlyChangedPrices:
if self == drink:
recentlyChangedPrices.remove(drink)
recentlyChangedPrices.append(drink)
return
# if price of drink wasnt changed yet
recentlyChangedPrices.append(self)
def newOrders(self):
""" Looks at every order inside self.orders and looks for orders performed in the current period.
returns self.period_order_count -> number of drinks purchased in the current period.
"""
current_time = time.time()
listOfItemsToRemove = []
self.period_order_count = 0 # counts number of times this drink was bought in the period
for element_time in self.orders:
if current_time - element_time <= iteration_interval:
self.period_order_count += 1
self.drinkWasPurchased += 1
# if current_time - element_time > iteration_interval * 10:
# # items from last period -- not important anymore
# listOfItemsToRemove.append(element_time)
# else:
# self.period_order_count = self.period_order_count + 1
# self.drinkWasPurchased += 1
# for i in listOfItemsToRemove:
# del self.orders[i] # cleanup orders (newDict) again
return self.period_order_count
@staticmethod
def get_allDrinks():
return allDrinks
@staticmethod
def get_drink_by_name(name):
for drink in allDrinks:
if drink.name == name:
return drink
return None
iteration_interval = 300 # in seconds
allDrinks = [
Drink("Sterni", 1.0, 0.05*5),
Drink("Berliner", 1.5, 0.05*5),
Drink("Amaretto", 1.0, 10),
Drink("Radler", 1.3, 0.025*5),
Drink("Weißwein", 1.3, 0.12*2),
Drink("Rotwein", 1.4, 0.14*2),
Drink("Spezi", 1.3, 0),
Drink("Mate", 1.3, 0),
Drink("Softdrink", 0.8, 0),
Drink("Augustiner", 1.5, 0.05*5),
Drink("Glücksgetränk", 1.4, 0)
]
recentlyChangedPrices = []
# customColorSet = ["#FF0000",
# "#FF8F00",
# "#4BF70B",
# "#0BF7C5",
# "#0B0FF7",
# "#C90BF7",
# "#F70B6F"
# ]
# def addNewRandomPrice(self, price_increase, change_price):
# if change_price:
# self.price_was_changed = self.price_was_changed + 1
# multiplicator = random.randint(0, 5) # max -50 cent
# oldPrice = self.price_history[-1]
# if price_increase:
# newPrice = oldPrice + (multiplicator * 0.1) # get a random lower price
# elif not price_increase:
# newPrice = oldPrice - (multiplicator * 0.1) # get a random higher price
# if self.minPrice < newPrice < self.maxPrice:
# self.addPrice(newPrice)
# else:
# self.addPrice(oldPrice)
# self.update_recentlyChangedPrices()
# else:
# self.addPrice(self.price_history[-1])