Commit 5a5f9bca authored by Bruno Thomazi Zanette's avatar Bruno Thomazi Zanette 🎱
Browse files

Add new file

parent df0c3c1a
import mysql.connector
import numpy as np
import matplotlib.pyplot as plt
from datetime import date
import seaborn
import random # importing the random module
import time
#### SQL
# Conectando ao sql
db_connection = mysql.connector.connect(
host='localhost',
user='COSMICPAMPApy',
passwd='5H4$%mrnsp4901',
auth_plugin='mysql_native_password'
)
# print(db_connection) # mostra se foi conectado
# Create a Cursor object to execute queries.
cur = db_connection.cursor()
# Seleciona banco de dados previamento criado a ser usado.
cur.execute("USE COSMICPAMPA;")
def plot_dist(data, x_label, y_label, tittle, number_bins, plot_output):
"""Plot data distribution
Args:
data (list): List with data to be plotted.
x_label (str): Plot x-label.
y_label (str): Plot y-label.
tittle (str): Plot tittle.
number_bins (int): Number of bins for distribution.
plot_output (str): Path to plot output.
"""
#plt.xlim([0, 24])
seaborn.set(color_codes='dark')
seaborn.set_style("white")
plt.figure(1, figsize=(9, 6))
sns_plot = seaborn.histplot(data, bins=number_bins, color="#5881C1")
sns_plot.set(xlabel=x_label, ylabel=y_label)
plt.title(tittle)
sns_plot.figure.savefig(plot_output, bbox_inches='tight', dpi=400)
plt.show()
plt.close()
# Recebe os dados
horas_grafico= 24
where= time.time()*1000 - horas_grafico*60*60*1000
mensagem=f'select hora from eventos where hora >= {where} and usuario="bruno";'
print(mensagem)
cur.execute(mensagem)
dados = np.array([],dtype=float)
for row in cur.fetchall() :
dados= np.append(dados,row)
print(len(dados))
# Arquivo texto
for i in range(1,len(dados)):
dados[i]= (dados[i] - dados[0])/(1000*60*60)
#dados[i]= (dados[i] - dados[0])
dados[0]=0.0
# 1ms * 1s/1000ms * 1min/60s * 1h/60min
# Data para o título
today = date.today()
## dd/mm/YY
d1 = today.strftime("%A %d/%b/%Y")
d2 = today.strftime("%Y%m%d")
#output= 'teste'+d2+'.png'
output= 'graficododia.png'
# Printando histograma
minutos= 30
bins=int(24*60/minutos)
Eventos= "Eventos/"+str(minutos)+"min"
plot_dist(dados, "Horas", Eventos, d1, bins, output)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment