<commit_before>
from datetime import date

from edx_data_research.reporting.edx_base import EdX

class Stats(EdX):

    def __init__(self, args):
        super(self.__class__, self).__init__(args)

    def stats(self):
        """Return general stats for a given course """
        self.collections = ['auth_userprofile']
        self._age()

    def _age(self):
        current_year = date.today().year
        print current_year
        
<commit_msg>Define methods to get gender stats, age stats and certificate stats<commit_after>from collections import defaultdict
from datetime import date

from edx_data_research.reporting.edx_base import EdX

class Stats(EdX):

    def __init__(self, args):
        super(self.__class__, self).__init__(args)
        self.number_of_students = 0

    def stats(self):
        """Return general stats for a given course """
        self.collections = ['auth_userprofile', 'certificates_generatedcertificate']
        self.number_of_students = self.collections['auth_userprofile'].count()
        age_stats = self._age()
        gender_stats = self._gender()
        certificate_stats = self._certificate()
	print certificate_stats

    def _age(self):
        age_breakdown = defaultdict(int)
        current_year = date.today().year
        cursor = self.collections['auth_userprofile'].find()
	for item in cursor:
	    year_of_birth = item['year_of_birth']
            if year_of_birth != 'NULL':
                age = current_year - int(year_of_birth)
		if age < 20:
		    age_breakdown['Age - Under 20'] += 1
		elif 20 <= age <= 29:
		    age_breakdown['Age - 20-29'] += 1
 		elif 30 <= age <= 39:
		    age_breakdown['Age - 30-39'] += 1
		elif 40 <= age <= 49:
		    age_breakdown['Age - 40-49'] += 1
		elif 50 <= age <= 69:
		    age_breakdown['Age - 50-69'] += 1
		elif age >= 70:
		    age_breakdown['Age - 70+'] += 1
	    else:
		age_breakdown['Age - None'] += 1
        return age_breakdown

    def _gender(self):
        gender_breakdown = defaultdict(int)
        cursor = self.collections['auth_userprofile'].find()
 	for item in cursor:
	    gender = item['gender']
	    if gender == 'm':
                gender_breakdown['Gender - Male'] += 1
	    elif gender == 'f':
                gender_breakdown['Gender - Female'] += 1
	    elif gender == 'o':
                gender_breakdown['Gender - Other'] += 1
            else:
                gender_breakdown['Gender - None'] += 1
        gender_breakdown = {key: value * 100.0 / self.number_of_students
                            for key, value in gender_breakdown.iteritems()}
        return gender_breakdown

    def _certificate(self):
        certificate_breakdown = defaultdict(int)
        cursor = self.collections['certificates_generatedcertificate'].find()
        for item in cursor:
            status = item['status']
            if status == 'notpassing':
                certificate_breakdown['Certificate - No'] += 1
            elif status == 'downloadable':
                certificate_breakdown['Certificate - Yes'] += 1
        certificate_breakdown = {key: value * 100.0 / self.number_of_students
                            for key, value in certificate_breakdown.iteritems()}
        return certificate_breakdown 


{'fraction_non_alphanumeric': 0.10980876002467613, 'fraction_numerical': 0.019123997532387416, 'mean_word_length': 2.4317460317460315, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4115194', 'n_tokens_mistral': 1033, 'n_tokens_neox': 915, 'n_words': 236}