Mudanças no grafico e implementação de acompanhamento
This commit is contained in:
parent
4495bae649
commit
16cf6f950e
@ -174,8 +174,8 @@ html_email = f"""
|
|||||||
<p>{boa}</p>
|
<p>{boa}</p>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
Segue o relatório semanal de estoque improdutivo referente aos estados de
|
Segue o relatório semanal de estoque improdutivo referente às regiões de
|
||||||
Alagoas (AL), Bahia (BA), Sergipe (SE) e região de Vitória da Conquista (VDC).
|
Alagoas (AL), Bahia (BA), Sergipe (SE), Vitória da Conquista (VDC) e Iracê.
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
|
|||||||
@ -4,17 +4,20 @@ import pyodbc
|
|||||||
import configparser
|
import configparser
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import pandas as pd
|
import pandas as pd
|
||||||
import matplotlib.pyplot as plt
|
|
||||||
import seaborn as sns
|
import seaborn as sns
|
||||||
|
import matplotlib.pyplot as plt
|
||||||
|
import matplotlib.dates as mdates
|
||||||
from email.message import EmailMessage
|
from email.message import EmailMessage
|
||||||
from email.utils import make_msgid
|
from email.utils import make_msgid
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from datetime import datetime, time
|
from datetime import datetime, time
|
||||||
|
|
||||||
|
|
||||||
from email.mime.image import MIMEImage
|
from email.mime.image import MIMEImage
|
||||||
|
|
||||||
hoje = datetime.today().strftime("%d/%m/%Y")
|
hoje = datetime.today().strftime("%d/%m/%Y")
|
||||||
|
|
||||||
|
|
||||||
config = configparser.ConfigParser()
|
config = configparser.ConfigParser()
|
||||||
config.read(r"C:\Users\joao.herculano\Documents\Enviador de email\credenciais.ini")
|
config.read(r"C:\Users\joao.herculano\Documents\Enviador de email\credenciais.ini")
|
||||||
|
|
||||||
@ -153,8 +156,20 @@ df4 = df3.groupby('uf', as_index=False)['quantidade_ruptura'].sum()
|
|||||||
|
|
||||||
df4['data'] = hoje
|
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'
|
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 = 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')
|
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
|
# Step 5: Format chart
|
||||||
plt.title('Evolução de Quantidade de Ruptura por Data', fontsize=14)
|
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.ylabel('Quantidade de Ruptura', fontsize=12)
|
||||||
plt.grid(True, linestyle='--', alpha=0.6)
|
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)
|
plt.xticks(rotation=45)
|
||||||
|
|
||||||
# Format x-axis as dd/mm/yyyy
|
# Format x-axis as dd/mm/yyyy
|
||||||
@ -188,16 +208,6 @@ plt.tight_layout()
|
|||||||
plt.savefig("grafico2.png")
|
plt.savefig("grafico2.png")
|
||||||
plt.close()
|
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:
|
with pd.ExcelWriter(excel_path, engine='openpyxl') as writer:
|
||||||
df2.to_excel(writer, sheet_name='Detalhado', index=False)
|
df2.to_excel(writer, sheet_name='Detalhado', index=False)
|
||||||
df3.to_excel(writer, sheet_name='Resumo', 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>
|
<p>Foram adicionados ao relatório os PDVs da região de Irecê.</p>
|
||||||
|
|
||||||
<img src="cid:{grafico_cid}">
|
<img src="cid:{grafico_cid}">
|
||||||
|
<img src="cid:{grafico2_cid}">
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
"""
|
"""
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user