Commit 2777be38 authored by Jomaro Rodrigues's avatar Jomaro Rodrigues
Browse files

Merge branch 'master' into analysis_modular

parents 5c119b8b ec677b38
......@@ -8,6 +8,7 @@ url = "https://pypi.python.org/simple"
[dev-packages]
coverage = "*"
ipython = "*"
[packages]
......@@ -18,3 +19,4 @@ pandas = "==0.18.1"
"psycopg2" = "*"
xlrd = "*"
django-extensions = "*"
ujson = "*"
{
"_meta": {
"hash": {
"sha256": "d5214020d9299022c9d9ddb86870692f94a493490acdbf67f5bbe199a995f204"
"sha256": "0b62cd0d5cd72fee71fa1f56dde87cabb220300bca052e3c9006ba8da5edeca6"
},
"host-environment-markers": {
"implementation_name": "cpython",
......@@ -36,10 +36,10 @@
},
"django-extensions": {
"hashes": [
"sha256:7c0db3b1a249bcfdd50c4314a617f8fb0aec979e2c01466e68ec0d60337313a9",
"sha256:308e4aa61b6accc249c67a0fb99daef6f8b233179dd50a52f408fae4f58b71ee"
"sha256:24c24bbc6ef6dd36fe6b2b7c48d171a9d22fe76895610fe19087af657fa27930",
"sha256:1f424a7f87974c2e2602b8b41cae52eb08105523f0c70320203abf58bcb84404"
],
"version": "==2.0.0"
"version": "==2.0.5"
},
"django-widget-tweaks": {
"hashes": [
......@@ -50,31 +50,31 @@
},
"numpy": {
"hashes": [
"sha256:e2335d56d2fd9fc4e3a3f2d3148aafec4962682375f429f05c45a64dacf19436",
"sha256:9b762e78739b6e021124adbea07611682db99cd3fca7f3c3a8b98b8f74ea5699",
"sha256:7d4c549e41507db4f04ec7cfab5597de8acf7871b16c9cf64cebcb9d39031ca6",
"sha256:b803306c4c201e7dcda0ce1b9a9c87f61a7c7ce43de2c60c8e56147b76849a1a",
"sha256:2da8dff91d489fea3e20155d41f4cd680de7d01d9a89fdd0ebb1bee6e72d3800",
"sha256:6b8c2daacbbffc83b4a2ba83a61aa3ce60c66340b07b962bd27b6c6bb175bee1",
"sha256:89b9419019c47ec87cf4cfca77d85da4611cc0be636ec87b5290346490b98450",
"sha256:49880b47d7272f902946dd995f346842c95fe275e2deb3082ef0495f0c718a69",
"sha256:3d7ddd5bdfb12ec9668edf1aa49a4a3eddb0db4661b57ea431477eb9a2468894",
"sha256:788e1757f8e409cd805a7cd82993cd9252fa19e334758a4c6eb5a8b334abb084",
"sha256:377def0873bbb1fbdedb14b3275b10a29b1b55619a3f7f775c4e7f9ce2461b9c",
"sha256:9501c9ccd081977ca5579a3ec4009d6baff6bacb04bf07214aade3324734195a",
"sha256:a1f5173df8190ef9c6235d260d70ca70c6fb029683ceb66e244c5cc6e335947a",
"sha256:12cf4b27039b88e407ad66894d99a957ef60fea0eeb442026af325add2ab264d",
"sha256:4e2fc841c8c642f7fd44591ef856ca409cedba6aea27928df34004c533839eee",
"sha256:e5ade7a69dccbd99c4fdbb95b6d091d941e62ffa588b0ed8fb0a2854118fef3f",
"sha256:6b1011ffc87d7e2b1b7bcc6dc21bdf177163658746ef778dcd21bf0516b9126c",
"sha256:a8bc80f69570e11967763636db9b24c1e3e3689881d10ae793cec74cf7a627b6",
"sha256:81b9d8f6450e752bd82e7d9618fa053df8db1725747880e76fb09710b57f78d0",
"sha256:e8522cad377cc2ef20fe13aae742cc265172910c98e8a0d6014b1a8d564019e2",
"sha256:a3d5dd437112292c707e54f47141be2f1100221242f07eda7bd8477f3ddc2252",
"sha256:c8000a6cbc5140629be8c038c9c9cdb3a1c85ff90bd4180ec99f0f0c73050b5e",
"sha256:fa0944650d5d3fb95869eaacd8eedbd2d83610c85e271bd9d3495ffa9bc4dc9c"
],
"version": "==1.14.1"
"sha256:719d914f564f35cce4dc103808f8297c807c9f0297ac183ed81ae8b5650e698e",
"sha256:0f6a5ed0cd7ab1da11f5c07a8ecada73fc55a70ef7bb6311a4109891341d7277",
"sha256:d0928076d9bd8a98de44e79b1abe50c1456e7abbb40af7ef58092086f1a6c729",
"sha256:d858423f5ed444d494b15c4cc90a206e1b8c31354c781ac7584da0d21c09c1c3",
"sha256:20cac3123d791e4bf8482a580d98d6b5969ba348b9d5364df791ba3a666b660d",
"sha256:528ce59ded2008f9e8543e0146acb3a98a9890da00adf8904b1e18c82099418b",
"sha256:56e392b7c738bd70e6f46cf48c8194d3d1dd4c5a59fae4b30c58bb6ef86e5233",
"sha256:99051e03b445117b26028623f1a487112ddf61a09a27e2d25e6bc07d37d94f25",
"sha256:768e777cc1ffdbf97c507f65975c8686ebafe0f3dc8925d02ac117acc4669ce9",
"sha256:675e0f23967ce71067d12b6944add505d5f0a251f819cfb44bdf8ee7072c090d",
"sha256:a958bf9d4834c72dee4f91a0476e7837b8a2966dc6fcfc42c421405f98d0da51",
"sha256:bb370120de6d26004358611441e07acda26840e41dfedc259d7f8cc613f96495",
"sha256:f2b1378b63bdb581d5d7af2ec0373c8d40d651941d283a2afd7fc71184b3f570",
"sha256:a1413d06abfa942ca0553bf3bccaff5fdb36d55b84f2248e36228db871147dab",
"sha256:7f76d406c6b998d6410198dcb82688dcdaec7d846aa87e263ccf52efdcfeba30",
"sha256:a7157c9ac6bddd2908c35ef099e4b643bc0e0ebb4d653deb54891d29258dd329",
"sha256:0fd65cbbfdbf76bbf80c445d923b3accefea0fe2c2082049e0ce947c81fe1d3f",
"sha256:8c18ee4dddd5c6a811930c0a7c7947bf16387da3b394725f6063f1366311187d",
"sha256:0739146eaf4985962f07c62f7133aca89f3a600faac891ce6c7f3a1e2afe5272",
"sha256:07e21f14490324cc1160db101e9b6c1233c33985af4cb1d301dd02650fea1d7f",
"sha256:e6120d63b50e2248219f53302af7ec6fa2a42ed1f37e9cda2c76dbaca65036a7",
"sha256:6be6b0ca705321c178c9858e5ad5611af664bbdfae1df1541f938a840a103888",
"sha256:facc6f925c3099ac01a1f03758100772560a0b020fb9d70f210404be08006bcb"
],
"version": "==1.14.2"
},
"pandas": {
"hashes": [
......@@ -132,10 +132,10 @@
},
"python-dateutil": {
"hashes": [
"sha256:95511bae634d69bc7329ba55e646499a842bc4ec342ad54a8cdb65645a0aad3c",
"sha256:891c38b2a02f5bb1be3e4793866c8df49c7d19baabf9c1bad62547e0b4866aca"
"sha256:07009062406cffd554a9b4135cd2ff167c9bf6b7aac61fe946c93e69fad1bbd8",
"sha256:8f95bb7e6edbb2456a51a1fb58c8dca942024b4f5844cae62c90aa88afe6e300"
],
"version": "==2.6.1"
"version": "==2.7.0"
},
"pytz": {
"hashes": [
......@@ -158,13 +158,11 @@
],
"version": "==1.11.0"
},
"typing": {
"ujson": {
"hashes": [
"sha256:b2c689d54e1144bbcfd191b0832980a21c2dbcf7b5ff7a66248a60c90e951eb8",
"sha256:3a887b021a77b292e151afb75323dea88a7bc1b3dfa92176cff8e44c8b68bddf",
"sha256:d400a9344254803a2368533e4533a4200d21eb7b6b729c173bc38201a74db3f2"
"sha256:f66073e5506e91d204ab0c614a148d5aa938bdbf104751be66f8ad7a222f5f86"
],
"version": "==3.6.4"
"version": "==1.35"
},
"xlrd": {
"hashes": [
......@@ -215,6 +213,105 @@
"sha256:f8a923a85cb099422ad5a2e345fe877bbc89a8a8b23235824a93488150e45f6e"
],
"version": "==4.5.1"
},
"decorator": {
"hashes": [
"sha256:94d1d8905f5010d74bbbd86c30471255661a14187c45f8d7f3e5aa8540fdb2e5",
"sha256:7d46dd9f3ea1cf5f06ee0e4e1277ae618cf48dfb10ada7c8427cd46c42702a0e"
],
"version": "==4.2.1"
},
"ipython": {
"hashes": [
"sha256:fcc6d46f08c3c4de7b15ae1c426e15be1b7932bcda9d83ce1a4304e8c1129df3",
"sha256:51c158a6c8b899898d1c91c6b51a34110196815cc905f9be0fa5878e19355608"
],
"version": "==6.2.1"
},
"ipython-genutils": {
"hashes": [
"sha256:72dd37233799e619666c9f639a9da83c34013a73e8bbc79a7a6348d93c61fab8",
"sha256:eb2e116e75ecef9d4d228fdc66af54269afa26ab4463042e33785b887c628ba8"
],
"version": "==0.2.0"
},
"jedi": {
"hashes": [
"sha256:d795f2c2e659f5ea39a839e5230d70a0b045d0daee7ca2403568d8f348d0ad89",
"sha256:d6e799d04d1ade9459ed0f20de47c32f2285438956a677d083d3c98def59fa97"
],
"version": "==0.11.1"
},
"parso": {
"hashes": [
"sha256:a7bb86fe0844304869d1c08e8bd0e52be931228483025c422917411ab82d628a",
"sha256:5815f3fe254e5665f3c5d6f54f086c2502035cb631a91341591b5a564203cffb"
],
"version": "==0.1.1"
},
"pexpect": {
"hashes": [
"sha256:6ff881b07aff0cb8ec02055670443f784434395f90c3285d2ae470f921ade52a",
"sha256:67b85a1565968e3d5b5e7c9283caddc90c3947a2625bed1905be27bd5a03e47d"
],
"markers": "sys_platform != 'win32'",
"version": "==4.4.0"
},
"pickleshare": {
"hashes": [
"sha256:c9a2541f25aeabc070f12f452e1f2a8eae2abd51e1cd19e8430402bdf4c1d8b5",
"sha256:84a9257227dfdd6fe1b4be1319096c20eb85ff1e82c7932f36efccfe1b09737b"
],
"version": "==0.7.4"
},
"prompt-toolkit": {
"hashes": [
"sha256:3f473ae040ddaa52b52f97f6b4a493cfa9f5920c255a12dc56a7d34397a398a4",
"sha256:1df952620eccb399c53ebb359cc7d9a8d3a9538cb34c5a1344bdbeb29fbcc381",
"sha256:858588f1983ca497f1cf4ffde01d978a3ea02b01c8a26a8bbc5cd2e66d816917"
],
"version": "==1.0.15"
},
"ptyprocess": {
"hashes": [
"sha256:e8c43b5eee76b2083a9badde89fd1bbce6c8942d1045146e100b7b5e014f4f1a",
"sha256:e64193f0047ad603b71f202332ab5527c5e52aa7c8b609704fc28c0dc20c4365"
],
"version": "==0.5.2"
},
"pygments": {
"hashes": [
"sha256:78f3f434bcc5d6ee09020f92ba487f95ba50f1e3ef83ae96b9d5ffa1bab25c5d",
"sha256:dbae1046def0efb574852fab9e90209b23f556367b5a320c0bcb871c77c3e8cc"
],
"version": "==2.2.0"
},
"simplegeneric": {
"hashes": [
"sha256:dc972e06094b9af5b855b3df4a646395e43d1c9d0d39ed345b7393560d0b9173"
],
"version": "==0.8.1"
},
"six": {
"hashes": [
"sha256:832dc0e10feb1aa2c68dcc57dbb658f1c7e65b9b61af69048abc87a2db00a0eb",
"sha256:70e8a77beed4562e7f14fe23a786b54f6296e34344c23bc42f07b15018ff98e9"
],
"version": "==1.11.0"
},
"traitlets": {
"hashes": [
"sha256:c6cb5e6f57c5a9bdaa40fa71ce7b4af30298fbab9ece9815b5d995ab6217c7d9",
"sha256:9c4bd2d267b7153df9152698efb1050a5d84982d3384a37b2c1f7723ba3e7835"
],
"version": "==4.3.2"
},
"wcwidth": {
"hashes": [
"sha256:f4ebe71925af7b40a864553f761ed559b43544f8f71746c2d756c7fe788ade7c",
"sha256:3df37372226d6e63e1b1e1eda15c594bca98a22d33a23832a90998faa96bc65e"
],
"version": "==0.1.7"
}
}
}
#! /bin/bash
FILE=$(tail -n +2 "$1") #sem cabeçalho
head -1 $1 #cabeçalho
while read line
do
ementa=$(echo "$line" | cut -d',' -f15)
re='^[0-9]+$'
if [[ $ementa =~ $re ]] ; then
echo "$line" | cut -d',' -f1-14 --output-delimiter="," | xargs echo -n
echo -n ",,"
echo "$line" | cut -d',' -f15- --output-delimiter=","
else
echo "$line"
fi
done <<< "$FILE"
#!/usr/bin/env python
# *-* coding:utf-8
from __future__ import print_function
import pandas as pd
import sys
def shift_evasao(row):
if row['ANO_EVASAO'] in ("1o. Semestre", "2o. Semestre"):
row['PERIODO_EVASAO'] = row['ANO_EVASAO']
row['ANO_EVASAO'] = row['DT_SAIDA']
row['DT_SAIDA'] = None
return row
def eprint(*args, **kwargs):
print(*args, file=sys.stderr, **kwargs)
PATH = sys.argv[1]
if not PATH:
eprint('Erro: Passe o caminho do relatório de matricula dos alunos como parametro')
df = pd.read_csv(PATH)
df = df.apply(shift_evasao, axis=1)
df.to_csv(sys.stdout, sep=',', encoding='utf-8')
#!/usr/bin/env python
# *-* coding:utf-8
from __future__ import print_function
import pandas as pd
import sys
def preenhce_situacao_limpa_media_credito(row):
if row['MEDIA_CREDITO'] != 'A':
row['SITUACAO_CURRICULO'] = row['MEDIA_CREDITO']
row['MEDIA_CREDITO'] = ''
return row
def eprint(*args, **kwargs):
print(*args, file=sys.stderr, **kwargs)
PATH = sys.argv[1]
if not PATH:
eprint('Erro: Passe o caminho do relatório do historico dos alunos como parametro')
df = pd.read_csv(PATH)
# shifta DESCR_ESTRUTURA e ID_ESTRUTURA_CUR uma coluna para direita
df = df.rename(columns={'DESCR_ESTRUTURA': 'OLD_DESCR_ESTRUTURA'})
df = df.rename(columns={'ID_ESTRUTURA_CUR': 'DESCR_ESTRUTURA'})
df = df.rename(columns={'ID_NOTA': 'ID_ESTRUTURA_CUR'})
df['ID_NOTA'] = pd.Series()
df = df.apply(preenhce_situacao_limpa_media_credito, axis=1)
df.to_csv(sys.stdout, sep=',', encoding='utf-8')
#!/usr/bin/env python
# coding: utf-8
from __future__ import print_function
import sys
import os
import django
import pandas as pd
sys.path.append("..")
os.environ["DJANGO_SETTINGS_MODULE"] = "adega.settings"
django.setup()
from django.db import models
from student.models import *
from curso.models import *
from turmaIngresso.models import *
from disciplina.models import *
from turma.models import *
from student.analysis import calcular_ira
from django.db import models
from django.core.exceptions import ObjectDoesNotExist
DIR_RELATORIOS = "../relatorios/"
CAMINHO_RELATORIO_DISCIPLINAS = DIR_RELATORIOS + "11.02.01.99.06-MUDA.csv"
CAMINHO_RELATORIO_MATRICULA = DIR_RELATORIOS + "11.02.04.99.43-MUDA.csv"
CAMINHO_RELATORIO_HISTORICOS = DIR_RELATORIOS + "11.02.05.99.33-historico-ira-curso-MUDA.csv"
"""
--------------------------------EXCEPTIONS--------------------------------
"""
class AlunoNaoExiste(Exception):
pass
class DisciplinaNaoExiste(Exception):
pass
class NenhumCursoEncontrado(Exception):
pass
class NenhumaGradeEncontrada(Exception):
pass
class GradeNaoEncontrada(Exception):
pass
class NenhumaDisciplinaEncontrada(Exception):
pass
_students = set()
m_students = dict()
"""
---------------------------------------------------------------------------
"""
# printa na saída de erros
def eprint(*args, **kwargs):
print(*args, file=sys.stderr, **kwargs)
"""
-------------------------FUNÇÕES LEITURA DOS RELATORIOS--------------------
"""
# todo: tratar exceptions
def ler_relatorio_disciplinas(listaDisciplinas):
# TODO: validar se existe codigo do curso
cursos_df = listaDisciplinas.drop_duplicates(subset=['COD_CURSO'])
if cursos_df.empty:
raise NenhumCursoEncontrado()
# Pega o curso do banco de dados, caso ele não exista cria
curso, curso_created = Curso.objects.get_or_create(codigo=cursos_df['COD_CURSO'][0],
nome=cursos_df['NOME_UNIDADE'][0])
if curso_created:
# grade criada, pois não temos todas as grades e queremos manter uma relação entre as disciplinas e o curso
grade_fake = Grade(ano_inicio=1000,
curso=curso)
grade_fake.save()
# Agrupa os relatório pela versões da grade
grades_df = listaDisciplinas[listaDisciplinas.COD_CURSO == curso.codigo].drop_duplicates(subset=['NUM_VERSAO'])
if grades_df.empty:
raise NenhumaGradeEncontrada()
# Percorre as grades do curso
for index, row in grades_df.iterrows():
# Pega a grade do banco de dados, caso ela ainda não exista cria
grade, grade_created = Grade.objects.get_or_create(curso=curso,
ano_inicio=row['NUM_VERSAO'])
ler_disciplinas_grade(listaDisciplinas, grade)
return curso
def ler_disciplinas_grade(listaDisciplinas, grade):
# Seleciona as linahs que são do curso da grade e da versão da grade
disciplinas_df = listaDisciplinas[(listaDisciplinas.COD_CURSO == grade.curso.codigo)
& (listaDisciplinas.NUM_VERSAO == grade.ano_inicio)].drop_duplicates(
subset=['COD_DISCIPLINA'])
if disciplinas_df.empty:
raise NenhumaDisciplinaEncontrada()
for index, row in disciplinas_df.iterrows():
# Pega a disciplina no banco de dados, caso ela não exista, cria
disciplina, disciplina_created = Disciplina.objects.get_or_create(
codigo=row['COD_DISCIPLINA'], defaults={
'nome': row['NOME_DISCIPLINA'],
'carga_horaria': row['CH_TOTAL'],
})
# Caso a disciplina não exista ainda no banco de dados também cria a relação com a grade
if disciplina_created:
dg = DisciplinaGrade(grade=grade,
disciplina=disciplina,
periodo=row['PERIODO_IDEAL'],
tipo_disciplina=row['TIPO_DISCIPLINA'])
dg.save()
def ler_relatorio_matriculas(matricula_aluno_df, curso):
# Muda valores que estão com NaN para None
matricula_aluno_df = matricula_aluno_df.where((pd.notnull(matricula_aluno_df)), None)
students = []
# Seleciona os alunos que são do curso
curso_df = matricula_aluno_df[matricula_aluno_df.COD_CURSO == curso.codigo]
# Agrupa os alunos pela versão da grade que está
grouped_grade_df = curso_df.groupby('VERSAO')
# Percorre as grades
for ano_grade, grade_df in grouped_grade_df:
try:
grade = curso.grade_set.get(ano_inicio=ano_grade)
except ObjectDoesNotExist as ex:
# raise GradeNaoEncontrada()
eprint("GradeNaoEncontrada: versao:{0}".format(ano_grade))
continue;
# TODO: Remover o filtro da data de ingresso no formato certo e adicionar validação
ti_df = curso_df[
matricula_aluno_df.DT_INGRESSO.str.contains("^(0[1-9]|[12][0-9]|3[01])[/](0[1-9]|1[012])[/](\d){4}$",
na=False)]
ti_df['DT_INGRESSO'] = pd.to_datetime(ti_df['DT_INGRESSO'], format="%d/%m/%Y")
ti_df['ANO'] = ti_df['DT_INGRESSO'].dt.year
ti_df['SEMESTRE'] = ti_df['DT_INGRESSO'].apply(lambda d: 1 if d.month <= 6 else 2)
grouped_ti_df = ti_df.groupby(['ANO', 'SEMESTRE'])
for names, group in grouped_ti_df:
ti, created_ti = TurmaIngresso.objects.get_or_create(ano=names[0], semestre=names[1], curso=curso)
for index, student_row in group.iterrows():
# TODO: Descobrir o que fazer com evasao anual
# anual e dado invalido é tratada como primeiro semestre por enquanto
semestre_evasao = None
if student_row['PERIODO_EVASAO'] in SEMESTRE:
semestre_evasao = SEMESTRE[student_row['PERIODO_EVASAO']]
elif student_row['PERIODO_EVASAO'] == "Anual":
semestre_evasao = 1
if student_row['MATRICULA'][3:] not in _students:
_students.add(student_row['MATRICULA'][3:])
student, created_student = Student.objects.get_or_create(grr=student_row['MATRICULA'][3:],
defaults={'name': student_row['ALUNO'],
'ira': 0,
'forma_evasao': student_row[
'FORMA_EVASAO'],
'ano_evasao': student_row[
'ANO_EVASAO'],
'semestre_evasao': semestre_evasao,
'turma_ingresso': ti,
'grade_atual': grade
})
m_students[student_row['MATRICULA'][3:]] = student
students.append(student)
return students
def ler_historico_aluno(historico_df, curso):
disciplinas_gdf = historico_df.groupby('COD_ATIV_CURRIC')
grade_fake = curso.grade_set.get(ano_inicio=1000)
# inicializa data relatorio com nulo, para ser preenchida durante a leitura
curso.ano_relatorio = 0
curso.semestre_relatorio = 0
for codigo_disciplina, disciplina_df in disciplinas_gdf:
try:
disciplina = Disciplina.objects.get(codigo=codigo_disciplina)
except ObjectDoesNotExist:
primeira_linha = disciplina_df.iloc[0]
descr_estrutura = primeira_linha['DESCR_ESTRUTURA']
carga_horaria = primeira_linha['CH_TOTAL']
nome_disciplina = primeira_linha['NOME_ATIV_CURRIC']
if descr_estrutura == "Disciplinas de outros cursos":
disciplina = Disciplina(codigo=codigo_disciplina,
nome=nome_disciplina,
carga_horaria=carga_horaria)
disciplina.save()
# FIXME: REMOVER GRADE FAKE DEPOIS DE OBTER DE TER CERTEZA QUE TEMOS TODOS OS CURRICULOS
elif descr_estrutura == "Discipl. de outros currículos do curso":
disciplina = Disciplina(codigo=codigo_disciplina,
nome=nome_disciplina,
carga_horaria=carga_horaria)
disciplina.save()
dg = DisciplinaGrade(grade=grade_fake,
disciplina=disciplina,
periodo=1,
tipo_disciplina=descr_estrutura)
dg.save()
# TODO:O que fazer com as atividades formativas? Elas não são disciplinas, porém o que fazer com elas? obs: existem poucos registros delas no relatório, talvez elas não devam contar nele mesmo
elif descr_estrutura == "Atividades Formativas Complementares":
eprint("Atividade Formativa Encontrada: codigo={0}".format(codigo_disciplina))
continue
else:
try:
raise DisciplinaNaoExiste("DisciplinaNaoExiste: codigo={0}".format(codigo_disciplina))
except DisciplinaNaoExiste as ex:
eprint(ex)
continue
# FIXME: Adicionar mais uma chave no group by para separar as turmas do mesmo ano e semestre(talvez sigla?)
turmas_gdf = disciplina_df.groupby(['ANO', 'PERIODO'])
# periodo do relatório na verdade é o semestre(1 ou 2)
for ano_periodo, turma_df in turmas_gdf:
if ano_periodo[1] not in SEMESTRE:
eprint(
"PERIODO INVALIDO: cod_disciplina={0} ano={1} periodo:{2}".format(codigo_disciplina, ano_periodo[0],
ano_periodo[1]))
continue
ano = ano_periodo[0]
semestre = SEMESTRE[ano_periodo[1]]
""""
Pega a maior data do historico para ser a data que as informações do relatório são válidas
"""
if ano > curso.ano_relatorio:
curso.ano_relatorio = ano
curso.semestre_relatorio = semestre
elif ano == curso.semestre_relatorio:
if semestre > curso.semestre_relatorio:
curso.semestre_relatorio = semestre
turma, created_turma = Turma.objects.get_or_create(disciplina=disciplina,
ano=ano,
semestre=semestre
)
# TODO: validar se existe estudantes iguais na turma
for index, student_row in turma_df.iterrows():
grr = student_row['MATR_ALUNO'][3:]
if grr not in _students:
try:
raise AlunoNaoExiste("AlunoNaoExiste: GRR={0}".format(grr))
except AlunoNaoExiste as ex:
eprint(ex)
continue
student = m_students[grr]
# TODO: Verficar se o valor 9999 é o valor real do relatório, ou foi atribuido na criptografia do relatório
nota = 0 if student_row['MEDIA_FINAL'] == 9999 else student_row['MEDIA_FINAL']
# Não adianta só checar o created_turma p/ saber se precisa ou não criar o aluno_turma, pois o relatório anteriormente enviado pode não conter o aluno ainda, por exemplo antes do reajuste de matricula
aluno_turma, create_aluno_turma = AlunoTurma.objects.get_or_create(
turma=turma, student=student, defaults={
'nota': nota,
'situacao': student_row['SITUACAO']
})
# salva ano, semestre do relatório
curso.save()
"""
--------------------------------------------------------------------------------
"""
def gerar():
# ofertaDisciplina = pd.read_csv(DIR_RELATORIOS + "11.02.03.99.05-MUDA.csv")