def testGetTimestampFromHour(self): """ @TODO: move this into a seperate unit Test for the getTimestamp Class but for now it is perfect here """ hour = 1 val = 3600 timestamp = getTimestamp.getTimeStampFromHours(hour) self.assertEqual(timestamp, val, "the conversion from timestamp {0:1d} to hour {1:1d} is wrong".format(timestamp, val))
def binify(self, target, fromTime, toTime = None, origin = 'seconds' ): """ push the data into bin according the binsize @param: binsize like minutes or hours @param: fromTime starting Point @param: toTime endPoint """ """ get the whole range at once """ """ @todo: these following function should be dependent from the origin """ if ( target == 'minutes'): fromTime_origin = getTimestamp.getTimeStampFromMinutes(fromTime) toTime_origin = getTimestamp.getTimeStampFromMinutes(toTime) elif ( target == 'hours'): fromTime_origin = getTimestamp.getTimeStampFromHours(fromTime) toTime_origin = getTimestamp.getTimeStampFromHours(toTime) elif ( target == 'days'): fromTime_origin = getTimestamp.getTimeStampFromDays(fromTime) toTime_origin = getTimestamp.getTimeStampFromDays(toTime) elif ( target == 'weeks'): fromTime_origin = getTimestamp.getTimeStampFromWeeks(fromTime) toTime_origin = getTimestamp.getTimeStampFromWeeks(toTime) idlist = self.getByTime( fromTime_origin, toTime_origin, 'seconds') """ now we have a list of all """ target_list = Set([]) for key, element in idlist.items(): target_list = target_list.union( Set(element) ) for dimension_id in target_list: self.save(dimension_id, fromTime, target ) self.setComputedIds(self.dimensionName, fromTime, toTime, target) return idlist
print "not able to create a database connection" cursor.execute("USE " + config_global.cassandra_default_keyspace) #config_global.dbname_dimensionList_rowKeys[0] #dL = DimensionListModel(config_global.dbname_dimensionList_rowKeys[0]) dL = DimensionListModel('user_ids') timestamp = int( time.time() ) for i in xrange(70): id = 2 curr_timestamp = timestamp + i dL.save( id, curr_timestamp ) binId = getTimestamp.gettimeStampIn_Hours( timestamp ) print timestamp print dL.getByTime(timestamp-60, timestamp+50) #dL.save_bin(1, 'hours', binId) print getTimestamp.getTimeStampFromHours( binId ) #print dL.getAll() print "binify" x = ( dL.binify('hours', binId-1, binId) ) print len( x )