Exemple #1
0
def update_value_empty():
    for candidate in models.data_reader.candidates:

        c = models.return_index(candidate.name)
        last_i = 0

        for i in range(0, len(dates_graph)):

            #Verifica se o candidato foi para o segundo turno
            # if(i <= 21 or models.data_reader.candidates[c].round2 == True):

            if (models.data_reader.candidates[c].facebook_male[i] == -100):
                models.data_reader.candidates[c].facebook_male[
                    i] = return_new_value_graph(
                        models.data_reader.candidates[c].facebook_male, last_i,
                        i)
                models.data_reader.candidates[c].facebook_female[
                    i] = return_new_value_graph(
                        models.data_reader.candidates[c].facebook_female,
                        last_i, i)
                models.data_reader.candidates[c].facebook_16a24[
                    i] = return_new_value_graph(
                        models.data_reader.candidates[c].facebook_16a24,
                        last_i, i)
                models.data_reader.candidates[c].facebook_25a34[
                    i] = return_new_value_graph(
                        models.data_reader.candidates[c].facebook_25a34,
                        last_i, i)
                models.data_reader.candidates[c].facebook_35a44[
                    i] = return_new_value_graph(
                        models.data_reader.candidates[c].facebook_35a44,
                        last_i, i)
                models.data_reader.candidates[c].facebook_45a54[
                    i] = return_new_value_graph(
                        models.data_reader.candidates[c].facebook_45a54,
                        last_i, i)
                models.data_reader.candidates[c].facebook_55[
                    i] = return_new_value_graph(
                        models.data_reader.candidates[c].facebook_55, last_i,
                        i)
                models.data_reader.candidates[c].facebook_norte_coeste[
                    i] = return_new_value_graph(
                        models.data_reader.candidates[c].facebook_norte_coeste,
                        last_i, i)
                models.data_reader.candidates[c].facebook_nordeste[
                    i] = return_new_value_graph(
                        models.data_reader.candidates[c].facebook_nordeste,
                        last_i, i)
                models.data_reader.candidates[c].facebook_sudeste[
                    i] = return_new_value_graph(
                        models.data_reader.candidates[c].facebook_sudeste,
                        last_i, i)
                models.data_reader.candidates[c].facebook_sul[
                    i] = return_new_value_graph(
                        models.data_reader.candidates[c].facebook_sul, last_i,
                        i)
                models.data_reader.candidates[c].facebook_fundamental[
                    i] = return_new_value_graph(
                        models.data_reader.candidates[c].facebook_fundamental,
                        last_i, i)
                models.data_reader.candidates[c].facebook_medio[
                    i] = return_new_value_graph(
                        models.data_reader.candidates[c].facebook_medio,
                        last_i, i)
                models.data_reader.candidates[c].facebook_superior[
                    i] = return_new_value_graph(
                        models.data_reader.candidates[c].facebook_superior,
                        last_i, i)
            else:
                last_i = i
Exemple #2
0
def read_json(comLula):
    if (comLula == True):
        with open(os.getcwd() +
                  '\..\Data\PresidentialElection-ComLula.json') as js:
            poolElection = json.load(js)
    else:
        with open(os.getcwd() +
                  '\..\Data\PresidentialElection-SemLula.json') as js:
            poolElection = json.load(js)

    for data in poolElection['elections_poll']:
        for candidate in data['candidates']:

            i = models.return_index(candidate['name'])

            if (i >= 0):
                if (data['institute'] == 'DataFolha'
                        or data['institute'] == 'Resultado'):
                    if (data["date"] in data_dfolha):
                        models.data_reader.candidates[i].dfolha_male.append(
                            candidate['gender']['male'])
                        models.data_reader.candidates[i].dfolha_female.append(
                            candidate['gender']['female'])

                        models.data_reader.candidates[i].dfolha_16a24.append(
                            candidate['age_intervals']['age_16_24'])
                        models.data_reader.candidates[i].dfolha_25a34.append(
                            candidate['age_intervals']['age_25_34'])
                        models.data_reader.candidates[i].dfolha_35a44.append(
                            candidate['age_intervals']['age_35_44'])
                        models.data_reader.candidates[i].dfolha_45a54.append(
                            candidate['age_intervals']['age_45_54'])
                        models.data_reader.candidates[i].dfolha_55.append(
                            candidate['age_intervals']['above_55'])

                        models.data_reader.candidates[
                            i].dfolha_norte_coeste.append(
                                candidate['regions']['north_midwest'])
                        models.data_reader.candidates[
                            i].dfolha_nordeste.append(
                                candidate['regions']['northeast'])
                        models.data_reader.candidates[i].dfolha_sudeste.append(
                            candidate['regions']['southeast'])
                        models.data_reader.candidates[i].dfolha_sul.append(
                            candidate['regions']['south'])

                        models.data_reader.candidates[
                            i].dfolha_fundamental.append(
                                candidate['education_status']
                                ['elementary_school'])
                        models.data_reader.candidates[i].dfolha_medio.append(
                            candidate['education_status']['high_school'])
                        models.data_reader.candidates[i].dfolha_superior.append(
                            candidate['education_status']['higher_education'])

                        models.data_reader.candidates[i].dfolha_score.append(
                            candidate['score'])

                if (data['institute'] == 'IBOPE'
                        or data['institute'] == 'Resultado'):
                    if (data["date"] in data_ibope):
                        models.data_reader.candidates[i].ibope_male.append(
                            candidate['gender']['male'])
                        models.data_reader.candidates[i].ibope_female.append(
                            candidate['gender']['female'])

                        models.data_reader.candidates[i].ibope_16a24.append(
                            candidate['age_intervals']['age_16_24'])
                        models.data_reader.candidates[i].ibope_25a34.append(
                            candidate['age_intervals']['age_25_34'])
                        models.data_reader.candidates[i].ibope_35a44.append(
                            candidate['age_intervals']['age_35_44'])
                        models.data_reader.candidates[i].ibope_45a54.append(
                            candidate['age_intervals']['age_45_54'])
                        models.data_reader.candidates[i].ibope_55.append(
                            candidate['age_intervals']['above_55'])

                        models.data_reader.candidates[
                            i].ibope_norte_coeste.append(
                                candidate['regions']['north_midwest'])
                        models.data_reader.candidates[i].ibope_nordeste.append(
                            candidate['regions']['northeast'])
                        models.data_reader.candidates[i].ibope_sudeste.append(
                            candidate['regions']['southeast'])
                        models.data_reader.candidates[i].ibope_sul.append(
                            candidate['regions']['south'])

                        models.data_reader.candidates[
                            i].ibope_fundamental.append(
                                candidate['education_status']
                                ['elementary_school'])
                        models.data_reader.candidates[i].ibope_medio.append(
                            candidate['education_status']['high_school'])
                        models.data_reader.candidates[i].ibope_superior.append(
                            candidate['education_status']['higher_education'])

                        models.data_reader.candidates[i].ibope_score.append(
                            candidate['score'])

            # #Repete o resultado da eleição no próximo ponto
            # if(data['institute'] == 'Resultado'):
            #     if(data["round"] == 1 and (candidate['name'] == "Jair Bolsonaro" or candidate['name'] == "Fernando Haddad")):
            #         models.data_reader.candidates[i].ibope_male.append(models.data_reader.candidates[i].ibope_male[-1])
            #         models.data_reader.candidates[i].ibope_female.append(models.data_reader.candidates[i].ibope_female[-1])

            #         models.data_reader.candidates[i].ibope_16a24.append(models.data_reader.candidates[i].ibope_16a24[-1])
            #         models.data_reader.candidates[i].ibope_25a34.append(models.data_reader.candidates[i].ibope_25a34[-1])
            #         models.data_reader.candidates[i].ibope_35a44.append(models.data_reader.candidates[i].ibope_35a44[-1])
            #         models.data_reader.candidates[i].ibope_45a54.append(models.data_reader.candidates[i].ibope_45a54[-1])
            #         models.data_reader.candidates[i].ibope_55.append(models.data_reader.candidates[i].ibope_55[-1])

            #         models.data_reader.candidates[i].ibope_norte_coeste.append(models.data_reader.candidates[i].ibope_norte_coeste[-1])
            #         models.data_reader.candidates[i].ibope_nordeste.append(models.data_reader.candidates[i].ibope_nordeste[-1])
            #         models.data_reader.candidates[i].ibope_sudeste.append(models.data_reader.candidates[i].ibope_sudeste[-1])
            #         models.data_reader.candidates[i].ibope_sul.append(models.data_reader.candidates[i].ibope_sul[-1])

            #         models.data_reader.candidates[i].ibope_fundamental.append(models.data_reader.candidates[i].ibope_fundamental[-1])
            #         models.data_reader.candidates[i].ibope_medio.append(models.data_reader.candidates[i].ibope_medio[-1])
            #         models.data_reader.candidates[i].ibope_superior.append(models.data_reader.candidates[i].ibope_superior[-1])

    models.complete_data_zero()
def update_value_empty():
    for candidate in models.data_reader.candidates:

        c = models.return_index(candidate.name)
        last_i_dfolha = 0
        last_i_ibope = 0

        for i in range(0, len(dates_graph)):

            #Verifica se o candidato foi para o segundo turno
            if (i <= 21 or models.data_reader.candidates[c].round2 == True):

                #DataFolha
                if (models.data_reader.candidates[c].dfolha_male[i] == -100):
                    models.data_reader.candidates[c].dfolha_male[
                        i] = return_new_value_graph(
                            models.data_reader.candidates[c].dfolha_male,
                            last_i_dfolha, i)
                    models.data_reader.candidates[c].dfolha_female[
                        i] = return_new_value_graph(
                            models.data_reader.candidates[c].dfolha_female,
                            last_i_dfolha, i)
                    models.data_reader.candidates[c].dfolha_16a24[
                        i] = return_new_value_graph(
                            models.data_reader.candidates[c].dfolha_16a24,
                            last_i_dfolha, i)
                    models.data_reader.candidates[c].dfolha_25a34[
                        i] = return_new_value_graph(
                            models.data_reader.candidates[c].dfolha_25a34,
                            last_i_dfolha, i)
                    models.data_reader.candidates[c].dfolha_35a44[
                        i] = return_new_value_graph(
                            models.data_reader.candidates[c].dfolha_35a44,
                            last_i_dfolha, i)
                    models.data_reader.candidates[c].dfolha_45a54[
                        i] = return_new_value_graph(
                            models.data_reader.candidates[c].dfolha_45a54,
                            last_i_dfolha, i)
                    models.data_reader.candidates[c].dfolha_55[
                        i] = return_new_value_graph(
                            models.data_reader.candidates[c].dfolha_55,
                            last_i_dfolha, i)
                    models.data_reader.candidates[c].dfolha_norte_coeste[
                        i] = return_new_value_graph(
                            models.data_reader.candidates[c].
                            dfolha_norte_coeste, last_i_dfolha, i)
                    models.data_reader.candidates[c].dfolha_nordeste[
                        i] = return_new_value_graph(
                            models.data_reader.candidates[c].dfolha_nordeste,
                            last_i_dfolha, i)
                    models.data_reader.candidates[c].dfolha_sudeste[
                        i] = return_new_value_graph(
                            models.data_reader.candidates[c].dfolha_sudeste,
                            last_i_dfolha, i)
                    models.data_reader.candidates[c].dfolha_sul[
                        i] = return_new_value_graph(
                            models.data_reader.candidates[c].dfolha_sul,
                            last_i_dfolha, i)
                    models.data_reader.candidates[c].dfolha_fundamental[
                        i] = return_new_value_graph(
                            models.data_reader.candidates[c].
                            dfolha_fundamental, last_i_dfolha, i)
                    models.data_reader.candidates[c].dfolha_medio[
                        i] = return_new_value_graph(
                            models.data_reader.candidates[c].dfolha_medio,
                            last_i_dfolha, i)
                    models.data_reader.candidates[c].dfolha_superior[
                        i] = return_new_value_graph(
                            models.data_reader.candidates[c].dfolha_superior,
                            last_i_dfolha, i)
                else:
                    last_i_dfolha = i

                #IBOPE
                if (models.data_reader.candidates[c].ibope_male[i] == -100):
                    models.data_reader.candidates[c].ibope_male[
                        i] = return_new_value_graph(
                            models.data_reader.candidates[c].ibope_male,
                            last_i_ibope, i)
                    models.data_reader.candidates[c].ibope_female[
                        i] = return_new_value_graph(
                            models.data_reader.candidates[c].ibope_female,
                            last_i_ibope, i)
                    models.data_reader.candidates[c].ibope_16a24[
                        i] = return_new_value_graph(
                            models.data_reader.candidates[c].ibope_16a24,
                            last_i_ibope, i)
                    models.data_reader.candidates[c].ibope_25a34[
                        i] = return_new_value_graph(
                            models.data_reader.candidates[c].ibope_25a34,
                            last_i_ibope, i)
                    models.data_reader.candidates[c].ibope_35a44[
                        i] = return_new_value_graph(
                            models.data_reader.candidates[c].ibope_35a44,
                            last_i_ibope, i)
                    models.data_reader.candidates[c].ibope_45a54[
                        i] = return_new_value_graph(
                            models.data_reader.candidates[c].ibope_45a54,
                            last_i_ibope, i)
                    models.data_reader.candidates[c].ibope_55[
                        i] = return_new_value_graph(
                            models.data_reader.candidates[c].ibope_55,
                            last_i_ibope, i)
                    models.data_reader.candidates[c].ibope_norte_coeste[
                        i] = return_new_value_graph(
                            models.data_reader.candidates[c].
                            ibope_norte_coeste, last_i_ibope, i)
                    models.data_reader.candidates[c].ibope_nordeste[
                        i] = return_new_value_graph(
                            models.data_reader.candidates[c].ibope_nordeste,
                            last_i_ibope, i)
                    models.data_reader.candidates[c].ibope_sudeste[
                        i] = return_new_value_graph(
                            models.data_reader.candidates[c].ibope_sudeste,
                            last_i_ibope, i)
                    models.data_reader.candidates[c].ibope_sul[
                        i] = return_new_value_graph(
                            models.data_reader.candidates[c].ibope_sul,
                            last_i_ibope, i)
                    models.data_reader.candidates[c].ibope_fundamental[
                        i] = return_new_value_graph(
                            models.data_reader.candidates[c].ibope_fundamental,
                            last_i_ibope, i)
                    models.data_reader.candidates[c].ibope_medio[
                        i] = return_new_value_graph(
                            models.data_reader.candidates[c].ibope_medio,
                            last_i_ibope, i)
                    models.data_reader.candidates[c].ibope_superior[
                        i] = return_new_value_graph(
                            models.data_reader.candidates[c].ibope_superior,
                            last_i_ibope, i)
                else:
                    last_i_ibope = i
Exemple #4
0
import models
import os
import numpy as np
import subprocess

# xticks = ["17\n11",  "18\n07",  "08\n06",  "09\n10",  "09\n17",  "09\n24",  "10\n01",  "10\n05", "10\n06",  "10\n08",  "10\n15",  "10\n22",  "10\n26", "10\n27",  "10\n29"]

xticks = [
    "10\n22", "11\n28", "11\n30", "06\n07", "06\n24", "07\n09", "08\n06",
    "08\n19", "08\n21", "09\n10", "09\n17", "09\n18", "09\n24", "09\n28",
    "09\n30", "10\n01", "10\n02", "10\n04", "10\n05", "10\n06", "10\n07",
    "10\n08", "10\n10", "10\n14", "10\n15", "10\n18", "10\n22", "10\n23",
    "10\n25", "10\n26", "10\n27", "10\n28", "10\n29"
]

i_bolsonaro = models.return_index("Jair Bolsonaro")
i_haddad = models.return_index("Fernando Haddad")
i_lula = models.return_index("Lula")
i_ciro = models.return_index("Ciro Gomes")
i_marina = models.return_index("Marina Silva")
i_alckmin = models.return_index("Geraldo Alckmin")
i_alvaro = models.return_index("Alvaro Dias")

v_index = [
    i_bolsonaro, i_haddad, i_ciro, i_marina, i_alckmin, i_marina, i_alvaro
]

error_facebook_1round = []
error_dfolha_1round = []
error_ibope_1round = []
def read_json(comLula):
    set_empty = True

    if (comLula == True):
        with open(os.getcwd() +
                  '\Graphics\Data\PresidentialElection-ComLula.json') as js:
            poolElection = json.load(js)
    else:
        with open(os.getcwd() +
                  '\Graphics\Data\PresidentialElection-SemLula.json') as js:
            poolElection = json.load(js)

    for date in dates_graph:
        vec_data = return_election_by_date(poolElection, date)

        set_empty = True
        if (len(vec_data) > 1):
            set_empty = False

        for data in vec_data:
            for candidate in data['candidates']:
                i = models.return_index(candidate['name'])

                if (i >= 0):
                    if (data['institute'] == 'DataFolha'
                            or data['institute'] == 'Resultado'):
                        models.data_reader.candidates[i].dfolha_male.append(
                            candidate['gender']['male'])
                        models.data_reader.candidates[i].dfolha_female.append(
                            candidate['gender']['female'])
                        models.data_reader.candidates[i].dfolha_16a24.append(
                            candidate['age_intervals']['age_16_24'])
                        models.data_reader.candidates[i].dfolha_25a34.append(
                            candidate['age_intervals']['age_25_34'])
                        models.data_reader.candidates[i].dfolha_35a44.append(
                            candidate['age_intervals']['age_35_44'])
                        models.data_reader.candidates[i].dfolha_45a54.append(
                            candidate['age_intervals']['age_45_54'])
                        models.data_reader.candidates[i].dfolha_55.append(
                            candidate['age_intervals']['above_55'])
                        models.data_reader.candidates[
                            i].dfolha_norte_coeste.append(
                                candidate['regions']['north_midwest'])
                        models.data_reader.candidates[
                            i].dfolha_nordeste.append(
                                candidate['regions']['northeast'])
                        models.data_reader.candidates[i].dfolha_sudeste.append(
                            candidate['regions']['southeast'])
                        models.data_reader.candidates[i].dfolha_sul.append(
                            candidate['regions']['south'])
                        models.data_reader.candidates[
                            i].dfolha_fundamental.append(
                                candidate['education_status']
                                ['elementary_school'])
                        models.data_reader.candidates[i].dfolha_medio.append(
                            candidate['education_status']['high_school'])
                        models.data_reader.candidates[i].dfolha_superior.append(
                            candidate['education_status']['higher_education'])
                    elif (set_empty):
                        set_value_empty(True, i)

                    if (data['institute'] == 'IBOPE'
                            or data['institute'] == 'Resultado'):
                        models.data_reader.candidates[i].ibope_male.append(
                            candidate['gender']['male'])
                        models.data_reader.candidates[i].ibope_female.append(
                            candidate['gender']['female'])
                        models.data_reader.candidates[i].ibope_16a24.append(
                            candidate['age_intervals']['age_16_24'])
                        models.data_reader.candidates[i].ibope_25a34.append(
                            candidate['age_intervals']['age_25_34'])
                        models.data_reader.candidates[i].ibope_35a44.append(
                            candidate['age_intervals']['age_35_44'])
                        models.data_reader.candidates[i].ibope_45a54.append(
                            candidate['age_intervals']['age_45_54'])
                        models.data_reader.candidates[i].ibope_55.append(
                            candidate['age_intervals']['above_55'])
                        models.data_reader.candidates[
                            i].ibope_norte_coeste.append(
                                candidate['regions']['north_midwest'])
                        models.data_reader.candidates[i].ibope_nordeste.append(
                            candidate['regions']['northeast'])
                        models.data_reader.candidates[i].ibope_sudeste.append(
                            candidate['regions']['southeast'])
                        models.data_reader.candidates[i].ibope_sul.append(
                            candidate['regions']['south'])
                        models.data_reader.candidates[
                            i].ibope_fundamental.append(
                                candidate['education_status']
                                ['elementary_school'])
                        models.data_reader.candidates[i].ibope_medio.append(
                            candidate['education_status']['high_school'])
                        models.data_reader.candidates[i].ibope_superior.append(
                            candidate['education_status']['higher_education'])
                    elif (set_empty):
                        set_value_empty(False, i)

        if (len(vec_data) == 0):
            for candidate in models.data_reader.candidates:
                set_value_empty(True, models.return_index(candidate.name))
                set_value_empty(False, models.return_index(candidate.name))
        else:
            achou = False
            #Seta empty nos candidatos que não estão na pesquisa
            for data in vec_data:
                for candidate in models.data_reader.candidates:
                    for c in data['candidates']:
                        if candidate.name == c["name"]:
                            achou = True
                            break
                    if (achou == False):
                        set_value_empty(True,
                                        models.return_index(candidate.name))
                        set_value_empty(False,
                                        models.return_index(candidate.name))
                    else:
                        achou = False
                break

    update_value_empty()