Skip to content

Commit

Permalink
Pair report.py with note book and give environment specific root vari…
Browse files Browse the repository at this point in the history
…ables so can test report generation locally
  • Loading branch information
HamishBrownPFR committed Jun 5, 2024
1 parent f429a50 commit 9677c75
Show file tree
Hide file tree
Showing 2 changed files with 128 additions and 6 deletions.
88 changes: 88 additions & 0 deletions TestGraphs/report.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 6,
"id": "c6317285-bf98-489f-a858-44925c83f9c3",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"import os\n",
"import aspose.words as aw\n",
"import os.path as osp\n",
"from glob import glob\n",
"from pathlib import Path\n",
"\n",
"def main():\n",
" try: \n",
" if os.environ[\"GITHUB_WORKSPACE\"] != None:\n",
" root = os.environ[\"GITHUB_WORKSPACE\"]\n",
" inPath = os.path.join(root, \"TestGraphs\", \"Outputs\")\n",
" \n",
" except: \n",
" rootfrags = os.path.abspath('WS2.py').split(\"\\\\\")\n",
" root = \"\"\n",
" for d in rootfrags:\n",
" if d == \"FieldNBalance\":\n",
" break\n",
" else:\n",
" root += d + \"\\\\\"\n",
" inPath = os.path.join(root,\"FieldNBalance\",\"TestGraphs\", \"Outputs\") \n",
" \n",
" if not osp.isdir(inPath):\n",
" raise FileNotFoundError(f\"Directory does not exist: {inPath}\")\n",
" \n",
" imgs = glob(osp.join(inPath, \"*.png\"))\n",
" if len(imgs) == 0:\n",
" raise FileNotFoundError(f\"No images found in directory: {inPath}\")\n",
" \n",
" doc = aw.Document()\n",
" builder = aw.DocumentBuilder(doc)\n",
"\n",
" for img in imgs:\n",
" builder.insert_image(img)\n",
"\n",
" outdir = \"html\"\n",
" Path(outdir).mkdir(parents=True, exist_ok=True) \n",
" doc.save(osp.join(outdir, \"index.html\"))\n",
"\n",
"if __name__ == \"__main__\":\n",
" main()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "f3ac9d83-1a3d-4c2f-b329-0e91215fc21f",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"jupytext": {
"formats": "ipynb,py:light"
},
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.13"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
46 changes: 40 additions & 6 deletions TestGraphs/report.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,47 @@
# ---
# jupyter:
# jupytext:
# formats: ipynb,py:light
# text_representation:
# extension: .py
# format_name: light
# format_version: '1.5'
# jupytext_version: 1.15.0
# kernelspec:
# display_name: Python 3 (ipykernel)
# language: python
# name: python3
# ---

# +
import os
import aspose.words as aw
import os.path as osp
from glob import glob
from pathlib import Path

def main():
img_path = osp.join("TestGraphs", "Outputs")
if not osp.isdir(img_path):
raise FileNotFoundError(f"Directory does not exist: {img_path}")
try:
if os.environ["GITHUB_WORKSPACE"] != None:
root = os.environ["GITHUB_WORKSPACE"]
inPath = os.path.join(root, "TestGraphs", "Outputs")

except:
rootfrags = os.path.abspath('WS2.py').split("\\")
root = ""
for d in rootfrags:
if d == "FieldNBalance":
break
else:
root += d + "\\"
inPath = os.path.join(root,"FieldNBalance","TestGraphs", "Outputs")

if not osp.isdir(inPath):
raise FileNotFoundError(f"Directory does not exist: {inPath}")

imgs = glob(osp.join(img_path, "*.png"))
imgs = glob(osp.join(inPath, "*.png"))
if len(imgs) == 0:
raise FileNotFoundError(f"No images found in directory: {img_path}")
raise FileNotFoundError(f"No images found in directory: {inPath}")

doc = aw.Document()
builder = aw.DocumentBuilder(doc)
Expand All @@ -23,4 +54,7 @@ def main():
doc.save(osp.join(outdir, "index.html"))

if __name__ == "__main__":
main()
main()
# -


0 comments on commit 9677c75

Please sign in to comment.