def __init__(self,session,hisId,dateTimeRange='today'): """ GET data from server and fill this object with historical info """ self.hisId = hisId self.name = self.getHisNameFromId(session,self.hisId) index = [] values = [] for eachRows in session.read('hisRead?id='+self.hisId+'&range='+dateTimeRange)['rows']: index.append(pd.Timestamp(pd.to_datetime(datetime.datetime(*map(int, re.split('[^\d]', eachRows['ts'].split(' ')[0])[:-2]))))) #This will allow conversion of Enum value to float so Pandas will work if (eachRows['val'] == 'F'): values.append(False) elif (eachRows['val'] == 'T'): values.append(True) # regex coding here to extract float value when units are part of value (ex. 21.8381°C) elif tools.isfloat(re.findall(r"[-+]?\d*\.*\d+", eachRows['val'])[0]): values.append(float(re.findall(r"[-+]?\d*\.*\d+", eachRows['val'])[0])) else: values.append(eachRows['val']) try: #Declare Series and localize using Site Timezone self.data = Series(values,index=index).tz_localize(session.timezone) #Renaming index so the name will be part of the serie self.data = self.data.reindex(self.data.index.rename([self.name])) except Exception: print('%s is an Unknown history type' % self.hisId)
def __init__(self, session, hisId , dateTimeRange='today', tz=None): """ GET Data from server and fill this object with historical info """ self.hisId = hisId.split(' ',1)[0].replace('r:','') self.name = hisId.split(' ',1)[1] index = [] values = [] if tz is None: tz = session.timezone # for eachRows in session.read('hisRead?id='+self.hisId+'&range="'+dateTimeRange+'"')['rows']: for eachRows in session.read('eval','readById('+self.hisId+').hisRead('+dateTimeRange+',{limit:null}).hisClip')['rows']: index.append(pd.Timestamp(pd.to_datetime(datetime.datetime(*map(int, re.split('[^\d]', eachRows['ts'].split(' ')[0])[2:-2]))))) #This will allow conversion of Enum value to float so Pandas will work if (eachRows['v0'] == 'F'): values.append(False) elif (eachRows['v0'] == 'T'): values.append(True) # regex coding here to extract float value when units are part of value (ex. 21.8381°C) elif tools.isfloat(re.findall(r"[-+]?\d*\.*\d+", eachRows['v0'])[0]): values.append(float(re.findall(r"[-+]?\d*\.*\d+", eachRows['v0'])[0])) else: values.append(eachRows['v0']) try: #Declare Series and localize using Site Timezone self.data = Series(values,index=index) #Renaming index so the name will be part of the serie self.data = self.data.reindex(self.data.index.rename([self.name])) except Exception as inst: print('%s is an Unknown history type' % self.hisId) print inst