Skip to content

Commit

Permalink
actualizado graficar
Browse files Browse the repository at this point in the history
  • Loading branch information
xhuniktzi committed Mar 8, 2021
1 parent 2773459 commit 4ee3060
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 7 deletions.
11 changes: 6 additions & 5 deletions src/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def load_file(data: ListaEnlazada):
data.get_last().insert(int(obj_attrib['x'])-1,
int(obj_attrib['y'])-1, int(obj.text))

data.get_last().print_matrix()
# data.get_last().print_matrix()


def process_file(data: ListaEnlazada, output: ListaEnlazada):
Expand All @@ -42,7 +42,7 @@ def process_file(data: ListaEnlazada, output: ListaEnlazada):
y_count = y_count + 1
output.add_to_end(output_matrix)
count = count + 1
output.get_last().print_matrix()
# output.get_last().print_matrix()


def write_file(output: ListaEnlazada):
Expand Down Expand Up @@ -87,15 +87,16 @@ def print_info():
print('> 4to Semestre')


def render_graph(data: ListaEnlazada):
def render_graph(data: ListaEnlazada, output: ListaEnlazada):
count = 0
print('Selecciona una matriz: ')
while data.get_size() > count:
print('{}. {}'.format(count, data.get_by_index(count).name))
count = count + 1

matrix_index = int(input('> '))
data.get_by_index(matrix_index).render_matrix()
output_matrix = output.get_by_index(matrix_index)
data.get_by_index(matrix_index).render_matrix(output_matrix)


def main_menu(data: ListaEnlazada, output: ListaEnlazada):
Expand Down Expand Up @@ -124,7 +125,7 @@ def main_menu(data: ListaEnlazada, output: ListaEnlazada):
print_info()
continue
if opt == '5':
render_graph(data)
render_graph(data, output)
continue
if opt == '6':
exit()
Expand Down
27 changes: 25 additions & 2 deletions src/models/Matriz.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from models import ListaEnlazada
from models import ListaEnlazada, Matriz
from os import system, startfile


Expand Down Expand Up @@ -38,7 +38,7 @@ def print_matrix(self):
count = count + 1
print()

def render_matrix(self):
def render_matrix(self, process: Matriz):
temp_file = open('graph.dot', 'w+')
temp_file.write('digraph G {\n') # begin file
temp_file.write('name [label="{}"];\n'.format(self.name))
Expand All @@ -47,6 +47,7 @@ def render_matrix(self):
temp_file.write('name -> m;')
temp_file.write('name -> n;')

# Gráfica entrada
x_count = 0
while self.m > x_count:

Expand All @@ -62,6 +63,28 @@ def render_matrix(self):

temp_file.write('name -> x{}y{};'.format(x_count, 0))
x_count = x_count + 1

# Gráfica salida procesada
temp_file.write('proc_name [label="{}"];\n'.format(process.name))
temp_file.write('proc_m [label="m={}"];\n'.format(process.m))
temp_file.write('proc_n [label="n={}"];\n'.format(process.n))
temp_file.write('proc_name -> proc_m;')
temp_file.write('proc_name -> proc_n;')
p_x_count = 0
while process.m > p_x_count:
p_y_count = 0
while process.n > p_y_count:
temp_file.write('px{}py{} [label="{}"];\n'.format(
p_x_count, p_y_count, process.get(p_x_count, p_y_count)))

if not (p_y_count + 1) >= process.n:
temp_file.write(
'px{}py{} -> px{}py{};\n'.format(p_x_count, p_y_count, p_x_count, p_y_count+1))
p_y_count = p_y_count + 1

temp_file.write('proc_name -> px{}py{};'.format(p_x_count, 0))
p_x_count = p_x_count + 1

temp_file.write('}\n') # end file
temp_file.close()
system('dot -Tsvg graph.dot -o output.svg')
Expand Down

0 comments on commit 4ee3060

Please sign in to comment.