Permalink
Browse files

Added shortcut for creating expression from Event

  • Loading branch information...
1 parent 9319922 commit 155a49c658ad77d8bfa9129d3a42929e129c3f6b @tsileo committed Oct 1, 2013
Showing with 12 additions and 1 deletion.
  1. +7 −0 README.rst
  2. +5 −1 cube/event.py
View
7 README.rst
@@ -129,6 +129,7 @@ Event helper
.. code-block:: python
from cube import Cube, Event
+ from cube.expression import Sum
cube = Cube()
@@ -144,6 +145,12 @@ Event helper
my_event.event('myevent(temp)')
+ temp = my_event.expression('temp').gt('temp', 15)
+ # => myevent(temp).gt(temp, 15)
+
+ my_event.metric(Sum(temp))
+ # => my_event.metric('sum(myevent(temp).gt(temp, 15))')
+
Changelog
=========
View
6 cube/event.py
@@ -1,4 +1,5 @@
# -*- encoding: utf-8 -*-
+from cube.expression import EventExpression
class Event(object):
@@ -15,4 +16,7 @@ def event(self, expression=None, **kwargs):
return self.cube.event(expression, **kwargs)
def metric(self, expression, **kwargs):
- return self.cube.metric(self, expression, **kwargs)
+ return self.cube.metric(expression, **kwargs)
+
+ def expression(self, event_properties):
+ return EventExpression(self.event_type, event_properties)

0 comments on commit 155a49c

Please sign in to comment.