Skip to content

Commit

Permalink
adding more markdown form elements
Browse files Browse the repository at this point in the history
  • Loading branch information
hyakuhei committed Dec 28, 2021
1 parent 7d60221 commit 336c377
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 36 deletions.
48 changes: 25 additions & 23 deletions examples/report.md
Original file line number Diff line number Diff line change
@@ -1,29 +1,31 @@
## User lists books
![User lists books](output/User%20lists%20books.png)
| From | To | Data |
| ---- | -- | ---- |
| client | Nginx | GET /books |
| Nginx | Database | All book titles |
| Database | Nginx | Titles |
| Nginx | client | Books |
| Id | From | To | Data |
| -- | ---- | -- | ---- |
| 1 | client | Nginx | GET /books |
| 2 | Nginx | Database | All book titles |
| 3 | Database | Nginx | Titles |
| 4 | Nginx | client | Books |
## User login
![User login](output/User%20login.png)
| From | To | Data |
| ---- | -- | ---- |
| client | Nginx | GET /login |
| Nginx | client | 302 Google Oauth |
| client | GoogleOauth | Request Token |
| GoogleOauth | client | Token |
| client | Nginx | Token |
| Nginx | client | Cookie |
| Id | From | To | Data |
| -- | ---- | -- | ---- |
| 1 | client | Nginx | GET /login |
| 2 | Nginx | client | 302 Google Oauth |
| 3 | client | GoogleOauth | Request Token |
| 4 | GoogleOauth | client | Token |
| 5 | client | Nginx | Token |
| 6 | Nginx | client | Cookie |
## User buys book
![User buys book](output/User%20buys%20book.png)
| From | To | Data |
| ---- | -- | ---- |
| client | Nginx | POST /buy?bookid=3 |
| Nginx | Ordering | User X buys book3 |
| Ordering | Warehouse | Start picking book3 for customer X |
| Warehouse | Database | Get address for customer X |
| Database | Warehouse | Customer address |
| Warehouse | Shipping | Prepare invoice for shipping to address |
| Shipping | DHL | Ship Order |
| Id | From | To | Data |
| -- | ---- | -- | ---- |
| 1 | client | Nginx | POST /buy?bookid=3 |
| 2 | Nginx | Ordering | User X buys book3 |
| 3 | Ordering | Warehouse | Start picking book3 for customer X |
| 4 | Warehouse | Database | Get address for customer X |
| 5 | Database | Warehouse | Customer address |
| 6 | Warehouse | Shipping | Prepare invoice for shipping to address |
| 7 | Shipping | DHL | Ship Order |
## High Level Architecture
![High Level Architecture](output/High%20Level%20Architecture.png)
33 changes: 20 additions & 13 deletions src/jtg.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def drawRecursiveBoundaries(doc, boundaryKey, graph, drawnBoundaries=None):


# TODO: Smartlinks
def genGraph(doc, sceneName, compoundLinks=False, linkCounters=True):
def genGraph(doc, sceneName, compoundLinks=False, linkCounters=True, printLabels=True):

sceneToDraw = None
for sceneDict in doc["scenes"]:
Expand Down Expand Up @@ -67,13 +67,17 @@ def genGraph(doc, sceneName, compoundLinks=False, linkCounters=True):
drawnActors[actor] = graph.newNode(actor, parent=parentBoundary)

linkCounter += 1
flowLabel = (
flow["data"] if linkCounters == False else f"{linkCounter} {flow['data']}"
)

flowLabel = ""
if linkCounters == True:
flowLabel = f"{linkCounter}."

if printLabels == True:
flowLabel = flowLabel + flow["data"]

link = graph.newLink(
drawnActors[flow["from"]], drawnActors[flow["to"]], label=flowLabel
)
# graph.styleApply("Flow", link)

return graph

Expand Down Expand Up @@ -110,7 +114,7 @@ def prepDoc(doc):
path = search(doc["boundaries"], actor)
return doc

def main(generateArchDiagram=True,markdown=False):
def main(generateArchDiagram=True, markdown=False, printLabels=False):
doc = json.loads(sys.stdin.read())
doc = prepDoc(doc)
graph = None
Expand All @@ -121,7 +125,7 @@ def main(generateArchDiagram=True,markdown=False):

for scene in doc["scenes"]:
for sceneName in scene.keys():
graph = genGraph(doc, sceneName)
graph = genGraph(doc, sceneName, printLabels=printLabels)

fileName = f"output/{sceneName}"
with open(f"{fileName}.dot", "w") as f:
Expand All @@ -134,15 +138,18 @@ def main(generateArchDiagram=True,markdown=False):
["dot", "-s100", "-Tpng", f"{fileName}.dot", f"-o{fileName}.png"], shell=False
)

if markdown and sceneName != ARCH:
if markdown:
print(f"## {sceneName}")
print(f"![{sceneName}]({fileName.replace(' ', '%20')}.png)")
print("| From | To | Data |")
print("| ---- | -- | ---- |")
for flow in scene[sceneName]:
print(f"| {flow['from']} | {flow['to']} | {flow['data']} |")
if sceneName != ARCH:
print("| Id | From | To | Data |")
print("| -- | ---- | -- | ---- |")
ctr = 1
for flow in scene[sceneName]:
print(f"| {ctr} | {flow['from']} | {flow['to']} | {flow['data']} |")
ctr+=1


if __name__ == "__main__":
#TODO argument handling
main(generateArchDiagram=True, markdown=True)
main(generateArchDiagram=True, markdown=True, printLabels=False)

0 comments on commit 336c377

Please sign in to comment.