forked from agoragames/kairos
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample
More file actions
executable file
·49 lines (40 loc) · 1.17 KB
/
Copy pathexample
File metadata and controls
executable file
·49 lines (40 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/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