Commit d2a9892f authored by Bruno Meyer's avatar Bruno Meyer 😢

Merge branch 'fix_course' into 'development'

Fix course

See merge request adega/adega!40
parents a8a54476 07e9d33f
# info de contas criadas no sistema
login_info
# base de dados
*.csv
......
This diff is collapsed.
version: '3'
services:
db:
container_name: adega_db_1
image: postgres
environment:
- POSTGRES_USER=adega
- POSTGRES_PASSWORD=adega
- POSTGRES_DB=adega
web:
container_name: adega_web_1
build:
context: .
dockerfile: ./docker_scripts/Dockerfile
......
......@@ -85,8 +85,8 @@
</tr>
<tr>
<td>Taxa Aprovação/Aproveitamento de Conhecimento</td>
<td>{% if analysis_result.taxa_aproveitamento_conhecimento >= 0%}
{{ analysis_result.taxa_aproveitamento_conhecimento|floatformat:2 }}%
<td>{% if analysis_result.taxa_conhecimento >= 0%}
{{ analysis_result.taxa_conhecimento|floatformat:2 }}%
{% else %}
Desconhecido
{% endif %}</td>
......@@ -147,4 +147,4 @@
});
</script>
{% endblock js-foot %}
\ No newline at end of file
{% endblock js-foot %}
......@@ -2,7 +2,7 @@ from degree.models import Degree
from uploads.models import Submission
import json
def get_data(session,degree,data_name):
def get_data(session, degree, data_name):
if "submission" in session:
submission = session["submission"]
else:
......@@ -17,16 +17,16 @@ def get_degree_information(session, degree):
return get_data(session,degree,"degree.json")
def get_list_admission(session, degree):
return get_data(session,degree,"admission/lista_turma_ingresso.json")
return get_data(session,degree,"admissions/lista_turma_ingresso.json")
def get_list_courses(session, degree):
return get_data(session,degree,"disciplina/disciplinas.json")
return get_data(session,degree,"courses/disciplinas.json")
def get_course_detail(session, degree, course_id):
return get_data(session,degree,"disciplina/"+course_id+".json")
return get_data(session,degree,"courses/"+course_id+".json")
def get_list_students(session, degree, list_name):
return get_data(session,degree,"students/list/"+list_name+".json")
def get_student_detail(session, degree, student_id):
return get_data(session,degree,"students/"+student_id+".json")
\ No newline at end of file
return get_data(session,degree,"students/"+student_id+".json")
......@@ -2,7 +2,15 @@
import numpy as np
from script.utils.situations import Situation as sit
from collections import namedtuple
rate = namedtuple("rate", ["name", "collumn_name", "fields_x", "fields_X"])
"""
Rate é uma tupla nomeada(deixa mais legivel fazer rate.name do que rate[0]) o
campo name define qual nome da taxa sera utilizado, collumn_name é qual coluna
do dataframe será utilizado para extrair dados, fields_x quais lista de valores
especifico será utilizado (numerador da taxa), fields_X é a lista de valores
gerais (denominador da taxa) e count_sel, assume valores 1 e 2, define qual quantidade será utilizada a
especifica ou a geral.
"""
rate = namedtuple("rate", ["name", "collumn_name", "fields_x", "fields_X", "count_sel"])
mean = namedtuple("mean", [
"name",
"collumn_name",
......@@ -45,7 +53,7 @@ class Analysis(object):
Calcula todas as taxas contida na lista rates para todos os dataframes
que estão dentro do groupby object groups.
O calculo de uma taxa, para um dataframe em especifico é feito da
seguinte maneira: filtrar se o dataframe de acordo com os valores da
seguinte maneira: filtra se o dataframe de acordo com os valores da
especificado em rate.collumn_name com os valores de rate.field_x para o
numerador e rate.fields_X para o denominador, a taxa é a divisão do
numerador pelo denominador.
......@@ -66,6 +74,7 @@ class Analysis(object):
X = self.count(groups, rate.collumn_name, rate.fields_X)
rate_c = x/X
rate_c[np.isnan(rate_c)] = 0.0
rate_c[np.isinf(rate_c)] = 0.0
rate_dict[rate.name] = [rate_c, x, X]
return rate_dict
......
# -*- coding: utf-8 -*-
from script.utils.situations import Situation as sit
from script.analysis.analysis import Analysis, rate, mean
import numpy as np
class Course(Analysis):
......@@ -27,31 +28,36 @@ class Course(Analysis):
"taxa_reprovacao_absoluta",
"SITUACAO",
list(sit.SITUATION_FAIL),
list(sit.SITUATION_COURSED)
list(sit.SITUATION_COURSED),
1
),
rate(
"taxa_aprovacao",
"SITUACAO",
list(sit.SITUATION_PASS),
list(sit.SITUATION_COURSED)
list(sit.SITUATION_FAIL) + list(sit.SITUATION_PASS),
2
),
rate(
"taxa_trancamento",
"SITUACAO",
[sit.SIT_CANCELADO],
list(sit.SITUATION_COURSED)
list(sit.SITUATION_CANCELLED),
list(sit.SITUATION_COURSED),
1
),
rate(
"taxa_conhecimento",
"SITUACAO",
[sit.SIT_CONHECIMENTO_APROVADO],
list(sit.SITUATION_KNOWLDGE)
),
list(sit.SITUATION_KNOWLDGE),
1
),
rate(
"taxa_reprovacao_frequencia",
"SITUACAO",
[sit.SIT_REPROVADO_FREQ],
list(sit.SITUATION_COURSED)
list(sit.SITUATION_COURSED),
1
)
]
__mean_set = [
......@@ -61,6 +67,7 @@ class Course(Analysis):
"MEDIA_FINAL")
]
__semestral_rate = [__rates[1]]
last_rate = [__rates[0], __rates[4]]
def __init__(self, df):
df_filted = df[df['SITUACAO'].isin(sit.SITUATION_COURSED)]
......@@ -103,6 +110,8 @@ class Course(Analysis):
self.semestral_count_submission()
self.graph_course()
self.coursed_count()
self.general_note_statistic()
self.last_year_rate()
self.__build_analyze = True
......@@ -118,11 +127,27 @@ class Course(Analysis):
o index para a coluna COD_ATIV_CURRIC, assim é possivel obter a serie.
"""
df = self.__data["normal_dataframe"]
df = self.__data["filted_dataframe"]
df = df[["COD_ATIV_CURRIC", "NOME_ATIV_CURRIC"]].drop_duplicates()
df = df.set_index("COD_ATIV_CURRIC")
self.analysis["courses"] = df["NOME_ATIV_CURRIC"]
def last_year_rate(self):
# reprovaçao rate
last_rates = self.last_rate
def f(x, rate):
x1 = x.loc[x.ANO == x.ANO.max()]
x_num = x1[x1[rate.collumn_name].isin(rate.fields_x)].shape[0]
x_deno = x1[x1[rate.collumn_name].isin(rate.fields_X)].shape[0]
return x_num / x_deno if x_deno > 0 else 0
groups = self.__data["normal_general_groupby"]
for r_it in last_rates:
g = groups.apply(lambda x: f(x, r_it))
self.analysis["last_year_" + r_it.name] = g
def general_rate(self):
"""
Calcula as taxas gerais para cada disciplina e a media das taxas.
......@@ -136,6 +161,8 @@ class Course(Analysis):
groups = self.__data["normal_general_groupby"]
rates = self.calc_rate(groups, self.__rates)
self.analysis["general_rates"] = rates
# calculo das rates do ultimo ano
# calcula estastistica gerais de todas disciplina
for rate_it in self.__rates:
rate_mean = self.analysis["general_rates"][rate_it.name][0].mean()
rate_std = self.analysis["general_rates"][rate_it.name][0].std()
......@@ -171,11 +198,23 @@ class Course(Analysis):
group = self.__data["filted_general_groupby"]
serie_mean = group.apply(lambda x: x["MEDIA_FINAL"].mean())
serie_std = group.apply(lambda x: x["MEDIA_FINAL"].std())
last_year_mean = group.apply(
lambda x: x.loc[x.ANO == x.ANO.max()].MEDIA_FINAL.mean())
last_year_std = group.apply(
lambda x: x.loc[x.ANO == x.ANO.max()].MEDIA_FINAL.std())
# caso tenha algum nan, troque por 0.0
serie_mean[np.isnan(serie_mean)] = 0.0
serie_std[np.isnan(serie_std)] = 0.0
last_year_mean[np.isnan(last_year_mean)] = 0.0
last_year_std[np.isnan(last_year_std)] = 0.0
general_mean = serie_mean.mean()
general_std = serie_mean.mean()
general_std = serie_std.mean()
self.analysis["general_note_statistic"] = [serie_mean, serie_std]
self.analysis["general_note_mean"] = general_mean
self.analysis["general_note_std"] = general_std
self.analysis["last_year_statistic"] = [last_year_mean, last_year_std]
self.analysis["general_last_year_mean"] = last_year_mean.mean()
self.analysis["general_last_year_std"] = last_year_std.mean()
def general_count_submission(self):
"""
......@@ -240,11 +279,20 @@ class Course(Analysis):
for df in self.__data[dict_name]:
if df[0][0] not in course_dict:
course_dict[df[0][0]] = dict.fromkeys(
[str(i) for i in range(1, 6)], 0)
[str(i) for i in range(1, 6)], 0)
count = df[1].shape[0] if df[1].shape[0] <= 5 else 5
course_dict[df[0][0]][str(count)] += 1
self.analysis["coursed_count"] = course_dict
# ratio coursed count
def f(x):
coursed_succes = x[x['SITUACAO'].isin(sit.SITUATION_PASS)].shape[0]
return (x.shape[0] / coursed_succes) if coursed_succes > 0 else -1
groups = self.__data["filted_dataframe"].groupby(["COD_ATIV_CURRIC"])
ratio_coursed = groups.apply(lambda x: f(x))
self.analysis["coursed_ratio"] = ratio_coursed.to_dict()
def build_general_course(self):
"""
......@@ -262,12 +310,15 @@ class Course(Analysis):
# cria cache
cache = {}
note = self.analysis["general_note_statistic"]
for rate_it in self.__rates:
rate_calc = self.analysis["general_rates"][rate_it.name][0]
for course in self.analysis["courses"].index:
if course not in cache:
cache[course] = {}
cache[course][rate_it.name] = rate_calc[course]
cache[course]["nota"] = [note[0][course], note[1][course]]
courses["cache"] = cache
# cria o campo compara_aprov
......@@ -293,12 +344,13 @@ class Course(Analysis):
if i[0] not in aprovacao_d:
aprovacao_d[i[0]] = {}
periodo = str(i[1])+"/"+str(i[2])
periodo = str(i[1]) + "/" + str(i[2])
aprovacao_d[i[0]][periodo] = [
float(rate_data[0][i]),
int(rate_data[1][i])
]
float(rate_data[0][i]),
int(rate_data[rate_it.count_sel][i])]
note = self.analysis["general_note_statistic"]
note_last_year = self.analysis["last_year_statistic"]
for course in self.analysis["courses"].index:
course_dict = {}
course_dict["disciplina_codigo"] = course
......@@ -306,16 +358,29 @@ class Course(Analysis):
# quantidade de matriculas
count = self.analysis["general_count_submission"][course]
course_dict["qtd_alunos"] = count
# notas
course_dict["qtd_cursada_aprov"] = self.analysis["coursed_ratio"][course]
course_dict["nota"] = [note[0][course], note[1][course]]
course_dict["nota_ultimo_ano"] = [
note_last_year[0][course],
note_last_year[1][course]
]
# taxas
for rate_it in self.__rates:
rate_data = self.analysis["general_rates"][rate_it.name]
course_dict[rate_it.name] = float(rate_data[0][course])
course_str = rate_it.name.replace("taxa", "qtd")
course_dict[course_str] = float(rate_data[1][course])
course_dict["grafico_qtd_cursada_aprov"] = \
self.analysis["coursed_count"][course]
# count_sel define qual quantidade vai para o json, a especifica
# ou geral
course_dict[course_str] = int(
rate_data[rate_it.count_sel][course])
# rate_calc = self.analysis["general_rates"][rate_it.name][0]
# taxas do ultimo anos
course_dict["taxa_reprovacao_ultimo_absoluto"] = self.analysis["last_year_taxa_reprovacao_absoluta"][course]
course_dict["taxa_reprovacao_ultimo_frequencia"] = self.analysis["last_year_taxa_reprovacao_frequencia"][course]
course_dict["grafico_qtd_cursada_aprov"] = self.analysis["coursed_count"][course]
course_dict["aprovacao_semestral"] = aprovacao_d[course]
courses.append(course_dict)
......
......@@ -27,8 +27,8 @@ def build_cache(dataframe,path):
path = path + '/'
generate_degree_data(path, df)
generate_student_data(path+'students/',df,student_analysis)
generate_admission_data(path+'admission/',df)
generate_course_data(path+'disciplina/' ,dataframe)
generate_admission_data(path+'admissions/',df)
generate_course_data(path+'courses/' ,dataframe)
generate_cepe_data(path+'/others/',df)
......
......@@ -188,5 +188,10 @@ class Situation:
SIT_CONHECIMENTO_REPROVADO,
SIT_REPROVADO_SEM_NOTA,
SIT_INCOMPLETO,
SIT_CANCELADO,
SIT_CANCELADO,
)
SITUATION_CANCELLED = (
SIT_TRANCAMENTO_TOTAL,
SIT_TRANCAMENTO_ADMINISTRATIVO,
SIT_CANCELADO
)
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