From 98986b8dc6b07eb63bd68ad16ffb4796fa63ca2b Mon Sep 17 00:00:00 2001 From: Xhunik Miguel Date: Sat, 6 Mar 2021 12:34:43 -0600 Subject: [PATCH] visualizar grafico --- .gitignore | 4 ++- Pipfile | 1 - Pipfile.lock | 84 ++++++++++++++++++-------------------------- src/app.py | 24 +++++++++++-- src/models/Matriz.py | 30 ++++++++++++++++ src/test.py | 4 +++ 6 files changed, 93 insertions(+), 54 deletions(-) create mode 100644 src/test.py diff --git a/.gitignore b/.gitignore index 1feec44..39c497f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ __pycache__/ -*.xml \ No newline at end of file +*.xml +*.dot +*.svg \ No newline at end of file diff --git a/Pipfile b/Pipfile index cf3cc36..234e474 100644 --- a/Pipfile +++ b/Pipfile @@ -4,7 +4,6 @@ verify_ssl = true name = "pypi" [packages] -graphviz = "*" [dev-packages] pylint = "*" diff --git a/Pipfile.lock b/Pipfile.lock index cae357e..a09bda7 100644 --- a/Pipfile.lock +++ b/Pipfile.lock @@ -1,7 +1,7 @@ { "_meta": { "hash": { - "sha256": "ef61071988de873926ec15ad0886a37457b374a78681cb0860108a8a45940bcd" + "sha256": "199b5fb1997b3b8bab5698ef85ed61e669d14b83a9186e79141f4c57e7be159f" }, "pipfile-spec": 6, "requires": { @@ -15,24 +15,15 @@ } ] }, - "default": { - "graphviz": { - "hashes": [ - "sha256:3cad5517c961090dfc679df6402a57de62d97703e2880a1a46147bb0dc1639eb", - "sha256:d2d25af1c199cad567ce4806f0449cb74eb30cf451fd7597251e1da099ac6e57" - ], - "index": "pypi", - "version": "==0.16" - } - }, + "default": {}, "develop": { "astroid": { "hashes": [ - "sha256:2f4078c2a41bf377eea06d71c9d2ba4eb8f6b1af2135bec27bbbb7d8f12bb703", - "sha256:bc58d83eb610252fd8de6363e39d4f1d0619c894b0ed24603b881c02e64c7386" + "sha256:21d735aab248253531bb0f1e1e6d068f0ee23533e18ae8a6171ff892b98297cf", + "sha256:cfc35498ee64017be059ceffab0a25bedf7548ab76f2bea691c5565896e7128d" ], - "markers": "python_version >= '3.5'", - "version": "==2.4.2" + "markers": "python_version >= '3.6'", + "version": "==2.5.1" }, "autopep8": { "hashes": [ @@ -60,30 +51,33 @@ }, "lazy-object-proxy": { "hashes": [ - "sha256:0c4b206227a8097f05c4dbdd323c50edf81f15db3b8dc064d08c62d37e1a504d", - "sha256:194d092e6f246b906e8f70884e620e459fc54db3259e60cf69a4d66c3fda3449", - "sha256:1be7e4c9f96948003609aa6c974ae59830a6baecc5376c25c92d7d697e684c08", - "sha256:4677f594e474c91da97f489fea5b7daa17b5517190899cf213697e48d3902f5a", - "sha256:48dab84ebd4831077b150572aec802f303117c8cc5c871e182447281ebf3ac50", - "sha256:5541cada25cd173702dbd99f8e22434105456314462326f06dba3e180f203dfd", - "sha256:59f79fef100b09564bc2df42ea2d8d21a64fdcda64979c0fa3db7bdaabaf6239", - "sha256:8d859b89baf8ef7f8bc6b00aa20316483d67f0b1cbf422f5b4dc56701c8f2ffb", - "sha256:9254f4358b9b541e3441b007a0ea0764b9d056afdeafc1a5569eee1cc6c1b9ea", - "sha256:9651375199045a358eb6741df3e02a651e0330be090b3bc79f6d0de31a80ec3e", - "sha256:97bb5884f6f1cdce0099f86b907aa41c970c3c672ac8b9c8352789e103cf3156", - "sha256:9b15f3f4c0f35727d3a0fba4b770b3c4ebbb1fa907dbcc046a1d2799f3edd142", - "sha256:a2238e9d1bb71a56cd710611a1614d1194dc10a175c1e08d75e1a7bcc250d442", - "sha256:a6ae12d08c0bf9909ce12385803a543bfe99b95fe01e752536a60af2b7797c62", - "sha256:ca0a928a3ddbc5725be2dd1cf895ec0a254798915fb3a36af0964a0a4149e3db", - "sha256:cb2c7c57005a6804ab66f106ceb8482da55f5314b7fcb06551db1edae4ad1531", - "sha256:d74bb8693bf9cf75ac3b47a54d716bbb1a92648d5f781fc799347cfc95952383", - "sha256:d945239a5639b3ff35b70a88c5f2f491913eb94871780ebfabb2568bd58afc5a", - "sha256:eba7011090323c1dadf18b3b689845fd96a61ba0a1dfbd7f24b921398affc357", - "sha256:efa1909120ce98bbb3777e8b6f92237f5d5c8ea6758efea36a473e1d38f7d3e4", - "sha256:f3900e8a5de27447acbf900b4750b0ddfd7ec1ea7fbaf11dfa911141bc522af0" + "sha256:1d33d6f789697f401b75ce08e73b1de567b947740f768376631079290118ad39", + "sha256:2f2de8f8ac0be3e40d17730e0600619d35c78c13a099ea91ef7fb4ad944ce694", + "sha256:3782931963dc89e0e9a0ae4348b44762e868ea280e4f8c233b537852a8996ab9", + "sha256:37d9c34b96cca6787fe014aeb651217944a967a5b165e2cacb6b858d2997ab84", + "sha256:38c3865bd220bd983fcaa9aa11462619e84a71233bafd9c880f7b1cb753ca7fa", + "sha256:429c4d1862f3fc37cd56304d880f2eae5bd0da83bdef889f3bd66458aac49128", + "sha256:522b7c94b524389f4a4094c4bf04c2b02228454ddd17c1a9b2801fac1d754871", + "sha256:57fb5c5504ddd45ed420b5b6461a78f58cbb0c1b0cbd9cd5a43ad30a4a3ee4d0", + "sha256:5944a9b95e97de1980c65f03b79b356f30a43de48682b8bdd90aa5089f0ec1f4", + "sha256:6f4e5e68b7af950ed7fdb594b3f19a0014a3ace0fedb86acb896e140ffb24302", + "sha256:71a1ef23f22fa8437974b2d60fedb947c99a957ad625f83f43fd3de70f77f458", + "sha256:8a44e9901c0555f95ac401377032f6e6af66d8fc1fbfad77a7a8b1a826e0b93c", + "sha256:b6577f15d5516d7d209c1a8cde23062c0f10625f19e8dc9fb59268859778d7d7", + "sha256:c8fe2d6ff0ff583784039d0255ea7da076efd08507f2be6f68583b0da32e3afb", + "sha256:cadfa2c2cf54d35d13dc8d231253b7985b97d629ab9ca6e7d672c35539d38163", + "sha256:cd1bdace1a8762534e9a36c073cd54e97d517a17d69a17985961265be6d22847", + "sha256:ddbdcd10eb999d7ab292677f588b658372aadb9a52790f82484a37127a390108", + "sha256:e7273c64bccfd9310e9601b8f4511d84730239516bada26a0c9846c9697617ef", + "sha256:e7428977763150b4cf83255625a80a23dfdc94d43be7791ce90799d446b4e26f", + "sha256:e960e8be509e8d6d618300a6c189555c24efde63e85acaf0b14b2cd1ac743315", + "sha256:ecb5dd5990cec6e7f5c9c1124a37cb2c710c6d69b0c1a5c4aa4b35eba0ada068", + "sha256:ef3f5e288aa57b73b034ce9c1f1ac753d968f9069cd0742d1d69c698a0167166", + "sha256:fa5b2dee0e231fa4ad117be114251bdfe6afe39213bd629d43deb117b6a6c40a", + "sha256:fa7fb7973c622b9e725bee1db569d2c2ee64d2f9a089201c5e8185d482c7352d" ], - "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'", - "version": "==1.4.3" + "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3, 3.4'", + "version": "==1.5.2" }, "mccabe": { "hashes": [ @@ -102,19 +96,11 @@ }, "pylint": { "hashes": [ - "sha256:718b74786ea7ed07aa0c58bf572154d4679f960d26e9641cc1de204a30b87fc9", - "sha256:e71c2e9614a4f06e36498f310027942b0f4f2fde20aebb01655b31edc63b9eaf" + "sha256:0e21d3b80b96740909d77206d741aa3ce0b06b41be375d92e1f3244a274c1f8a", + "sha256:d09b0b07ba06bcdff463958f53f23df25e740ecd81895f7d2699ec04bbd8dc3b" ], "index": "pypi", - "version": "==2.6.2" - }, - "six": { - "hashes": [ - "sha256:30639c035cdb23534cd4aa2dd52c3bf48f06e5f4a941509c8bafd8ce11080259", - "sha256:8b74bedcbbbaca38ff6d7491d76f2b06b3592611af620f8426e82dddb04a5ced" - ], - "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'", - "version": "==1.15.0" + "version": "==2.7.2" }, "toml": { "hashes": [ diff --git a/src/app.py b/src/app.py index 8279962..4192a6f 100644 --- a/src/app.py +++ b/src/app.py @@ -19,9 +19,26 @@ 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() -def process_file(data: ListaEnlazada, output: ListaEnlazada): - pass + +def print_info(): + print('> Xhunik Nikol Miguel Mutzutz') + print('> 201900462') + print('> Introducción a la Programación y Computación 2, Sección D') + print('> Ingenieria en Ciencias y Sistemas') + print('> 4to Semestre') + + +def render_graph(data: 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() def main_menu(data: ListaEnlazada, output: ListaEnlazada): @@ -41,13 +58,14 @@ def main_menu(data: ListaEnlazada, output: ListaEnlazada): load_file(data) continue if opt == '2': - process_file(data, output) continue if opt == '3': continue if opt == '4': + print_info() continue if opt == '5': + render_graph(data) continue if opt == '6': exit() diff --git a/src/models/Matriz.py b/src/models/Matriz.py index 5a61084..17042a4 100644 --- a/src/models/Matriz.py +++ b/src/models/Matriz.py @@ -1,4 +1,5 @@ from models import ListaEnlazada +from os import system, startfile class Matriz: @@ -35,3 +36,32 @@ def print_matrix(self): self.row_list.get_by_index(count).print_list() count = count + 1 print() + + def render_matrix(self): + temp_file = open('graph.dot', 'w+') + temp_file.write('digraph G {\n') # begin file + temp_file.write('name [label="{}"];\n'.format(self.name)) + temp_file.write('m [label="m={}"];\n'.format(self.m)) + temp_file.write('n [label="n={}"];\n'.format(self.n)) + temp_file.write('name -> m;') + temp_file.write('name -> n;') + + x_count = 0 + while self.m > x_count: + + y_count = 0 + while self.n > y_count: + temp_file.write('x{}y{} [label="{}"];\n'.format( + x_count, y_count, self.get(x_count, y_count))) + + if not (y_count + 1) >= self.n: + temp_file.write( + 'x{}y{} -> x{}y{};\n'.format(x_count, y_count, x_count, y_count+1)) + y_count = y_count + 1 + + temp_file.write('name -> x{}y{};'.format(x_count, 0)) + x_count = x_count + 1 + temp_file.write('}\n') # end file + temp_file.close() + system('dot -Tsvg graph.dot -o output.svg') + startfile('output.svg') diff --git a/src/test.py b/src/test.py new file mode 100644 index 0000000..264f4f4 --- /dev/null +++ b/src/test.py @@ -0,0 +1,4 @@ +from models import Matriz + +matrix = Matriz('nombre', 3, 3) +matrix.print_matrix()