doador_partido_sg ,
				doador_partido_nr ,
				doador_esfera_partidaria_cd  ,
				doador_esfera_partidaria_ds
);
"""

mtse.execute_query(query_insert_orgaos_partidarios_receptores)
mtse.execute_query(query_insert_orgaos_partidarios_doadores)

# In[6]:

mtse.pandas_query(f"""
select orgao_partidario_id from (
select orgao_partidario_id,count(*) qtd from {table_orgaos_partidarios} op 
group by orgao_partidario_id
) t
where qtd >1
;
""")

# In[7]:

mtse.execute_query(f"""
delete from {table_orgaos_partidarios}
where orgao_partidario_id in (
select orgao_partidario_id from (
select orgao_partidario_id,count(*) qtd from {table_orgaos_partidarios} op 
group by orgao_partidario_id
) t
where qtd >1
)
示例#2
0
# In[11]:

query_calcula_custo_voto = f"""
    update {table_candidaturas}
        set custo_voto = case when total_votos > 0 then round(receita_total / total_votos,2) else 0 end
"""
mtse.execute_query(query_calcula_custo_voto)

# ### Verifica Candidatos com mais de um registro

# In[12]:

mtse.pandas_query(f"""
 select candidato_id, q
 from (select candidato_id, count(*)  as q from {table_candidaturas} 
 group by candidato_id) t
 where q>1 
 order by q desc
 ;
 """)

# ## Muda o id do registro mais antigo de candidato com mais de um  registro

# ### exclui candidato_id mais antigo quando dois registros para o mesmo candidato
# def exclui_duplo_id():
#     p=mtse.pandas_query(f"""
#     select candidato_id, tse_id from {table_candidaturas}
#     where candidato_id in(
#      select candidato_id
#      from (select  candidato_id, count(*)  as q from {table_candidaturas}
#      group by candidato_id) t
#      where q>1
    


# In[13]:


import pandas as pd
import shutil

if os.path.exists(csv_dir):
    shutil.rmtree(csv_dir)
os.makedirs(csv_dir)  
 
salva_rede_brasil(csv_dir,rede)
    
df_uf = mtse.pandas_query(f'select sg_uf from {table_candidaturas} group by sg_uf order by sg_uf')                         
for index, row in df_uf.iterrows():
    sg_uf = row['sg_uf']
    salva_rede_csv_uf(csv_dir,rede,sg_uf)


# In[14]:


import datetime
print(datetime.datetime.now())


# In[ ]:

示例#4
0
    c.candidato_id  = id
    and
    nr_turno = '2'  
;



"""
mtse.execute_query(query_inclui_table_gephi_nodes)

# In[9]:

mtse.pandas_query(f"""
 select id, q
 from (select ID, count(*)  as q from {table_gephi_nodes} 
 group by id) t
 where q>1 
 ;
 """)

# In[10]:

### atualiza os atributos de órgãos partidários na tabela de nós
### com base na tabela de órgãos partidários

query_inclui_orgaos_partidarios = f"""
    insert into {table_gephi_nodes}
    select
        orgao_partidario_id,
        label,
        'OP',
示例#5
0
# In[12]:

query_calcula_custo_voto = f"""
    update {table_candidaturas}
        set custo_voto = case when total_votos > 0 then round(receita_total / total_votos,2) else 0 end
"""
mtse.execute_query(query_calcula_custo_voto)

# ### Verifica Candidatos com mais de um registro

# In[13]:

mtse.pandas_query(f"""
 select candidato_id, q
 from (select candidato_id, count(*)  as q from {table_candidaturas} 
 group by candidato_id) t
 where q>1 
 order by q desc
 ;
 """)

# ## Muda o id do registro mais antigo de candidato com mais de um  registro

# ### exclui candidato_id mais antigo quando dois registros para o mesmo candidato
# def exclui_duplo_id():
#     p=mtse.pandas_query(f"""
#     select candidato_id, tse_id from {table_candidaturas}
#     where candidato_id in(
#      select candidato_id
#      from (select  candidato_id, count(*)  as q from {table_candidaturas}
#      group by candidato_id) t
#      where q>1
        and
        receita_origem_sg = 'RPP'
        and 
        doador_tipo_cd = 'PJ'
        and
        doador_cpf_cnpj = op.prestador_contas_cnpj
;
"""

mtse.execute_query(query_update_doadores_id_origem_RPP_OP_2018)

# In[9]:

mtse.pandas_query(f"""
select count(*) from {table_receitas}
where
receita_origem_sg in ('RPP')
and
doador_tipo_cd = 'PJ'""")

# In[10]:

query_update_doador_id_RPP_OP_2014 = f"""

update {table_receitas} as r
    set doador_id      = get_orgao_partidario_id(doador_cpf_cnpj),
        doador_tipo_cd = 'OP',
        doador_tipo_ds = 'Órgão Partidário' 
    where
        {ano_eleicao} = '2014'
        and
        receita_origem_sg in ('RPP', 'ROC')
示例#7
0
  doador_tipo_cd,
  receptor_tipo_cd,
  receptor_uf


 select * from rede2018.gephi_nodes_2018 gn 
 


# In[45]:


mtse.pandas_query(f"""
select id, nr_candidato, ds_sit_tot_turno, ds_situacao_candidatura from rede2018.gephi_nodes_2018 
where id in 
(
'CAMA5122',
'CAMG4055'
)
""")


# In[46]:


mtse.pandas_query(f"""
select nr_candidato, ds_sit_tot_turno, ds_situacao_candidatura from rede2018.candidaturas_2018 
where candidatura_id in 
(
'CAMA5122',
'CAMG4055'
)