Commit 8c18ad0e authored by maria ruy's avatar maria ruy

adega#47: Add admission_class_ira_per_semester function on admission_analysis.py

parent 16bacd46
......@@ -9,6 +9,59 @@ import numpy as np
ANO_ATUAL = 2017
SEMESTRE_ATUAL = 2
def admission_class_ira_per_semester(df):
"""
Calculate the average IRA in every semester of the admission classes.
This function group the dataframe by admission classes.
Then group each class by semesters.
And finally group each semester by student.
Calculate each student's IRA and then the average IRA for the class.
Parameters
----------
df : DataFrame
Returns
-------
dict of {list:dict}
dict_admission={
(admission_class1):{semester1:ira, semester2:ira, ...},
(admission_class2):{semester1:ira, semester2:ira, ...},
...
}
Examples
--------
{('2005', '1'): {(2012, '1o. Semestre'): 0.485,
(2007, '1o. Semestre'): 0.6186531973412296, ...} ...}
"""
df = df[df['SITUACAO'].isin(Situation.SITUATION_AFFECT_IRA)]
df = df[ df['TOTAL_CARGA_HORARIA'] != 0]
admission_grouped = df.groupby(['ANO_INGRESSO_y','SEMESTRE_INGRESSO'])
dict_admission = {}
for admission in admission_grouped:
#admission_grouped is a tuple of tuples, each tuple contains 0-tuple year/semester & 1-dataframe
dict_ira_semester = {}
semester_grouped = admission[1].groupby(['ANO','PERIODO'])
for semester in semester_grouped:
student_grouped = semester[1].groupby('ID_ALUNO')
ira_class = 0
for student in student_grouped:
#TODO: Verify if this can be calculated without groupby
ira_individual =( (student[1].MEDIA_FINAL*student[1].TOTAL_CARGA_HORARIA).sum() )/(100*student[1].TOTAL_CARGA_HORARIA.sum())
ira_class += ira_individual
ira_class = ira_class / len(student_grouped)
dict_ira_semester.update({semester[0]:ira_class})
dict_admission.update({admission[0]:dict_ira_semester})
return dict_admission
def iras_alunos_turmas_ingressos(df):
iras = ira_alunos(df)
......
......@@ -21,7 +21,7 @@ def build_cache(dataframe,path):
path = path + '/'
generate_degree_data(path, df)
generate_student_data(path+'students/',df)
generate_admission_data(path+'/admission/',df)
generate_admission_data(path+'admission/',df)
generate_course_data(path+'disciplina/' ,dataframe)
def generate_degree_data(path, dataframe):
......@@ -121,33 +121,38 @@ def generate_student_list(path):
def generate_admission_data(path,df):
listagem = []
listagem = []
analises = [
("ira", media_ira_turma_ingresso(df)),
("desvio_padrao", desvio_padrao_turma_ingresso(df)),
]
analises = [
("ira", media_ira_turma_ingresso(df)),
("std", desvio_padrao_turma_ingresso(df)),
("ira_per_semester", admission_class_ira_per_semester(df)),
]
# cria um dicionario com as analises para cada turma
turmas = defaultdict(dict)
for a in analises:
for x in a[1]:
turmas[x][ a[0] ] = a[1][x]
# cria um dicionario com as analises para cada turma
turmas = defaultdict(dict)
for a in analises:
for x in a[1]:
valor = a[1][x]
x = ( str(x[0]), str(x[1]))
turmas[x][ a[0] ] = valor
listagem = []
listagem = []
for t in turmas:
resumo_turma = {
"ano": x[0],
"semestre": x[1]
}
for t in turmas:
resumo_turma = {
"ano": t[0],
"semestre": t[1]
}
for analise in turmas[t]:
resumo_turma[analise] = turmas[t][analise]
listagem.append(resumo_turma)
for analise in turmas[t]:
resumo_turma[analise] = turmas[t][analise]
listagem.append(resumo_turma)
save_json(path+"lista_turma_ingresso.json", listagem)
save_json(path+"lista_turma_ingresso.json", listagem)
def generate_admission_list(path,df):
......@@ -164,3 +169,5 @@ def generate_course_data(path,df):
disciplinas = listagem_disciplina(df,lista_disciplinas)
save_json(path+'disciplinas.json',disciplinas)
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