def get_coordinates(concept_system): import tempfile import os import fca temp_dot_path = tempfile.mktemp() temp_plain_path = tempfile.mktemp() coordinates = {} from fca.readwrite import uwrite_dot uwrite_dot(concept_system, temp_dot_path) try: dot_path = os.path.join(graphviz_path, "dot") subprocess.call([dot_path, "-Tplain", "-o{0}".format(temp_plain_path), temp_dot_path]) except: dot_path = os.path.join(graphviz_path, "dot.exe") subprocess.call([dot_path, "-Tplain", "-o{0}".format(temp_plain_path), temp_dot_path]) import codecs plain_dot_file = codecs.open(temp_plain_path, "r", "utf-8") for line in plain_dot_file: spl_line = line.split(" ") if spl_line[0] == "graph": canvas_width = float(spl_line[2]) canvas_height = float(spl_line[3]) elif spl_line[0] == "node": i = int(spl_line[1][1:]) xy = (float(spl_line[2])/canvas_width, float(spl_line[3])/canvas_height) coordinates[concept_system[i]] = xy plain_dot_file.close() # now clean for ourselves os.unlink(temp_plain_path) os.unlink(temp_dot_path) return coordinates
def save_lattice(cls, group): temp_dot_path = tempfile.mktemp() dir_path = os.path.join(MEDIA_ROOT, "img", group.slug) cxt = cls._explorations[group].db._cxt._get_self_as_fca_context(pk=False) concept_system = fca.ConceptLattice(cxt) uwrite_dot(concept_system, temp_dot_path, full=True) if not os.path.exists(dir_path): os.makedirs(dir_path) svg_path = os.path.join(dir_path, "lattice.svg") try: subprocess.call(["dot", "-Tsvg", "-o{0}".format(svg_path), temp_dot_path]) except: # TODO: workaround for windows systems pass
def save_lattice(cls, group): temp_dot_path = tempfile.mktemp() dir_path = os.path.join(MEDIA_ROOT, "img", group.slug) cxt = cls._explorations[group].db._cxt._get_self_as_fca_context( pk=False) concept_system = fca.ConceptLattice(cxt) uwrite_dot(concept_system, temp_dot_path, full=True) if not os.path.exists(dir_path): os.makedirs(dir_path) svg_path = os.path.join(dir_path, "lattice.svg") try: subprocess.call( ["dot", "-Tsvg", "-o{0}".format(svg_path), temp_dot_path]) except: # TODO: workaround for windows systems pass