feat: initial documentation of state machine

This commit is contained in:
Ferrari Martino Giordano
2024-03-20 14:28:44 +01:00
parent d5e129c057
commit 553ec62de1
3 changed files with 51 additions and 5 deletions
+6 -4
View File
@@ -7,6 +7,7 @@ from datetime import datetime
import common as doc
from doc_state import *
from doc_state_machine import doc_state_machine
def __doc_app_state__(state, tab=""):
@@ -20,7 +21,7 @@ def __doc_app_state__(state, tab=" │ "):
def __doc_application__(label, app):
mdapp = f'\n## Real-time application "{label[1:]}"\n\n'
mdapp = f'\n## Real-time application: "{label[1:]}"\n\n'
mdapp += f"Below are descrbed the states and threads of the real-time application {label[1:]}.\n"
mdapp += "\n"
@@ -44,7 +45,7 @@ def __doc_application__(label, app):
mdapp += "```\n"
for label, obj in states.items():
if label[0] == "+":
mdapp += f'\n### State "{label[1:]}"\n'
mdapp += f'\n### State: "{label[1:]}"\n'
mdapp += doc_state(label, obj, app)
return mdapp
@@ -71,7 +72,8 @@ def document(fname, args, config):
if obj["Class"] == "RealTimeApplication":
mddoc += __doc_application__(label, obj)
if obj["Class"] == "StateMachine":
mddoc += f'\n## State-Machine "{label[1:]}"'
mddoc += f'\n## State-Machine: "{label[1:]}"\n'
mddoc += doc_state_machine(label[1:], obj)
fpath = os.path.join(doc.path(), f"{fname}.md")
outpath = os.path.join(doc.path(), fname)
logging.info(f"Saving markdown: {fpath}")
@@ -79,7 +81,7 @@ def document(fname, args, config):
file.write(mddoc)
logging.info(f"Generating html: {outpath}.html")
os.system(
f"pandoc --css styling.css --resource-path={doc.path()} --embed-resource --to html5 -s {fpath} -o {outpath}.html"
f"pandoc --css pandoc/styling.css --resource-path={doc.path()} --embed-resource --to html5 -s {fpath} -o {outpath}.html"
)
logging.info(f"Generating pdf: {outpath}.pdf")
os.system(
+1 -1
View File
@@ -575,7 +575,7 @@ def __simple_edges__(edges, datasources):
def __state_simple_graph__(label, state, app):
graph = f"digraph {label[1:]}" + "{\n"
graph += "rankdir = LR;\n"
graph += 'node [shape=rect, style="rounded, filled", fillcolor=white];\n'
graph += 'node [shape=rect, style="filled", fillcolor=white];\n'
graph += f"label=<State: <B>{label[1:]}</B>>;\n"
graph += "fontsize=40;\n"
graph += "\n"
+44
View File
@@ -0,0 +1,44 @@
"""
State machine documentation.
"""
import logging
import os
import common
def doc_state_machine(name, obj):
"""Document state machine."""
graph = f"digraph {name}" + "{\n"
graph += "rankdir = LR;\n"
# graph += "layout = circo;\n"
graph += 'node [shape=egg, style="filled"];\n'
first = True
for key in obj:
if key[0] == "+":
state = key[1:]
ids = common.format_name(state)
graph += f" {ids} [label=<<B>{state}</B>>"
if first:
graph += ", fillcolor=lightblue"
first = False
graph += "];\n"
for x, y in obj[key].items():
if x[0] == "+":
for a, b in y.items():
if a == "NextState":
graph += (
f" {ids} -> {common.format_name(b)}[label={x[1:]}];\n"
)
graph += "\n}"
gpath = os.path.join(common.path(), name)
logging.info(f"Saving state machine graph: {gpath}.dot")
with open(gpath + ".dot", "w") as f:
f.write(graph)
logging.info(f"Converting state machine graph: {gpath}.svg")
os.system(f"dot -Tsvg -o{gpath}.svg {gpath}.dot")
return f"![{name}]({name}.svg)" + "{width=90%}\n"