-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpower.py
More file actions
71 lines (62 loc) · 2.45 KB
/
power.py
File metadata and controls
71 lines (62 loc) · 2.45 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
'''Module with helpful classes and decorators'''
def humanize(func: int)->str:
'''Decorator that turns big int numbers to human readable text'''
def wrapper(*args, **kwargs)->str:
original_result = func(*args, **kwargs)
prefixes = ["", "K", "M", "B", "T", "Qd", "Qn", "Sx", "Sp", "Oc",
"No", "De", "UDe", "DDe", "TDe", "QdDe", "QnDe", "SxDe", "SpDe",
"OcDe", "NoDe", "Vt", "UVt", "DVt", "TVg", "QaVg", "QiVg", "SxVg"]
prefix = 0
for i in range(1, len(prefixes)):
if original_result / (1000 ** (i-1)) >= 1000:
prefix += 1
else: break
modified_result = original_result / (1000 ** prefix)
modified_result = "{:.2f}".format(modified_result) + prefixes[prefix]
return modified_result
return wrapper
def humanizeFunc(num: int)->str:
prefixes = ["", "K", "M", "B", "T", "Qd", "Qn", "Sx", "Sp", "Oc",
"No", "De", "UDe", "DDe", "TDe", "QdDe", "QnDe", "SxDe", "SpDe",
"OcDe", "NoDe", "Vt", "UVt", "DVt", "TVg", "QaVg", "QiVg", "SxVg"]
prefix = 0
for i in range(1, len(prefixes)):
if num / (1000 ** (i-1)) >= 1000:
prefix += 1
else: break
modified_result = num / (1000 ** prefix)
modified_result = "{:.2f}".format(modified_result) + prefixes[prefix]
return modified_result
class Units(list):
'''Array that contains items of type Unit'''
pass
class Unit:
'''Class that makes object whith name, power and description'''
def __init__(self, name, power, desc=""):
'''initialization'''
self.__name:str = name
self.__power:int = power
self.__desc:str = desc
@property
def power(self)->int:
'''method that returns power when you write object.power'''
return self.__power
@property
def name(self)->str:
'''method that returns name when you write object.name'''
return self.__name
@property
def description(self) -> str:
'''method that returns description when you write object.description'''
if self.__desc != "":
return self.__desc
return ""
@humanize
def __str__(self):
'''magic method that returns power
as human readable text
when you write str(object)'''
return self.power
def set_power(self, value):
'''setter for power'''
self.__power = value