Giter Site home page Giter Site logo

okfn-brasil / perfil-politico Goto Github PK

View Code? Open in Web Editor NEW
159.0 22.0 40.0 3.37 MB

A platform for profiling public figures in Brazilian politics

Home Page: https://perfilpolitico.serenata.ai/

License: GNU General Public License v3.0

Jupyter Notebook 50.72% Python 46.68% Dockerfile 0.29% Procfile 0.01% PLpgSQL 2.30%
django python

perfil-politico's Issues

Swap the order between running and initial setup on README.md

I think in README.md the order of running and initial setup should be swapped.
When $ docker-compose up is runned first the API is not made available at localhost:8000, so I had to run $ docker-compose run django ./manage.py migrate and after that run $ docker-compose up.
Talking with other people in the chat during the sprint, they had a similar issue.

A documentação do argumento `clean-previous-data` não está correta | The documentation of the `clean-previous-data` argument is not correct

Português

A documentação do argumento clean-previous-data do comando base atualmente não corresponde ao funcionamento do argumento (remover todos os objetos existentes).

parser.add_argument(
"clean-previous-data",
default=False,
nargs="?",
help=(
"Creates politicians for all affiliations "
"regardless if the politician exists or not."
),
)

English

The documentation of the base command's clean-previous-data argument currently isn't related to the argument's actual function (delete all existing objects).

parser.add_argument(
"clean-previous-data",
default=False,
nargs="?",
help=(
"Creates politicians for all affiliations "
"regardless if the politician exists or not."
),
)

[Otimização][spike] Investigar otimização do comando load_affiliations

Problema
O comando load_afilliations leva muito tempo para completar.

Descrição da tarefa
Explorar formas de otimização do comando e propor uma estratégia para implementar a otimização do comando

Critérios de aceite

  • Documentar a investigação nesta issue
  • Criar uma nova issue propondo uma estratégia de otimização para o comando load_affiliations

Get a new unique identifier for `Person` model

Since 'unique' fields are complicated to gather. A combination of name-birthday could be considered a "good enough" unique field for our dataset. since this could be a sensitive information, we can transform this slug into a hash.

This would facilitate working with difficult databases and use a lot of information that are not
rightly gathered by some sources.

Use the ORM to get most recent affiliation and his assets for each politician

Solve these TODO#load_affiliations and TODO#load_assets

def politicians_from_affiliation():
# TODO use the ORM (get most recent affiliation for each `voter_id`)
sql = """
SELECT core_affiliation.*
FROM core_affiliation
INNER JOIN (
SELECT voter_id, MAX(started_in) AS started_in
FROM core_affiliation
GROUP BY voter_id
) AS most_recent
ON most_recent.voter_id = core_affiliation.voter_id
WHERE status = 'R';
"""
yield from (
Politician(current_affiliation=affiliation)
for affiliation in Affiliation.objects.raw(sql).iterator()
)

@staticmethod
def assets_per_politician_per_year():
# TODO use the ORM?
Row = namedtuple("Row", ("politician_id", "year", "value"))
sql = """
SELECT
core_candidate.politician_id,
core_candidate.year,
SUM(core_asset.value) AS total
FROM core_asset
INNER JOIN core_candidate
ON core_candidate.id = core_asset.candidate_id
WHERE core_candidate.politician_id IS NOT NULL
GROUP BY core_candidate.politician_id, core_candidate.year
ORDER BY core_candidate.year DESC
"""

Is it possible to use the ORM in these cases? Will the change turn it more readable?

Add code climate.

@cuducos for adding codeclimate you just have to add the github app.

like:

  1. Open codeclimate.com
  2. Login on it.
  3. Select "Add repository"

image

  1. Add the repo you want to.

image

  1. Have a look at you repository on codeclimate

image

  1. You can install codeclimate app on the github repository by going to the tab of settings

image

[Raspador Legislativo] Corrigir spider do senado

A spider do senado do Raspador Legislativo não está funciondo. Ela deve ser corrigida para podermos atualizar os dados de bills do Perfil Político.

Critério de aceite

  • PR para corrigir a spider do senado mergeada no master do Raspador Legislativo

[Integração de dados] Implementar live-update do comando load_bills

Para atualizar o banco de dados de produção sem perder as referências ao IDs existentes, é necessário implementar e documentar como é feita essa rotina de live-update dos projetos de lei.

Critérios de aceite:

  • Verificar necessidade de adicionar novas subrotinas para update do comando load_bills, caso necessário, tê-las implementadas e testadas
  • Documentar procedimento para realização do update do banco no README

New data of Affiliation with Null values on electoral_section and type has float

When try load new data from affiliation from Brasil.io using docker-compose run django python manage.py load_affiliations /mnt/data/filiacao.csv get somes errors:

ValueError: invalid literal for int() with base 10: ''

image

After remove some rows with nulls values on electoral_section filed , got a second error:

ValueError: invalid literal for int() with base 10: '83.0'

image

Model from Affiliation expect a Integer Field not null

electoral_section = models.IntegerField()
but new data contains null values and electoral_section are float.

Discussion: Where the data should come from?

I think a valid discussion we could have is where the data should come from.
Currently some data comes from brasil.io website and they are not updated frequently. So if the idea behind this project is to have something that is updated with certain frequency maybe would be interesting to have a scrip to get the data from TSE website and make it available in the cloud.

Clarification on #142

PR #142 is a bit awkward to me. The description has no context or purpose for the changes, which break the tests:

Surely I can fix that, but before I would like to know more about the context of these changes.

My point is: as tests weren't updated, code edits were not mentioned or justified, and no one in the PR discussion seemed to worry about the CI being red I am not sure if this new state is intentional. Therefore I don't know the direction the fix should go:

  • Should the tests be updated to match the code state after the PR being merged?
  • Or should the code edited in the PR be reverted (keeping only the docs update)?

cc people involved in that PR @adorilson @dehatanes @BrunaNayara @julianyraiol @sergiomario
also cc @giuliocc

[Integração de dados] Verificar funcionamento do Raspador Legislativo

A atualização dos projetos de lei precisa dos dados do Raspador Legislativo. É necessário verificar se ainda está funcionando a integração dos dados do projeto com o Perfil.

Critérios de aceite:

  • Análise da integração do Raspador Legislativo realizada e documentada nessa issue
  • Caso algum problema ocorra, ter as tarefas necessárias para corrigí-los elaboradas
  • Caso nenhum problema ocorra, comando load_bills testado e funcionando

Running tests with pipenv

Traceback (most recent call last):
  File "/Users/amadeucavalcantefilho/.local/share/virtualenvs/perfil-hF4nD9Ih/bin/pytest", line 11, in <module>
    sys.exit(main())
  File "/Users/amadeucavalcantefilho/.local/share/virtualenvs/perfil-hF4nD9Ih/lib/python3.7/site-packages/_pytest/config/__init__.py", line 55, in main
    config = _prepareconfig(args, plugins)
  File "/Users/amadeucavalcantefilho/.local/share/virtualenvs/perfil-hF4nD9Ih/lib/python3.7/site-packages/_pytest/config/__init__.py", line 180, in _prepareconfig
    pluginmanager=pluginmanager, args=args
  File "/Users/amadeucavalcantefilho/.local/share/virtualenvs/perfil-hF4nD9Ih/lib/python3.7/site-packages/pluggy/__init__.py", line 617, in __call__
    return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
  File "/Users/amadeucavalcantefilho/.local/share/virtualenvs/perfil-hF4nD9Ih/lib/python3.7/site-packages/pluggy/__init__.py", line 222, in _hookexec
    return self._inner_hookexec(hook, methods, kwargs)
  File "/Users/amadeucavalcantefilho/.local/share/virtualenvs/perfil-hF4nD9Ih/lib/python3.7/site-packages/pluggy/__init__.py", line 216, in <lambda>
    firstresult=hook.spec_opts.get('firstresult'),
  File "/Users/amadeucavalcantefilho/.local/share/virtualenvs/perfil-hF4nD9Ih/lib/python3.7/site-packages/pluggy/callers.py", line 196, in _multicall
    gen.send(outcome)
  File "/Users/amadeucavalcantefilho/.local/share/virtualenvs/perfil-hF4nD9Ih/lib/python3.7/site-packages/_pytest/helpconfig.py", line 89, in pytest_cmdline_parse
    config = outcome.get_result()
  File "/Users/amadeucavalcantefilho/.local/share/virtualenvs/perfil-hF4nD9Ih/lib/python3.7/site-packages/pluggy/callers.py", line 76, in get_result
    raise ex[1].with_traceback(ex[2])
  File "/Users/amadeucavalcantefilho/.local/share/virtualenvs/perfil-hF4nD9Ih/lib/python3.7/site-packages/pluggy/callers.py", line 180, in _multicall
    res = hook_impl.function(*args)
  File "/Users/amadeucavalcantefilho/.local/share/virtualenvs/perfil-hF4nD9Ih/lib/python3.7/site-packages/_pytest/config/__init__.py", line 612, in pytest_cmdline_parse
    self.parse(args)
  File "/Users/amadeucavalcantefilho/.local/share/virtualenvs/perfil-hF4nD9Ih/lib/python3.7/site-packages/_pytest/config/__init__.py", line 777, in parse
    self._preparse(args, addopts=addopts)
  File "/Users/amadeucavalcantefilho/.local/share/virtualenvs/perfil-hF4nD9Ih/lib/python3.7/site-packages/_pytest/config/__init__.py", line 739, in _preparse
    early_config=self, args=args, parser=self._parser
  File "/Users/amadeucavalcantefilho/.local/share/virtualenvs/perfil-hF4nD9Ih/lib/python3.7/site-packages/pluggy/__init__.py", line 617, in __call__
    return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
  File "/Users/amadeucavalcantefilho/.local/share/virtualenvs/perfil-hF4nD9Ih/lib/python3.7/site-packages/pluggy/__init__.py", line 222, in _hookexec
    return self._inner_hookexec(hook, methods, kwargs)
  File "/Users/amadeucavalcantefilho/.local/share/virtualenvs/perfil-hF4nD9Ih/lib/python3.7/site-packages/pluggy/__init__.py", line 216, in <lambda>
    firstresult=hook.spec_opts.get('firstresult'),
  File "/Users/amadeucavalcantefilho/.local/share/virtualenvs/perfil-hF4nD9Ih/lib/python3.7/site-packages/pluggy/callers.py", line 201, in _multicall
    return outcome.get_result()
  File "/Users/amadeucavalcantefilho/.local/share/virtualenvs/perfil-hF4nD9Ih/lib/python3.7/site-packages/pluggy/callers.py", line 76, in get_result
    raise ex[1].with_traceback(ex[2])
  File "/Users/amadeucavalcantefilho/.local/share/virtualenvs/perfil-hF4nD9Ih/lib/python3.7/site-packages/pluggy/callers.py", line 180, in _multicall
    res = hook_impl.function(*args)
  File "/Users/amadeucavalcantefilho/.local/share/virtualenvs/perfil-hF4nD9Ih/lib/python3.7/site-packages/pytest_django/plugin.py", line 246, in pytest_load_initial_conftests
    dj_settings.DATABASES
  File "/Users/amadeucavalcantefilho/.local/share/virtualenvs/perfil-hF4nD9Ih/lib/python3.7/site-packages/django/conf/__init__.py", line 56, in __getattr__
    self._setup(name)
  File "/Users/amadeucavalcantefilho/.local/share/virtualenvs/perfil-hF4nD9Ih/lib/python3.7/site-packages/django/conf/__init__.py", line 43, in _setup
    self._wrapped = Settings(settings_module)
  File "/Users/amadeucavalcantefilho/.local/share/virtualenvs/perfil-hF4nD9Ih/lib/python3.7/site-packages/django/conf/__init__.py", line 106, in __init__
    mod = importlib.import_module(self.SETTINGS_MODULE)
  File "/Users/amadeucavalcantefilho/.local/share/virtualenvs/perfil-hF4nD9Ih/lib/python3.7/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 728, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/Users/amadeucavalcantefilho/Developer/perfil/api/api/settings.py", line 20, in <module>
    MONGO_URL = config('MONGO_URL')
  File "/Users/amadeucavalcantefilho/.local/share/virtualenvs/perfil-hF4nD9Ih/lib/python3.7/site-packages/decouple.py", line 197, in __call__
    return self.config(*args, **kwargs)
  File "/Users/amadeucavalcantefilho/.local/share/virtualenvs/perfil-hF4nD9Ih/lib/python3.7/site-packages/decouple.py", line 85, in __call__
    return self.get(*args, **kwargs)
  File "/Users/amadeucavalcantefilho/.local/share/virtualenvs/perfil-hF4nD9Ih/lib/python3.7/site-packages/decouple.py", line 70, in get
    raise UndefinedValueError('{} not found. Declare it as envvar or define a default value.'.format(option))
decouple.UndefinedValueError: MONGO_URL not found. Declare it as envvar or define a default value.

I don't know whether I have be running mongo while runing test.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.