Commit 5dff2bc0 authored by Bruno Meyer's avatar Bruno Meyer 😢

Merge branch '136-rep-por-freq-na-disciplina' into 'development'

Resolve "rep por freq na disciplina"

Closes #136

See merge request adega/adega!38
parents dbb7507b 03058dfa
"""This resolution from CEPE deals with the cases where studants might have
their academic record canceled."""
import numpy as np
import pandas as pd
import pandas as pd
import pprint
from script.utils.situations import *
fails_by_course = [10] # used at: student_three_fails_course
fails_by_semester = [6, 10] # used at: n_fails_semester
fails_by_freq = [3, 5, 7] # used at: n_fails_by_freq
pp = pprint.PrettyPrinter(indent=4)
......@@ -21,12 +23,12 @@ def student_fails_course(df):
X, Y, Z ... are declared in the list "fails_by_course" at the top of analysis.
This function is inspired by CEPE 96/15 ART.9:
Students with 3 fails in the same course would have their registration suspended.
Students with 3 fails in the same course would have their registration suspended.
Parameters
----------
df : DataFrame
Returns
-------
dict of {int:dict}
......@@ -36,7 +38,7 @@ def student_fails_course(df):
"7":{aluno1:GRR, aluno2:GRR, ...},
...
}
Examples
--------
"3" : {
......@@ -49,7 +51,7 @@ def student_fails_course(df):
"José da Silva Carvalho": 20114027,
"Pedro dos Santos" : 20152678,
...
}
}
"""
# Filters based on the students that have failed at least once
# and are still registered on the University
......@@ -75,25 +77,24 @@ def student_fails_course(df):
def n_fails_semester (df):
def fails_semester (df):
"""
Lists of students that failed X, Y, Z ... courses in the same semester.
X, Y, Z ... are declared in the list "fails_by_semester" at the top.
This function is inspired by CEPE 96/15 ART.9:
Students with 3 fails in the semester would have their registration suspended.
First this function filters students who are still registrered in the University
First this function filters students who are still registrered in the University
and have failed courses.
Then it creates a dictionary of semesters.
Inside each semester there is a second dictionary of names and df with the failed courses
Inside each semester there is a second dictionary of names and df with the failed courses
This second dictionary will be turned into a list of names according to each N in fails_by_semester
Parameters
----------
df : DataFrame
Returns
-------
dict of {int:dict}
......@@ -123,8 +124,8 @@ def n_fails_semester (df):
failed_people_df = people_studying_df[people_studying_df['SITUACAO'].isin(Situation.SITUATION_FAIL)]
failed_people_per_semester_grouped = failed_people_df.groupby(['ANO','PERIODO'])
# semester_dict = { (2017/1): names_dict1, (2017/2): names_dict2, ...}
# names_dict = { (nome, grr): df, (nome. grr): df, ...)
semester_dict = {}
# names_dict = { (nome, grr): df, (nome. grr): df, ...)
semester_dict = {}
for semester in failed_people_per_semester_grouped:
names_dict = {}
student_grouped = semester[1].groupby(["NOME_PESSOA", "MATR_ALUNO"])
......@@ -139,11 +140,67 @@ def n_fails_semester (df):
semester_finaldict = {}
for semester in semester_dict:
name_list = []
for student in semester_dict[semester]:
for student in semester_dict[semester]:
if semester_dict[semester][student].shape[0] == n:
name_list.append(student)
semester_finaldict[semester] = name_list
final_dict[str(n)] = semester_finaldict
final_dict[str(n)] = semester_finaldict
# pp.pprint (final_dict)
return final_dict
def fails_by_freq(df):
"""
Lists of students that failed a course X, Y, Z ... times, all of them by lack of frequency!
X, Y, Z ... are declared in the list "fails_by_freq" at the top.
This function is inspired by CEPE 96/15 ART.4:
Students will be categorize with insuficient academic rendimento
when failing 2 times a course
First this function filters students who are still registrered in the University
and have failed courses by lack of frequenecy.
Then for each n in fails_by_freq, filters if a course repeat n times for a student
Parameters
----------
df : DataFrame
Returns
-------
dict of {int: list of tuples}
final_dict = {
"X":[ {student: student, course: course, ...},
{student: student, course: course, ...},
... ]
"Y":[ {student: student, course: course, ...},
{student: student, course: course, ...},
... ]
... }
Examples
--------
{ 5: [ ('António Cardoso Mendes', 'CI067'),
('Artur Lima Silva', 'CI068'),
...
('Ângelo Castro da Mota', 'CI237')],
7: [ ('Daniel Gomes Martins', 'CI077'),
('Joaquim Rodrigues Carvalho', 'CI210'),
...
('Pietra Martins Moreira', 'CI210')]}
"""
people_studying_df = df[df['FORMA_EVASAO'] == EvasionForm.EF_ATIVO]
// workaround: SIT_REPROVADO_FREQ é o item 1 na tupla SITUATION_FAIL
failedbyfreq = people_studying_df.loc[people_studying_df['SITUACAO'] == Situation.SITUATION_FAIL[1]]
coursefailed_bystudent = failedbyfreq.groupby(["NOME_PESSOA", "MATR_ALUNO", "COD_ATIV_CURRIC"])
final_dict = {}
for n in fails_by_freq:
final_dict[n] = []
for fail in coursefailed_bystudent:
if fail[1].shape[0] == n:
final_dict[n].append((fail[0][0], fail[0][2]))
# pp.pprint (final_dict)
return final_dict
......@@ -35,7 +35,8 @@ def build_cache(dataframe,path):
def generate_cepe_data(path,df):
cepe_dict = {}
cepe_dict["student_fails_course"] = student_fails_course(df)
cepe_dict["n_fails_semester"] = n_fails_semester(df)
cepe_dict["fails_semester"] = fails_semester(df)
cepe_dict["fails_by_freq"] = fails_by_freq(df)
save_json(path+"cepe9615.json", cepe_dict)
def generate_degree_data(path, dataframe):
......@@ -76,7 +77,7 @@ def generate_student_data(path, dataframe, student_analysis):
all_grrs = list(dataframe["MATR_ALUNO"].drop_duplicates())
for x in all_grrs:
student_data[x] = dict()
analysis = [
# tuple that contains in the first element the function that returns a dictionary with {"GRR": value}
# and in the second position the name that this analysis will have in json
......@@ -108,7 +109,7 @@ def generate_student_data(path, dataframe, student_analysis):
(student_analysis.student_info(),
"student"),
]
for x in student_data:
for a in analysis: # Use this to verify
student_data[x][a[1]] = a[0][x] # null fields in analysis
......
......@@ -188,5 +188,5 @@ class Situation:
SIT_CONHECIMENTO_REPROVADO,
SIT_REPROVADO_SEM_NOTA,
SIT_INCOMPLETO,
SIT_CANCELADO,
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