Permalink
Browse files

Now start and stop for queries support both date str and datetime.

  • Loading branch information...
tsileo committed Oct 1, 2013
1 parent 8341c5e commit 9f84dd68f567e2a11f9e594be15f76abf57bde85
Showing with 40 additions and 21 deletions.
  1. +27 −20 README.rst
  2. +13 −1 cube/__init__.py
View
@@ -42,7 +42,7 @@ Overview
>>> c.event('sample_data') >>> c.event('sample_data')
[{u'time': u'2012-10-01T13:04:04.453Z'}, {u'time': u'2012-10-01T13:04:39.725Z'}] [{u'time': u'2012-10-01T13:04:04.453Z'}, {u'time': u'2012-10-01T13:04:39.725Z'}]
>>> c.event('sample_data(myval)'') >>> c.event('sample_data(myval)')
[{u'data': {u'myval': 10}, u'time': u'2012-10-01T13:04:04.453Z'}, {u'data': {u'myval': 20}, u'time': u'2012-10-01T13:04:39.725Z'}] [{u'data': {u'myval': 10}, u'time': u'2012-10-01T13:04:04.453Z'}, {u'data': {u'myval': 20}, u'time': u'2012-10-01T13:04:39.725Z'}]
>>> c.metric('sum(sample_data)', step=ONE_HOUR, start='2012-10-01') >>> c.metric('sum(sample_data)', step=ONE_HOUR, start='2012-10-01')
@@ -91,7 +91,7 @@ Usage
# Request metrics # Request metrics
cube.metric('sum(myevent(temp))', step='36e5', start='2013-9-01')) cube.metric('sum(myevent(temp))', step='36e5', start='2013-9-01'))
# or # or
cube.metric('sum(myevent(temp))', step=ONE_HOUR, start='2013-9-01')) cube.metric('sum(myevent(temp))', step=ONE_HOUR, start=datetime(2013, 9, 1))
# Request known event types # Request known event types
cube.types() cube.types()
@@ -105,24 +105,6 @@ Usage
cube.metric(Sum(temp), step=ONE_HOUR, start='2013-10-1') cube.metric(Sum(temp), step=ONE_HOUR, start='2013-10-1')
Metric resolutions shortcut
---------------------------
- **TEN_SECOND** for **1e4** - 10-second
- **ONE_MINUTE** for **6e4** - 1-minute
- **FIVE_MINUTE** for **3e5** - 5-minute
- **ONE_HOUR** for **36e5** - 1-hour
- **ONE_DAY** for **864e5** - 1-day
::
from cube import ONE_HOUR, FIVE_MINUTE
Time utils
----------
Event helper Event helper
------------ ------------
@@ -151,6 +133,31 @@ Event helper
# => my_event.metric('sum(myevent(temp).gt(temp, 15))') # => my_event.metric('sum(myevent(temp).gt(temp, 15))')
Metric resolutions shortcut
---------------------------
- **TEN_SECOND** for **1e4** - 10-second
- **ONE_MINUTE** for **6e4** - 1-minute
- **FIVE_MINUTE** for **3e5** - 5-minute
- **ONE_HOUR** for **36e5** - 1-hour
- **ONE_DAY** for **864e5** - 1-day
::
from cube import ONE_HOUR, FIVE_MINUTE
Time utils
----------
::
from cube import ONE_HOUR
from cube.time_utils import timeago
c.metric('sum(myevent(key))', step=ONE_HOUR, start=timeago('6h'))
Changelog Changelog
========= =========
View
@@ -52,9 +52,21 @@ def put(self, event_type, event_data={}, **kwargs):
return [event] return [event]
def make_query(self, query_type, expression, **kwargs): def make_query(self, query_type, expression, **kwargs):
"""
Actually perform the query,
try to convert datetime to isoformat on the fly
"""
data = dict(expression=str(expression), data = dict(expression=str(expression),
stop=kwargs.get('stop', datetime.utcnow().isoformat())) stop=kwargs.get('stop', datetime.utcnow()))
data.update(kwargs) data.update(kwargs)
for k in ['start', 'stop']:
if k in data:
try:
data[k] = data[k].isoformat()
except AttributeError:
pass
r = requests.get(self.evaluator_url + query_type, params=data) r = requests.get(self.evaluator_url + query_type, params=data)
r.raise_for_status() r.raise_for_status()

0 comments on commit 9f84dd6

Please sign in to comment.