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

Bruno Meyer's avatar
Bruno Meyer committed
3
4
5
6
#~ TODO:
#~ FAZER CACHE DE TUDO
#~ AO CHAMAR A FUNCAO VERIFICAR SE TEM ALGO NA CACHE

7
from utils.situations import *
Bruno Meyer's avatar
Bruno Meyer committed
8
import pandas as pd
Bruno Meyer's avatar
Bruno Meyer committed
9

Bruno Meyer's avatar
Bruno Meyer committed
10
11
ANO_ATUAL = 2017
SEMESTRE_ATUAL = 2
Bruno Meyer's avatar
Bruno Meyer committed
12

13

Bruno Meyer's avatar
Bruno Meyer committed
14
15
16
17
18
def listagem_alunos(df):
	#~ ativos = df[["MATR_ALUNO", "NOME_PESSOA",]][df["FORMA_EVASAO"] == EvasionForm.EF_ATIVO].drop_duplicates()
	situacoes = df.groupby(["MATR_ALUNO", "NOME_PESSOA", "FORMA_EVASAO"])
	situacoes = list(pd.DataFrame({'count' : situacoes.size()}).reset_index().groupby(["FORMA_EVASAO"]))
	#~ Cria lista de nome de listagens
bhm15's avatar
bhm15 committed
19
20
21
22
	retorno = {}
	for s in situacoes:
		#Busca a lista de alunos relacionados a um codigo
		retorno[s[0]] = list(s[1]["MATR_ALUNO"])
Bruno Meyer's avatar
Bruno Meyer committed
23

bhm15's avatar
bhm15 committed
24
	return retorno
Bruno Meyer's avatar
Bruno Meyer committed
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39

def ira_alunos(df):
	iras = ira_por_quantidade_disciplinas(df)
	for i in iras:
		ira_total = 0
		carga_total = 0
		for semestre in iras[i]:
			ira_total += iras[i][semestre][0]*iras[i][semestre][2]
			carga_total+=iras[i][semestre][2]
		
		if(carga_total != 0):
			iras[i] = ira_total/carga_total
		else:
			iras[i] = 0
	return iras
40
	
Bruno Meyer's avatar
Bruno Meyer committed
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
def taxa_aprovacao(df):
	aprovacoes_semestres = indice_aprovacao_semestral(df)
	
	for aluno in aprovacoes_semestres:
		total = sum([aprovacoes_semestres[aluno][s][1] for s in aprovacoes_semestres[aluno]])
		aprovacoes = sum([aprovacoes_semestres[aluno][s][0] for s in aprovacoes_semestres[aluno]])
		total = float(total)
		aprovacoes = float(aprovacoes)
		if(total != 0):
			aprovacoes_semestres[aluno] = aprovacoes/total
		else:
			aprovacoes_semestres[aluno] = None
		#~ for semestre in aprovacoes_semestres[aluno]:
			#~ aprovacoes+=aprovacoes_semestres[aluno][semestre][0]
			#~ total+=aprovacoes_semestres[semestre][1]
			
	return aprovacoes_semestres
	
	
Bruno Meyer's avatar
Bruno Meyer committed
60

Bruno Meyer's avatar
Bruno Meyer committed
61
def posicao_turmaIngresso_semestral(df):
62
63
64
65
66
67
68
69
70
71
72
73
74
75
	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
76

Bruno Meyer's avatar
Bruno Meyer committed
77
78

def periodo_real(df):
79
80
81
82
83
	aux = df.groupby(["MATR_ALUNO"])
	students = {}
	for x in aux:
		students[x[0]] = None
	return students
84

Bruno Meyer's avatar
Bruno Meyer committed
85

Bruno Meyer's avatar
Bruno Meyer committed
86
def periodo_pretendido(df):
87
88
89
90
91
	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
92

Bruno Meyer's avatar
Bruno Meyer committed
93

94
95
96
97
98
99
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
100

Bruno Meyer's avatar
Bruno Meyer committed
101

Bruno Meyer's avatar
Bruno Meyer committed
102
def ira_por_quantidade_disciplinas(df):
103
104
105
106
107
	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
108
		matr = df["MATR_ALUNO"][i]
109
110
111
112
113
114
115
		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
116
		carga = float(df["CH_TOTAL"][i])
Bruno Meyer's avatar
Bruno Meyer committed
117
		#media_credito = int(df["MEDIA_CREDITO"][i])
Bruno Meyer's avatar
Bruno Meyer committed
118
119
		
		
Bruno Meyer's avatar
Bruno Meyer committed
120
121
		#if (situacao in Situation.SITUATION_AFFECT_IRA and media_credito != 0):
		if (situacao in Situation.SITUATION_AFFECT_IRA):
122
			if not (ano + "/" + semestre in students[matr]):
Bruno Meyer's avatar
Bruno Meyer committed
123
124
125
				students[matr][ano + "/" + semestre] = [0, 0, 0]
			
			students[matr][ano + "/" + semestre][0] += nota*carga
126
			students[matr][ano + "/" + semestre][1] += 1
Bruno Meyer's avatar
Bruno Meyer committed
127
			students[matr][ano + "/" + semestre][2] += carga
128
129
130

	for matr in students:
		for periodo in students[matr]:
Bruno Meyer's avatar
Bruno Meyer committed
131
132
			if (students[matr][periodo][2] != 0):
				students[matr][periodo][0] /= students[matr][periodo][2] * 100
Bruno Meyer's avatar
Bruno Meyer committed
133
	
134
	return (students)
135

Bruno Meyer's avatar
Bruno Meyer committed
136

Bruno Meyer's avatar
Bruno Meyer committed
137
def indice_aprovacao_semestral(df):
138
139
140
141
142
143
144
	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] = {}
145

146
147
148
		ano = str(int(df["ANO"][i]))
		semestre = str(df["PERIODO"][i])
		situacao = int(df["SITUACAO"][i])
149

150
151
		if not (ano + "/" + semestre in students[matr]):
			students[matr][ano + "/" + semestre] = [0, 0]
152

153
154
155
156
157
		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
Bruno Meyer's avatar
Bruno Meyer committed
158
		
159
	return (students)
160

Bruno Meyer's avatar
Bruno Meyer committed
161

Bruno Meyer's avatar
Bruno Meyer committed
162
def aluno_turmas(df):
163
164
	students = {}
	df = df.dropna(subset=['MEDIA_FINAL'])
165

166
	situations = dict(Situation.SITUATIONS)
167

168
169
	for matr, hist in df.groupby('MATR_ALUNO'):
		students[matr] = []
170

171
172
173
174
175
176
177
178
179
		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)
			}
180

181
			students[matr].append(data)
182

183
	return students