Skip to content

Commit

Permalink
ProgressReporter documentation was added
Browse files Browse the repository at this point in the history
  • Loading branch information
okolo committed Dec 6, 2023
1 parent 523a9f5 commit 5044ac4
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 0 deletions.
97 changes: 97 additions & 0 deletions doc/source/user_guide/ProgressReporter.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Progress reporting for long running tasks"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"from oda_api.api import ProgressReporter\n",
"import time"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Initialise ProgressReporter"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"pr = ProgressReporter()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Split your task into subtasks to enable progress report\n",
"use ProgressReporter.report_progress method to send progress reports"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"n_steps = 5\n",
"for step in range(n_steps):\n",
" stage = f\"simulation stage {step}\"\n",
" progress = 100 * step // n_steps\n",
" n_substeps = 10\n",
" \n",
" # optionally define subtasks\n",
" for substep in range(n_substeps):\n",
" substage = f\"subtask {substep}\"\n",
" subtask_progress = 100 * substep // n_substeps\n",
"\n",
" time.sleep(0.001) # replace this by actual calculation\n",
"\n",
" # report progress, optionally adding extra message\n",
" message='some message'\n",
" \n",
" pr.report_progress(stage=stage, progress=progress, substage=substage, subprogress=subtask_progress, message=message)"
]
}
],
"metadata": {
"kernel_info": {
"name": "python2"
},
"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.9.18"
},
"nteract": {
"version": "0.15.0"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
2 changes: 2 additions & 0 deletions doc/source/user_guide/tutorial_main.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ The following tutorial covers a large fraction of the code features. The example

Upload a product to the Product Gallery <UploadToGallery.ipynb>

Progress reporting for long running tasks <ProgressReporter.ipynb>

Examples of workflows <https://github.com/cdcihub/oda_api_benchmark>


Expand Down

0 comments on commit 5044ac4

Please sign in to comment.