forked from heroku/python-getting-started
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvisual.py
More file actions
70 lines (55 loc) · 1.92 KB
/
Copy pathvisual.py
File metadata and controls
70 lines (55 loc) · 1.92 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
BASE_WIDTH = 26
class Slot:
def __init__(self, **kwargs):
self.__dict__.update(kwargs)
class Solution:
def __init__(self):
self.rows = []
@classmethod
def from_submission(cls, input_file, output_file):
self = cls()
infile = input_file.read().decode('utf-8').split('\n')
def getl(index):
return map(int, infile[index].split())
index = 0
rows_nb, slots_nb, bslots_nb, pools_nb, servers_nb = getl(index)
self.row_width = (slots_nb + 2) * (BASE_WIDTH + 5)
rows = []
servers = []
for row_i in range(rows_nb):
rows.append([])
# -1 slot available
# -2 slot blocked
rows[row_i] = [-1] * slots_nb
for bad_i in range(bslots_nb):
index += 1
x, y = getl(index)
rows[x][y] = -2
for serv_i in range(servers_nb):
index += 1
servers.append(list(getl(index)))
outfile = output_file.read().decode('utf-8').split('\n')
serv_i = 0
for of in outfile:
serv = of.split()
if len(serv) == 3:
x, y, p = list(map(int, serv))
rows[x][y] = (serv_i, p)
serv_i += 1
initcolor = 150000
for row in rows:
self.rows.append(out := [])
stop = 0
for r in row:
if stop > 0:
stop -= 1
elif r == -1:
out.append(Slot(width=20, color='AAA', content='.'))
elif r == -2:
out.append(Slot(width=20, color='F00', content='X'))
else:
color = '{0:06X}'.format(initcolor * (r[1] + 1))
size = servers[r[0]][0]
stop = size - 1
out.append(Slot(width=(stop * 29) + 20, color=color, content=r[0]))
return self