Skip to content

Instantly share code, notes, and snippets.

@mathjazz
Last active February 22, 2019 16:08
Show Gist options
  • Save mathjazz/6cf62f7d51ae556ffb5fcab850b09ed6 to your computer and use it in GitHub Desktop.
Save mathjazz/6cf62f7d51ae556ffb5fcab850b09ed6 to your computer and use it in GitHub Desktop.
Active contributors for given locales, timeframe and roles
"""
Retrieve a list of active contributors for given locales, timeframe and roles.
Output is formatted as CSV with the following columns:
* locale
* date_joined
* profile_url
* user_role
* total_submission_count
* approved_count
* rejected_count
* unreviewed_count
* approved_rejected_ratio
Run the script in Pontoon's Django shell, e.g.:
heroku run --app mozilla-pontoon ./manage.py shell
"""
# Configuration
LOCALES = ['ko', 'my', 'th', 'tl', 'vi']
MONTHS_AGO = 6
ROLES = [
# 'Admin',
'Contributor',
# 'Manager',
# 'Translator',
]
# Script
from __future__ import division
from dateutil.relativedelta import relativedelta
from django.db.models import Q
from django.conf import settings
from django.urls import reverse
from django.utils import timezone
from pontoon.base.models import Locale
from pontoon.contributors.utils import users_with_translations_counts
locales = Locale.objects.filter(code__in=LOCALES)
start_date = (timezone.now() + relativedelta(months=-MONTHS_AGO))
def get_profile(username):
import urlparse
return urlparse.urljoin(
settings.SITE_URL,
reverse(
'pontoon.contributors.contributor.username',
args=[username]
)
)
def get_ratio(approved, rejected):
try:
return format(approved / rejected, '.2f')
except ZeroDivisionError:
return '∞'
for locale in locales:
print '\n{name} ({code})'.format(name=locale.name, code=locale.code)
contributors = users_with_translations_counts(start_date, Q(locale=locale), None)
for contributor in contributors:
role = contributor.user_role.split(' ')[0]
if role not in ROLES:
continue
print('{},{},{},{},{},{},{},{},{}'.format(
locale.code,
contributor.date_joined.date(),
get_profile(contributor.username),
role,
contributor.translations_count,
contributor.translations_approved_count,
contributor.translations_rejected_count,
contributor.translations_unapproved_count,
get_ratio(contributor.translations_approved_count, contributor.translations_rejected_count)
))
# Output
"""
Burmese (my)
my,2018-03-23,https://mozilla-pontoon-staging.herokuapp.com/contributors/bNSOsphV1Upz_CvtUyCZC1hYsi0/,Contributor,340,282,55,3,5.13
my,2018-08-29,https://mozilla-pontoon-staging.herokuapp.com/contributors/Pl1CfBYCnVd5vLlfNUNDeGKxnGU/,Contributor,16,16,0,0,∞
Korean (ko)
ko,2018-12-11,https://mozilla-pontoon-staging.herokuapp.com/contributors/NzY1F_CZ1CL68jCYMTBucymeVXw/,Contributor,387,244,60,83,4.07
ko,2016-11-28,https://mozilla-pontoon-staging.herokuapp.com/contributors/1Y_bMkTrGdGcHuENgPOp-jJm5p4/,Contributor,128,92,34,2,2.71
ko,2018-09-13,https://mozilla-pontoon-staging.herokuapp.com/contributors/l_eNCvL-Eq8_FUSf5U0VvzHfVWA/,Contributor,96,73,20,3,3.65
ko,2018-10-05,https://mozilla-pontoon-staging.herokuapp.com/contributors/w3k7Z7vDz3rnItIUO2SxF6q7kqo/,Contributor,51,26,23,2,1.13
ko,2018-12-08,https://mozilla-pontoon-staging.herokuapp.com/contributors/-l8rpKiew676xUettqbGUEfQVCc/,Contributor,38,19,19,0,1.00
ko,2018-10-05,https://mozilla-pontoon-staging.herokuapp.com/contributors/FNf7VWTZji-meTGVCsP-K8yX1Eo/,Contributor,33,8,25,0,0.32
ko,2019-02-06,https://mozilla-pontoon-staging.herokuapp.com/contributors/yU9yD6eKpmKETzhbxwD8npjhGrg/,Contributor,26,0,2,24,0.00
ko,2018-07-16,https://mozilla-pontoon-staging.herokuapp.com/contributors/rhAnpbrBDrbo-ZPTWMa438WyJw8/,Contributor,19,11,8,0,1.38
ko,2018-09-19,https://mozilla-pontoon-staging.herokuapp.com/contributors/6vbMUPjU3mq7joI7uwcC9MlMxEw/,Contributor,16,5,11,0,0.45
ko,2018-10-30,https://mozilla-pontoon-staging.herokuapp.com/contributors/o9LMSGMFgXn2dXmee0v5XSj6LOc/,Contributor,16,13,3,0,4.33
ko,2016-01-31,https://mozilla-pontoon-staging.herokuapp.com/contributors/_jPBXeRigl1frJceZSgvcZm6Pe0/,Contributor,7,4,3,0,1.33
ko,2018-10-05,https://mozilla-pontoon-staging.herokuapp.com/contributors/RJ7loR3tAI0f_1BLAtWZLtXEuxY/,Contributor,4,1,3,0,0.33
ko,2019-02-18,https://mozilla-pontoon-staging.herokuapp.com/contributors/WSXYa2YjuoesIdwEZ44axsbWwMo/,Contributor,4,0,4,0,0.00
ko,2018-10-05,https://mozilla-pontoon-staging.herokuapp.com/contributors/sctwBqiDRmS1n1WN-lYXNrYQyDI/,Contributor,3,2,1,0,2.00
ko,2018-12-05,https://mozilla-pontoon-staging.herokuapp.com/contributors/pxMRenJKzhewHQUrS0sR68r5RxI/,Contributor,3,0,1,2,0.00
ko,2018-11-12,https://mozilla-pontoon-staging.herokuapp.com/contributors/apiNLoXQYcRE1qEPwFT0srS8ntg/,Contributor,2,2,0,0,∞
ko,2018-12-07,https://mozilla-pontoon-staging.herokuapp.com/contributors/YaGXNcJ_c_BAn8CkFLrycuP-sQ4/,Contributor,2,1,0,1,∞
Tagalog (tl)
tl,2017-08-01,https://mozilla-pontoon-staging.herokuapp.com/contributors/A1E89AZ-A4KsJaZmuMkGWPNaJ90/,Contributor,189,106,41,42,2.59
tl,2018-11-20,https://mozilla-pontoon-staging.herokuapp.com/contributors/rM_6vRhLZ_rnLzpoAdf1KpbXCdA/,Contributor,63,44,17,2,2.59
tl,2016-11-06,https://mozilla-pontoon-staging.herokuapp.com/contributors/tlupB9u2iC857WTFixBHqvwo4Po/,Contributor,48,17,30,1,0.57
tl,2019-01-14,https://mozilla-pontoon-staging.herokuapp.com/contributors/T0A6Cg22lCNABYXZ9P0p7H0NEZU/,Contributor,31,0,0,31,∞
tl,2018-08-22,https://mozilla-pontoon-staging.herokuapp.com/contributors/juv8dXY-7PXkVPgPAMrKYWze_Mg/,Contributor,1,1,0,0,∞
Thai (th)
th,2017-07-02,https://mozilla-pontoon-staging.herokuapp.com/contributors/4gMJniLZ_TgfG3mGnZx-sTidKmw/,Contributor,2708,391,132,2185,2.96
th,2018-03-06,https://mozilla-pontoon-staging.herokuapp.com/contributors/waGUT7LBkumzGUTfjsEuEEmewIQ/,Contributor,224,25,10,189,2.50
th,2018-03-04,https://mozilla-pontoon-staging.herokuapp.com/contributors/dzsoaTga0Yu9DE8ZDaxfvdmt4ME/,Contributor,116,57,5,54,11.40
th,2018-09-24,https://mozilla-pontoon-staging.herokuapp.com/contributors/iDof-v9thxT82oyhl-MQ0cvRPOo/,Contributor,46,11,5,30,2.20
th,2019-02-21,https://mozilla-pontoon-staging.herokuapp.com/contributors/I-1VMcOYvbowSY9yJkPetu1EoH0/,Contributor,24,0,0,24,∞
th,2018-12-26,https://mozilla-pontoon-staging.herokuapp.com/contributors/4jZDgCl2Z3gsh_QjP8MlDzpb0zE/,Contributor,16,2,0,14,∞
th,2017-01-22,https://mozilla-pontoon-staging.herokuapp.com/contributors/AEuHOnYI8q7i8qcENtukKGfej_I/,Contributor,13,0,0,13,∞
th,2018-09-24,https://mozilla-pontoon-staging.herokuapp.com/contributors/rDQAYBtQfJKsiAXFu89RCYOC0VU/,Contributor,10,2,3,5,0.67
th,2019-02-17,https://mozilla-pontoon-staging.herokuapp.com/contributors/IU7qIpuRWg57Bnyv3KMVG8epYPc/,Contributor,7,0,0,7,∞
th,2018-11-18,https://mozilla-pontoon-staging.herokuapp.com/contributors/KsDT6YQbyKqgUdhvAdXHj8w26-0/,Contributor,6,0,1,5,0.00
th,2018-09-24,https://mozilla-pontoon-staging.herokuapp.com/contributors/cvOfiH0Bdc3e3XA-v-mRG40Ckl8/,Contributor,5,0,0,5,∞
th,2019-02-16,https://mozilla-pontoon-staging.herokuapp.com/contributors/vgqe62LDrEG08De6mg2AXJK67yM/,Contributor,4,0,0,4,∞
th,2018-09-24,https://mozilla-pontoon-staging.herokuapp.com/contributors/7yBk16-Q4yUIPI1Pn2aaBauTeJI/,Contributor,2,0,2,0,0.00
th,2018-09-24,https://mozilla-pontoon-staging.herokuapp.com/contributors/5pTOtsMR0A65Zhkr5Xiv4_B1Ldk/,Contributor,1,0,0,1,∞
Vietnamese (vi)
vi,2017-04-25,https://mozilla-pontoon-staging.herokuapp.com/contributors/r12FdRKMYT4Jfp72HX5BhwO92e8/,Contributor,445,340,105,0,3.24
vi,2018-10-13,https://mozilla-pontoon-staging.herokuapp.com/contributors/Dy6jpG0mPEgC3ojfrvWimpRjSTs/,Contributor,353,320,33,0,9.70
vi,2017-11-21,https://mozilla-pontoon-staging.herokuapp.com/contributors/2Oh0Yg4nYWp7tkyv3D3UX27NGIg/,Contributor,45,21,24,0,0.88
vi,2018-09-21,https://mozilla-pontoon-staging.herokuapp.com/contributors/lPVdEkgKH1I-Hm5XhzHtXqmKkQw/,Contributor,22,10,11,1,0.91
vi,2018-09-06,https://mozilla-pontoon-staging.herokuapp.com/contributors/tLdqmdZZXOzk2-2jEnFp_-wLKy4/,Contributor,19,10,8,1,1.25
vi,2017-03-02,https://mozilla-pontoon-staging.herokuapp.com/contributors/vghhYZ6ST4zdB_PVDARO-CbMnig/,Contributor,3,2,1,0,2.00
vi,2018-09-07,https://mozilla-pontoon-staging.herokuapp.com/contributors/Q2jr4btxIZfvRQ-U1vxoF9izVcg/,Contributor,2,2,0,0,∞
vi,2018-09-11,https://mozilla-pontoon-staging.herokuapp.com/contributors/3NxSh5e1VTSZbrazKFo6op1Tklc/,Contributor,2,0,2,0,0.00
vi,2019-01-31,https://mozilla-pontoon-staging.herokuapp.com/contributors/LePU0slA2Oni1ZYvOwRipU-CJWU/,Contributor,1,0,0,1,∞
"""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment