Fixed division by 0 error in calc_imputations
This commit is contained in:
parent
58c4aa2a97
commit
3c0e8af223
2 changed files with 13 additions and 3 deletions
|
|
@ -114,13 +114,13 @@ class Teacher(models.Model):
|
|||
for key in imputations:
|
||||
imputations[key] += round(imputations[key] / tot * activities['tot_formation'])
|
||||
|
||||
# Split EDE périods in EDEpe and EDEps columns, in proportion
|
||||
# Split EDE periods in EDEpe and EDEps columns, in proportion
|
||||
ede = courses.filter(imputation='EDE').aggregate(models.Sum('period'))['period__sum'] or 0
|
||||
if ede > 0:
|
||||
pe = imputations['EDEpe']
|
||||
ps = imputations['EDEps']
|
||||
pe_percent = pe / (pe + ps)
|
||||
pe_plus = pe * pe_percent
|
||||
pe_percent = (pe / (pe + ps)) if (pe + ps) > 0 else 0.5
|
||||
pe_plus = round(ede * pe_percent)
|
||||
imputations['EDEpe'] += pe_plus
|
||||
imputations['EDEps'] += ede - pe_plus
|
||||
|
||||
|
|
|
|||
|
|
@ -218,6 +218,16 @@ class TeacherTests(TestCase):
|
|||
result = self.teacher.calc_imputations()
|
||||
self.assertEqual(result[1]['ASSC'], 9)
|
||||
self.assertEqual(result[1]['EDEpe'], 5)
|
||||
# Test with only EDE data
|
||||
t2 = Teacher.objects.create(
|
||||
first_name='Isidore', last_name='Gluck', birth_date='1986-01-01'
|
||||
)
|
||||
Course.objects.create(
|
||||
teacher=t2, period=5, subject='Cours EDE', imputation='EDE',
|
||||
)
|
||||
result = t2.calc_imputations()
|
||||
self.assertEqual(result[1]['EDEpe'], 2)
|
||||
self.assertEqual(result[1]['EDEps'], 3)
|
||||
|
||||
def test_export_imputations(self):
|
||||
self.client.login(username='me', password='mepassword')
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue