From 2cf2a15bce5654581b85fc6b33e5c81b984ce0b6 Mon Sep 17 00:00:00 2001 From: Quek Ching Yee Date: Sun, 3 Nov 2024 11:54:47 +0800 Subject: [PATCH] docs: allow jupyter notebook --- docs/gettingstarted/demo/workflow.ipynb | 241 ++++++++++++++++++++++++ docs/requirements.txt | 1 + mkdocs.yml | 4 +- pyproject.toml | 3 +- 4 files changed, 247 insertions(+), 2 deletions(-) create mode 100644 docs/gettingstarted/demo/workflow.ipynb diff --git a/docs/gettingstarted/demo/workflow.ipynb b/docs/gettingstarted/demo/workflow.ipynb new file mode 100644 index 00000000..3e35d240 --- /dev/null +++ b/docs/gettingstarted/demo/workflow.ipynb @@ -0,0 +1,241 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# 📋 Workflow Demonstration\n", + "\n", + "There are existing implementations of workflows to showcase how `bigtree` can be used!" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "vscode": { + "languageId": "plaintext" + } + }, + "source": [ + "## To Do Application\n", + "There are functions to:\n", + "\n", + "- Add or remove list to To-Do application\n", + "- Add or remove item to list, default list is the 'General' list\n", + "- Prioritize a list/item by reordering them as first list/item\n", + "- Save and import To-Do application to and from an external JSON file\n", + "- Show To-Do application, which prints tree to console\n" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "To Do App\n", + "├── School\n", + "│ └── Homework 1\n", + "├── Groceries\n", + "│ ├── Milk [description=Urgent]\n", + "│ └── Bread [description=Urgent]\n", + "└── General\n", + " └── Cook\n" + ] + } + ], + "source": [ + "from bigtree import AppToDo\n", + "\n", + "app = AppToDo(\"To Do App\")\n", + "app.add_item(item_name=\"Homework 1\", list_name=\"School\")\n", + "app.add_item(item_name=[\"Milk\", \"Bread\"], list_name=\"Groceries\", description=\"Urgent\")\n", + "app.add_item(item_name=\"Cook\")\n", + "app.show()" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [], + "source": [ + "app.save(\"list.json\")\n", + "app2 = AppToDo.load(\"list.json\")" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Calendar Application\n", + "\n", + "There are functions to:\n", + "\n", + "- Add or remove event from Calendar\n", + "- Find event by name, or name and date\n", + "- Display calendar, which prints events to console\n", + "- Export calendar to pandas DataFrame" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "My Calendar\n", + "2023-01-01 00:00:00 - Dinner (budget: 20)\n", + "2023-01-01 18:00:00 - Gym\n", + "2023-01-02 18:00:00 - Gym\n" + ] + } + ], + "source": [ + "import datetime as dt\n", + "from bigtree import Calendar\n", + "\n", + "calendar = Calendar(\"My Calendar\")\n", + "calendar.add_event(\"Gym\", \"2023-01-01 18:00\")\n", + "calendar.add_event(\"Dinner\", \"2023-01-01\", date_format=\"%Y-%m-%d\", budget=20)\n", + "calendar.add_event(\"Gym\", \"2023-01-02 18:00\")\n", + "calendar.show()" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "2023-01-01 18:00:00 - Gym\n", + "2023-01-02 18:00:00 - Gym\n" + ] + } + ], + "source": [ + "calendar.find_event(\"Gym\")" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "My Calendar\n", + "2023-01-01 00:00:00 - Dinner (budget: 20)\n", + "2023-01-02 18:00:00 - Gym\n" + ] + } + ], + "source": [ + "calendar.delete_event(\"Gym\", dt.date(2023, 1, 1))\n", + "calendar.show()" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
pathnamedatetimebudget
0/My Calendar/2023/01/01/DinnerDinner2023-01-0100:00:0020.0
1/My Calendar/2023/01/02/GymGym2023-01-0218:00:00NaN
\n", + "
" + ], + "text/plain": [ + " path name date time budget\n", + "0 /My Calendar/2023/01/01/Dinner Dinner 2023-01-01 00:00:00 20.0\n", + "1 /My Calendar/2023/01/02/Gym Gym 2023-01-02 18:00:00 NaN" + ] + }, + "execution_count": 6, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "data_calendar = calendar.to_dataframe()\n", + "data_calendar" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "bigtree", + "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.14" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/docs/requirements.txt b/docs/requirements.txt index 4d502d47..67681b8d 100644 --- a/docs/requirements.txt +++ b/docs/requirements.txt @@ -3,6 +3,7 @@ IPython mdx_truly_sane_lists==1.3 mkdocs==1.5.3 mkdocs-glightbox==0.3.7 +mkdocs-jupyter mkdocs-material[imaging]==9.5.17 mkdocstrings[python]>=0.25.0 # griffe.collections error pandas diff --git a/mkdocs.yml b/mkdocs.yml index 42fd33fa..f061cdf5 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -23,7 +23,7 @@ nav: - gettingstarted/demo/tree.md - gettingstarted/demo/binarytree.md - gettingstarted/demo/dag.md - - gettingstarted/demo/workflow.md + - gettingstarted/demo/workflow.ipynb - Resources: - gettingstarted/resources/articles.md - gettingstarted/resources/glossary.md @@ -93,6 +93,8 @@ theme: plugins: - glightbox # expand images + - mkdocs-jupyter + include_source: True - search - social: cards_layout_options: diff --git a/pyproject.toml b/pyproject.toml index 5c2fe40e..a08e43de 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -101,10 +101,11 @@ dependencies = [ "docstr-coverage", "IPython", "mkdocs==1.5.3", + "mkdocs-glightbox", + "mkdocs-jupyter", "mkdocs-material[imaging]==9.5.17", "mdx_truly_sane_lists==1.3", "mkdocstrings[python]==0.24.0", - "mkdocs-glightbox", "requests", "termynal==0.11.1", ]