Esempio n. 1
0
    def get_school_categories(self, obj):
        categories = obj.schools(obj.session).values('sch_category').annotate(
            sum_schools_total=Count('sch_category'),
            sum_schools_classrooms_leq_3=CountWhen('sch_category',
                                                   when='tot_clrooms <= 3'),
            sum_schools_classrooms_eq_4=CountWhen('sch_category',
                                                  when='tot_clrooms = 4'),
            sum_schools_classrooms_eq_5=CountWhen('sch_category',
                                                  when='tot_clrooms = 5'),
            sum_schools_classrooms_mid_67=CountWhen(
                'sch_category', when='tot_clrooms IN (6, 7)'),
            sum_schools_classrooms_geq_8=CountWhen('sch_category',
                                                   when='tot_clrooms >= 8'),
            sum_boys=Sum('total_boys'),
            sum_girls=Sum('total_girls'),
            sum_classrooms=Sum('tot_clrooms'),
        )
        for category in categories:
            category['id'] = category['sch_category']
            category['name'] = search_choices_by_key(SCHOOL_CATEGORY,
                                                     category['id'])
            del category['sch_category']

            category_copy = category.copy()
            category['sum_schools'] = dict()
            for key, value in category_copy.iteritems():
                if key.startswith('sum_schools'):
                    category['sum_schools'][key.replace('sum_schools_',
                                                        '')] = value
                    del category[key]

        categories = sorted(categories, key=lambda k: k['id'])
        return categories
Esempio n. 2
0
    def get_school_categories(self, obj):
        categories = obj.schools(obj.session).values('sch_category').annotate(
            sum_schools_total=Count('sch_category'),
            sum_schools_classrooms_leq_3=CountWhen('sch_category', when='tot_clrooms <= 3'),
            sum_schools_classrooms_eq_4=CountWhen('sch_category', when='tot_clrooms = 4'),
            sum_schools_classrooms_eq_5=CountWhen('sch_category', when='tot_clrooms = 5'),
            sum_schools_classrooms_mid_67=CountWhen('sch_category', when='tot_clrooms IN (6, 7)'),
            sum_schools_classrooms_geq_8=CountWhen('sch_category', when='tot_clrooms >= 8'),
            sum_boys=Sum('total_boys'),
            sum_girls=Sum('total_girls'),
            sum_classrooms=Sum('tot_clrooms'),
        )
        for category in categories:
            category['id'] = category['sch_category']
            category['name'] = search_choices_by_key(SCHOOL_CATEGORY, category['id'])
            del category['sch_category']

            category_copy = category.copy()
            category['sum_schools'] = dict()
            for key, value in category_copy.iteritems():
                if key.startswith('sum_schools'):
                    category['sum_schools'][key.replace('sum_schools_', '')] = value
                    del category[key]

        categories = sorted(categories, key=lambda k: k['id'])
        return categories
Esempio n. 3
0
    def get_school_categories(self, obj):
        categories = obj.schools(obj.session).values('sch_category').annotate(
            sum_schools=Count('sch_category'),
            sum_boys=Sum('total_boys'),
            sum_girls=Sum('total_girls')
        )
        for category in categories:
            category['id'] = category['sch_category']
            category['name'] = search_choices_by_key(SCHOOL_CATEGORY, category['id'])
            del category['sch_category']

        categories = sorted(categories, key=lambda k: k['id'])
        return categories
Esempio n. 4
0
    def get_medium_of_instructions(self, obj):
        moes = obj.schools(obj.session).values('medium_of_instruction').annotate(
            sum_schools=Count('medium_of_instruction'),
            sum_boys=Sum('total_boys'),
            sum_girls=Sum('total_girls')
        )
        for moe in moes:
            moe['id'] = moe['medium_of_instruction']
            moe['name'] = search_choices_by_key(MEDIUM, moe['id'])
            del moe['medium_of_instruction']

        moes = sorted(moes, key=lambda k: k['sum_schools'], reverse=True)
        return moes
Esempio n. 5
0
    def get_medium_of_instructions(self, obj):
        moes = obj.schools(
            obj.session).values('medium_of_instruction').annotate(
                sum_schools=Count('medium_of_instruction'),
                sum_boys=Sum('total_boys'),
                sum_girls=Sum('total_girls'))
        for moe in moes:
            moe['id'] = moe['medium_of_instruction']
            moe['name'] = search_choices_by_key(MEDIUM, moe['id'])
            del moe['medium_of_instruction']

        moes = sorted(moes, key=lambda k: k['sum_schools'], reverse=True)
        return moes