From 4ee3060ca201cd61213353f08ad6d7bee7892858 Mon Sep 17 00:00:00 2001 From: Xhunik Miguel Date: Mon, 8 Mar 2021 14:28:36 -0600 Subject: [PATCH] actualizado graficar --- src/app.py | 11 ++++++----- src/models/Matriz.py | 27 +++++++++++++++++++++++++-- 2 files changed, 31 insertions(+), 7 deletions(-) diff --git a/src/app.py b/src/app.py index b4ab46b..b0fc132 100644 --- a/src/app.py +++ b/src/app.py @@ -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): @@ -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): @@ -87,7 +87,7 @@ 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: @@ -95,7 +95,8 @@ def render_graph(data: ListaEnlazada): 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): @@ -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() diff --git a/src/models/Matriz.py b/src/models/Matriz.py index 87ef17d..5334f8d 100644 --- a/src/models/Matriz.py +++ b/src/models/Matriz.py @@ -1,4 +1,4 @@ -from models import ListaEnlazada +from models import ListaEnlazada, Matriz from os import system, startfile @@ -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)) @@ -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: @@ -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')