{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import numpy as np\n",
    "from datetime import datetime, timedelta"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "#campaigns\n",
    "init_date = datetime.now()\n",
    "\n",
    "campaigns = {1:{'name': 'ABC field test',\n",
    "                'multiplier': 2.5,\n",
    "                'min_raise': 984.0, \n",
    "                'max_raise': 1500.0, \n",
    "                'cutoff_date': init_date+timedelta(days=365*2/12.0),\n",
    "                'expected_time': timedelta(days=365*8/12.0)},\n",
    "             2:{'name': 'Giveth field test',\n",
    "                'multiplier': 2.0,\n",
    "                'min_raise': 726.0, \n",
    "                'max_raise': 1500.0, \n",
    "                'cutoff_date': init_date+timedelta(days=365*4/12),\n",
    "                'expected_time': timedelta(days=365*6/12.0)},\n",
    "             3:{'name': 'CV field test',\n",
    "                'multiplier': 1.5,\n",
    "                'min_raise': 1140.0, \n",
    "                'max_raise': 2000.0, \n",
    "                'cutoff_date': init_date+timedelta(days=365*6/12),\n",
    "                'expected_time': timedelta(days=365*12/12)},\n",
    "             4:{'name': 'Analytics',\n",
    "                'multiplier': 1.0,\n",
    "                'min_raise': 780.0, \n",
    "                'max_raise': 1500.0, \n",
    "                'cutoff_date': init_date+timedelta(days=365*4/12.0),\n",
    "                'expected_time': timedelta(days=365*16/12.0)},\n",
    "             5:{'name': 'Mobile first',\n",
    "                'multiplier': 1.0,\n",
    "                'min_raise': 1610.0, \n",
    "                'max_raise': 2500.0, \n",
    "                'cutoff_date': init_date+timedelta(days=365*8/12.0),\n",
    "                'expected_time': timedelta(days=365*24/12.0)},\n",
    "             6:{'name': 'Easy Deploy',\n",
    "                'multiplier': 1.0,\n",
    "                'min_raise': 1500.0, \n",
    "                'max_raise': 3000.0, \n",
    "                'cutoff_date': init_date+timedelta(days=365*6/12.0),\n",
    "                'expected_time': timedelta(days=365*30/12.0)},\n",
    "    \n",
    "}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{1: {'cutoff_date': datetime.datetime(2019, 9, 24, 6, 59, 26, 296512),\n",
       "  'expected_time': datetime.timedelta(243, 28800),\n",
       "  'max_raise': 1500.0,\n",
       "  'min_raise': 984.0,\n",
       "  'multiplier': 2.5,\n",
       "  'name': 'ABC field test'},\n",
       " 2: {'cutoff_date': datetime.datetime(2019, 11, 24, 2, 59, 26, 296512),\n",
       "  'expected_time': datetime.timedelta(182, 43200),\n",
       "  'max_raise': 1500.0,\n",
       "  'min_raise': 726.0,\n",
       "  'multiplier': 2.0,\n",
       "  'name': 'Giveth field test'},\n",
       " 3: {'cutoff_date': datetime.datetime(2020, 1, 23, 22, 59, 26, 296512),\n",
       "  'expected_time': datetime.timedelta(365),\n",
       "  'max_raise': 2000.0,\n",
       "  'min_raise': 1140.0,\n",
       "  'multiplier': 1.5,\n",
       "  'name': 'CV field test'},\n",
       " 4: {'cutoff_date': datetime.datetime(2019, 11, 24, 2, 59, 26, 296512),\n",
       "  'expected_time': datetime.timedelta(486, 57600),\n",
       "  'max_raise': 1500.0,\n",
       "  'min_raise': 780.0,\n",
       "  'multiplier': 1.0,\n",
       "  'name': 'Analytics'},\n",
       " 5: {'cutoff_date': datetime.datetime(2020, 3, 24, 18, 59, 26, 296512),\n",
       "  'expected_time': datetime.timedelta(730),\n",
       "  'max_raise': 2500.0,\n",
       "  'min_raise': 1610.0,\n",
       "  'multiplier': 1.0,\n",
       "  'name': 'Mobile first'},\n",
       " 6: {'cutoff_date': datetime.datetime(2020, 1, 23, 22, 59, 26, 296512),\n",
       "  'expected_time': datetime.timedelta(912, 43200),\n",
       "  'max_raise': 3000.0,\n",
       "  'min_raise': 1500.0,\n",
       "  'multiplier': 1.0,\n",
       "  'name': 'Easy Deploy'}}"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "campaigns"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "tranches = { tr:{'raised':0, 'status':'not_started'} for tr in range(2,7)}\n",
    "tranches[1] = {'raised':0, 'status':'active'}\n",
    "state = {'new_raised':0,'total_raised': 0, 'active_tranche':1,'tranches': tranches}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'active_tranche': 1,\n",
       " 'new_raised': 0,\n",
       " 'total_raised': 0,\n",
       " 'tranches': {1: {'raised': 0, 'status': 'active'},\n",
       "  2: {'raised': 0, 'status': 'not_started'},\n",
       "  3: {'raised': 0, 'status': 'not_started'},\n",
       "  4: {'raised': 0, 'status': 'not_started'},\n",
       "  5: {'raised': 0, 'status': 'not_started'},\n",
       "  6: {'raised': 0, 'status': 'not_started'}}}"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "state"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "T = 52*3\n",
    "dt = timedelta(weeks =1)\n",
    "\n",
    "def gen_raise(thresh = .3, scale = 10):\n",
    "    rv = np.random.rand()\n",
    "    if rv < thresh:\n",
    "        return 0\n",
    "    else :\n",
    "        return rv*scale"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<img src=\"camp_logics.png\">"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "ename": "IndentationError",
     "evalue": "expected an indented block (<ipython-input-7-391e9e4fe3a3>, line 12)",
     "output_type": "error",
     "traceback": [
      "\u001b[0;36m  File \u001b[0;32m\"<ipython-input-7-391e9e4fe3a3>\"\u001b[0;36m, line \u001b[0;32m12\u001b[0m\n\u001b[0;31m    elif week > campaigns[ct]['cutoff_date']:\u001b[0m\n\u001b[0m       ^\u001b[0m\n\u001b[0;31mIndentationError\u001b[0m\u001b[0;31m:\u001b[0m expected an indented block\n"
     ]
    }
   ],
   "source": [
    "  \n",
    "def tranche_iter_logic(week, state):\n",
    "    \n",
    "    ct = state['active_tranche']\n",
    "    \n",
    "    ct_data = state['tranches'][ct]\n",
    "    \n",
    "    #is the deadline passed:\n",
    "    if ct_data['raised'] > ct_data['max_raise']:\n",
    "        \n",
    "    \n",
    "    elif week > campaigns[ct]['cutoff_date']:\n",
    "    \n",
    "    #is the cap reached\n",
    "    elif :\n",
    "    \n",
    "    \n",
    "    \n",
    "    return "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "tranch_status"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "states = [state]\n",
    "for t in range(T):\n",
    "    new_raise = gen_raise()\n",
    "    state['new_raised'] = new_raise\n",
    "    state['total_raised'] = state['total_raised'] + new_raise\n",
    "    \n",
    "    #\n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "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.6.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
