From d1109cba5acd39402f759292162cb687bf9c85fc Mon Sep 17 00:00:00 2001 From: "gasperfele@fri1.uni-lj.si" Date: Fri, 7 Oct 2016 11:26:27 +0000 Subject: Started adding the drawing of computer and network setups for each task git-svn-id: https://svn.lusy.fri.uni-lj.si/kpov-public-svn/kpov-public@357 5cf9fbd1-b2bc-434c-b4b7-e852f4f63414 --- kpov_judge/web/kpov_judge/icons/computer.svg | 1877 +++++++++++ kpov_judge/web/kpov_judge/icons/drive-harddisk.svg | 491 +++ kpov_judge/web/kpov_judge/icons/internet.svg | 3398 ++++++++++++++++++++ kpov_judge/web/kpov_judge/kpov_draw_setup.py | 37 + kpov_judge/web/kpov_judge/kpov_judge.py | 7 + 5 files changed, 5810 insertions(+) create mode 100644 kpov_judge/web/kpov_judge/icons/computer.svg create mode 100644 kpov_judge/web/kpov_judge/icons/drive-harddisk.svg create mode 100644 kpov_judge/web/kpov_judge/icons/internet.svg create mode 100644 kpov_judge/web/kpov_judge/kpov_draw_setup.py diff --git a/kpov_judge/web/kpov_judge/icons/computer.svg b/kpov_judge/web/kpov_judge/icons/computer.svg new file mode 100644 index 0000000..6da674d --- /dev/null +++ b/kpov_judge/web/kpov_judge/icons/computer.svg @@ -0,0 +1,1877 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/kpov_judge/web/kpov_judge/icons/drive-harddisk.svg b/kpov_judge/web/kpov_judge/icons/drive-harddisk.svg new file mode 100644 index 0000000..5f36f85 --- /dev/null +++ b/kpov_judge/web/kpov_judge/icons/drive-harddisk.svg @@ -0,0 +1,491 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + Drive - Hard Disk + + + Jakub Steiner + + + + + hdd + hard drive + fixed + media + solid + + + + + http://jimmac.musichall.cz + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/kpov_judge/web/kpov_judge/icons/internet.svg b/kpov_judge/web/kpov_judge/icons/internet.svg new file mode 100644 index 0000000..5efbd24 --- /dev/null +++ b/kpov_judge/web/kpov_judge/icons/internet.svg @@ -0,0 +1,3398 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/kpov_judge/web/kpov_judge/kpov_draw_setup.py b/kpov_judge/web/kpov_judge/kpov_draw_setup.py new file mode 100644 index 0000000..a6ffc82 --- /dev/null +++ b/kpov_judge/web/kpov_judge/kpov_draw_setup.py @@ -0,0 +1,37 @@ +import pygraphviz as pgv + +def draw_setup(computers, networks, destination = None): + G = pgv.AGraph() + have_internet = [] + for net, net_params in networks.iteritems(): + if net_params.get('public', False): + have_internet.append(net) + G.add_node('net-' + net, label=net, shape='rectangle') + if len(have_internet): + G.add_node('net-' + 'internet', + label='internet', + labelloc='b', image='icons/internet.svg', shape='none') + for n in have_internet: + G.add_edge('net-' + n, 'net-internet') + for c, properties in computers.iteritems(): + G.add_node('comp-' + c, + label = c, + image='icons/computer.svg', + shape='none', labelloc='b') + G_sub = G.add_subgraph(['comp-' + c], name='cluster-' + c, + label = c, + rank='same', pack=True) + for hdd in properties.get('disks', []): + G_sub.add_node('disk-' + hdd['name'], + label=hdd['name'], + shape='none', + image='icons/drive-harddisk.svg') + G_sub.add_edge('comp-' + c, 'disk-' + hdd['name']) + for iface in properties.get('network_interfaces'): + G.add_edge('comp-' + c, 'net-' + iface['network']) + return G.draw(path=destination, format='svg', prog='dot') + +if __name__ == '__main__': + import sample_task as task + print draw_setup(task.computers, task.networks) + diff --git a/kpov_judge/web/kpov_judge/kpov_judge.py b/kpov_judge/web/kpov_judge/kpov_judge.py index d5669d8..d02ba99 100755 --- a/kpov_judge/web/kpov_judge/kpov_judge.py +++ b/kpov_judge/web/kpov_judge/kpov_judge.py @@ -8,6 +8,7 @@ import random import settings import datetime import kpov_random_helpers +from kpov_draw_setup import draw_setup import traceback app = Flask(__name__) @@ -103,6 +104,12 @@ def results_json(task_id): return json.dumps(results_post(task_id, json.loads(flask.app.request.form['results']))) return json.dumps(results_dict(task_id)) +@app.route('/tasks//setup.svg', methods=['GET']) +def setup_svg(task_id): + networks = db.networks.find({'task_id': task_id}) + computers = db.computers_meta.find({'task_id': task_id}) + return draw_setup(computers, networks) + @app.route('/tasks///results.html') def results_html(task_id, lang): return render_template('results.html', results=results_dict(task_id)) -- cgit v1.2.1