Skip to content
This repository has been archived by the owner on Aug 7, 2018. It is now read-only.

Commit

Permalink
Merge pull request #430 from RadarParlamentar-MES2017-1/plenaria_mode…
Browse files Browse the repository at this point in the history
…lagem

 Migração dos módulos Plenaria e Modelagem para python3
  • Loading branch information
diraol committed Jun 2, 2017
2 parents 1428734 + 4435592 commit e378e1b
Show file tree
Hide file tree
Showing 15 changed files with 885 additions and 520 deletions.
6 changes: 3 additions & 3 deletions radar_parlamentar/analises/grafico.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def _list_periodos(self):
var_explicada = round(
(eigen0 + eigen1) / ap.pca.eigen.sum() * 100, 1)
dict_ap['nvotacoes'] = ap.num_votacoes
dict_ap['nome'] = ap.periodo.string
dict_ap['nome'] = str(ap.periodo)
dict_ap['var_explicada'] = var_explicada
dict_ap['cp1'] = self._dict_cp1(ap)
dict_ap['cp2'] = self._dict_cp2(ap)
Expand Down Expand Up @@ -152,15 +152,15 @@ def _list_votacoes_do_periodo(self, ap):
dict_votacao['id'] = str(votacao).replace('"', "'")
list_votacoes.append(dict_votacao)
return list_votacoes

def _list_chefes_do_periodo(self, ap):
list_chefes = []
for chefe in ap.chefes_executivos:
dict_chefe = {}
dict_chefe['nome'] = str(chefe).replace('"', "'")
list_chefes.append(dict_chefe)
return list_chefes

def _list_partidos_instrumented(self):
db.reset_queries()
logger.info('comecando lista de partidos')
Expand Down
1 change: 0 additions & 1 deletion radar_parlamentar/exportadores/exportador_csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ def write_csv(self):


def main():
print((models.CasaLegislativa))
try:
cdep = models.CasaLegislativa.objects.get(nome_curto='cdep')
except models.CasaLegislativa.DoesNotExist:
Expand Down
30 changes: 10 additions & 20 deletions radar_parlamentar/modelagem/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
# You should have received a copy of the GNU General Public License
# along with Radar Parlamentar. If not, see <http://www.gnu.org/licenses/>.

from __future__ import unicode_literals

from django.db import models
from django.utils.dateparse import parse_datetime
import re
Expand Down Expand Up @@ -264,7 +264,7 @@ class ChefeExecutivo(models.Model):
mandato_ano_fim = models.IntegerField()
casas_legislativas = models.ManyToManyField(CasaLegislativa)
titulo = None

def __unicode__(self):
self.titulo = self.get_titulo_chefe()
return self.titulo + ": " + self.nome + " - " + self.partido.nome
Expand All @@ -273,10 +273,10 @@ def __unicode__(self):
def por_casa_legislativa_e_periodo(casa_legislativa,
data_inicial=None,
data_final=None):

chefes_executivo = ChefeExecutivo.objects.filter(
casas_legislativas__nome_curto=casa_legislativa.nome_curto)

chefes = []
if data_inicial is not None and data_final is not None:
ano_inicio = int(data_inicial.year)
Expand All @@ -289,7 +289,7 @@ def por_casa_legislativa_e_periodo(casa_legislativa,
chefes = chefes_executivo

return chefes

@staticmethod
def get_chefe_anual(ano, chefes_executivo):
chefes = []
Expand All @@ -304,7 +304,7 @@ def get_chefe_anual(ano, chefes_executivo):
def get_chefe_periodo(ano_inicio, ano_fim, chefes_executivo):
chefes = []
for chefe in chefes_executivo:
ano_inicio_valido = ano_inicio >= chefe.mandato_ano_inicio and ano_inicio <= chefe.mandato_ano_fim
ano_inicio_valido = ano_inicio >= chefe.mandato_ano_inicio and ano_inicio <= chefe.mandato_ano_fim
ano_fim_valido = ano_fim >= chefe.mandato_ano_inicio and ano_fim <= chefe.mandato_ano_fim
mandato_ano_inicio_valido = chefe.mandato_ano_inicio >= ano_inicio and chefe.mandato_ano_inicio <= ano_fim
mandato_ano_fim_valido = chefe.mandato_ano_fim >= ano_inicio and chefe.mandato_ano_fim <= ano_fim
Expand All @@ -317,7 +317,7 @@ def get_titulo_chefe(self):
titulo = ""
casas_legislativas = self.casas_legislativas.all()
for casa in casas_legislativas:
esfera = casa.esfera
esfera = casa.esfera
genero_masculino = self.genero == M
if(esfera == FEDERAL):
if(genero_masculino):
Expand All @@ -329,7 +329,7 @@ def get_titulo_chefe(self):
titulo = "Prefeito"
else:
titulo = "Prefeita"
return titulo
return titulo


class PeriodoCasaLegislativa(object):
Expand All @@ -344,18 +344,8 @@ def __init__(self, data_inicio, data_fim, quantidade_votacoes=0):
self.ini = data_inicio
self.fim = data_fim
self.quantidade_votacoes = quantidade_votacoes
self.string = ""
self.string = unicode(self)

def __str__(self):
return self.__unicode__()

def __unicode__(self):
if not self.string:
self._build_string()
return self.string

def _build_string(self):
data_string = ''
# data_string = str(self.ini.year) # sempre começa com o ano
delta = self.fim - self.ini
Expand Down Expand Up @@ -389,7 +379,7 @@ def _build_string(self):
elif delta.days < 1500: # periodo é um quadriênio
data_string += str(self.ini.year) + " a "
data_string += str(self.fim.year)
self.string = data_string
return data_string


class Parlamentar(models.Model):
Expand Down Expand Up @@ -597,7 +587,7 @@ def __unicode__(self):
return '(%s, %s, %s)' % (self.sim, self.nao, self.abstencao)

def __str__(self):
return unicode(self).encode('utf-8')
return str(self).encode('utf-8')


class VotoPartido(VotosAgregados):
Expand Down
Loading

0 comments on commit e378e1b

Please sign in to comment.