publicando mudanças
This commit is contained in:
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,18 @@
|
||||
[credenciais]
|
||||
remetente=joao.herculano@grupoginseng.com.br
|
||||
senha=Cecigaming@21
|
||||
|
||||
[email]
|
||||
assunto = ACOMPANHAMENTO IMPRODUTIVOS
|
||||
destinatarios=lucas.Barbosa@grupoginseng.com.br,Andressa.Rocha@grupoginseng.com.br,Lais.Santos@grupoginseng.com.br,Daniel.Rodrigues@grupoginseng.com.br,Darlin.Cunha@grupoginseng.com.br,Dielly.Gomes@grupoginseng.com.br,Haryadne.Gomes@grupoginseng.com.br,Lucas.Bento@grupoginseng.com.br,Marcyara.Batista@grupoginseng.com.br,Pedro.Horgos@grupoginseng.com.br,Thayllan.Santos@grupoginseng.com.br,Jefferson.Ferreira@grupoginseng.com.br,Luan.Omena@grupoginseng.com.br,vinicius.souza@grupoginseng.com.br
|
||||
|
||||
[email_ruptura]
|
||||
assunto = ACOMPANHAMENTO DE RUPTURA PROJETADA
|
||||
destinatarios=Lucas.Barbosa@grupoginseng.com.br,Andressa.Rocha@grupoginseng.com.br,Lais.Santos@grupoginseng.com.br,Daniel.Rodrigues@grupoginseng.com.br,Darlin.Cunha@grupoginseng.com.br,Dielly.Gomes@grupoginseng.com.br,Haryadne.Gomes@grupoginseng.com.br,Lucas.Bento@grupoginseng.com.br,Marcyara.Batista@grupoginseng.com.br,Pedro.Horgos@grupoginseng.com.br,Thayllan.Santos@grupoginseng.com.br,Jefferson.Ferreira@grupoginseng.com.br,Luan.Omena@grupoginseng.com.br,vinicius.souza@grupoginseng.com.br
|
||||
|
||||
|
||||
[banco]
|
||||
host = 10.77.77.10
|
||||
user = hubsupply
|
||||
password = =c6#94sE&(v2
|
||||
|
||||
@@ -6,6 +6,7 @@ import pyodbc
|
||||
import configparser
|
||||
import pandas as pd
|
||||
import matplotlib.pyplot as plt
|
||||
import matplotlib.dates as mdates
|
||||
import matplotlib.ticker as mtick
|
||||
import seaborn as sns
|
||||
from email.message import EmailMessage
|
||||
@@ -16,7 +17,7 @@ from datetime import datetime, time
|
||||
|
||||
|
||||
config = configparser.ConfigParser()
|
||||
config.read(r"C:\Users\joao.herculano\Documents\Enviador de email\credenciais.ini")
|
||||
config.read(r"relatório_improdutivo\credenciais.ini")
|
||||
|
||||
print(config['banco']['host'],config['banco']['user'],config['banco']['password'])
|
||||
|
||||
@@ -57,7 +58,9 @@ assunto = config['email']['assunto']
|
||||
|
||||
print(remetente,senha,destinatarios,assunto)
|
||||
|
||||
pdvs = pd.read_excel(r"C:\Users\joao.herculano\Documents\PDV_ATT.xlsx")
|
||||
pdvs = pd.read_excel(r"relatório_improdutivo\PDV_ATT.xlsx")
|
||||
|
||||
|
||||
|
||||
df['loja_id'] = df['loja_id'].astype('Int64')
|
||||
pdvs['PDV'] = pdvs['PDV'].astype('Int64')
|
||||
@@ -108,22 +111,45 @@ excel_path = Path("relatorio.xlsx")
|
||||
df2.to_excel(excel_path, index=False)
|
||||
|
||||
|
||||
# 2. Criar e salvar gráfico
|
||||
# Gerar gráfico melhorado - Estoque parado por UF
|
||||
plot_df = df2.groupby('UF')['valor_estoque_parado'].sum().reset_index()
|
||||
plt.figure(figsize=(6, 4))
|
||||
ax = sns.barplot(data=plot_df, x='UF', y='valor_estoque_parado', errorbar=None)
|
||||
|
||||
sns.set_theme(style="whitegrid")
|
||||
|
||||
plt.figure(figsize=(12, 7))
|
||||
ax = sns.barplot(
|
||||
data=plot_df,
|
||||
x='UF',
|
||||
y='valor_estoque_parado',
|
||||
palette='crest',
|
||||
errorbar=None
|
||||
)
|
||||
|
||||
ax.yaxis.set_major_formatter(mtick.StrMethodFormatter('R${x:,.2f}'))
|
||||
|
||||
# Anotar valores em cima das barras
|
||||
for p in ax.patches:
|
||||
valor = p.get_height()
|
||||
ax.annotate(f'R$ {valor:,.2f}', (p.get_x() + p.get_width() / 2, valor),
|
||||
ha='center', va='bottom', fontsize=9)
|
||||
plt.title("Estoque parado por UF")
|
||||
plt.ylabel("Valor em Reais")
|
||||
plt.xlabel("UF")
|
||||
ax.annotate(
|
||||
f'R$ {valor:,.2f}',
|
||||
(p.get_x() + p.get_width() / 2, valor),
|
||||
ha='center', va='bottom',
|
||||
fontsize=10,
|
||||
fontweight='bold'
|
||||
)
|
||||
|
||||
plt.title("Estoque Parado por UF", fontsize=18, fontweight='bold')
|
||||
plt.ylabel("Valor em Reais", fontsize=13)
|
||||
plt.xlabel("UF", fontsize=13)
|
||||
plt.xticks(fontsize=11)
|
||||
plt.yticks(fontsize=11)
|
||||
|
||||
sns.despine()
|
||||
plt.tight_layout()
|
||||
plt.savefig("grafico.png")
|
||||
plt.close()
|
||||
|
||||
|
||||
# Obtém a hora atual
|
||||
agora = datetime.now().time()
|
||||
hoje = datetime.today().strftime("%d/%m/%Y")
|
||||
@@ -147,7 +173,7 @@ df2['DATA'] = hoje
|
||||
|
||||
df3 = df2.groupby('DATA', as_index=False)['valor_estoque_parado'].sum()
|
||||
|
||||
path2 = r'C:\Users\joao.herculano\OneDrive - GRUPO GINSENG\Documentos\acompanhamentos\40D sem Venda\acompanhamento40DSV.xlsx'
|
||||
path2 = r'relatório_improdutivo\acompanhamento40DSV.xlsx'
|
||||
|
||||
# Tenta abrir e escrever com append
|
||||
with pd.ExcelWriter(path2, mode='a', engine='openpyxl', if_sheet_exists='overlay') as writer:
|
||||
@@ -159,8 +185,47 @@ with pd.ExcelWriter(path2, mode='a', engine='openpyxl', if_sheet_exists='overlay
|
||||
# Escreve sem cabeçalho se não for a primeira linha
|
||||
df3.to_excel(writer, index=False, header=not start_row > 1, startrow=start_row)
|
||||
|
||||
de_effi = pd.read_excel(r'relatório_improdutivo\acompanhamento40DSV.xlsx')
|
||||
|
||||
de_effi['Data'] = pd.to_datetime(de_effi['Data'], errors='coerce')
|
||||
|
||||
# Step 2: Group and sort
|
||||
grouped = (
|
||||
de_effi.groupby('Data')['Valor']
|
||||
.sum()
|
||||
.sort_index()
|
||||
)
|
||||
|
||||
# Step 3: Plot
|
||||
plt.figure(figsize=(12, 6))
|
||||
plt.plot(grouped.index, grouped.values, marker='o', linestyle='-', color='cornflowerblue', linewidth=2)
|
||||
|
||||
# Step 4: Format numbers with dot ('.') separator, no decimals
|
||||
for x, y in zip(grouped.index, grouped.values):
|
||||
label = f"{y:,.0f}".replace(",", ".") # format like 75.063
|
||||
plt.text(x, y + max(grouped.values) * 0.015, label, ha='center', fontsize=9)
|
||||
|
||||
# Step 5: Format chart
|
||||
plt.title('Evolução de Estoque Improdutivo por Data', fontsize=14)
|
||||
plt.xlabel('Data', fontsize=8)
|
||||
plt.ylabel('Estoque Improdutivo', fontsize=12)
|
||||
plt.grid(True, linestyle='--', alpha=0.6)
|
||||
|
||||
# ✅ Set xticks to match the actual data points
|
||||
ax = plt.gca()
|
||||
ax.set_xticks(grouped.index)
|
||||
ax.xaxis.set_major_formatter(mdates.DateFormatter('%d/%m/%Y'))
|
||||
plt.xticks(rotation=45)
|
||||
|
||||
# Format x-axis as dd/mm/yyyy
|
||||
plt.gca().set_xticklabels([d.strftime('%d/%m/%Y') for d in grouped.index])
|
||||
plt.tight_layout()
|
||||
plt.savefig("grafico2.png")
|
||||
plt.close()
|
||||
|
||||
# 3. Criar e-mail com imagem embutida
|
||||
grafico_cid = make_msgid()[1:-1] # remove < >
|
||||
grafico2_cid = make_msgid()[1:-1]
|
||||
msg = EmailMessage()
|
||||
msg['From'] = remetente
|
||||
msg['To'] = ', '.join(destinatarios)
|
||||
@@ -175,7 +240,7 @@ html_email = f"""
|
||||
|
||||
<p>
|
||||
Segue o relatório semanal de estoque improdutivo referente às regiões de
|
||||
Alagoas (AL), Bahia (BA), Sergipe (SE), Vitória da Conquista (VDC) e Iracê.
|
||||
Alagoas (AL), Bahia (BA), Sergipe (SE), Vitória da Conquista (VDC), Jacobina e Iracê.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
@@ -200,7 +265,8 @@ html_email = f"""
|
||||
</p>
|
||||
|
||||
<p><b>Segue resumo:</b></p>
|
||||
<img src="cid:{grafico_cid}">
|
||||
<p><img src="cid:{grafico_cid}"></p>
|
||||
<p><img src="cid:{grafico2_cid}"></p>
|
||||
</body>
|
||||
</html>
|
||||
"""
|
||||
@@ -213,6 +279,9 @@ msg.add_alternative(html_email, subtype='html')
|
||||
with open("grafico.png", 'rb') as img:
|
||||
msg.get_payload()[1].add_related(img.read(), 'image', 'png', cid=grafico_cid)
|
||||
|
||||
with open("grafico2.png", 'rb') as img2:
|
||||
msg.get_payload()[1].add_related(img2.read(), 'image', 'png', cid=grafico2_cid)
|
||||
|
||||
|
||||
# 5. Anexar o arquivo Excel
|
||||
with open(excel_path, 'rb') as f:
|
||||
|
||||
Reference in New Issue
Block a user