Пример #1
0
    def get_context_data(self, **kwargs):
        context = super(SchoolInfoAndResultsView,
                        self).get_context_data(**kwargs)
        school_id = kwargs.pop('school_id')
        school = School.objects.get(pk=school_id)

        calculator = AverageResultsCalculator(school)
        result = calculator.calculate()
        context['school'] = school
        context['students_count'] = NTC.objects.filter(school=school).count()
        context['school_averages'] = result.get_school_averages()
        context['country_averages'] = result.get_country_averages()
        context['subjects'] = json.dumps(result.get_subjects())
        return context
Пример #2
0
class AverageResultsCalculatorTests(TestCase):
    fixtures = ['geo.json', 'schools.json', 'ntc.json']

    def setUp(self):
        school = School.objects.get(pk=74)
        self.calculator = AverageResultsCalculator(school)

    def test_calculate(self):
        actual = self.calculator.calculate()

        actual_school_averages = actual.get_school_averages()
        actual_country_averages = actual.get_country_averages()
        actual_subjects = actual.get_subjects()

        expected_school_averages = [17.0, 13.833333333333334, 17.904761904761905, 14.5, 17.818181818181817, 4.0, 14.0, 16.5625]
        expected_country_averages = [19.053763440860216, 17.538205980066444, 17.5203488372093, 13.31496062992126, 19.462222222222223, 8.947368421052632, 17.273224043715846, 20.609595484477893]
        expected_subjects = [ugettext("Kyrgyz language"), ugettext("Biology"), ugettext("Russian language"), ugettext("Geography"), ugettext("Chemistry"),
                             ugettext("Physics"), ugettext("English language"), ugettext("History")]

        self.assertEqual(actual_school_averages, expected_school_averages)
        self.assertEqual(actual_country_averages, expected_country_averages)
        self.assertEqual(actual_subjects, expected_subjects)
Пример #3
0
 def setUp(self):
     school = School.objects.get(pk=74)
     self.calculator = AverageResultsCalculator(school)