student_analysis.py 3.37 KB
Newer Older
1
import numpy as np
Bruno Meyer's avatar
Bruno Meyer committed
2

3
from utils.situations import *
Bruno Meyer's avatar
Bruno Meyer committed
4

Bruno Meyer's avatar
Bruno Meyer committed
5
6
ANO_ATUAL = 2017
SEMESTRE_ATUAL = 2
Bruno Meyer's avatar
Bruno Meyer committed
7

8

9
10
11
def listagem_alunos_ativos(df):
	return list(df["MATR_ALUNO"][df["FORMA_EVASAO"] == EvasionForm.EF_ATIVO].drop_duplicates())
	
12
13


Bruno Meyer's avatar
Bruno Meyer committed
14

Bruno Meyer's avatar
Bruno Meyer committed
15
def posicao_turmaIngresso_semestral(df):
16
17
18
19
20
21
22
23
24
25
26
27
28
29
	iras = ira_semestral(df)
	iraMax = {}
	for matr in iras:
		for semestreAno in iras[matr]:
			if not (semestreAno in iraMax):
				iraMax[semestreAno] = iras[matr][semestreAno]
			else:
				if (iras[matr][semestreAno] > iraMax[semestreAno]):
					iraMax[semestreAno] = iras[matr][semestreAno]
	for matr in iras:
		for semestreAno in iras[matr]:
			iras[matr][semestreAno] /= iraMax[semestreAno]

	return iras
30

Bruno Meyer's avatar
Bruno Meyer committed
31
32

def periodo_real(df):
33
34
35
36
37
	aux = df.groupby(["MATR_ALUNO"])
	students = {}
	for x in aux:
		students[x[0]] = None
	return students
38

Bruno Meyer's avatar
Bruno Meyer committed
39

Bruno Meyer's avatar
Bruno Meyer committed
40
def periodo_pretendido(df):
41
42
43
44
45
	aux = df.groupby(["MATR_ALUNO", "ANO_INGRESSO", "SEMESTRE_INGRESSO"])
	students = {}
	for x in aux:
		students[x[0][0]] = (ANO_ATUAL - int(x[0][1])) * 2 + SEMESTRE_ATUAL - int(x[0][2]) + 1
	return students
46

Bruno Meyer's avatar
Bruno Meyer committed
47

48
49
50
51
52
53
def ira_semestral(df):
	aux = ira_por_quantidade_disciplinas(df)
	for matr in aux:
		for periodo in aux[matr]:
			aux[matr][periodo] = aux[matr][periodo][0]
	return aux
54

Bruno Meyer's avatar
Bruno Meyer committed
55

Bruno Meyer's avatar
Bruno Meyer committed
56
def ira_por_quantidade_disciplinas(df):
57
58
59
60
61
	students = {}
	df = df.dropna(subset=["MEDIA_FINAL"])

	total_students = len(df["MATR_ALUNO"])
	for i in range(total_students):
Bruno Meyer's avatar
Bruno Meyer committed
62
		matr = df["MATR_ALUNO"][i]
63
64
65
66
67
68
69
		if (not (matr in students)):
			students[matr] = {}

		ano = str(int(df["ANO"][i]))
		semestre = str(df["PERIODO"][i])
		situacao = int(df["SITUACAO"][i])
		nota = float(df["MEDIA_FINAL"][i])
Bruno Meyer's avatar
Bruno Meyer committed
70
		carga = float(df["CH_TOTAL"][i])
71
		media_credito = int(df["MEDIA_CREDITO"][i])
Bruno Meyer's avatar
Bruno Meyer committed
72
73
		
		
74
75
		if (situacao in Situation.SITUATION_AFFECT_IRA and media_credito != 0):
			if not (ano + "/" + semestre in students[matr]):
Bruno Meyer's avatar
Bruno Meyer committed
76
77
78
				students[matr][ano + "/" + semestre] = [0, 0, 0]
			
			students[matr][ano + "/" + semestre][0] += nota*carga
79
			students[matr][ano + "/" + semestre][1] += 1
Bruno Meyer's avatar
Bruno Meyer committed
80
			students[matr][ano + "/" + semestre][2] += carga
81
82
83

	for matr in students:
		for periodo in students[matr]:
Bruno Meyer's avatar
Bruno Meyer committed
84
85
			if (students[matr][periodo][2] != 0):
				students[matr][periodo][0] /= students[matr][periodo][2] * 100
86
	return (students)
87

Bruno Meyer's avatar
Bruno Meyer committed
88

Bruno Meyer's avatar
Bruno Meyer committed
89
def indice_aprovacao_semestral(df):
90
91
92
93
94
95
96
	students = {}
	df = df.dropna(subset=['MEDIA_FINAL'])
	total_students = len(df["MATR_ALUNO"])
	for i in range(total_students):
		matr = (df["MATR_ALUNO"][i])
		if (not (matr in students)):
			students[matr] = {}
97

98
99
100
		ano = str(int(df["ANO"][i]))
		semestre = str(df["PERIODO"][i])
		situacao = int(df["SITUACAO"][i])
101

102
103
		if not (ano + "/" + semestre in students[matr]):
			students[matr][ano + "/" + semestre] = [0, 0]
104

105
106
107
108
109
110
		if situacao in Situation.SITUATION_PASS:
			students[matr][ano + "/" + semestre][0] += 1
			students[matr][ano + "/" + semestre][1] += 1
		if situacao in Situation.SITUATION_FAIL:
			students[matr][ano + "/" + semestre][1] += 1
	return (students)
111

Bruno Meyer's avatar
Bruno Meyer committed
112

Bruno Meyer's avatar
Bruno Meyer committed
113
def aluno_turmas(df):
114
115
	students = {}
	df = df.dropna(subset=['MEDIA_FINAL'])
116

117
	situations = dict(Situation.SITUATIONS)
118

119
120
	for matr, hist in df.groupby('MATR_ALUNO'):
		students[matr] = []
121

122
123
124
125
126
127
128
129
130
		for _, row in hist.iterrows():
			data = {
				'ano': str(int(row["ANO"])),
				'codigo': row["COD_ATIV_CURRIC"],
				'nome': row["NOME_ATIV_CURRIC"],
				'nota': row["MEDIA_FINAL"],
				'semestre': row["PERIODO"],
				'situacao': situations.get(row["SITUACAO"], Situation.SIT_OUTROS)
			}
131

132
			students[matr].append(data)
133

134
	return students