def getDimensaoTemporal(param): mes = 0 cnx = mySqlConn.getConnection() cursor = cnx.cursor() query = '''select PK_TEMPORAL from TBL_DIMENSAO_TEMPORAL where mes = %s and ano = %s ''' cursor.execute(query, (param, ano)) results = cursor.fetchall() for result in results: mes = result[0] return mes
import utils.mySqlConn as mySqlConn import pandas as pd import matplotlib.pyplot as plt query = '''select P.NM_PROGRAMA_ORCAMENTARIO AS 'Nome Programa', sum(F.VLR_LIQUIDADO) AS 'Valor Liquidado' from TBL_FATO F, TBL_DIMENSAO_PROGRAMA P where P.PK_PROGRAMA = F.FK_PROGRAMA group by P.NM_PROGRAMA_ORCAMENTARIO order by sum(F.VLR_LIQUIDADO) DESC''' dataFrame = pd.read_sql(query, con=mySqlConn.getConnection()) dataFrame.loc[(dataFrame['Valor Liquidado'] <= 800000000000.00), 'Nome Programa'] = 'Outros' dataFrame = dataFrame.groupby('Nome Programa').agg({'Valor Liquidado': sum}) dataFrame.plot(kind='pie', y='Valor Liquidado', shadow=False, label='', legend=True, autopct='%1.1f%%', startangle=357, title='Execução da despesa por Programa Orçamentário', figsize=(15, 12)) print(dataFrame) plt.show()
def getDimensaoAreaAtuacao(): cnx = mySqlConn.getConnection() cursor = cnx.cursor() query = 'SELECT PK_AREA_ATUACAO, CD_FUNCAO, NM_FUNCAO, CD_SUBFUNCAO, NM_SUBFUNCAO FROM TBL_DIMENSAO_AREA_ATUACAO' cursor.execute(query) return cursor.fetchall()
def getDimensaoPrograma(): cnx = mySqlConn.getConnection() cursor = cnx.cursor() query = 'select PK_PROGRAMA, CD_PROGRAMA_ORCAMENTARIO, CD_ACAO from TBL_DIMENSAO_PROGRAMA' cursor.execute(query) return cursor.fetchall()
def getDimensaoOrgao(): cnx = mySqlConn.getConnection() cursor = cnx.cursor() query = 'select PK_ORGAO, CD_ORGAO_SUPERIOR, CD_ORGAO_SUBORDINADO, CD_UNIDADE_ORCAMENTARIA from TBL_DIMENSAO_ORGAO' cursor.execute(query) return cursor.fetchall()
resultMergeDF['ChaveDimensaoAtuacao'] ]) resultDF = grouped_keys.agg({ 'Orçamento Realizado (R$)': sum, 'Valor Liquidado (R$)': sum }).reset_index() resultDF['Orçamento Realizado (R$)'] = resultDF[ 'Orçamento Realizado (R$)'].apply(lambda x: x / 12) resultDF['Orçamento Realizado (R$)'] = resultDF[ 'Orçamento Realizado (R$)'].apply(lambda x: round(x, 2)) resultDF['Valor Liquidado (R$)'] = resultDF['Valor Liquidado (R$)'].apply( lambda x: round(x, 2)) values.append(list(resultDF.itertuples(index=False, name=None))) out = listUtil.geraLista(values) cnx = mySqlConn.getConnection() cursor = cnx.cursor() query = '''INSERT INTO TBL_FATO (FK_TEMPORAL, FK_PROGRAMA, FK_ORGAO, FK_AREA_ATUACAO, VLR_ORCADO, VLR_LIQUIDADO) VALUES (%s, %s, %s, %s, %s, %s)''' cursor.executemany(query, out) cnx.commit() print(f'Etl Fato: {cursor.rowcount} linha(s) inserida(s)') print(f'Fim do processo')