Mudanças no grafico e implementação de acompanhamento
This commit is contained in:
parent
4495bae649
commit
16cf6f950e
@ -157,7 +157,7 @@ with pd.ExcelWriter(path2, mode='a', engine='openpyxl', if_sheet_exists='overlay
|
||||
start_row = sheet.max_row
|
||||
|
||||
# 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)
|
||||
df3.to_excel(writer, index=False, header=not start_row > 1, startrow=start_row)
|
||||
|
||||
# 3. Criar e-mail com imagem embutida
|
||||
grafico_cid = make_msgid()[1:-1] # remove < >
|
||||
@ -174,8 +174,8 @@ html_email = f"""
|
||||
<p>{boa}</p>
|
||||
|
||||
<p>
|
||||
Segue o relatório semanal de estoque improdutivo referente aos estados de
|
||||
Alagoas (AL), Bahia (BA), Sergipe (SE) e região de Vitória da Conquista (VDC).
|
||||
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ê.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
|
||||
@ -4,17 +4,20 @@ import pyodbc
|
||||
import configparser
|
||||
import numpy as np
|
||||
import pandas as pd
|
||||
import matplotlib.pyplot as plt
|
||||
import seaborn as sns
|
||||
import matplotlib.pyplot as plt
|
||||
import matplotlib.dates as mdates
|
||||
from email.message import EmailMessage
|
||||
from email.utils import make_msgid
|
||||
from pathlib import Path
|
||||
from datetime import datetime, time
|
||||
|
||||
|
||||
from email.mime.image import MIMEImage
|
||||
|
||||
hoje = datetime.today().strftime("%d/%m/%Y")
|
||||
|
||||
|
||||
config = configparser.ConfigParser()
|
||||
config.read(r"C:\Users\joao.herculano\Documents\Enviador de email\credenciais.ini")
|
||||
|
||||
@ -152,9 +155,21 @@ df3 = df3.groupby(['uf', 'canal','pdv'])['quantidade_ruptura'].sum().sort_values
|
||||
df4 = df3.groupby('uf', as_index=False)['quantidade_ruptura'].sum()
|
||||
|
||||
df4['data'] = hoje
|
||||
|
||||
df4['data'] = pd.to_datetime(df4['data'], dayfirst=True)
|
||||
|
||||
path2 = r'C:\Users\joao.herculano\OneDrive - GRUPO GINSENG\Documentos\acompanhamentos\estudo ruptura\AcompanhamentoRuptura.xlsx'
|
||||
|
||||
# Tenta abrir e escrever com append
|
||||
with pd.ExcelWriter(path2, mode='a', engine='openpyxl', if_sheet_exists='overlay') as writer:
|
||||
# Encontra a última linha preenchida
|
||||
book = writer.book
|
||||
sheet = writer.sheets['Sheet1'] if 'Sheet1' in writer.sheets else writer.book.active
|
||||
start_row = sheet.max_row
|
||||
|
||||
# Escreve sem cabeçalho se não for a primeira linha
|
||||
df4.to_excel(writer, index=False, header=not start_row > 1, startrow=start_row)
|
||||
|
||||
de_effi = pd.read_excel(r"C:\Users\joao.herculano\OneDrive - GRUPO GINSENG\Documentos\acompanhamentos\estudo ruptura\AcompanhamentoRuptura.xlsx")
|
||||
|
||||
de_effi['data'] = pd.to_datetime(de_effi['data'], errors='coerce')
|
||||
@ -177,9 +192,14 @@ for x, y in zip(grouped.index, grouped.values):
|
||||
|
||||
# Step 5: Format chart
|
||||
plt.title('Evolução de Quantidade de Ruptura por Data', fontsize=14)
|
||||
plt.xlabel('Data', fontsize=12)
|
||||
plt.xlabel('Data', fontsize=8)
|
||||
plt.ylabel('Quantidade de Ruptura', 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
|
||||
@ -188,16 +208,6 @@ plt.tight_layout()
|
||||
plt.savefig("grafico2.png")
|
||||
plt.close()
|
||||
|
||||
# Tenta abrir e escrever com append
|
||||
with pd.ExcelWriter(path2, mode='a', engine='openpyxl', if_sheet_exists='overlay') as writer:
|
||||
# Encontra a última linha preenchida
|
||||
book = writer.book
|
||||
sheet = writer.sheets['Sheet1'] if 'Sheet1' in writer.sheets else writer.book.active
|
||||
start_row = sheet.max_row
|
||||
|
||||
# Escreve sem cabeçalho se não for a primeira linha
|
||||
df4.to_excel(writer, index=False, header=not start_row > 1, startrow=start_row)
|
||||
|
||||
with pd.ExcelWriter(excel_path, engine='openpyxl') as writer:
|
||||
df2.to_excel(writer, sheet_name='Detalhado', index=False)
|
||||
df3.to_excel(writer, sheet_name='Resumo', index=False)
|
||||
@ -250,6 +260,7 @@ html_email = f"""
|
||||
<p>Foram adicionados ao relatório os PDVs da região de Irecê.</p>
|
||||
|
||||
<img src="cid:{grafico_cid}">
|
||||
<img src="cid:{grafico2_cid}">
|
||||
</body>
|
||||
</html>
|
||||
"""
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user