{
 "cells": [
  {
   "cell_type": "markdown",
   "source": [
    "# Getting started"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": true,
    "ExecuteTime": {
     "start_time": "2023-04-15T17:35:25.835323Z",
     "end_time": "2023-04-15T17:35:25.861260Z"
    }
   },
   "outputs": [],
   "source": [
    "import sys\n",
    "from datetime import datetime\n",
    "sys.path.append('../../../src')\n",
    "from pjplan import Task, ForwardScheduler, WBS, MermaidGantt, WeeklyCalendar, Resource, MermaidNetwork"
   ]
  },
  {
   "cell_type": "markdown",
   "source": [
    "Let's define simple project WBS:"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "outputs": [],
   "source": [
    "with WBS() as prj:\n",
    "  prj // Task(1, 'Task 1', estimate=40, resource='Developer')\n",
    "  prj // Task(2, 'Task 2', predecessors=[prj[1]], estimate=20, resource='Developer')\n",
    "  with prj // Task(3, 'Task 3') as t3:\n",
    "    t3 // Task(4, 'Task 4', predecessors=[prj[2]], estimate=100, resource='Tester')\n",
    "    t3 // Task(5, 'Task 5', predecessors=[prj[2]], estimate=50, resource='Tester')"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "start_time": "2023-04-15T17:35:25.863261Z",
     "end_time": "2023-04-15T17:35:25.874232Z"
    }
   }
  },
  {
   "cell_type": "markdown",
   "source": [
    "Let's define resources:"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "outputs": [],
   "source": [
    "work_calendar = WeeklyCalendar(days=[0,1,2,3,4], units_per_day=8)\n",
    "\n",
    "developer = Resource(name='Developer', calendar=work_calendar)\n",
    "tester = Resource(name='Tester', calendar=work_calendar)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "start_time": "2023-04-15T17:35:25.876232Z",
     "end_time": "2023-04-15T17:35:25.896792Z"
    }
   }
  },
  {
   "cell_type": "markdown",
   "source": [
    "Now we can create schedule for our project:"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "outputs": [],
   "source": [
    "schedule = ForwardScheduler(\n",
    "    start=datetime.now(),\n",
    "    resources=[developer, tester]\n",
    ").calc(prj)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "start_time": "2023-04-15T17:35:25.891269Z",
     "end_time": "2023-04-15T17:35:25.907303Z"
    }
   }
  },
  {
   "cell_type": "markdown",
   "source": [
    "and visualise it as Mermaid Gantt:"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "outputs": [
    {
     "data": {
      "text/plain": "<pjplan.viz.mermaid.gantt.MermaidGantt at 0x1b60959e350>",
      "text/html": "<iframe srcdoc=\"&lt;html&gt;\n&lt;meta charset=&quot;UTF-8&quot;&gt;\n&lt;body&gt;\n&lt;style&gt;\n\n&lt;/style&gt;\n\n&lt;div class=&quot;mermaid&quot;&gt;\ngantt\n  dateFormat DD.MM.YYYY HH:mm\n  tickInterval 10day\n    Task 1:  id_1, 17.04.2023 00:00, 22.04.2023 00:00\n    Task 2:  id_2, 24.04.2023 00:00, 26.04.2023 12:00\n    Task 3:  id_3, 26.04.2023 00:00, 22.05.2023 18:00\n    Task 4:  id_4, 26.04.2023 00:00, 12.05.2023 12:00\n    Task 5:  id_5, 12.05.2023 12:00, 22.05.2023 18:00\n\n&lt;/div&gt;\n\n&lt;script src=&quot;https://cdn.jsdelivr.net/npm/mermaid/dist/mermaid.min.js&quot;&gt;&lt;/script&gt;\n&lt;script&gt;\n    mermaid.ganttConfig = {\n        mirrorActor: true\n    }\n    mermaid.initialize({\n        startOnLoad: true\n    });\n&lt;/script&gt;\n&lt;/body&gt;\n&lt;/html&gt;\" width=\"100%\" height=\"300\" style=\"border:none !important;\" allowfullscreen webkitallowfullscreen mozallowfullscreen></iframe>"
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "MermaidGantt(schedule.schedule, tick_interval=\"10day\")"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "start_time": "2023-04-15T17:36:30.205955Z",
     "end_time": "2023-04-15T17:36:30.221956Z"
    }
   }
  },
  {
   "cell_type": "markdown",
   "source": [
    "and Network diagram:"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "outputs": [
    {
     "data": {
      "text/plain": "<pjplan.viz.mermaid.network.MermaidNetwork at 0x1b6095234f0>",
      "text/html": "<iframe srcdoc=\"&lt;html&gt;\n&lt;meta charset=&quot;UTF-8&quot;&gt;\n&lt;body&gt;\n&lt;div class=&quot;mermaid&quot;&gt;\nflowchart LR\n  0((Start)) --&gt; 1{{Task 1}}\n  1{{Task 1}} --&gt; 2{{Task 2}}\n  0((Start)) --&gt; 3{{Task 3}}\n  2{{Task 2}} --&gt; 4{{Task 4}}\n  2{{Task 2}} --&gt; 5{{Task 5}}\n\n&lt;/div&gt;\n\n&lt;script src=&quot;https://cdn.jsdelivr.net/npm/mermaid/dist/mermaid.min.js&quot;&gt;&lt;/script&gt;\n&lt;script&gt;\n    mermaid.ganttConfig = {\n        mirrorActor: true\n    }\n    mermaid.initialize({\n        startOnLoad: true\n    });\n&lt;/script&gt;\n&lt;/body&gt;\n&lt;/html&gt;\" width=\"100%\" height=\"300\" style=\"border:none !important;\" allowfullscreen webkitallowfullscreen mozallowfullscreen></iframe>"
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "MermaidNetwork(schedule.schedule)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "start_time": "2023-04-15T17:35:25.922302Z",
     "end_time": "2023-04-15T17:35:25.945171Z"
    }
   }
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
