#!/usr/bin/env python import sys, os sys.path.append(os.path.abspath(".")) sys.path.append(os.path.abspath("..")) from kairos import Timeseries import redis # Change these constants to see the differences. When toggling the # count flag, you'll have to reset the redis database if there is # already data for the same time window COUNT_ONLY = False CONDENSED = False STEP = 60 RESOLUTION = 10 client = redis.Redis('localhost', 6379) t = Timeseries(client, { 'minute':{ 'step':STEP, 'steps':10, # last 10 minutes 'read_cast' : float, # cast all results as floats 'resolution': RESOLUTION, 'count_only': COUNT_ONLY } }) t.insert('example', 3.14159) t.insert('example', 2.71828) print 'get last minute' print t.get('example', 'minute', condensed=CONDENSED) print '\ncount last minute' print t.count('example', 'minute', condensed=CONDENSED) print '\nlast 4 minutes' for interval,series in t.series('example', 'minute', 4, condensed=CONDENSED).iteritems(): print interval if CONDENSED: print ' ', series continue if STEP==RESOLUTION: print ' ',series else: for resolution,data in series.iteritems(): print ' ',resolution, data