{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import floatview\n",
    "import numpy as np\n",
    "import pandas as pd\n",
    "import re\n",
    "from pybtex.database.input import bibtex"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "def bibtex2pd(filename):\n",
    "    parser = bibtex.Parser()\n",
    "    bibdata = parser.parse_file(filename)\n",
    "    data = []\n",
    "    for bib_id in bibdata.entries:\n",
    "        b = bibdata.entries[bib_id].fields\n",
    "        try:\n",
    "            id = bib_id\n",
    "            title = b[\"title\"].upper()\n",
    "            journal = b[\"journal\"].upper()\n",
    "            year = b[\"year\"]\n",
    "            for author in bibdata.entries[bib_id].persons[\"author\"]:\n",
    "                first = \" \".join(author.first_names).upper()\n",
    "                last = \" \".join(author.last_names).upper()\n",
    "                data.append([id, title, journal, year, first, last, first + \" \" + last])\n",
    "        # field may not exist for a reference\n",
    "        except(KeyError):\n",
    "            continue\n",
    "    df = pd.DataFrame(data, columns=['ID', 'Title', 'Journal', 'Year', 'First', 'Last', 'Full'])\n",
    "    return df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "filename = \"bibtex.bib\"\n",
    "tab = bibtex2pd(filename)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "tab = bibtex2pd(\"bibtex.bib\")\n",
    "tab = tab[~tab['Full'].str.contains(\"KLIMECK\")]\n",
    "\n",
    "tab = tab[tab['Journal'].str.contains(\"PHYSICS\")]\n",
    "#tab = tab.sort_values(by=['Year'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "gmw = floatview.GlueManagerWidget(tab, modal=False, label=\"citations\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "columns_input = [\n",
    "    'Full',\n",
    "    'Year',\n",
    "    'Journal',\n",
    "]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "for year in range(2010,2019):\n",
    "    state = np.nonzero(gmw.gluemanager.data['Year']==str(year))\n",
    "    gmw.gluemanager.updateSelection(state)\n",
    "    gmw.gluemanager.createSubsetFromSelection(label=year)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#gmw.gluemanager.newView(\"sankey\", columns_input, \"Sankey\");\n",
    "#gmw.gluemanager.newView(\"parallels\", columns_input, \"Parallels\");\n",
    "#gmw.gluemanager.newView(\"histogram\", ['Year'], \"\");\n",
    "gmw.gluemanager.newView(\"network\", ['Full', 'Journal'], \"Network\",only_subsets=False);"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "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.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
