1 # -*- coding: utf-8 -*-
2 #Author: Pierre Ratinaud
3 #Copyright (c) 2008-2020 Pierre Ratinaud
4 #modification pour python 3 : Laurent Mérat, 6x7 - mai 2020
7 #------------------------------------
8 # import des modules python
9 #------------------------------------
13 from random import randint
17 def __init__(self, nodesfile, edgesfile, jsonout, parametres = {}):
19 with codecs.open(edgesfile, 'r', 'utf8') as f :
21 content = content.replace('"', '')
22 content = content.splitlines()
24 titles_edges = content.pop(0)
25 titles_edges = titles_edges.split('\t')
26 edges = [line.split('\t') for line in content]
30 with codecs.open(nodesfile, 'r', 'utf8') as f :
32 content = content.replace('"','')
33 content = content.splitlines()
34 titles = content.pop(0)
35 titles = titles.split('\t')
38 xr = titles.index('x')
39 yr = titles.index('y')
41 zr = titles.index('z')
44 wr = titles.index('weight')
51 ni = titles.index('name')
53 nodes = [line.split('\t') for line in content]
55 graph = {'edges': [], 'nodes' : {}}
57 we = titles_edges.index('weight')
58 if edges is not None :
60 graph['edges'].append({'source' : edge[0], 'target' : edge[1], 'weight' : edge[we]})
63 coefcoord = parametres.get('coefcoord', 1)
64 coefweight = parametres.get('coefweight', 1)
69 graph['nodes'][node[ni]] = {"location" : [float(node[xr])*coefcoord, float(node[yr])*coefcoord, float(node[zr])*coefcoord], 'weight' : float(node[wr])/coefweight, 'color': (int(node[r]),int(node[g]),int(node[b]))}
71 x = parametres.get('randomx', 0)
74 graph['nodes'][node[ni]] = {"location" : [ x, float(node[xr]), float(node[yr])], 'weight' : float(node[wr]), 'color': (int(node[r]),int(node[g]),int(node[b]))}
76 with open(jsonout, 'w') as f :