Created
July 10, 2018 03:21
-
-
Save alexgleith/9258fecf157441a14e4b27bec05890a7 to your computer and use it in GitHub Desktop.
Contributors ODC
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"execution_count": 1, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"import requests\n", | |
"import json\n", | |
"import datetime" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 6, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"url = \"https://api.github.com/repos/opendatacube/datacube-core/stats/contributors\"\n", | |
"\n", | |
"response = requests.get(url)\n", | |
"\n", | |
"users = response.json()\n", | |
"\n", | |
"today = datetime.datetime.now()\n", | |
"one_month_ago = today - datetime.timedelta(days=32)\n", | |
"\n", | |
"user_data = []\n", | |
"\n", | |
"for user in users:\n", | |
" name = user['author']['login']\n", | |
" a = 0\n", | |
" d = 0\n", | |
" c = 0\n", | |
" for row in user['weeks']:\n", | |
" week_start = datetime.datetime.fromtimestamp(row['w'])\n", | |
" \n", | |
" if week_start > one_month_ago:\n", | |
" a += row['a']\n", | |
" d += row['d']\n", | |
" c += row['c']\n", | |
"\n", | |
" data = [name, a, d, c]\n", | |
" if (a and d and c):\n", | |
" user_data.append(data)\n", | |
" \n", | |
"# print(\"User, Additions, Deletions, Commits\")\n", | |
"# for user in user_data:\n", | |
"# print(\"{}, {}, {}, {}\".format(user, *user_data[user]))" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 15, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/html": [ | |
"<div>\n", | |
"<style scoped>\n", | |
" .dataframe tbody tr th:only-of-type {\n", | |
" vertical-align: middle;\n", | |
" }\n", | |
"\n", | |
" .dataframe tbody tr th {\n", | |
" vertical-align: top;\n", | |
" }\n", | |
"\n", | |
" .dataframe thead th {\n", | |
" text-align: right;\n", | |
" }\n", | |
"</style>\n", | |
"<table border=\"1\" class=\"dataframe\">\n", | |
" <thead>\n", | |
" <tr style=\"text-align: right;\">\n", | |
" <th></th>\n", | |
" <th>Name</th>\n", | |
" <th>Additions</th>\n", | |
" <th>Deletions</th>\n", | |
" <th>Commits</th>\n", | |
" </tr>\n", | |
" </thead>\n", | |
" <tbody>\n", | |
" <tr>\n", | |
" <th>1</th>\n", | |
" <td>jeannettestrand</td>\n", | |
" <td>20</td>\n", | |
" <td>3</td>\n", | |
" <td>1</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>2</th>\n", | |
" <td>walsh-andrew</td>\n", | |
" <td>8</td>\n", | |
" <td>4</td>\n", | |
" <td>1</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>0</th>\n", | |
" <td>santoshamohan</td>\n", | |
" <td>1</td>\n", | |
" <td>1</td>\n", | |
" <td>1</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>3</th>\n", | |
" <td>omad</td>\n", | |
" <td>1</td>\n", | |
" <td>1</td>\n", | |
" <td>1</td>\n", | |
" </tr>\n", | |
" </tbody>\n", | |
"</table>\n", | |
"</div>" | |
], | |
"text/plain": [ | |
" Name Additions Deletions Commits\n", | |
"1 jeannettestrand 20 3 1\n", | |
"2 walsh-andrew 8 4 1\n", | |
"0 santoshamohan 1 1 1\n", | |
"3 omad 1 1 1" | |
] | |
}, | |
"execution_count": 15, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"import pandas as pd\n", | |
"df = pd.DataFrame(user_data, columns=[\"Name\", \"Additions\", \"Deletions\", \"Commits\"])\n", | |
"df.sort_values(by=['Additions'], inplace=True, ascending=False)\n", | |
"df" | |
] | |
}, | |
{ | |
"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.5" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 2 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment