-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
124 lines (105 loc) · 3.24 KB
/
main.py
File metadata and controls
124 lines (105 loc) · 3.24 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
from anytree import Node, RenderTree
class Grid:
def __init__(self, power, is_city):
self.transformer_power = power
self.nodes = [GridNode("[00]", 0, power, None)]
self.root = self.nodes[0]
self.num_nodes = 0
self.owners = 0
self.is_city = is_city
def add_node(self, length, receive, parent_id):
self.num_nodes += 1
if self.num_nodes > 9:
name = "[" + str(self.num_nodes) + "]"
else:
name = "[0" + str(self.num_nodes) + "]"
if receive[0] == "e":
pwr = int(receive[1:]) * 7.18
self.owners += int(receive[1:])
elif receive[0] == "p":
pwr = float(receive[1:])
self.owners += 1
else:
pwr = 0
self.nodes.append(GridNode(name, length, pwr, self.nodes[parent_id]))
def __len__(self):
max_len = 0
for n in self.nodes:
if n.is_leaf:
if len(n) > max_len:
max_len = len(n)
return max_len
def evaluate_grid_current(self, from_node=0):
"""
:param from_node:
:param owners: liczba odbiorcow
:param is_city: czy miejscowosc jest miastem
:return: prad obwodu
"""
kj = self.get_kj()
print("kj: ", kj)
return round((kj * self.nodes[from_node].all_power()) / (1.73 * 400 * .93), 2)
def get_kj(self):
"""
:param self: liczba odbiorcow
:param is_city: czy miejscowosc jest miastem
:return: wspolczynnik jednoczesnosci
"""
city_kj = {
1: 1,
2: .94,
3: .9,
4: .83,
5: .8,
6: .72,
7: .7,
8: .6,
9: .55,
10: .5,
}
vill_kj = {
1: 1,
2: .8,
3: .7,
4: .6,
5: .55,
6: .45,
7: .45,
8: .4,
9: .36,
10: .33,
}
return self.is_city and city_kj.get(self.owners, .4) or vill_kj.get(self.owners, .3)
def voltage(self):
# TODO: oblicza spadek napiecia obowu
pass
class GridNode(Node):
def __init__(self, name, length, power, parent):
super().__init__(name, parent)
self.length = length
self.power = power
def __len__(self):
if self.is_root or self.parent.name == "[00]":
return self.length
else:
return self.length + len(self.parent)
def all_power(self):
if self.is_leaf:
return self.power
return sum([child.all_power() for child in self.children])
typ = input("Typ miejscowsci (m/w): ") == "m"
transformer_power = input("Moc transformatora [kVA]: ")
grid = Grid(int(transformer_power), typ)
while True:
for pre, fill, node in RenderTree(grid.root):
print("%s%s" % (pre, node.name))
choice = input("<>: ").split()
if choice[0] == "exit":
break
elif choice[0] == "add":
grid.add_node(int(choice[2]), choice[3], int(choice[1]))
elif choice[0] == "len":
print(len(grid.nodes[int(choice[1])]))
elif choice[0] == "i":
print("I:", grid.evaluate_grid_current(), "A")
print(len(grid))