WIP: DATA Représentation Dilemna: Client <vs> XML Initial commit
This commit is contained in:
parent
768e3ca8a3
commit
f230ad3a73
|
@ -0,0 +1,160 @@
|
|||
import model
|
||||
|
||||
|
||||
# from anytree import Node, AnyNode, NodeMixin, RenderTree, find_by_attr
|
||||
# from anytree.exporter import DotExporter from ete3 import Tree
|
||||
|
||||
# https://stackoverflow.com/
|
||||
|
||||
# read-data-from-a-file-and-create-a-tree-using-anytree-in-python
|
||||
# https://www.delftstack.com/howto/python/trees-in-python/
|
||||
# https://python-gtk-3-tutorial.readthedocs.io/en/latest/treeview.html
|
||||
# https://anytree.readthedocs.io/en/latest/
|
||||
|
||||
# TODO Contrôles de cohérence des données
|
||||
# 1) node_id <> pas de doublon
|
||||
# 2) pas de node sans un node_parent_id
|
||||
|
||||
conditions_set = set()
|
||||
|
||||
# TODO cnd.get_coord("y"),...
|
||||
for i in range(0, len(model.testmodel.get_conditions().get_conditions_array())):
|
||||
cnd = model.testmodel.get_conditions().get_condition(i)
|
||||
conditions_set.add((cnd.get_node_self_id(),
|
||||
cnd.get_node_parent_id(),
|
||||
cnd.get_coord("x"),
|
||||
cnd.get_site(),
|
||||
cnd.get_weight()))
|
||||
|
||||
|
||||
class TreeNode(object):
|
||||
|
||||
# TODO self.y = y,...
|
||||
def __init__(self, id, parent, x, site, weight):
|
||||
self.id = id
|
||||
self.parent = parent
|
||||
self.ch = []
|
||||
self.x = x
|
||||
self.site = site
|
||||
self.weight = weight
|
||||
|
||||
def id(self):
|
||||
return id
|
||||
|
||||
def add_child(self, ch_id):
|
||||
self.ch.append(ch_id)
|
||||
self.ch = sorted(self.ch, key=id)
|
||||
|
||||
|
||||
lll = []
|
||||
|
||||
for i in conditions_set: # sorted(conditions_set, key=id):
|
||||
cndt = TreeNode(i[0], i[1], i[2], i[3], i[4]) # TODO y,z,...
|
||||
lll.append(cndt)
|
||||
|
||||
for i in lll:
|
||||
for j in lll:
|
||||
if (i.id == j.parent):
|
||||
i.add_child(j)
|
||||
|
||||
print('\n', "conditions (node_id, parent_id, nb enfants, liste enfants)", '\n')
|
||||
|
||||
dsp = ''
|
||||
|
||||
for i in lll:
|
||||
dsp = str(i.id) + ' ' + str(i.parent) + ' n=' + str(len(i.ch)) + ' '
|
||||
if len(i.ch) > 0:
|
||||
for c in range(0, len(i.ch)):
|
||||
dsp += str(i.ch[c].id) + ', '
|
||||
print(dsp)
|
||||
|
||||
|
||||
"""
|
||||
##
|
||||
|
||||
A = Node("A")
|
||||
A1 = Node("A1", parent=A)
|
||||
A2 = Node("A2", parent=A)
|
||||
A21 = Node("A21", parent=A2)
|
||||
|
||||
root = Node([0])
|
||||
|
||||
|
||||
https://python-gtk-3-tutorial.readthedocs.io/en/latest/treeview.html
|
||||
|
||||
|
||||
A
|
||||
├── A1
|
||||
└── A2
|
||||
└── A21
|
||||
|
||||
with open('input.txt', 'r') as f:
|
||||
lines = f.readlines()[1:]
|
||||
root = Node(lines[0].split(" ")[0])
|
||||
|
||||
for line in lines:
|
||||
line = line.split(" ")
|
||||
Node("".join(line[1:]).strip(), parent=find_by_attr(root, line[0]))
|
||||
|
||||
for pre, _, node in RenderTree(root):
|
||||
print("%s%s" % (pre, node.name))
|
||||
|
||||
|
||||
##
|
||||
|
||||
print("\n*** Conditions tree ***")
|
||||
print(type(model.testmodel.get_conditions()))
|
||||
print("\n")
|
||||
print(model.testmodel.get_conditions().get_condition(0).get_coord('x'))
|
||||
print("\n")
|
||||
print()
|
||||
|
||||
|
||||
sp = model.testmodel.get_states().get_space(0)
|
||||
size = model.testmodel.get_parameters().spaceparam.get_dimension().get_x()
|
||||
sites = int(model.testmodel.get_parameters().spaceparam.get_site_multiplicity())
|
||||
nb_arrows = int(model.testmodel.get_states().get_space(0).get_nb_arrows())
|
||||
|
||||
|
||||
print("\n space size = ", size, " nb de sites par cellule = ", sites,
|
||||
" nb total de flèches dans l'espace = ", nb_arrows)
|
||||
|
||||
print(' | ', end=' ')
|
||||
|
||||
# TODO Contrôles de cohérence des données
|
||||
# condition et arrow
|
||||
# 1) weight < weight_max (à définir)
|
||||
# 2) arrow.site < site_multiplicity
|
||||
# 3) arrow.x < space-param.dimension.x (idem autres axes)
|
||||
# condition
|
||||
# 1) parent <= condition.node_id max value (donc deux lectures)
|
||||
# 2) pas de node sans un node_parent_id
|
||||
|
||||
|
||||
for n in range(0, size + 1):
|
||||
for s in range(0, sites):
|
||||
arr = 0
|
||||
for a in range(0, nb_arrows):
|
||||
if (
|
||||
sp.get_arrow(a).get_coord("x") == n
|
||||
and sp.get_arrow(a).get_site() == s
|
||||
):
|
||||
arr = sp.get_arrow(a).get_weight()
|
||||
if arr > 0:
|
||||
print(str(arr), end=' ')
|
||||
else:
|
||||
print('.', end=' ')
|
||||
|
||||
print(' | ', end=' ')
|
||||
|
||||
print('\n ' + ' ' * sites * 2, end='')
|
||||
|
||||
|
||||
for k in range(0, size + 1):
|
||||
if k < 9:
|
||||
print(k + 1, end=' ' + ' ' * sites * 2)
|
||||
else:
|
||||
print(k + 1, end=' ' + ' ' * sites * 2)
|
||||
|
||||
print('\n', end = "")
|
||||
"""
|
|
@ -0,0 +1,50 @@
|
|||
import model
|
||||
|
||||
sp = model.testmodel.get_states().get_space(0)
|
||||
size = model.testmodel.get_parameters().spaceparam.get_dimension().get_x()
|
||||
sites = int(model.testmodel.get_parameters().spaceparam.get_site_multiplicity())
|
||||
nb_arrows = int(model.testmodel.get_states().get_space(0).get_nb_arrows())
|
||||
|
||||
|
||||
print("\n space size = ", size, " nb de sites par cellule = ", sites,
|
||||
" nb total de flèches dans l'espace = ", nb_arrows)
|
||||
|
||||
print(' | ', end=' ')
|
||||
|
||||
# TODO Contrôles de cohérence des données
|
||||
# condition et arrow
|
||||
# 1) weight < weight_max (à définir)
|
||||
# 2) arrow.site < site_multiplicity
|
||||
# 3) arrow.x < space-param.dimension.x (idem autres axes)
|
||||
# condition
|
||||
# 1) parent <= condition.node_id max value (donc deux lectures)
|
||||
# 2) pas de node sans un node_parent_id
|
||||
|
||||
|
||||
for n in range(0, size + 1):
|
||||
for s in range(0, sites):
|
||||
arr = 0
|
||||
for a in range(0, nb_arrows):
|
||||
if (
|
||||
sp.get_arrow(a).get_coord("x") == n
|
||||
and sp.get_arrow(a).get_site() == s
|
||||
):
|
||||
arr = sp.get_arrow(a).get_weight()
|
||||
if arr > 0:
|
||||
print(str(arr), end=' ')
|
||||
else:
|
||||
print('.', end=' ')
|
||||
|
||||
print(' | ', end=' ')
|
||||
|
||||
print('\n ' + ' ' * sites * 2, end='')
|
||||
|
||||
|
||||
for k in range(0, size + 1):
|
||||
if k < 9:
|
||||
print(k + 1, end=' ' + ' ' * sites * 2)
|
||||
else:
|
||||
print(k + 1, end=' ' + ' ' * sites * 2)
|
||||
|
||||
print('\n', end = "")
|
||||
|
Loading…
Reference in New Issue