Rfaulk has submitted this change and it was merged.

Change subject: add - Aggregator class.
......................................................................


add - Aggregator class.

Change-Id: Id050b7ccf6ac19449f3dff8e0cb7f4398547ba17
---
M user_metrics/etl/aggregator.py
1 file changed, 42 insertions(+), 1 deletion(-)

Approvals:
  Rfaulk: Verified; Looks good to me, approved



diff --git a/user_metrics/etl/aggregator.py b/user_metrics/etl/aggregator.py
index 6d165b7..9a8c175 100644
--- a/user_metrics/etl/aggregator.py
+++ b/user_metrics/etl/aggregator.py
@@ -69,7 +69,6 @@
 # 2. header attribute for a type of metric aggregation methods
 # 3. name attribute for a type of metric aggregation methods
 # 4. keyword arg attribute for a type of metric aggregation methods
-# TODO - move these to the module dedicated for aggregation processing
 METRIC_AGG_METHOD_FLAG = 'metric_agg_flag'
 METRIC_AGG_METHOD_HEAD = 'metric_agg_head'
 METRIC_AGG_METHOD_NAME = 'metric_agg_name'
@@ -330,3 +329,45 @@
     """ Basic exception class for aggregators """
     def __init__(self, message="Aggregation error."):
         Exception.__init__(self, message)
+
+
+class Aggregator(object):
+    """
+    Base class for aggregators.  Standard method for applying aggregators.
+    This class family maintains internal state of the result.
+
+    Each subclass will implement the data_etl & post_process methods.
+
+    The method header returns the object properties that store the aggregated
+    results.
+    """
+
+    def __init__(self, method=None):
+        """
+        Initialize the aggregator method
+        """
+        self._method = method
+
+    def data_etl(self, data):
+        """
+        Handle
+        """
+        return data
+
+    def post_process(self, data):
+        """
+        Define
+        """
+        self._result =  data
+
+    def run(self, data):
+        """
+        Pass data through aggregate method
+        """
+        self.post_process(
+            self._method(
+            self.data_etl(data)))
+        return self
+
+    def header(self):
+        return ['result']

-- 
To view, visit https://gerrit.wikimedia.org/r/80955
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: Id050b7ccf6ac19449f3dff8e0cb7f4398547ba17
Gerrit-PatchSet: 1
Gerrit-Project: analytics/user-metrics
Gerrit-Branch: master
Gerrit-Owner: Rfaulk <rfaulk...@wikimedia.org>
Gerrit-Reviewer: Rfaulk <rfaulk...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to