{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pyscisci.all as pyscisci\n",
    "\n",
    "import pandas as pd\n",
    "import numpy as np\n",
    "import matplotlib.pylab as plt\n",
    "try:\n",
    "    import seaborn as sns\n",
    "    sns.set_style('white')\n",
    "except:\n",
    "    pass\n",
    "\n",
    "%matplotlib inline"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[0.75 0.25]\n",
      "{1: 0, 2: 1}\n"
     ]
    }
   ],
   "source": [
    "# Fig 1A\n",
    "# move d to have ids: 11 - 15\n",
    "pub2ref  = [[11, 0], [11, 1], [11, 2], [11, 3]] # d1 citations\n",
    "pub2ref  += [[12, 0], [12, 2], [12, 3]] # d2 citations\n",
    "pub2ref  += [[13, 0], [13, 2], [13, 4]] # d3 citations\n",
    "pub2ref  += [[14, 0]] # d4 citations\n",
    "pub2ref  += [[15, 0], [15, 2], [15, 3], [15, 4]] # d5 citations\n",
    "pub2ref  = pd.DataFrame(pub2ref , columns = ['CitingPublicationId', 'CitedPublicationId'])\n",
    "\n",
    "# authors have ids 1 - 8, assume each grey author is different\n",
    "pub2authorA  = [[0, 1], [0, 2], [1, 1], [2,3], [2,1], [2,4], [2,5], [3,1], [4,6], [4,7], [4,8]]\n",
    "pub2authorA  = pd.DataFrame(pub2authorA , columns = ['PublicationId', 'AuthorId'])\n",
    "\n",
    "credit_share, author2int = pyscisci.credit_share(focus_pid=0, \n",
    "                                            pub2ref =pub2ref , \n",
    "                                            pub2author =pub2authorA , \n",
    "                                            temporal=False, \n",
    "                                            normed=True,\n",
    "                                            show_progress=False)\n",
    "\n",
    "print(credit_share)\n",
    "print(author2int)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[0.5 0.5]\n",
      "{1: 0, 2: 1}\n"
     ]
    }
   ],
   "source": [
    "# Fig 1B\n",
    "\n",
    "# notice the difference between 1A and 1B is the authorships of papers 1-4\n",
    "# authors have ids 1 - 8, assume each grey author is different\n",
    "pub2authorB  = [[0,1], [0,2], [1,2], [1,1], [2,2], [2,3], [2,4], [2,1], [3,5], [3,1], [3,2], [4,6], [4,7]]\n",
    "pub2authorB  = pd.DataFrame(pub2authorB , columns = ['PublicationId', 'AuthorId'])\n",
    "\n",
    "credit_share, author2int = pyscisci.credit_share(focus_pid=0, \n",
    "                                            pub2ref =pub2ref , \n",
    "                                            pub2author =pub2authorB , \n",
    "                                            temporal=False, \n",
    "                                            normed=True,\n",
    "                                            show_progress=False)\n",
    "\n",
    "print(credit_share)\n",
    "print(author2int)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[0.84615385 0.77777778 0.74193548 0.75      ]\n",
      " [0.15384615 0.22222222 0.25806452 0.25      ]]\n",
      "{1: 0, 2: 1}\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/Users/ajgates/.pyenv/versions/3.9.0/lib/python3.9/site-packages/tqdm/std.py:699: FutureWarning: The Panel class is removed from pandas. Accessing it from the top-level namespace will also be removed in the next version\n",
      "  from pandas import Panel\n"
     ]
    }
   ],
   "source": [
    "# now lets make the pub2ref  temporal\n",
    "pub2year = {11:2014, 12:2015, 13:2015, 14:2018, 15:2020}\n",
    "pub2ref ['CitingYear'] = [pub2year.get(pid) for pid in pub2ref ['CitingPublicationId']]\n",
    "\n",
    "credit_share, author2int, years = pyscisci.credit_share(focus_pid=0, \n",
    "                                            pub2ref =pub2ref , \n",
    "                                            pub2author =pub2authorA , \n",
    "                                            temporal=True, \n",
    "                                            normed=True,\n",
    "                                            show_progress=False)\n",
    "\n",
    "print(credit_share)\n",
    "print(author2int)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "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.8.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
