{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": true,
    "ExecuteTime": {
     "start_time": "2023-04-10T08:41:02.765261Z",
     "end_time": "2023-04-10T08:41:03.084831Z"
    }
   },
   "outputs": [],
   "source": [
    "import sys\n",
    "\n",
    "import pandas as pd\n",
    "\n",
    "sys.path.append('../../src')\n",
    "from pjplan import Task, WBS, DefaultScheduler, Resource"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "outputs": [],
   "source": [
    "with WBS() as prj:\n",
    "    prj // Task(1, 'Task 1', estimate=40, resource='Tester', attr=1)\n",
    "    prj // Task(2, 'Task 2', predecessors=[prj[1]], estimate=20, resource='Tester')\n",
    "    with prj // Task(3, 'Task 3') as t:\n",
    "        t // Task(4, 'Task 4', predecessors=[prj[2]], estimate=100, resource='Developer')\n",
    "        t // Task(5, 'Task 5', predecessors=[prj[2]], estimate=50, resource='Developer')\n",
    "    with prj // Task(6, 'Task 6') as t:\n",
    "        t // Task(7, 'Task 7', predecessors=[prj[5]], estimate=16, resource='Developer')\n",
    "        t // Task(8, 'Task 9', predecessors=[prj[7]], estimate=16, resource='Developer')"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "start_time": "2023-04-10T08:41:03.087828Z",
     "end_time": "2023-04-10T08:41:03.099832Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "outputs": [
    {
     "data": {
      "text/plain": "   id    name   resource start   end  milestone  attr\n0   1  Task 1     Tester  None  None      False   1.0\n1   2  Task 2     Tester  None  None      False   NaN\n2   3  Task 3       None  None  None      False   NaN\n3   4  Task 4  Developer  None  None      False   NaN\n4   5  Task 5  Developer  None  None      False   NaN\n5   6  Task 6       None  None  None      False   NaN\n6   7  Task 7  Developer  None  None      False   NaN\n7   8  Task 9  Developer  None  None      False   NaN",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>id</th>\n      <th>name</th>\n      <th>resource</th>\n      <th>start</th>\n      <th>end</th>\n      <th>milestone</th>\n      <th>attr</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>1</td>\n      <td>Task 1</td>\n      <td>Tester</td>\n      <td>None</td>\n      <td>None</td>\n      <td>False</td>\n      <td>1.0</td>\n    </tr>\n    <tr>\n      <th>1</th>\n      <td>2</td>\n      <td>Task 2</td>\n      <td>Tester</td>\n      <td>None</td>\n      <td>None</td>\n      <td>False</td>\n      <td>NaN</td>\n    </tr>\n    <tr>\n      <th>2</th>\n      <td>3</td>\n      <td>Task 3</td>\n      <td>None</td>\n      <td>None</td>\n      <td>None</td>\n      <td>False</td>\n      <td>NaN</td>\n    </tr>\n    <tr>\n      <th>3</th>\n      <td>4</td>\n      <td>Task 4</td>\n      <td>Developer</td>\n      <td>None</td>\n      <td>None</td>\n      <td>False</td>\n      <td>NaN</td>\n    </tr>\n    <tr>\n      <th>4</th>\n      <td>5</td>\n      <td>Task 5</td>\n      <td>Developer</td>\n      <td>None</td>\n      <td>None</td>\n      <td>False</td>\n      <td>NaN</td>\n    </tr>\n    <tr>\n      <th>5</th>\n      <td>6</td>\n      <td>Task 6</td>\n      <td>None</td>\n      <td>None</td>\n      <td>None</td>\n      <td>False</td>\n      <td>NaN</td>\n    </tr>\n    <tr>\n      <th>6</th>\n      <td>7</td>\n      <td>Task 7</td>\n      <td>Developer</td>\n      <td>None</td>\n      <td>None</td>\n      <td>False</td>\n      <td>NaN</td>\n    </tr>\n    <tr>\n      <th>7</th>\n      <td>8</td>\n      <td>Task 9</td>\n      <td>Developer</td>\n      <td>None</td>\n      <td>None</td>\n      <td>False</td>\n      <td>NaN</td>\n    </tr>\n  </tbody>\n</table>\n</div>"
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Convert wbs to pandas DataFrame\n",
    "df = pd.DataFrame([t.to_dict() for t in prj.tasks])\n",
    "df"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "start_time": "2023-04-10T08:41:03.101831Z",
     "end_time": "2023-04-10T08:41:03.129831Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "outputs": [
    {
     "data": {
      "text/plain": "     resource       date  task_id  units\n0      Tester 2023-04-10        1      8\n1      Tester 2023-04-11        1      8\n2      Tester 2023-04-12        1      8\n3      Tester 2023-04-13        1      8\n4      Tester 2023-04-14        1      8\n5      Tester 2023-04-17        2      8\n6      Tester 2023-04-18        2      8\n7      Tester 2023-04-19        2      4\n8   Developer 2023-04-19        4      8\n9   Developer 2023-04-20        4      8\n10  Developer 2023-04-21        4      8\n11  Developer 2023-04-24        4      8\n12  Developer 2023-04-25        4      8\n13  Developer 2023-04-26        4      8\n14  Developer 2023-04-27        4      8\n15  Developer 2023-04-28        4      8\n16  Developer 2023-05-01        4      8\n17  Developer 2023-05-02        4      8\n18  Developer 2023-05-03        4      8\n19  Developer 2023-05-04        4      8\n20  Developer 2023-05-05        4      4\n21  Developer 2023-05-05        5      4\n22  Developer 2023-05-08        5      8\n23  Developer 2023-05-09        5      8\n24  Developer 2023-05-10        5      8\n25  Developer 2023-05-11        5      8\n26  Developer 2023-05-12        5      8\n27  Developer 2023-05-15        5      6\n28  Developer 2023-05-15        7      2\n29  Developer 2023-05-16        7      8\n30  Developer 2023-05-17        7      6\n31  Developer 2023-05-17        8      2\n32  Developer 2023-05-18        8      8\n33  Developer 2023-05-19        8      6",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>resource</th>\n      <th>date</th>\n      <th>task_id</th>\n      <th>units</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>Tester</td>\n      <td>2023-04-10</td>\n      <td>1</td>\n      <td>8</td>\n    </tr>\n    <tr>\n      <th>1</th>\n      <td>Tester</td>\n      <td>2023-04-11</td>\n      <td>1</td>\n      <td>8</td>\n    </tr>\n    <tr>\n      <th>2</th>\n      <td>Tester</td>\n      <td>2023-04-12</td>\n      <td>1</td>\n      <td>8</td>\n    </tr>\n    <tr>\n      <th>3</th>\n      <td>Tester</td>\n      <td>2023-04-13</td>\n      <td>1</td>\n      <td>8</td>\n    </tr>\n    <tr>\n      <th>4</th>\n      <td>Tester</td>\n      <td>2023-04-14</td>\n      <td>1</td>\n      <td>8</td>\n    </tr>\n    <tr>\n      <th>5</th>\n      <td>Tester</td>\n      <td>2023-04-17</td>\n      <td>2</td>\n      <td>8</td>\n    </tr>\n    <tr>\n      <th>6</th>\n      <td>Tester</td>\n      <td>2023-04-18</td>\n      <td>2</td>\n      <td>8</td>\n    </tr>\n    <tr>\n      <th>7</th>\n      <td>Tester</td>\n      <td>2023-04-19</td>\n      <td>2</td>\n      <td>4</td>\n    </tr>\n    <tr>\n      <th>8</th>\n      <td>Developer</td>\n      <td>2023-04-19</td>\n      <td>4</td>\n      <td>8</td>\n    </tr>\n    <tr>\n      <th>9</th>\n      <td>Developer</td>\n      <td>2023-04-20</td>\n      <td>4</td>\n      <td>8</td>\n    </tr>\n    <tr>\n      <th>10</th>\n      <td>Developer</td>\n      <td>2023-04-21</td>\n      <td>4</td>\n      <td>8</td>\n    </tr>\n    <tr>\n      <th>11</th>\n      <td>Developer</td>\n      <td>2023-04-24</td>\n      <td>4</td>\n      <td>8</td>\n    </tr>\n    <tr>\n      <th>12</th>\n      <td>Developer</td>\n      <td>2023-04-25</td>\n      <td>4</td>\n      <td>8</td>\n    </tr>\n    <tr>\n      <th>13</th>\n      <td>Developer</td>\n      <td>2023-04-26</td>\n      <td>4</td>\n      <td>8</td>\n    </tr>\n    <tr>\n      <th>14</th>\n      <td>Developer</td>\n      <td>2023-04-27</td>\n      <td>4</td>\n      <td>8</td>\n    </tr>\n    <tr>\n      <th>15</th>\n      <td>Developer</td>\n      <td>2023-04-28</td>\n      <td>4</td>\n      <td>8</td>\n    </tr>\n    <tr>\n      <th>16</th>\n      <td>Developer</td>\n      <td>2023-05-01</td>\n      <td>4</td>\n      <td>8</td>\n    </tr>\n    <tr>\n      <th>17</th>\n      <td>Developer</td>\n      <td>2023-05-02</td>\n      <td>4</td>\n      <td>8</td>\n    </tr>\n    <tr>\n      <th>18</th>\n      <td>Developer</td>\n      <td>2023-05-03</td>\n      <td>4</td>\n      <td>8</td>\n    </tr>\n    <tr>\n      <th>19</th>\n      <td>Developer</td>\n      <td>2023-05-04</td>\n      <td>4</td>\n      <td>8</td>\n    </tr>\n    <tr>\n      <th>20</th>\n      <td>Developer</td>\n      <td>2023-05-05</td>\n      <td>4</td>\n      <td>4</td>\n    </tr>\n    <tr>\n      <th>21</th>\n      <td>Developer</td>\n      <td>2023-05-05</td>\n      <td>5</td>\n      <td>4</td>\n    </tr>\n    <tr>\n      <th>22</th>\n      <td>Developer</td>\n      <td>2023-05-08</td>\n      <td>5</td>\n      <td>8</td>\n    </tr>\n    <tr>\n      <th>23</th>\n      <td>Developer</td>\n      <td>2023-05-09</td>\n      <td>5</td>\n      <td>8</td>\n    </tr>\n    <tr>\n      <th>24</th>\n      <td>Developer</td>\n      <td>2023-05-10</td>\n      <td>5</td>\n      <td>8</td>\n    </tr>\n    <tr>\n      <th>25</th>\n      <td>Developer</td>\n      <td>2023-05-11</td>\n      <td>5</td>\n      <td>8</td>\n    </tr>\n    <tr>\n      <th>26</th>\n      <td>Developer</td>\n      <td>2023-05-12</td>\n      <td>5</td>\n      <td>8</td>\n    </tr>\n    <tr>\n      <th>27</th>\n      <td>Developer</td>\n      <td>2023-05-15</td>\n      <td>5</td>\n      <td>6</td>\n    </tr>\n    <tr>\n      <th>28</th>\n      <td>Developer</td>\n      <td>2023-05-15</td>\n      <td>7</td>\n      <td>2</td>\n    </tr>\n    <tr>\n      <th>29</th>\n      <td>Developer</td>\n      <td>2023-05-16</td>\n      <td>7</td>\n      <td>8</td>\n    </tr>\n    <tr>\n      <th>30</th>\n      <td>Developer</td>\n      <td>2023-05-17</td>\n      <td>7</td>\n      <td>6</td>\n    </tr>\n    <tr>\n      <th>31</th>\n      <td>Developer</td>\n      <td>2023-05-17</td>\n      <td>8</td>\n      <td>2</td>\n    </tr>\n    <tr>\n      <th>32</th>\n      <td>Developer</td>\n      <td>2023-05-18</td>\n      <td>8</td>\n      <td>8</td>\n    </tr>\n    <tr>\n      <th>33</th>\n      <td>Developer</td>\n      <td>2023-05-19</td>\n      <td>8</td>\n      <td>6</td>\n    </tr>\n  </tbody>\n</table>\n</div>"
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Let's build plan\n",
    "schedule = DefaultScheduler(resources=[Resource(name='Tester'), Resource(name='Developer')]).calc(prj)\n",
    "\n",
    "# Convert usage to DataFrame\n",
    "pd.DataFrame(schedule.resource_usage.rows())"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "start_time": "2023-04-10T08:41:03.117830Z",
     "end_time": "2023-04-10T08:41:03.173834Z"
    }
   }
  }
 ],
 "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
}
