import epmwebapi as epm
import datetime as dt
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
sns.set(style="whitegrid")
%matplotlib inline
import os
credentials = os.environ.get('user_and_password').split(';')
user = credentials[0]
password = credentials[1]
#cria conexao
#para ter acesso ao ECC entre em contato com epm@elipse.com.br
epmConn = epm.EpmConnection('http://ecc.elipse.com.br:44333', 'http://ecc.elipse.com.br:44332', user, password)
iniTime = dt.datetime(2018, 9, 1, 0, 0, 0, 0)
endTime = iniTime + dt.timedelta(days=60)
array_dfs = []
paths = ['ERSF11R4_Temp2', 'ERSF11R4_Temp2SP', 'ERSF11R4_ACCompr2', 'ERSF11R4_ACVent2']
processInterval = dt.timedelta(minutes=5)
#cria objeto queryperiod
queryPeriod = epm.QueryPeriod(iniTime, endTime)
aggInterpDetails = epm.AggregateDetails(processInterval, epm.AggregateType.Interpolative)
for path in paths:
bv = epmConn.getDataObjects(path)
result= bv[path].historyReadAggregate(aggInterpDetails, queryPeriod)
#======================================================================================
# Transformação em DataFrame do pandas
#======================================================================================
#corrige o erro: ValueError: Big-endian buffer not supported on little-endian compiler
new_Quality = result[:]['Quality'].byteswap().newbyteorder()
new_Timestamp = result[:]['Timestamp']
new_Value = result[:]['Value'].byteswap().newbyteorder()
d = {'Value':new_Value, 'Timestamp':new_Timestamp, 'Quality':new_Quality}
df_original = pd.DataFrame(d)
#======================================================================================
# Converte de UTC PARA LOCALTIME
#======================================================================================
df_original['Timestamp'] = df_original['Timestamp'].dt.tz_convert('America/Sao_Paulo')
#array de dataframes
array_dfs.append(df_original)
epmConn.close()
array_dfs[0].shape
array_dfs[0].head()
dfs_filtered = []
for df in array_dfs:
mask = (
((df.Timestamp.dt.weekday.between(0,4)) & (df.Timestamp.dt.hour.between(8,11) | (df.Timestamp.dt.hour.between(13,18) )))
#& (df.Quality == 0)
)
df_aux = df.loc[mask]
dfs_filtered.append(df_aux)
df_01 = dfs_filtered[0][['Timestamp']].copy()
df_01['Temperatura'] = dfs_filtered[0][['Value']].copy()
df_01['TemperaturaSP'] = dfs_filtered[1][['Value']].copy()
df_01['Compressor'] = dfs_filtered[2][['Value']].copy()
df_01['Ventilacao'] = dfs_filtered[3][['Value']].copy()
df_01.shape
df_01.dtypes
df_01.loc[df_01.Timestamp.dt.hour==12]
df_01.describe(include='all')
df_01.Temperatura.plot(kind='hist', bins=20)
df_01.TemperaturaSP.plot(kind='hist', bins=20)
def conforto(a):
if a>=24.5 and a<=25.5:
return 'dentro'
if a<24.5:
return 'abaixo'
else:
return 'acima'
df_01['conforto_termico'] = df_01.Temperatura.apply(conforto)
df_01.head()
grouped_temp = df_01.groupby(['conforto_termico']).Temperatura.agg(['count', 'max', 'min']).reset_index()
grouped_temp
def make_autopct(values):
#values -> valores enviados
def my_autopct(pct):
#pct -> %
total = sum(values)
val = int(round(pct*total/100.0))
return '{p:.2f}%\n({v:d})'.format(p=pct,v=val)
return my_autopct
df_01.groupby(['conforto_termico']).Temperatura.count().plot(kind='pie', subplots=True, autopct=make_autopct(grouped_temp['count']))
grouped_comp = df_01.groupby(['Compressor']).Compressor.agg(['count']).reset_index()
grouped_comp
df_01.groupby(['Compressor']).Compressor.count().plot(kind='pie', subplots=True, autopct=make_autopct(grouped_comp['count']))
plt.axis('off')