-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPrice.py
54 lines (43 loc) · 2.21 KB
/
Price.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
elem_dict = {'sodium': 480, 'hydrogen': 600, 'oxygen': 540, 'chlorine': 550, 'carbon': 700, 'calcium': 500}
comp_dict = {'arcaspace': 2000, 'astroscale': 2350, 'astrorocket': 2250, 'blueorigin': 2300, 'celestis': 2400, 'spacex': 2200, 'virgingalactic': 2050}
compound_dict = {'marble': 0, 'propane': 0, 'salt': 0, 'sugar': 0, 'water': 0}
class elements:
def __init__(self, element_dict=elem_dict, company_dict=comp_dict):
for k, v in element_dict.items():
self.__setattr__(k, v)
for k, v in company_dict.items():
self.__setattr__(k, v)
self.calculate_compounds()
self.elems = [self.sodium, self.hydrogen, self.oxygen, self.chlorine, self.carbon, self.calcium]
self.compounds = [self.marble, self.propane, self.salt, self.sugar, self.water]
self.companies = [self.arcaspace, self.astroscale, self.astrorocket, self.blueorigin, self.celestis, self.spacex, self.virgingalactic]
def calculate_compounds(self):
self.marble = self.calcium + self.carbon + (2 * self.oxygen)
self.propane = 2 * (self.calcium + self.hydrogen)
self.salt = self.sodium + self.chlorine
self.sugar = self.carbon + self.oxygen + (2 * self.hydrogen)
self.water = (2 * self.hydrogen) + self.oxygen
def incur_change(self, ins, ch):
try:
x = self.__getattribute__(ins)
x += self.myround(float(ch/100)*x, 50)
self.__setattr__(ins, x)
except:
pass
def myround(self, x, base=5):
return base * round(x / base)
def get_formatted_price(self):
self.calculate_compounds()
text = 'Quote Update\n' \
'Elements : Price\n'
for each in elem_dict.keys():
text += each + ': ' + str(self.__getattribute__(each)) + '\n'
text += '\n' \
'Companies : Price\n'
for each in compound_dict.keys():
text += each + ': ' + str(self.__getattribute__(each)) + '\n'
text += '\n' \
'Companies : Price\n'
for each in comp_dict.keys():
text += each + ': ' + str(self.__getattribute__(each)) + '\n'
return text