First implementation of RecordGraph
Created RecordGraph class for testing record nodes.
This commit is contained in:
parent
178e035e0b
commit
1db41615aa
@ -2,10 +2,13 @@ FROM alpine
|
|||||||
RUN apk add --no-cache \
|
RUN apk add --no-cache \
|
||||||
yq \
|
yq \
|
||||||
python3 \
|
python3 \
|
||||||
|
py3-pip \
|
||||||
py3-yaml \
|
py3-yaml \
|
||||||
graphviz
|
graphviz
|
||||||
|
|
||||||
COPY run.sh /run.sh
|
COPY run.sh /run.sh
|
||||||
RUN chmod +x /run.sh
|
RUN chmod +x /run.sh
|
||||||
|
|
||||||
|
RUN pip3 install graphviz --break-system-packages # Fix?
|
||||||
|
|
||||||
CMD ["/run.sh"]
|
CMD ["/run.sh"]
|
||||||
|
|||||||
@ -4,8 +4,15 @@
|
|||||||
## Development
|
## Development
|
||||||
|
|
||||||
Start implementing graph.py with Graphviz Python library.
|
Start implementing graph.py with Graphviz Python library.
|
||||||
|
First created in new_graph.py, but will replace graph.py.
|
||||||
|
|
||||||
New architecture for creating dot. No clusters; one node contains one row table with each column for a person.
|
### Graph
|
||||||
|
|
||||||
|
Based on current cluster architecture.
|
||||||
|
|
||||||
|
### RecordGraph
|
||||||
|
|
||||||
|
New architecture for creating dot. No clusters; one node (record) contains one row table with each column for a person.
|
||||||
~~~
|
~~~
|
||||||
dot.node('<this node id>', fr'{(<node id>) <text>}|...')
|
dot.node('<this node id>', fr'{(<node id>) <text>}|...')
|
||||||
dot.edge('<this node id>:<other node id>', '<other node id>')
|
dot.edge('<this node id>:<other node id>', '<other node id>')
|
||||||
|
|||||||
@ -1,6 +1,14 @@
|
|||||||
import graphviz
|
import graphviz
|
||||||
|
|
||||||
class Graph:
|
# One cluster of nodes per block
|
||||||
|
class Graph():
|
||||||
|
def __init__(self):
|
||||||
|
self.dot = None
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# One node per block
|
||||||
|
class RecordGraph:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.dot = None
|
self.dot = None
|
||||||
self.edges = []
|
self.edges = []
|
||||||
@ -8,34 +16,39 @@ class Graph:
|
|||||||
|
|
||||||
def create_graph(self, config, data):
|
def create_graph(self, config, data):
|
||||||
# TODO: process config, use for graph init
|
# TODO: process config, use for graph init
|
||||||
self.dot = graphviz.Graph()
|
self.dot = graphviz.Graph('testgraph', graph_attr={'center': 'true', 'compound': 'true'}, node_attr={'shape': 'record'})
|
||||||
|
self.dot.format = 'svg' # TODO: move to export
|
||||||
|
|
||||||
blocks = data.get('blocks', [])
|
blocks = data.get('blocks', [])
|
||||||
for block in blocks:
|
for block in blocks:
|
||||||
self.node_counter += 1
|
self.node_counter += 1
|
||||||
|
|
||||||
# Create node id
|
# Create node id
|
||||||
node_id = f'f{self.node_counter}'
|
node_id = f'nr{self.node_counter}'
|
||||||
links = block.get('links', [])
|
links = block.get('links', [])
|
||||||
if len(links) > 0:
|
if len(links) > 0:
|
||||||
node_id = f'{links[0]}'
|
node_id = f'n{links[0]}'
|
||||||
|
|
||||||
# Create text table for node
|
# Create text table for node
|
||||||
texts = []
|
texts = []
|
||||||
for text in block.get('texts', []):
|
for text in block.get('texts', []):
|
||||||
person = text.get('text', '')
|
person = text.get('text', '').replace('\n', '\\n')
|
||||||
link = text.get('links', [])
|
link = text.get('links', [])
|
||||||
if len(link) > 0:
|
if len(link) > 0:
|
||||||
person = f'<{link[0]}> {person}'
|
person = fr'<l{link[0]}> {person}'
|
||||||
self.edges.append((link[0], f'{node_id}:{link[0]}'))
|
self.edges.append((fr'{node_id}:l{link[0]}', fr'n{link[0]}'))
|
||||||
texts.append(person)
|
texts.append(person)
|
||||||
|
|
||||||
# Add node
|
# Add node
|
||||||
table = "|".join(texts)
|
table = r"|".join(texts)
|
||||||
self.dot.node(node_id, fr'{table}')
|
self.dot.node(node_id, table)
|
||||||
|
|
||||||
# Add edges
|
# Add edges
|
||||||
self.dot.edges(self.edges)
|
self.dot.edges(self.edges)
|
||||||
|
|
||||||
|
def export_graph(self, out_dir):
|
||||||
|
self.dot.render(directory=out_dir)
|
||||||
|
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.dot.source
|
return self.dot.source
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
from db import load_data, load_config
|
from db import load_data, load_config
|
||||||
from graph import Graph
|
from graph import Graph
|
||||||
|
import new_graph as ng
|
||||||
import os
|
import os
|
||||||
|
|
||||||
DATA_DIR="/data"
|
DATA_DIR="/data"
|
||||||
@ -20,6 +20,13 @@ def main():
|
|||||||
graph.set_config(config)
|
graph.set_config(config)
|
||||||
graph.process_blocks(data)
|
graph.process_blocks(data)
|
||||||
graph.build_dot()
|
graph.build_dot()
|
||||||
|
|
||||||
|
# Test new dot generation
|
||||||
|
new_graph = ng.RecordGraph()
|
||||||
|
new_graph.create_graph(config, data)
|
||||||
|
#print(new_graph)
|
||||||
|
new_graph.export_graph(DATA_DIR)
|
||||||
|
|
||||||
# Use the base name of the YAML file (without extension) as the output name
|
# Use the base name of the YAML file (without extension) as the output name
|
||||||
base_name = os.path.splitext(yaml_file)[0]
|
base_name = os.path.splitext(yaml_file)[0]
|
||||||
dot_file = os.path.join(DATA_DIR, f"{base_name}.gv")
|
dot_file = os.path.join(DATA_DIR, f"{base_name}.gv")
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
Binary file not shown.
File diff suppressed because it is too large
Load Diff
|
Before Width: | Height: | Size: 272 KiB After Width: | Height: | Size: 272 KiB |
Loading…
x
Reference in New Issue
Block a user