Commit 7af12cdf authored by João Denis Rodrigues's avatar João Denis Rodrigues
Browse files

Fix cache student + funcoes disciplinas

parent 033c6b82
from __future__ import division
from student.models import Student
from klass.models import *
from admission.models import Admission
from course.models import *
from degree.models import *
from datetime import datetime
from student.analysis import *
import math
def average_grade(klasses): # calcular_nota_media(turmas)
grade = 0
amount_student = 0
for klass in klasses:
student_klasses = StudentKlass.objects.filter(klass = klass,
situation__in = SITUATION_COURSE_VALID_GRADE)
for student_klass in student_klasses:
if student_klass.grade is not None:
grade += student_klass.grade
amount_student += 1
if amount_student == 0:
return -1
else:
return grade / amount_student
def average_grade_standard_deviation(klasses): # calcular_nota_media_desvio_padrao
average_grade = average_grade(klasses)
amount_student = 0
variance = 0
for klass in klasses:
student_klasses = StudentKlass.objects.filter(klass = klass,
situation__in = SITUATION_COURSE_VALID_GRADE)
for student_klass in student_klasses:
if student_klass.grade is not None:
variance += math.pow(student_klass.grade - average_grade, 2)
amount_student += 1
if amount_student == 0:
return -1
standard_deviation = math.sqrt(variance/amount_student)
return (average_grade, standard_deviation)
def average_grade_last_year(klasses): # calcular_nota_media_ultimo_ano
grades = 0
amount_student = 0
now = datetime.now()
for klass in klasses:
if klass.year == (now.year - 1):
student_klasses = StudentKlass.objects.filter(klass = klass)
for student_klass in student_klasses:
if student_klass.grade is not None:
grades += student_klass.grade
amount_student += 1
if amount_student == 0:
return -1
return grades / student_amount
def average_grade_last_year_standard_deviation(klasses): # calcular_nota_media_ultimo_ano_desvio_padrao
average_grade = average_grade_last_year(klasses)
if average_gradde == -1:
return (-1, -1)
amount_student = 0
variance = 0
now = datetime.now()
for klass in klasses:
if klass.year == (now.year - 1):
student_klasses = StudentKlass.objects.filter(klass = klass)
for student_klass in student_klasses:
if student_klass.grade is not None:
variance += math.pow(student_klass.grade - average_grade, 2)
amount_student += 1
if amount_student == 0:
return (-1,-1)
standard_deviation = math.sqrt(variance / amount_student)
return (average_grade, standard_deviation)
#def absolute_pass_rate(klasses): # calcular_taxa_reprovacao_absoluta
def frequency_failure(klasses): # calcular_taxa_reprovacao_frequencia
amount_failure = 0
amounte_student = 0
for klass in klasses:
student_klasses = StudentKlass.objects.filter(klass = klass)
for student_klass in student_klasses:
if student_klass.situation is not None:
if student.situation == "Reprovado por Frequência":
amount_failure += 1
amount_student += 1
if amount_student == 0:
return -1
amount_failure *= 100
return amount_failure / amount_student
...@@ -108,7 +108,7 @@ def generate_student_data(degree, path): ...@@ -108,7 +108,7 @@ def generate_student_data(degree, path):
for student in students: for student in students:
student_klasses = StudentKlass.objects.filter(student=student) student_klasses = StudentKlass.objects.filter(student=student)
amount_courses_semester = get_student_courses_completed(student_klasses) amount_courses_semester = get_amount_courses_completed(student)
failures_semester = semester_pass_rate(student) failures_semester = semester_pass_rate(student)
failures_amount_courses_semester = merge_dicts( failures_amount_courses_semester = merge_dicts(
['reprovacoes', 'cursadas'], ['reprovacoes', 'cursadas'],
......
...@@ -17,6 +17,8 @@ class Student(models.Model): ...@@ -17,6 +17,8 @@ class Student(models.Model):
klasses = models.ManyToManyField('klass.Klass', through = 'klass.StudentKlass') klasses = models.ManyToManyField('klass.Klass', through = 'klass.StudentKlass')
def get_time_in_degree(self): def get_time_in_degree(self):
year_end = self.admission.degree.report_year
semester_end = self.admission.degree.report_semester
if self.evasion_year is not None: if self.evasion_year is not None:
year_end = self.evasion_year year_end = self.evasion_year
if self.evasion_semester is None: if self.evasion_semester is None:
......
...@@ -87,6 +87,41 @@ SITUATION_FAILURE_COMPLETED = ( # Situacoes reprovacao cursada ate o fim ...@@ -87,6 +87,41 @@ SITUATION_FAILURE_COMPLETED = ( # Situacoes reprovacao cursada ate o fim
u'Reprovado sem nota', u'Reprovado sem nota',
) )
SITUATION_COURSES_VALID = (
u'Reprovado por nota',
u'Aprovado',
u'Reprovado por Frequência',
u'Reprovado sem nota',
u'Equivalência de Disciplina',
u'Aprovado Conhecimento',
u'Reprovado Conhecimento',
u'Aprovado Adiantamento',
u'Horas',
u'Dispensa de Disciplinas (com nota)',
u'Dispensa de Disciplinas (sem nota))',
u'Matrícula',
)
SITUATION_COURSES_LOCKED = (
u'Cancelado',
u'Trancamento Total',
u'Trancamento Administrativo',
)
SITUATION_COURSES_VALID_GRADE = (
u'Reprovado por nota',
u'Aprovado',
u'Reprovado por Frequência',
u'Reprovado sem nota',
u'Equivalência de Disciplina',
u'Aprovado Conhecimento',
u'Reprovado Conhecimento',
u'Aprovado Adiantamento',
u'Horas',
u'Dispensa de Disciplinas (com nota)',
u'Dispensa de Disciplinas (sem nota))',
)
def difference_between_semesters(year_start, semester_start, year_end, semester_end): def difference_between_semesters(year_start, semester_start, year_end, semester_end):
return 2 * (year_end - year_start) + (semester_end - semester_start) + 1 return 2 * (year_end - year_start) + (semester_end - semester_start) + 1
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment