{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import plotnine as p9\n",
    "from textwrap import wrap\n",
    "import sys\n",
    "sys.path.append(\"../\")\n",
    "\n",
    "from k8s_survey_analysis.plot_utils import (\n",
    "    make_likert_chart_multi_year,\n",
    "    make_bar_chart_multi_year\n",
    ")\n",
    "\n",
    "from k8s_survey_analysis import prepare_2019, prepare_2018"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "pd.options.display.max_columns = 999\n",
    "pd.options.display.max_rows = 999"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Match Field Names and Multiple Choice Options as much as possible\n",
    "df_2019 = prepare_2019.get_df('../2019/contribex-survey-2019.csv').assign(year=2019)\n",
    "df_2018 = prepare_2018.get_df('../2018/contribex-survey-2018.csv').assign(year=2018)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Build a single dataset for comparison\n",
    "\n",
    "In this notebook we will compare responses between the 2018 and 2019 surveys. Only those questions which appeared in both surveys are useful to compare. Some questions that appeared in both surveys were different enough in their format to make comparisons not useful."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "shared_columns = set(df_2019.columns).intersection(df_2018.columns)\n",
    "survey_data = pd.concat([df_2019[shared_columns], df_2018[shared_columns]])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Compare univariate data between 2018 and 2019"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "length_year_totals = (\n",
    "    survey_data[survey_data[\"Contributing_Length\"].notnull()]\n",
    "    .groupby([\"year\"])\n",
    "    .count()[\"Collector_ID\"]\n",
    "    .reset_index()\n",
    ")\n",
    "\n",
    "length_counts = (\n",
    "    survey_data.groupby([\"Contributing_Length\", \"year\"])\n",
    "    .count()[\"Collector_ID\"]\n",
    "    .reset_index()\n",
    ")\n",
    "\n",
    "length_percents = length_counts.merge(length_year_totals, on=\"year\")\n",
    "\n",
    "length_percents = length_percents.assign(\n",
    "    percent=length_percents[\"Collector_ID_x\"] / length_percents[\"Collector_ID_y\"]\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "(\n",
    "    p9.ggplot(\n",
    "        length_percents,\n",
    "        p9.aes(x=\"Contributing_Length\", fill=\"factor(year)\", y=\"percent\"),\n",
    "    )\n",
    "    + p9.geom_bar(position=\"dodge\", stat=\"identity\")\n",
    "    + p9.theme(axis_text_x=p9.element_text(angle=45))\n",
    "    + p9.scale_x_discrete(\n",
    "        limits=[\n",
    "            \"less than one year\",\n",
    "            \"one to two years\",\n",
    "            \"two to three years\",\n",
    "            \"three+ years\",\n",
    "        ]\n",
    "    )\n",
    "    + p9.ggtitle(\"Number of Contributors by Length of Contribution\")\n",
    "    + p9.xlab(\"Length of Contribution\")\n",
    "    + p9.ylab(\"Number of Contributors\")\n",
    ")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "As expected, due to the advertisement of the survey on Twitter, a higher proportion of respondents are newer contributors this year."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "level_year_totals = survey_data[survey_data['Level_of_Contributor'].notnull()].groupby(['year']).count()['Collector_ID'].reset_index()\n",
    "level_counts = survey_data.groupby(['Level_of_Contributor','year']).count()['Collector_ID'].reset_index()\n",
    "level_percents = level_counts.merge(level_year_totals,on='year')\n",
    "level_percents = level_percents.assign(percent = level_percents['Collector_ID_x']/level_percents['Collector_ID_y'])\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "(\n",
    "    p9.ggplot(\n",
    "        level_percents,\n",
    "        p9.aes(x=\"Level_of_Contributor\", fill=\"factor(year)\", y=\"percent\"),\n",
    "    )\n",
    "    + p9.geom_bar(position=\"dodge\", stat=\"identity\")\n",
    "    + p9.theme(axis_text_x=p9.element_text(angle=45, ha=\"right\"))\n",
    "    + p9.ggtitle(\"Number of Contributors by Contributor Level\")\n",
    "    + p9.xlab(\"Contributor Level\")\n",
    "    + p9.ylab(\"Proportion of Contributors\")\n",
    ")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "A larger proportion of respondents this year are in higher roles in the contributor ladder. It appears most of these are due to the smaller proportion of respondents who are not a member for one reason or another."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "oss_counts = (\n",
    "    survey_data.groupby([\"year\", \"Contribute_to_other_OSS\"])\n",
    "    .count()[\"Collector_ID\"]\n",
    "    .reset_index()\n",
    ")\n",
    "oss_year_totals = (\n",
    "    survey_data[survey_data[\"Contribute_to_other_OSS\"].notnull()]\n",
    "    .groupby([\"year\"])\n",
    "    .count()[\"Collector_ID\"]\n",
    "    .reset_index()\n",
    ")\n",
    "\n",
    "oss_percents = oss_counts.merge(oss_year_totals, on=\"year\")\n",
    "oss_percents = oss_percents.assign(\n",
    "    percent=oss_percents[\"Collector_ID_x\"] / oss_percents[\"Collector_ID_y\"]\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "(\n",
    "    p9.ggplot(\n",
    "        oss_percents,\n",
    "        p9.aes(x=\"Contribute_to_other_OSS\", fill=\"factor(year)\", y=\"percent\"),\n",
    "    )\n",
    "    + p9.geom_bar(position=\"dodge\", stat=\"identity\")\n",
    "    + p9.theme(axis_text_x=p9.element_text(angle=45, ha=\"right\"))\n",
    "    + p9.scale_x_discrete(\n",
    "        limits=[\"this is my first open source project!\", \"1 other\", \"2 or more\"]\n",
    "    )\n",
    "    + p9.ggtitle(\"Participation in Other Open Source Projects\")\n",
    "    + p9.xlab(\"Number of other OSS Projects\")\n",
    "    + p9.ylab(\"Number of Contributors\")\n",
    ")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "There is a small increase in the proportion of contributors for whom Kuberetes is their first open source project. Because the change is so small, no major changes should be based on this finding."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "counts = survey_data.groupby([\"Upstream_supported_at_employer\", \"year\"]).count()[\n",
    "    \"Respondent_ID\"\n",
    "]\n",
    "\n",
    "total = survey_data.groupby([\"year\"]).count()[\"Respondent_ID\"]\n",
    "\n",
    "employee_percents = (\n",
    "    counts.to_frame().reset_index().merge(total.to_frame().reset_index(), on=\"year\")\n",
    ")\n",
    "\n",
    "employee_percents = employee_percents.assign(\n",
    "    percent=employee_percents[\"Respondent_ID_x\"] / employee_percents[\"Respondent_ID_y\"]\n",
    ")\n",
    "\n",
    "(\n",
    "    p9.ggplot(\n",
    "        employee_percents,\n",
    "        p9.aes(x=\"Upstream_supported_at_employer\", fill=\"factor(year)\", y=\"percent\"),\n",
    "    )\n",
    "    + p9.geom_bar(position=p9.position_dodge(preserve=\"single\"), stat=\"identity\")\n",
    "    + p9.labs(\n",
    "        title=\"Support at Employer\", fill=\"Year\", y=\"Proportion\", x=\"Support Level\"\n",
    "    )\n",
    "    + p9.theme(axis_text_x=p9.element_text(angle=45, ha=\"right\"))\n",
    ")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "This question was a required question in 2019 but not in 2018. In addition, the student option was not present in this year's survey. Nonetheless, the proportion of contributors supported by their employer dropped slightly this year. It is difficult to make any conclusions due to the change in the question, but this is a trend to keep a close eye on in future surveys."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Cross-tabulations"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "pd.crosstab(\n",
    "    survey_data.World_Region, [survey_data.Level_of_Contributor, survey_data.year]\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "pd.crosstab(\n",
    "    survey_data.Contributing_Length,\n",
    "    [survey_data.Level_of_Contributor, survey_data.year],\n",
    ").loc[[\"less than one year\", \"one to two years\", \"two to three years\", \"three+ years\"]]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "pd.crosstab(\n",
    "    survey_data.Contributing_Length,\n",
    "    [survey_data.Contribute_to_other_OSS, survey_data.year],\n",
    ").loc[\n",
    "    [\"less than one year\", \"one to two years\", \"two to three years\", \"three+ years\"],\n",
    "    [\"this is my first open source project!\", \"1 other\", \"2 or more\"],\n",
    "]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "pd.crosstab(\n",
    "    survey_data.Level_of_Contributor,\n",
    "    [survey_data.Upstream_supported_at_employer, survey_data.year],\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "pd.crosstab(\n",
    "    survey_data.Contributing_Length,\n",
    "    [survey_data.Upstream_supported_at_employer, survey_data.year],\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "pd.crosstab(\n",
    "    survey_data.Interested_in_next_level,\n",
    "    [survey_data.Level_of_Contributor, survey_data.year],\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Challenges/Blockers Faced"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "blocker_ratings = [\"A frequent blocker\",'Often a problem','Sometimes a problem','Rarely a problem','Not a problem']\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "(\n",
    "    make_likert_chart_multi_year(survey_data, \"Blocker:\", blocker_ratings)\n",
    "    + p9.labs(\n",
    "        x=\"Year\",\n",
    "        y=\"\",\n",
    "        fill=\"Rating\",\n",
    "        color=\"Rating\",\n",
    "        title=\"Blockers (New Contributors Included)\",\n",
    "    )\n",
    "    + p9.theme(\n",
    "        legend_margin=5,\n",
    "        figure_size=(12, (9 / 4) * 3),\n",
    "        strip_text_x=p9.element_text(\n",
    "            margin={\"t\": 0.35, \"b\": 0.35, \"l\": 1, \"r\": 1, \"units\": \"in\"}\n",
    "        ),\n",
    "    )\n",
    "    + p9.ylim(-1, 1)\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "(\n",
    "    make_likert_chart_multi_year(survey_data, \"Blocker:\", blocker_ratings)\n",
    "    + p9.labs(\n",
    "        x=\"Year\",\n",
    "        y=\"\",\n",
    "        fill=\"Rating\",\n",
    "        color=\"Rating\",\n",
    "        title=\"Blockers (New Contributors Included)\",\n",
    "    )\n",
    "    + p9.theme(\n",
    "        legend_margin=5,\n",
    "        figure_size=(12, (9 / 4) * 3),\n",
    "        strip_text_x=p9.element_text(\n",
    "            margin={\"t\": 0.35, \"b\": 0.35, \"l\": 1, \"r\": 1, \"units\": \"in\"}\n",
    "        ),\n",
    "    )\n",
    "    + p9.ylim(-1, 1)\n",
    ")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Respondents across the board reported feeling more blocked this past year than in 2018. The only exception is GitHub tooling. To ensure this was not due to a higher proportion of new contributors we looked at the data without them. This is show below."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "(\n",
    "    make_likert_chart_multi_year(\n",
    "        survey_data, \"Blocker:\", blocker_ratings, exclude_new_contributors=True\n",
    "    )\n",
    "    + p9.labs(\n",
    "        x=\"Blocker\",\n",
    "        y=\"Count\",\n",
    "        fill=\"Rating\",\n",
    "        color=\"Rating\",\n",
    "        title=\"Blockers (New Contributors Excluded)\",\n",
    "    )\n",
    "    + p9.theme(\n",
    "        legend_margin=5,\n",
    "        figure_size=(12, (9 / 4) * 3),\n",
    "        strip_text_x=p9.element_text(\n",
    "            margin={\"t\": 0.35, \"b\": 0.35, \"l\": 1, \"r\": 1, \"units\": \"in\"}\n",
    "        ),\n",
    "    )\n",
    "    + p9.ylim(-1, 1)\n",
    ")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "After removing contributors who reported having being involved for less than a year, the overall trend holds. One concern in comparing these two datasets is that this year respondents were asked how challenging these areas were, not how much they are blocked by them. Consistent wording will make these more comparable between future surveys. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "(\n",
    "    make_likert_chart_multi_year(\n",
    "        survey_data, \"Blocker:\", blocker_ratings, [\"Contributing_Length\", \".\"]\n",
    "    )\n",
    "    + p9.labs(\n",
    "        x=\"Year\",\n",
    "        y=\"\",\n",
    "        fill=\"Rating\",\n",
    "        color=\"Rating\",\n",
    "        title=\"Blockers by Length of Contribution\",\n",
    "    )\n",
    "    + p9.theme(\n",
    "        figure_size=(12, (9 / 4) * 3),\n",
    "        strip_text_x=p9.element_text(\n",
    "            margin={\"t\": 0.35, \"b\": 0.35, \"l\": 1, \"r\": 1, \"units\": \"in\"}\n",
    "        ),\n",
    "        strip_text_y=p9.element_text(margin={\"r\": 0.8, \"units\": \"in\"}),\n",
    "    )\n",
    ")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Contributors who have been contributing for two years or more are more rate the areas as being as difficult or slightly less of an issue than in 2018. The trend is reversed for contributors with less than two years of experience. They rate items as being more difficult in 2019, suggesting potential for outreach and improvement among this group."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "(\n",
    "    make_likert_chart_multi_year(\n",
    "        survey_data, \"Blocker:\", blocker_ratings, [\"Level_of_Contributor\", \".\"]\n",
    "    )\n",
    "    + p9.labs(\n",
    "        x=\"Blocker\",\n",
    "        y=\"Count\",\n",
    "        fill=\"Rating\",\n",
    "        color=\"Rating\",\n",
    "        title=\"Blockers by Level on Ladder\",\n",
    "    )\n",
    "    + p9.theme(\n",
    "        figure_size=(12, (9 / 4) * 3),\n",
    "        strip_text_x=p9.element_text(\n",
    "            margin={\"t\": 0.35, \"b\": 0.35, \"l\": 1, \"r\": 1, \"units\": \"in\"}\n",
    "        ),\n",
    "        strip_text_y=p9.element_text(margin={\"r\": 0.9, \"units\": \"in\"}),\n",
    "    )\n",
    ")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Subproject owners report less challenges in 2019 than in 2018. This is contrast to other cohorts whose challenges have increased or stayed level. This is especially clear in the columns for finding the right SIG, and code/documentation review to a lesser extent."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "(\n",
    "    make_likert_chart_multi_year(\n",
    "        survey_data, \"Blocker:\", blocker_ratings, [\"Interested_in_next_level\", \".\"]\n",
    "    )\n",
    "    + p9.labs(\n",
    "        x=\"Blocker\",\n",
    "        y=\"Count\",\n",
    "        fill=\"Rating\",\n",
    "        color=\"Rating\",\n",
    "        title=\"Blockers by Interest in Next Level\",\n",
    "    )\n",
    "    + p9.theme(\n",
    "        figure_size=(12, (9 / 4) * 3),\n",
    "        strip_text_x=p9.element_text(\n",
    "            margin={\"t\": 0.35, \"b\": 0.35, \"l\": 1, \"r\": 1, \"units\": \"in\"}\n",
    "        ),\n",
    "        strip_text_y=p9.element_text(margin={\"r\": 0.9, \"units\": \"in\"}),\n",
    "    )\n",
    ")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "This plot shows an interesting difference between contributors interested in the next level not conditional on support, and those whose interest is conditioned on further support. In contrast to what we would expect, those who are interested irrespective of the support available report more challenges in 2019 than in 2018 with finding issues to work on and finding the right SIG. Combining this finding with the cross tabulation above showing contributors across the spectrum responding more with unconditional interest suggests several things. One is that what the mentoring program is and how it could help may need more publication. The other may be that there is a sense of pride in not needing mentoring, and so finding a way to break down that stigma may lead to happier contributors in the long run."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Sources Checked for News"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "make_bar_chart_multi_year(survey_data, \"Check_for_news:\") + p9.labs(\n",
    "    title=\"Sources Checked for News\", fill=\"Year\", x=\"Source\"\n",
    ")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "This question does not require users to choose only one option, so the proportions add up to more than 1. Most news sources see an increase in use. The largest jump is the kubernetes-dev mailing list, with over 60% of respondents checking the mailing list. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "make_bar_chart_multi_year(\n",
    "    survey_data, \"Check_for_news:\", exclude_new_contributors=True\n",
    ") + p9.labs(\n",
    "    title=\"Sources Checked for News (Excluding New Contributors)\",\n",
    "    fill=\"Year\",\n",
    "    x=\"Source\",\n",
    ")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "After excluding newer contributors, an even larger percent of contributors get their news from the mailing list, suggesting it is important for new users to be introduced to the mailing list. The other change from the previous plot is that the use of Twitter now shows a downward trend from 2018 to 2019. This confirms that advertising the survey on Twitter may have skewed the results slightly. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "(\n",
    "    make_bar_chart_multi_year(\n",
    "        survey_data, \"Check_for_news:\", facet_by=[\".\", \"Contributing_Length\"]\n",
    "    )\n",
    "    + p9.theme(strip_text_y=p9.element_text(margin={\"r\": 0.8, \"units\": \"in\"}))\n",
    "    + p9.labs(title=\"Sources Checked for News\", fill=\"Year\", x=\"Source\", y=\"Count\")\n",
    ")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "In addition to the large increase in the use of Twitter by new contributors, there are a few other changes in new consumption in relation to the length of participation in Kubernetes. The proportion of new contributors using Slack has increased greatly. There is a consistent pattern across contributors who have been involved for one to two years, with many of the resources seeing decreased use. It is not clear why this is, but it not a large concern, as the most widely used resources are the same among all groups: the mailing list, Slack, and the blog. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "(\n",
    "    make_bar_chart_multi_year(\n",
    "        survey_data, \"Check_for_news:\", facet_by=[\".\", \"Interested_in_next_level\"]\n",
    "    )\n",
    "    + p9.theme(strip_text_y=p9.element_text(margin={\"r\": 0.9, \"units\": \"in\"}))\n",
    "    + p9.labs(title=\"Sources Checked for News\", fill=\"Year\", x=\"Source\", y=\"Proportion\")\n",
    ")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Resource Usage"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "use_ratings = [\n",
    "    \"Every Day\",\n",
    "    \"Several Times a Week\",\n",
    "    \"Several Times a Month\",\n",
    "    \"Occasionally\",\n",
    "    \"Never\",\n",
    "]\n",
    "use_ratings.reverse()\n",
    "(\n",
    "    make_likert_chart_multi_year(\n",
    "        survey_data, \"Use_freq:\", use_ratings, five_is_high=True\n",
    "    )\n",
    "    + p9.labs(x=\"Resource\", y=\"\", fill=\"Rating\", color=\"Rating\", title=\"Resource Use\")\n",
    "    + p9.theme(\n",
    "        figure_size=(12, (9 / 4) * 3),\n",
    "        strip_text_x=p9.element_text(\n",
    "            margin={\"t\": 0.35, \"b\": 0.35, \"l\": 1, \"r\": 1, \"units\": \"in\"}\n",
    "        ),\n",
    "        strip_text_y=p9.element_text(margin={\"r\": 0.9, \"units\": \"in\"}),\n",
    "    )\n",
    ")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The frequency of use across communication channels has fallen from 2018 to 2019 for most options. The only two with a positive trend are Slack and Google Groups/Mailing List. GitHub discussions saw a slight decrease, but is still a very heavily used tool. The decrease is due to the higher number of new contributors as shown in the plot below."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "use_ratings = [\n",
    "    \"Every Day\",\n",
    "    \"Several Times a Week\",\n",
    "    \"Several Times a Month\",\n",
    "    \"Occasionally\",\n",
    "    \"Never\",\n",
    "]\n",
    "use_ratings.reverse()\n",
    "(\n",
    "    make_likert_chart_multi_year(\n",
    "        survey_data,\n",
    "        \"Use_freq:\",\n",
    "        use_ratings,\n",
    "        five_is_high=True,\n",
    "        exclude_new_contributors=True,\n",
    "    )\n",
    "    + p9.labs(\n",
    "        x=\"Resource\",\n",
    "        y=\"\",\n",
    "        fill=\"Rating\",\n",
    "        color=\"Rating\",\n",
    "        title=\"Resource Use (First Year Contributors Excluded)\",\n",
    "    )\n",
    "    + p9.theme(\n",
    "        figure_size=(12, (9 / 4) * 3),\n",
    "        strip_text_x=p9.element_text(\n",
    "            margin={\"t\": 0.35, \"b\": 0.35, \"l\": 1, \"r\": 1, \"units\": \"in\"}\n",
    "        ),\n",
    "        strip_text_y=p9.element_text(margin={\"r\": 0.9, \"units\": \"in\"}),\n",
    "    )\n",
    ")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "After excluding contributors with less than one year of experience, GitHub use no longer decreases. With this smaller data, we can see that out of all options and all respondents in 2018 and 2019, the use of GitHub in 2019 is the only resource to have no contributors report they never used the service."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "(\n",
    "    make_likert_chart_multi_year(\n",
    "        survey_data,\n",
    "        \"Use_freq:\",\n",
    "        use_ratings,\n",
    "        facet_by=[\"Level_of_Contributor\", \".\"],\n",
    "        five_is_high=True,\n",
    "    )\n",
    "    + p9.labs(\n",
    "        x=\"Resource\",\n",
    "        y=\"Count\",\n",
    "        fill=\"Rating\",\n",
    "        color=\"Rating\",\n",
    "        title=\"Resource Use by Contributor Level\",\n",
    "    )\n",
    "    + p9.theme(\n",
    "        figure_size=(12, (9 / 4) * 3),\n",
    "        strip_text_x=p9.element_text(\n",
    "            margin={\"t\": 0.35, \"b\": 0.35, \"l\": 1, \"r\": 1, \"units\": \"in\"}\n",
    "        ),\n",
    "        strip_text_y=p9.element_text(margin={\"r\": 0.9, \"units\": \"in\"}),\n",
    "    )\n",
    ")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Most trends are consistent across levels of the contributor ladder. The one exception is that subproject owners, and especially reviewers, used the mailing list and Google Groups less frequently in 2019 than in 2018."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Contribution Areas"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "(\n",
    "    make_bar_chart_multi_year(survey_data, \"Contribute:\")\n",
    "    + p9.labs(x=\"Contribution\", y=\"Count\", title=\"Areas Contributed To\", fill=\"Year\")\n",
    ")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Most areas saw increases in contributors, with the exception of code inside Kubernetes/Kubernetes and other. This reflects the continuing effort to only keep core code in the Kubernetes/Kuberenetes repository, moving other contributions to additional repositories in the Kubernetes organization. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "(\n",
    "    make_bar_chart_multi_year(\n",
    "        survey_data, \"Contribute:\", facet_by=[\"Contributing_Length\", \".\"]\n",
    "    )\n",
    "    + p9.labs(\n",
    "        x=\"Contribution\", y=\"Proportion\", title=\"Areas Contributed To\", fill=\"Year\"\n",
    "    )\n",
    "    + p9.theme(\n",
    "        figure_size=(12, (9 / 4) * 3),\n",
    "        strip_text_y=p9.element_text(margin={\"r\": 0.9, \"units\": \"in\"}),\n",
    "    )\n",
    ")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Contributors who have less than one year of experience saw the greatest increase in their contributions. The largest gains were seen in the areas of Documentation and related projects. Other cohorts saw the proportions contributing to documentation slightly decrease. This isn't a bad thing if all necessary documentation is getting done, but a trend to keep an eye on if it falls below the desired standard. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "(\n",
    "    make_bar_chart_multi_year(\n",
    "        survey_data[\n",
    "            survey_data.Upstream_supported_at_employer.isin(\n",
    "                [\"Didn't Answer\", \"I’m a student\"]\n",
    "            )\n",
    "            == False\n",
    "        ],\n",
    "        \"Contribute:\",\n",
    "        facet_by=[\"Upstream_supported_at_employer\", \".\"],\n",
    "    )\n",
    "    + p9.labs(\n",
    "        x=\"Contribution\",\n",
    "        y=\"Count\",\n",
    "        title=\"Areas Contributed To by Employer Support\",\n",
    "        fill=\"Proportion\",\n",
    "    )\n",
    "    + p9.theme(\n",
    "        figure_size=(12, (9 / 4) * 3),\n",
    "        strip_text_y=p9.element_text(margin={\"r\": 1, \"units\": \"in\"}),\n",
    "    )\n",
    ")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The plot above shows the proportion of each cohort that contributes to a certain area. A large drop is seen among those who use their own time in their contribution to the core repository. This is matched by an almost equal increase in the same group's contributions to other repositories owned by the Kubernetes project. \n",
    "\n",
    "Contributions from those who can use company time decreased in all areas. As contributors can select more than on area, this suggests that each person is contributing to less areas. This is confirmed in the table below."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "survey_data.groupby([\"Upstream_supported_at_employer\", \"year\"]).apply(\n",
    "    lambda x: x[x.columns[x.columns.str.startswith(\"Contribute\")]].sum(axis=1).mean()\n",
    ").reset_index().rename(columns={0: \"Average Number of Areas\"})"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "(\n",
    "    make_bar_chart_multi_year(\n",
    "        survey_data, \"Contribute:\", facet_by=[\"Interested_in_next_level\", \".\"]\n",
    "    )\n",
    "    + p9.labs(\n",
    "        x=\"Contribution\",\n",
    "        y=\"Count\",\n",
    "        title=\"Areas Contributed To by Interest in Next Level\",\n",
    "        fill=\"Year\",\n",
    "    )\n",
    "    + p9.theme(\n",
    "        figure_size=(12, (9 / 4) * 3),\n",
    "        strip_text_y=p9.element_text(margin={\"r\": 1, \"units\": \"in\"}),\n",
    "    )\n",
    ")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Core code contributions dropped from 2018 to 2019 among all groups except subproject owners. Those who want support to reach the next level contributed more across all areas. Those who want to move to the next level but do not condition their interest on receiving help contributed less across most areas than in 2018. This again suggests that more clarification is needed around the mentorship program, as many of those who think they need more support contribute widely, while those that don't contribute as much don't feel they need support. "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Use of Help Wanted and Good First Issue Labels"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "help_wanted = survey_data[\n",
    "    survey_data[\n",
    "        \"Do_you_use_the\\xa0Help_Wanted_and/or_Good_First_Issue_labels_on_issues_you_file_to_find_contributors\"\n",
    "    ].isna()\n",
    "    == False\n",
    "]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "help_counts = (\n",
    "    help_wanted.rename(\n",
    "        columns={\n",
    "            \"Do_you_use_the\\xa0Help_Wanted_and/or_Good_First_Issue_labels_on_issues_you_file_to_find_contributors\": \"help\"\n",
    "        }\n",
    "    )\n",
    "    .groupby([\"year\", \"help\"])\n",
    "    .count()[\"Collector_ID\"]\n",
    "    .reset_index()\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "help_year_counts = help_counts.groupby(\"year\").sum().reset_index()\n",
    "help_percents = help_year_counts.merge(help_counts, on=\"year\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "help_percents = help_percents.assign(\n",
    "    percent=help_percents[\"Collector_ID_y\"] / help_percents[\"Collector_ID_x\"]\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "help_plot = (\n",
    "    p9.ggplot(help_percents, p9.aes(x=\"help\", y=\"percent\", fill=\"factor(year)\"))\n",
    "    + p9.geom_bar(position=p9.position_dodge(preserve=\"single\"), stat=\"identity\")\n",
    "    + p9.theme(axis_text_x=p9.element_text(angle=45, ha=\"right\"))\n",
    "    + p9.labs(\n",
    "        x=\"Used Label\",\n",
    "        title=\"Use of Help Wanted and/or Good First Issue Labels\",\n",
    "        y=\"Proportion\",\n",
    "        fill=\"Year\",\n",
    "    )\n",
    ")\n",
    "\n",
    "help_plot"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Use of the help wanted and good first labels clearly increased from 2018 to 2019."
   ]
  }
 ],
 "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.7.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
