def setComputedIds(self, dimension, rangeStart, rangeEnd = None, binSize = 'minutes'): """ set the ids which indicated which data was already computed """ self.conn.cursor.execute("USE " + config_global.cassandra_default_keyspace) key = self.dimensionName + "_by_" + binSize + "_done" timerange = getTimestamp.convertTimeStampsPairToRange(rangeStart, rangeEnd, binSize, binSize ) """ TODO make one query out of this """ for dimension_id in timerange: cql_query = """UPDATE :table SET :dimension_id = :dimension_id WHERE dimension_name = :dimension_name """ self.conn.cursor.execute(cql_query, dict(table=self.column_family, dimension_name = key, dimension_id = dimension_id ))
def getByTime(self, timestampStart, timestampEnd = None, binSize = 'seconds', renew = False): """ grab all entries for the dimensions @param: timeStampStart start of range or single point @param: timeStampEnd end of the range @param: binSize default ist seconds otherwise aggregated data is requested """ self.conn.cursor.execute("USE " + config_global.cassandra_default_keyspace) if (binSize == 'seconds'): """ we access the raw data """ else: """ if the binsize is not seconds, there is a chance it is already computed and therefore doesn'have to be computed again """ r = self.getComputedIds(self.dimensionName, timestampStart, timestampEnd, binSize) """ according to the result we might need to compute something """ #print r requestIdRange = list(xrange(timestampStart,timestampEnd+1)) if (not renew): for rIR in requestIdRange: if (rIR in r): requestIdRange.remove(rIR) else: pass for i in requestIdRange: self.binify(binSize, i, i+1) if ( timestampStart != None and timestampEnd != None ) : # origin = 'seconds' origin = binSize ids = getTimestamp.convertTimeStampsPairToRange(timestampStart, timestampEnd, binSize, origin) basekey = self.dimensionName + "_by_" + binSize + "_" if len(ids) > 1 : """ check for the lists """ ids = [basekey + str(id) for id in ids] ids = tuple(ids) self.conn.cursor.execute("SELECT * FROM :table WHERE dimension_name in :ids", dict(table=self.column_family, ids = ids )) else: """ in case there is only one result """ ids = ids[0] ids = basekey + str(ids) self.conn.cursor.execute("SELECT * FROM :table WHERE dimension_name = :ids", dict(table=self.column_family, ids = ids )) """ interpret the result since the format suck """ self.dict = {} r = self.conn.cursor.fetchone() d = self.conn.cursor.description while r : if ( len(r) > 1): self.dict[ r[0] ] = [] for i in xrange(1, len(r)): self.dict[ r[0] ].append( d[i][0] ) r = self.conn.cursor.fetchone() d = self.conn.cursor.description return self.dict