Created
April 8, 2018 23:40
-
-
Save a-r-g-v/c00dbfc27804d0df7b7edbce2682350d to your computer and use it in GitHub Desktop.
generate arrow digram from csv input
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding: utf-8 | |
""" | |
module | |
~~~~~~~~~ | |
""" | |
from __future__ import absolute_import, division, print_function, unicode_literals | |
import csv | |
def reader(): | |
with open('./task.csv') as csvfile: | |
r = csv.reader(csvfile, delimiter=',') | |
r.__next__() | |
for i in r: | |
yield i | |
class Task(object): | |
def __init__(self, id, category, name, cost, description, depencies): | |
self.id = id.replace("-", "_") | |
self.category = category | |
self.name = name | |
self.cost = cost | |
if not cost or cost == '?': | |
self.cost = 'empty' | |
self.description = description | |
self.depencies = depencies.split("\n") | |
def __repr__(self): | |
return "{id} {category} {name} {cost}".format(id=self.id, category=self.category, name=self.name, cost=self.cost) | |
def dump(self, l): | |
print("{id} [label={cost}]".format(id=self.id, cost=self.cost)) | |
for dep in self.depencies: | |
if dep: | |
dep=dep.replace("-", "_") | |
print("{dep} -> {id} [label=\"{name}\"] ".format(dep=dep, id=self.id, name=l[dep].name)) | |
def build_tasks_list(): | |
tasks = {} | |
for r in reader(): | |
task = Task(*r) | |
if task.id == '': | |
continue | |
tasks[task.id] = task | |
return tasks | |
import sys | |
l = build_tasks_list() | |
print("digraph{") | |
for i in l.values(): | |
i.dump(l) | |
print("}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment