{ "cells": [ { "cell_type": "markdown", "id": "9a51a013-8798-4327-bd2b-5aaf0427cda4", "metadata": {}, "source": [ "# pvcaptest" ] }, { "cell_type": "code", "execution_count": null, "id": "50531b9f-821b-4f17-ae11-535b6241dee6", "metadata": {}, "outputs": [], "source": [ "import utils\n", "import pandas as pd\n", "\n", "from bokeh.plotting import figure, show\n", "from bokeh.models import HoverTool\n", "from bokeh.transform import jitter\n", "from bokeh.io import output_notebook" ] }, { "cell_type": "code", "execution_count": null, "id": "c987023b-ca0a-4ebf-9b9d-33793d3cf8f8", "metadata": {}, "outputs": [], "source": [ "output_notebook()" ] }, { "cell_type": "markdown", "id": "10d7f560-2768-42ac-a21a-258c6b2ffdbe", "metadata": {}, "source": [ "## ReadTheDocs" ] }, { "cell_type": "code", "execution_count": null, "id": "6c7a30e9-97a4-4344-b832-ba526d2836e9", "metadata": {}, "outputs": [], "source": [ "df = utils.get_rtd_analytics_data('pvcaptest')\n", "data_period = df['Date'].min().strftime('%Y-%m-%d') + ' to ' + df['Date'].max().strftime('%Y-%m-%d')" ] }, { "cell_type": "code", "execution_count": null, "id": "60c947c9-f9c2-4ccf-b5e7-c9c9f3359e05", "metadata": {}, "outputs": [], "source": [ "total_by_version = df.groupby('Version')['Views'].sum().reset_index()\n", "\n", "p = figure(x_range=total_by_version['Version'], height=350, tooltips=[(\"Version\", \"@Version\"), (\"Views\", \"@Views\")],\n", " title=f\"Page views by RTD version ({data_period})\",)\n", "p.vbar(x='Version', top='Views', width=0.75, source=total_by_version,\n", " line_color='white')\n", "p.xaxis.major_label_orientation = 3.14/2\n", "p.yaxis.axis_label = 'Total page views'\n", "show(p)" ] }, { "cell_type": "code", "execution_count": null, "id": "2104961b-ff35-43b3-bf0b-dfdf7c932c55", "metadata": {}, "outputs": [], "source": [ "daily_views = df.pivot_table(values='Views', index='Date', columns='Version', aggfunc='sum')[['stable', 'latest']].fillna(0)\n", "\n", "p = figure(x_axis_type=\"datetime\", height=350, title=f\"Daily views by RTD version\")\n", "hover_tool = HoverTool(tooltips=[('Date', '@x{%Y-%m-%d}'), ('Views', '@y')],\n", " formatters={'@x': 'datetime'})\n", "hover_tool.point_policy = 'snap_to_data'\n", "p.add_tools(hover_tool)\n", "p.line(daily_views.index, daily_views['stable'], legend_label='stable')\n", "p.line(daily_views.index, daily_views['latest'], legend_label='latest', color='#ff7f0e')\n", "p.yaxis.axis_label = 'Daily page views'\n", "show(p)" ] }, { "cell_type": "code", "execution_count": null, "id": "2413e533-b4fa-4b2b-b308-a4bd9a4254d0", "metadata": {}, "outputs": [], "source": [ "df2 = df.loc[df['Version'] == 'latest', :].copy()\n", "pathviews = df2.groupby('Path')['Views'].sum().reset_index()" ] }, { "cell_type": "code", "execution_count": null, "id": "29f9acd5-f445-4aa9-a0c8-aa80b7af611d", "metadata": {}, "outputs": [], "source": [ "n = 20\n", "subset = pathviews.sort_values('Views', ascending=False)[:n]\n", "p = figure(y_range=subset['Path'], height=400, tooltips=[(\"URL\", \"@Path\"), (\"Views\", \"@Views\")],\n", " title=f\"Views by URL (Top {n}, {data_period})\")\n", "p.hbar(y='Path', right='Views', source=subset, height=0.75,\n", " line_color='white')\n", "p.xaxis.axis_label = 'Total page views'\n", "show(p)" ] }, { "cell_type": "code", "execution_count": null, "id": "b5d056f6-793c-4423-9598-c97349def706", "metadata": {}, "outputs": [], "source": [ "prefixes = ['/examples', ]\n", "pathviews['Prefix'] = pathviews['Path'].str.rsplit(\"/\", 1).str[0]\n", "groupviews = pathviews.loc[pathviews['Prefix'].isin(prefixes), :].groupby('Prefix')['Views'].sum().loc[prefixes].sort_values().reset_index()\n", "\n", "p = figure(x_range=groupviews['Prefix'], height=350, tooltips=[(\"Section\", \"@Prefix\"), (\"Views\", \"@Views\")],\n", " title=f\"Page views by docs section ({data_period})\")\n", "p.vbar(x='Prefix', top='Views', width=0.75, source=groupviews)\n", "p.yaxis.axis_label = 'Total page views'\n", "show(p)" ] }, { "cell_type": "code", "execution_count": null, "id": "b9cd913d-b115-4212-880a-4d86dbe05d62", "metadata": {}, "outputs": [], "source": [ "subset = pathviews.loc[pathviews['Prefix'].isin(prefixes), :]\n", "\n", "p = figure(x_range=prefixes, height=350, tooltips=[(\"URL\", \"@Path\"), (\"Views\", \"@Views\")],\n", " title=f\"Page views by docs page ({data_period})\")\n", "p.scatter(x=jitter('Prefix', width=0.1, range=p.x_range, distribution='normal'),\n", " y='Views', source=subset)\n", "p.yaxis.axis_label = 'Total page views'\n", "show(p)" ] }, { "cell_type": "code", "execution_count": null, "id": "a3ef457c-5c98-4250-9507-bff27d257b69", "metadata": {}, "outputs": [], "source": [ "for prefix in prefixes:\n", " subset = pathviews.loc[pathviews['Prefix'] == prefix, :]\n", " subset = subset.loc[~subset['Path'].str.endswith('/index.html'), :]\n", " subset = subset.sort_values('Views', ascending=False)[:n]\n", " subset['Path_Clean'] = subset['Path'].str.replace('^'+prefix+'/', '', regex=True)\n", "\n", " height = (400 // 5) * len(subset)\n", " extra = f\"Top {n}, \" if len(subset) == n else ''\n", " p = figure(y_range=subset['Path_Clean'], width=750, height=height, tooltips=[(\"URL\", \"@Path\"), (\"Views\", \"@Views\")],\n", " title=f\"{prefix}: Views by URL ({extra}{data_period})\")\n", " p.hbar(y='Path_Clean', right='Views', source=subset, height=0.75,\n", " line_color='white')\n", " p.xaxis.axis_label = 'Total page views'\n", " show(p)" ] }, { "cell_type": "code", "execution_count": null, "id": "5451b58c-6550-41c1-849d-afb5bc1260a1", "metadata": {}, "outputs": [], "source": [ "release_dates = {\n", " 'v0.10.0': '2021-07-25',\n", "}\n", "stable = df.loc[df['Version'] == 'stable', :].copy()\n", "stable['Real_Version'] = '?'\n", "for version, date in release_dates.items():\n", " stable.loc[stable['Date'] >= date, 'Real_Version'] = version\n", "\n", "pivot = stable.pivot_table(values='Views', index='Date', columns='Real_Version', aggfunc='sum')\n", "realigned = pd.DataFrame({\n", " version: pd.Series(pivot.loc[date:, version].values, index=(pivot.loc[date:, :].index - pd.to_datetime(date)).days)\n", " for version, date in release_dates.items()\n", "}).cumsum()\n", "\n", "tab10 = ['#1f77b4', '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b', '#e377c2', '#7f7f7f', '#bcbd22', '#17becf']\n", "\n", "p = figure(height=350, title=f\"Cumulative views since release date ({data_period})\")\n", "hover_tool = HoverTool(tooltips=[('Days since release', '@x'), ('Cumulative Views', '@y')])\n", "hover_tool.point_policy = 'snap_to_data'\n", "p.add_tools(hover_tool)\n", "\n", "for i, column in enumerate(realigned.columns):\n", " label = column\n", " if column == 'v0.1.1':\n", " label = label + ' (partial)'\n", " p.line(realigned.index, realigned[column], legend_label=label, color=tab10[i])\n", "\n", "p.yaxis.axis_label = 'Total page views'\n", "p.xaxis.axis_label = 'Days since release'\n", "p.legend.location = \"top_left\"\n", "show(p)" ] }, { "cell_type": "markdown", "id": "23e08435-cb15-4c27-93db-2c7a9617a77f", "metadata": {}, "source": [ "## GitHub" ] }, { "cell_type": "code", "execution_count": null, "id": "e9959e5d-5244-448b-a120-08d038b5c804", "metadata": {}, "outputs": [], "source": [ "gh_proj_path = 'pvcaptest/pvcaptest'" ] }, { "cell_type": "code", "execution_count": null, "id": "0a7abd61-24ed-46e1-9686-4af7333fbf76", "metadata": {}, "outputs": [], "source": [ "gh = utils.get_github_stars(gh_proj_path)" ] }, { "cell_type": "code", "execution_count": null, "id": "8c18098d-7eb0-4a4b-b807-4bcbe74d8f48", "metadata": {}, "outputs": [], "source": [ "p = utils.plot_github_stars_timeseries(gh)\n", "show(p)" ] }, { "cell_type": "code", "execution_count": null, "id": "f8de7c4e-b91e-4c6d-971f-3ff0cf6a3a5d", "metadata": {}, "outputs": [], "source": [ "contributor_ts, _ = utils.get_github_contributor_timeseries(gh_proj_path)\n", "p = utils.plot_github_contributors_timeseries(contributor_ts)\n", "show(p)" ] }, { "cell_type": "code", "execution_count": null, "id": "a3aa29df-57d2-442d-bc0f-857b0904efa0", "metadata": {}, "outputs": [], "source": [ "contributors = utils.get_github_contributors(gh_proj_path)" ] }, { "cell_type": "code", "execution_count": null, "id": "805f57a0-2301-4fb8-8e17-92c038d06c90", "metadata": {}, "outputs": [], "source": [ "mosaic = utils.make_github_contributors_mosaic(contributors)\n", "mosaic" ] } ], "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.7.11" } }, "nbformat": 4, "nbformat_minor": 5 }