-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAnalysesBox.py
118 lines (91 loc) · 3.72 KB
/
AnalysesBox.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
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
from PyQt6.QtWidgets import QGroupBox, QLabel, QFormLayout
class AnalysesBox(QGroupBox):
def __init__(self):
"""
Initializes the total purchase, sale, profit and variance QLabels widgets and calls the init_ui method to set up
the layout
"""
super(AnalysesBox, self).__init__("Analyses")
self.quantity = 1
self.purchase_cost = 0
self.sale_cost = 0
# Create QLabel to show the CryptoCurrency purchase total
self.total_purchased = QLabel("$00.00")
# Create QLabel to show the CryptoCurrency sell total
self.total_sold = QLabel("$00.00")
# Create QLabel to show the CryptoCurrency profit total
self.total_profit = QLabel("$00.00")
# Create QLabel to show the variance percentage
self.total_variance = QLabel("00.00%")
self._init_ui()
def _init_ui(self):
"""
This method, initializes and sets up the UI layout for this Dialog
:return: void
"""
# Set box layout
analyses_layout = QFormLayout()
analyses_layout.addRow("Total Purchased:", self.total_purchased)
analyses_layout.addRow("Total Sold:", self.total_sold)
analyses_layout.addRow("Total Profit:", self.total_profit)
analyses_layout.addRow("Total Variance:", self.total_variance)
self.setLayout(analyses_layout)
def update_quantity(self, quantity):
"""
Updates the value of quantity and calls update_total_purchased and update_total_sale
:param quantity: new purchase quantity of the coin
:return: void
"""
self.quantity = quantity
self._update_total_purchased()
self._update_total_sale()
def update_purchase_cost(self, purchase_cost):
"""
Updates the value of purchase_cost and calls update_total_purchased
:param purchase_cost: new purchase cost of the coin
:return: void
"""
self.purchase_cost = purchase_cost
self._update_total_purchased()
def update_sale_cost(self, sale_cost):
"""
Updates the value of sale_cost and calls update_total_sale
:param sale_cost: new sale cost of the coin
:return: void
"""
self.sale_cost = sale_cost
self._update_total_sale()
def _update_total_purchased(self):
"""
Calculates the total cost of the purchase and updates the total_purchased widget accordingly
:return: void
"""
total = self.quantity * self.purchase_cost
# updates the total_purchase following the dollar format
self.total_purchased.setText('${:,.2f}'.format(total))
self._update_total_profit()
self._update_total_variance()
def _update_total_sale(self):
"""
Calculates the total cost of the sale and updates the total_sale widget accordingly
:return: void
"""
total = self.quantity * self.sale_cost
# updates the total_sold text following the dollar format
self.total_sold.setText('${:,.2f}'.format(total))
self._update_total_profit()
self._update_total_variance()
def _update_total_profit(self):
"""
Calculates the total profit and updates the total_profit widget accordingly
:return: void
"""
total = self.quantity * (self.sale_cost - self.purchase_cost)
self.total_profit.setText('${:,.2f}'.format(total))
def _update_total_variance(self):
"""
Calculates the total variance and updates the total_variance widget accordingly
:return: void
"""
total = (self.sale_cost / self.purchase_cost - 1) * 100
self.total_variance.setText('{:,.2f}%'.format(total))