Commit 9993aae7 authored by bhm15's avatar bhm15
Browse files

adega#115: Create class StudentAnalysis & Create student app

parent e5ee20d2
......@@ -47,6 +47,7 @@ INSTALLED_APPS = [
'educator',
'admission',
'course',
'student',
'report_api',
'uploads'
]
......
......@@ -63,7 +63,7 @@
<ul class="nav navbar-nav hidden-md hidden-lg">
<li><a href="#">Alunos</a></li>
<li><a href="{% url 'student:index' degree_id=degree.code%}">Alunos</a></li>
<li><a href="{% url 'course:index' degree_id=degree.code%}">Turmas de Ingresso</a></li>
<li class="dropdown">
<a href="{% url 'course:index' degree_id=degree.code%}" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">
......
<div class="sidebar left hidden-sm hidden-xs">
<ul class="list-sidebar">
<li><a href="#">Alunos</a></li>
<li><a href="{% url 'student:index' degree_id=degree.code%}">Alunos</a></li>
<li style="display: block;">
<div>
<a href="{% url 'course:index' degree_id=degree.code%}">Disciplinas</a>
......
......@@ -13,6 +13,8 @@ urlpatterns = [
url(r'^course/(?P<degree_id>\w*)/', include('course.urls', namespace='course')),
url(r'^student/(?P<degree_id>\w*)/', include('student.urls', namespace='student')),
url(r'^degree/(?P<degree_id>\w*)/', include('degree.urls', namespace='degree')),
url(r'^public/', include('public.urls', namespace='public')),
......
......@@ -23,4 +23,7 @@ def get_list_courses(session,degree):
return get_data(session,degree,"disciplina/disciplinas.json")
def get_course_detail(session,degree, course_id):
return get_data(session,degree,"disciplina/"+course_id+".json")
\ No newline at end of file
return get_data(session,degree,"disciplina/"+course_id+".json")
def get_list_students(session, degree, list_name):
return get_data(session,degree,"students/list/"+list_name+".json")
\ No newline at end of file
import numpy as np
from script.utils.situations import *
from script.analysis.student_analysis import ira_alunos
from script.analysis.student_analysis import StudentAnalysis
from collections import defaultdict
import numpy as np
......@@ -10,8 +10,9 @@ ANO_ATUAL = 2017
SEMESTRE_ATUAL = 2
def iras_alunos_turmas_ingressos(df):
iras = ira_alunos(df)
student_analysis = StudentAnalysis(df)
iras = student_analysis.ira_alunos()
turmas_ingresso_grr = df.groupby([
"ANO_INGRESSO",
"SEMESTRE_INGRESSO",
......
......@@ -5,179 +5,223 @@ import numpy as np
#~ AO CHAMAR A FUNCAO VERIFICAR SE TEM ALGO NA CACHE
from script.utils.situations import *
from script.utils.utils import memoize
import pandas as pd
from collections import defaultdict
CURRENT_YEAR = 2017
CURRENT_SEMESTER = 1
class StudentAnalysis:
data_frame = None
def list_students(df):
#~ ativos = df[["MATR_ALUNO", "NOME_PESSOA",]][df["FORMA_EVASAO"] == EvasionForm.EF_ATIVO].drop_duplicates()
situations = df.groupby(["MATR_ALUNO", "NOME_PESSOA", "FORMA_EVASAO"])
situations = list(pd.DataFrame({'count' : situations.size()}).reset_index().groupby(["FORMA_EVASAO"]))
#~ Cria lista de nome de listagens
list_situations = {}
for s in situations:
#Busca a lista de alunos relacionados a um codigo
list_situations[s[0]] = list(s[1]["MATR_ALUNO"])
return list_situations
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
def taxa_aprovacao(df):
aprovacoes_semestres = indice_aprovacao_semestral(df)
def __init__(self, df):
self.data_frame = 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]
@memoize
def list_students(self, df=None):
df = df if df is not None else self.data_frame
#~ ativos = df[["MATR_ALUNO", "NOME_PESSOA",]][df["FORMA_EVASAO"] == EvasionForm.EF_ATIVO].drop_duplicates()
situations = df.groupby(["MATR_ALUNO", "NOME_PESSOA", "FORMA_EVASAO"])
situations = list(pd.DataFrame({'count' : situations.size()}).reset_index().groupby(["FORMA_EVASAO"]))
#~ Cria lista de nome de listagens
iras = self.ira_alunos()
list_situations = defaultdict(list)
for sit in situations:
#Busca a lista de alunos relacionados a um codigo
grrs = list(sit[1]["MATR_ALUNO"])
people_names = list(sit[1]["NOME_PESSOA"])
return aprovacoes_semestres
evasion_form_name = EvasionForm.code_to_str(sit[0])
for i, student in enumerate(grrs):
list_situations[sit[0]].append({
"forma_evasao": evasion_form_name,
"grr": grrs[i],
"ira": iras[ grrs[i] ],
"nome": people_names[i]
})
return list_situations
@memoize
def ira_alunos(self, df=None):
df = df if df is not None else self.data_frame
iras = self.ira_por_quantidade_disciplinas()
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
def posicao_turmaIngresso_semestral(df):
iras = ira_semestral(df)
iraMax = {}
for matr in iras:
for semestreAno in iras[matr]:
if not (semestreAno in iraMax):
iraMax[semestreAno] = iras[matr][semestreAno]
@memoize
def taxa_aprovacao(self, df=None):
df = df if df is not None else self.data_frame
aprovacoes_semestres = self.indice_aprovacao_semestral()
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:
if (iras[matr][semestreAno] > iraMax[semestreAno]):
aprovacoes_semestres[aluno] = None
#~ for semestre in aprovacoes_semestres[aluno]:
#~ aprovacoes+=aprovacoes_semestres[aluno][semestre][0]
#~ total+=aprovacoes_semestres[semestre][1]
return aprovacoes_semestres
@memoize
def posicao_turmaIngresso_semestral(self, df=None):
df = df if df is not None else self.data_frame
iras = self.ira_semestral()
iraMax = {}
for matr in iras:
for semestreAno in iras[matr]:
if not (semestreAno in iraMax):
iraMax[semestreAno] = iras[matr][semestreAno]
for matr in iras:
for semestreAno in iras[matr]:
iras[matr][semestreAno] /= iraMax[semestreAno]
return iras
def periodo_real(df):
aux = df.groupby(["MATR_ALUNO"])
students = {}
for x in aux:
students[x[0]] = None
return students
def periodo_pretendido(df):
aux = df.groupby(["MATR_ALUNO", "ANO_INGRESSO", "SEMESTRE_INGRESSO"])
students = {}
for x in aux:
students[x[0][0]] = (CURRENT_YEAR - int(x[0][1])) * 2 + CURRENT_SEMESTER - int(x[0][2]) + 1
return students
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
def ira_por_quantidade_disciplinas(df):
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] = {}
ano = str(int(df["ANO"][i]))
semestre = str(df["PERIODO"][i])
situacao = int(df["SITUACAO"][i])
nota = float(df["MEDIA_FINAL"][i])
carga = float(df["CH_TOTAL"][i])
#media_credito = int(df["MEDIA_CREDITO"][i])
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
@memoize
def periodo_real(self, df=None):
df = df if df is not None else self.data_frame
aux = df.groupby(["MATR_ALUNO"])
students = {}
for x in aux:
students[x[0]] = None
return students
@memoize
def periodo_pretendido(self, df=None):
df = df if df is not None else self.data_frame
#if (situacao in Situation.SITUATION_AFFECT_IRA and media_credito != 0):
if (situacao in Situation.SITUATION_AFFECT_IRA):
if not (ano + "/" + semestre in students[matr]):
students[matr][ano + "/" + semestre] = [0, 0, 0]
aux = df.groupby(["MATR_ALUNO", "ANO_INGRESSO", "SEMESTRE_INGRESSO"])
students = {}
for x in aux:
students[x[0][0]] = (CURRENT_YEAR - int(x[0][1])) * 2 + CURRENT_SEMESTER - int(x[0][2]) + 1
return students
@memoize
def ira_semestral(self, df=None):
df = df if df is not None else self.data_frame
aux = self.ira_por_quantidade_disciplinas()
for matr in aux:
for periodo in aux[matr]:
aux[matr][periodo] = aux[matr][periodo][0]
return aux
@memoize
def ira_por_quantidade_disciplinas(self, df=None):
df = df if df is not None else self.data_frame
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] = {}
ano = str(int(df["ANO"][i]))
semestre = str(df["PERIODO"][i])
situacao = int(df["SITUACAO"][i])
nota = float(df["MEDIA_FINAL"][i])
carga = float(df["CH_TOTAL"][i])
#media_credito = int(df["MEDIA_CREDITO"][i])
students[matr][ano + "/" + semestre][0] += nota*carga
students[matr][ano + "/" + semestre][1] += 1
students[matr][ano + "/" + semestre][2] += carga
for matr in students:
for periodo in students[matr]:
if (students[matr][periodo][2] != 0):
students[matr][periodo][0] /= students[matr][periodo][2] * 100
return (students)
def indice_aprovacao_semestral(df):
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] = {}
ano = str(int(df["ANO"][i]))
semestre = str(df["PERIODO"][i])
situacao = int(df["SITUACAO"][i])
if not (ano + "/" + semestre in students[matr]):
students[matr][ano + "/" + semestre] = [0, 0]
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
#if (situacao in Situation.SITUATION_AFFECT_IRA and media_credito != 0):
if (situacao in Situation.SITUATION_AFFECT_IRA):
if not (ano + "/" + semestre in students[matr]):
students[matr][ano + "/" + semestre] = [0, 0, 0]
students[matr][ano + "/" + semestre][0] += nota*carga
students[matr][ano + "/" + semestre][1] += 1
students[matr][ano + "/" + semestre][2] += carga
for matr in students:
for periodo in students[matr]:
if (students[matr][periodo][2] != 0):
students[matr][periodo][0] /= students[matr][periodo][2] * 100
return students
@memoize
def indice_aprovacao_semestral(self, df=None):
df = df if df is not None else self.data_frame
return (students)
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] = {}
ano = str(int(df["ANO"][i]))
semestre = str(df["PERIODO"][i])
situacao = int(df["SITUACAO"][i])
if not (ano + "/" + semestre in students[matr]):
students[matr][ano + "/" + semestre] = [0, 0]
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)
def aluno_turmas(df):
students = {}
df = df.dropna(subset=['MEDIA_FINAL'])
@memoize
def aluno_turmas(self, df=None):
df = df if df is not None else self.data_frame
students = {}
df = df.dropna(subset=['MEDIA_FINAL'])
situations = dict(Situation.SITUATIONS)
situations = dict(Situation.SITUATIONS)
for matr, hist in df.groupby('MATR_ALUNO'):
students[matr] = []
for matr, hist in df.groupby('MATR_ALUNO'):
students[matr] = []
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)
}
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)
}
students[matr].append(data)
students[matr].append(data)
return students
return students
from script.utils.utils import *
from script.utils.situations import *
from script.analysis.degree_analysis import *
from script.analysis.student_analysis import *
from script.analysis.student_analysis import StudentAnalysis
from script.analysis.course_analysis import *
from script.analysis.admission_analysis import *
......@@ -13,16 +13,21 @@ except NameError:
to_unicode = str
student_analysis = None
def build_cache(dataframe,path):
# os.chdir("../src")
ensure_path_exists(path)
student_analysis = StudentAnalysis(dataframe)
for cod, df in dataframe.groupby('COD_CURSO'):
path = path + '/'
# generate_degree_data(path, df)
generate_student_data(path+'students/',df)
# generate_admission_data(path+'/admission/',df)
# generate_course_data(path+'disciplina/' ,dataframe)
generate_degree_data(path, df)
generate_student_data(path+'students/', dataframe, student_analysis)
generate_admission_data(path+'/admission/',df)
generate_course_data(path+'disciplina/' ,dataframe)
def generate_degree_data(path, dataframe):
ensure_path_exists(path)
......@@ -57,7 +62,7 @@ def process_semestre(per, df):
def generate_student_data(path, dataframe):
def generate_student_data(path, dataframe, student_analysis):
student_data = dict()
all_grrs = list(dataframe["MATR_ALUNO"].drop_duplicates())
for x in all_grrs:
......@@ -68,29 +73,29 @@ def generate_student_data(path, dataframe):
# tupla que contem no primeiro elemento a funcao que retorna um dicionario com {"GRR": valor}
# e na segunda posicao o nome que esta analise tera no json
# (posicao_turmaIngresso_semestral(dataframe),
# "posicao_turmaIngresso_semestral"),
(student_analysis.posicao_turmaIngresso_semestral(),
"posicao_turmaIngresso_semestral"),
# (periodo_real(dataframe),
# "periodo_real"),
(student_analysis.periodo_real(),
"periodo_real"),
# (periodo_pretendido(dataframe),
# "periodo_pretendido"),
(student_analysis.periodo_pretendido(),
"periodo_pretendido"),
# (ira_semestral(dataframe),
# "ira_semestral"),
(student_analysis.ira_semestral(),
"ira_semestral"),
# (ira_por_quantidade_disciplinas(dataframe),
# "ira_por_quantidade_disciplinas"),
(student_analysis.ira_por_quantidade_disciplinas(),
"ira_por_quantidade_disciplinas"),
# (indice_aprovacao_semestral(dataframe),
# "indice_aprovacao_semestral"),
(student_analysis.indice_aprovacao_semestral(),
"indice_aprovacao_semestral"),
# (aluno_turmas(dataframe),
# "aluno_turmas"),
(student_analysis.aluno_turmas(),
"aluno_turmas"),
# (taxa_aprovacao(dataframe),
# "taxa_aprovacao"),
(student_analysis.taxa_aprovacao(),
"taxa_aprovacao"),
]
for x in student_data:
......@@ -103,14 +108,18 @@ def generate_student_data(path, dataframe):
EvasionForm.EF_ABANDONO,
EvasionForm.EF_DESISTENCIA,
EvasionForm.EF_FORMATURA,
EvasionForm.EF_ATIVO
EvasionForm.EF_ATIVO,
EvasionForm.EF_OUTROS
]
list_situations = list_students(dataframe)
for l in list_situations:
if(l in files_list):
list_name = EvasionForm.code_to_str(int(l))
save_json(path+"list/"+list_name+".json", list_situations[l])
list_situations = student_analysis.list_students()
for fl in files_list:
list_name = EvasionForm.code_to_str(int(fl))
list_content = []
if(fl in list_situations):
list_content = list_situations[fl]
save_json(path+"list/"+list_name+".json", list_content)
......
import os
import copy
import ujson as json
......@@ -10,6 +11,18 @@ except:
DEBUG = True
# Use this class as decorator to save functions returns
def memoize(f):
memo = {}
def helper(x):
if str(x) not in memo:
memo[str(x)] = f(x)
return copy.deepcopy(memo[str(x)])
return helper
def invert_dict(d):
return {v: k for k, v in d}
......
from django.contrib import admin
# Register your models here.
from django.apps import AppConfig
class StudentConfig(AppConfig):
name = 'student'
from django.db import models