-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathelementpower.py
More file actions
26 lines (22 loc) · 769 Bytes
/
Copy pathelementpower.py
File metadata and controls
26 lines (22 loc) · 769 Bytes
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
import math
class ElementPower:
@staticmethod
def calculate(data):
v1 = float(data.get('v1', 0)) # nominal power
v2 = float(data.get('v2', 0)) # required power
rr = float(data.get('rr', 0)) # resistance
calc_by = data.get('by', '')
result = []
if calc_by == 'power': # Calculate by power
r = 220 * 220 / v1
u = math.sqrt(v2 * r)
result = [
['ولتاژ', round(u, 2), 'ولت'],
['مقاومت', round(r, 2), 'اهم']
]
else: # Calculate by resistance
u = math.sqrt(v2 * rr)
result = [
['ولتاژ', round(u, 2), 'ولت']
]
return result