Commit 32f5bac6 authored by João Denis Rodrigues's avatar João Denis Rodrigues
Browse files

Preenchendo funcoes do curso

parent 3d637604
......@@ -6,7 +6,8 @@ from student.models import Student
from klass.models import *
from admission.models import Admission
from degree.models import *
from datetime import datetimme
from datetime import datetime
from utils.data import *
import collections
import json
import math
......@@ -26,7 +27,7 @@ def calculate_average_ira(admission):
average /= n
return average
def calculate_avera_ira_standard_deviation(admission):
def calculate_average_ira_standard_deviation(admission):
average_ira = calculate_average_ira(admission)
students = admission.student_set.all()
variance = 0
......@@ -42,7 +43,7 @@ def calculate_avera_ira_standard_deviation(admission):
else:
variance /= n
standard_deviation = math.sqrt(variance)
return (average_ira, standard_deviation]
return (average_ira, standard_deviation)
def calculate_ira_semester(admission, year, semester, amount_semesters):
students = admission.student_set.all()
......@@ -60,7 +61,7 @@ def calculate_ira_semester(admission, year, semester, amount_semesters):
average += ira_semester
amount += 1
if amount == 0
if amount == 0:
return -1
else:
return average/amount
......@@ -72,7 +73,7 @@ def calculate_ira_semester_standard_deviation(average, admission, year, semester
for student in students:
time = student.get_time_in_degree()
if amount_semesters = time
if amount_semesters == time:
amount_semesters = time
student_klass_semester = student.studentklass_set.filter(klass__year = year, klass__semester = semester)
ira_semester = calculate_ira(student_klass_semesters)
......@@ -81,7 +82,7 @@ def calculate_ira_semester_standard_deviation(average, admission, year, semester
variance += math.pow(ira_semester - average, 2)
amount += 1
if amount == 0
if amount == 0:
return -1
else:
return math.sqrt(variancia/amount)
......@@ -114,3 +115,32 @@ def calculate_pass_rate_semester(students):
total_semesters = {}
new_semesters = {}
temp_semesters = {}
def calculate_evasion_rate(admission):
return
def calculate_evasion_rate_semester(admission):
students = Student.objects.filter(admission = admission)
total_amount = students.count()
evasion_semester = {}
for student in students.exclude(evasion_form__in=SITUATION_NO_EVASION):
if student.evasion_year is None or student.evasion_semester is None:
continue
date = str(student.evasion_year) + "/" + str(student.evasion_semester)
if date not in evasion_semester:
evasion_semester[date] = {'amount_evasion': 1}
else:
evasion_semester[date]['amount_evasion'] += 1
if total_amount != 0:
for key in evasion_semester:
evasion_semester[key]['rate'] = 100 * evasion_semester[key]['amount_evasion'] / total_amount
else:
for key in evasion_semester:
evasion_semester[key]['rate'] = 0
return evasion_semester
# -*- coding: utf-8 -*-
from .models import Degree
from student.analysis import *
from student.models import Student
from admission.analysis import *
from admission.models import Admission
from klass.models import Klass, StudentKlass
from utils.data import *
import numpy as np
import math
def average_graduation(degree): # media_formandos
pass
student_list = Student.objects.filter(admission__degree = degree)
total_student = student_list.count()
graduate = student_list.filter(evasion_form = "Formatura").count()
graduation_rate = graduate / total_student * 100
return [graduation_rate, total_student]
def average_time_graduation_degree(degree): # tempo_medio_formatura_curso
pass
students = Student.objects.filter(admission__degree = degree)
student_amount = students.count()
graduated = students.filter(evasion_form = "Formatura")
graduated_amount = graduated.count()
average_time = 0
for g in graduated:
average_time += g.get_time_in_degree()
average_time /= graduated_amount
average_time /= 2
return average_time
def average_general_failure(students):
courses = 0
failures = 0
for student in students:
student_klasses = StudentKlass.objects.filter(student=student)
for sk in student_klasses:
courses += 1
if sk.situation in SITUATION_FAILURE:
failures += 1
return failures / courses * 100
def average_general_failure_standard_deviation(degree): # media_reprovacao_geral_desvio_padrao
students = Student.objects.filter(admission__degree = degree)
average_failure = average_general_failure(students)
variance = 0
for student in students:
courses = 0
failures = 0
student_klasses = StudentKlass.objects.filter(student=student)
for sk in student_klasses:
courses += 1
if sk.situation in SITUATION_FAILURE:
failures += 1
variance += math.pow((failures / courses) - average_failure, 2)
variance /= students.count()
standard_deviation = math.sqrt(variance)
return [average_failure, standard_deviation]
pass
def average_actives_failure_standard_deviation(degree): # media_reprovacao_alunos_cursando_desvio_padrao
......@@ -25,7 +77,11 @@ def calculate_average_actives_ira_standard_deviation(degree): # calcular_ira_med
pass
def calculate_general_evasion(degree): # calcular_evasao_geral
pass
students = Student.objects.filter(admission__degree = degree)
student_amount = students.count()
evasion_amount = students.exclude(evasion_form__in = SITUATION_NO_EVASION).count()
return 0 if student_amount == 0 else evasion_amount / student_amount
def graph_evasion(degree): # grafico_periodo
admissions = Admission.objects.filter(degree = degree)
......@@ -36,7 +92,67 @@ def graph_evasion(degree): # grafico_periodo
for admission in admissions:
year = admission.year
semester = admission.semester
index_semester_evasion = 0
evasion_semester_rate = calculate_evasion_rate_semester(admission)
for esr in evasion_semester_rate:
date = esr.split('/')
year_s = 2*(int(date[0]) - year)
if int(date[1]) - semester < 0:
semester_s = 1
else:
semester_s = int(date[1]) - semester
if year_s + semester_s + 1 > 8:
continue
date = '{}º Período'.format(year_s + semester_s + 1)
if date not in dict_amount:
dict_amount[date] = 0
dict_amount[date] += evasion_semester_rate[esr]['amount_evasion']
evasion += evasion_semester_rate[esr]['amount_evasion']
for da in dict_amount:
amount = dict_amount[da]
dic[da] = {'amount': amount, 'rate': (amount/evasion)*100}
return dic
def graph_average_ira(degree): # grafico_ira_medioi
students = Student.objects.filter(admission__degree = degree)
dic = build_dict_average_ira(students)
return dic
def graph_average_ira_evasion_semester(degree): # grafico_ira_medio_sem_evasao
students = Student.objects.filter(admission__degree = degree, evasion_form = 'Sem evasão')
dic = build_dict_average_ira(students)
return dic
def graph_average_ira_graduation(degree): # grafico_ira_medio_formatura
students = Student.objects.filter(admission__degree = degree, evasion_form = "Formatura")
dic = build_dict_average_ira(students)
return dic
def build_dict_average_ira(students):
dic = {"00-4.9":0, "05-9.9":0, "10-14.9":0, "15-19.9":0, "20-24.9":0, "25-29.9":0, "30-34.9":0,
"35-39.9":0, "40-44.9":0, "45-49.9":0, "50-54.9":0, "55-59.9":0, "60-64.9":0, "65-69.9":0,
"70-74.9":0, "75-79.9":0, "80-84.9":0, "85-89.9":0, "90-94.9": 0,"95-100":0}
iras = []
for student in students:
if student.ira is not None:
iras.append(student.ira)
for d in dic:
aux = d.split('-')
v1 = float(aux[0])
if v1 == 0.0:
v1 += 0.01
v2 = float(aux[1])
dic[d] = sum((float(num) >= v1) and (float(num) < v2) for num in iras)
return dic
def student_retirement(degree): # jubilamento_alunos
year = degree.report_year
......@@ -50,8 +166,9 @@ def student_retirement(degree): # jubilamento_alunos
return students
def amount_students_actives(degree): # quantidade_alunos_atual
pass
def amount_student_actives(degree): # quantidade_alunos_atual
amount_student = Student.objects.filter(admission__degree = degree, evasion_form = "Sem evasão").count()
return amount_student
def student_lock(degree): # trancamento_alunos
students = Student.objects.filter(admission__degree = degree,
......
......@@ -15,7 +15,7 @@ class Curriculum(models.Model):
current = models.BooleanField()
def get_amount_of_semesters(self):
max_period = CourseCurriculum.objecs.filter(curriculum = self).aggregate(Max('period'))
max_period = CourseCurriculum.objects.filter(curriculum = self).aggregate(Max('period'))
return max_period['period__max']
class CourseCurriculum(models.Model):
......
......@@ -46,7 +46,7 @@ def generate_data():
os.mkdir(path)
path = 'cache/curso'
if not os.path.ecists(path):
if not os.path.exists(path):
os.mkdir(path)
degrees = Degree.objects.all()
......@@ -66,13 +66,13 @@ def generate_data():
def generate_degree_data(degree, path):
print("Fazendo analises do Curso - {}".format(degree.name))
average_graduation = average_graduation(degree) # media_formandos
average_grad = average_graduation(degree) # media_formandos
dic = merge_dicts(graph_average_ira(degree), graph_average_ira_evasion_semester(degree), graph_average_ira_graduation(degree), ['average_ira', 'semester_evasion', 'graduation'])
degree_data = {
'time_graduation': average_time_graduation_degree(degree),
'graduation_rate': average_graduation[0],
'student_amount': average_graduation[1],
'graduation_rate': average_grad[0],
'student_amount': average_grad[1],
'failure_rate': average_general_failure_standard_deviation(degree),
'failure_actives': average_actives_failure_standard_deviation(degree),
'ira_average': calculate_average_general_ira_standard_deviation(degree),
......@@ -82,7 +82,6 @@ def generate_degree_data(degree, path):
'evasion_graph': json.dumps(sorted(graph_evasion(degree).items())),
'retirement': student_retirement(degree),
'amount_student_actives': amount_student_actives(degree),
'total_students': Student.objects.filter(admission__degree = degree).count(),
'amount_locking': student_lock(degree),
'gradueted': student_gradueted(degree)
}
......@@ -94,28 +93,28 @@ def generate_degree_data(degree, path):
def generate_student_data(degree, path):
print("\t- Fazendo analises dos alunos")
pass
return
def generate_student_list_data(degree, path):
print("\t- Criando lista de alunos"
pass
print("\t- Criando lista de alunos")
return
def generate_admission_data(degree, path):
pass
return
def generate_admission_list_data(degree, path):
pass
return
def generate_course_data(degree, path):
print("\t - Fazendo analises das disciplinas")
pass
return
def generate_course_general_data(degree, path):
print("\t- Fazendo analise geral das disciplinas")
pass
return
def generate_cp9615_data(degree, path):
pass
def generate_cepe9615_data(degree, path):
return
if __name__ == '__main__':
main()
......@@ -5,7 +5,7 @@ from admission.models import Admission
from degree.models import *
from datetime import datetime
from django.db.models import Max
from adega.utils.data import *
from utils.data import *
def pass_amount(student_klasses): # calcular_indice_aprovacao
amount_pass = 0
......@@ -85,7 +85,7 @@ def calculate_ira(student_klasses):
return ira / 100
def get_ira_semester(student)
def get_ira_semester(student):
iras = {}
amount_semesters = student.get_time_in_degree()
......@@ -96,7 +96,7 @@ def get_ira_semester(student)
student_klass_semester = student.studentklass_set.filter(klass__year = year, klass__semester = semester)
semester_ira = calculate_ira(student_klass_semester)
if semester_ira >= 0
if semester_ira >= 0:
key = "{}/{}".format(year, semester)
iras[key] = semester_ira
......@@ -109,7 +109,7 @@ def get_student_position(student):
student_iras = get_ira_semester(student)
positions = {}
positions = positions.fromkeys(student_iras.keys())
positions = {semester: {'position': 1, 'amount_student': 1} for semester, value in student_iras.items())}
positions = {semester: {'position': 1, 'amount_student': 1} for semester, value in student_iras.items()}
admission_students = Student.objects.filter(admission = student.admission).exclude(grr = student.grr)
......
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