{ "cells": [ { "cell_type": "markdown", "metadata": { "collapsed": false }, "source": [ "# Download counts for nteract" ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": false }, "outputs": [], "source": [ "import IPython.display\n", "import pandas as pd" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "collapsed": false }, "outputs": [], "source": [ "import requests\n", "\n", "# Note: \n", "data = requests.get('https://api.github.com/repos/nteract/nteract/releases').json()" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "collapsed": false, "inputHidden": false, "outputHidden": false }, "outputs": [ { "data": { "text/plain": [ "{'documentation_url': 'https://developer.github.com/v3/#rate-limiting',\n", " 'message': \"API rate limit exceeded for 24.103.236.65. (But here's the good news: Authenticated requests get a higher rate limit. Check out the documentation for more details.)\"}" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "data" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "collapsed": false }, "outputs": [ { "ename": "KeyError", "evalue": "0", "output_type": "error", "traceback": [ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[0;31mKeyError\u001b[0m Traceback (most recent call last)", "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[1;32m 1\u001b[0m print(\"{}:\\n\\t{}\\n\\t{}\".format(\n\u001b[0;32m----> 2\u001b[0;31m \u001b[0mdata\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m'tag_name'\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 3\u001b[0m \u001b[0mdata\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m'assets'\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m'browser_download_url'\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 4\u001b[0m \u001b[0mdata\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m'assets'\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m'download_count'\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 5\u001b[0m ))\n", "\u001b[0;31mKeyError\u001b[0m: 0" ] } ], "source": [ "print(\"{}:\\n\\t{}\\n\\t{}\".format(\n", " data[0]['tag_name'],\n", " data[0]['assets'][0]['browser_download_url'],\n", " data[0]['assets'][0]['download_count']\n", "))\n" ] }, { "cell_type": "markdown", "metadata": { "collapsed": false }, "source": [ "The releases API only has context of the filename, so we'll convert:\n", "\n", "```\n", "https://github.com/nteract/nteract/releases/download/v0.0.13/nteract-darwin-x64.zip\n", "```\n", "\n", "to\n", "\n", "```\n", "darwin-x64\n", "```\n", "\nWhich means we're reliant on our release naming to keep this a nice consistent structure" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "def strip_off_release(browser_download_url):\n", " filename = browser_download_url.split('/')[-1]\n", " basename = filename.split('.')[0]\n", " system = basename.split('-')[1:]\n", " return \"-\".join(system)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "releases = [\n", " {\n", " 'version': x['tag_name'], \n", " 'counts': { strip_off_release(y['browser_download_url']): y['download_count'] for y in x['assets'] }\n", " } \n", " for x in data\n", "]\n", "releases" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "versions = []\n", "frames = []\n", "\n", "for release in releases:\n", " versions.append(release['version'])\n", " frames.append(pd.DataFrame.from_dict(release['counts'], orient='index'))\n", "\n", "df = pd.concat(frames, keys=versions).reset_index()\n", "df.columns = ['version', 'os', 'count']\n", "df['os'] = df.os.replace('os-x', 'darwin-x64')\n", "df" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "It would be really interesting to know how these counts change over time." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "from distutils.version import LooseVersion\n", "\n", "versions = set(df.version.values.tolist())\n", "versions = sorted(versions, key=LooseVersion)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false, "scrolled": false }, "outputs": [], "source": [ "import matplotlib.pyplot as plt\n", "import seaborn as sns\n", "%matplotlib inline\n", "%config InlineBackend.figure_format = 'retina'\n", "\n", "with sns.color_palette(\"colorblind\", len(versions)):\n", " fig = plt.figure(figsize=(10, 6))\n", " ax = fig.add_subplot(1, 1, 1)\n", " ax = sns.barplot(x='version', y=\"count\", hue=\"os\", data=df, order=versions)\n", " ax.set_xticklabels(versions, rotation=30)\n", " ax.set(xlabel='Version', ylabel='Count')\n", " plt.legend(bbox_to_anchor=(1, 1), loc=2, borderaxespad=0)\n", " plt.show()" ] } ], "metadata": { "anaconda-cloud": {}, "kernel_info": { "name": "python3" }, "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.7.2" }, "nteract": { "version": "nteract-on-jupyter@2.0.4" }, "title": "Glean the Download Statistics for nteract Desktop" }, "nbformat": 4, "nbformat_minor": 0 }