climate-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jo...@apache.org
Subject svn commit: r1566128 - /incubator/climate/trunk/ocw-ui/backend/processing.py
Date Sat, 08 Feb 2014 21:00:23 GMT
Author: joyce
Date: Sat Feb  8 21:00:23 2014
New Revision: 1566128

URL: http://svn.apache.org/r1566128
Log:
CLIMATE-332 - Remove unneeded metric helper

Modified:
    incubator/climate/trunk/ocw-ui/backend/processing.py

Modified: incubator/climate/trunk/ocw-ui/backend/processing.py
URL: http://svn.apache.org/viewvc/incubator/climate/trunk/ocw-ui/backend/processing.py?rev=1566128&r1=1566127&r2=1566128&view=diff
==============================================================================
--- incubator/climate/trunk/ocw-ui/backend/processing.py (original)
+++ incubator/climate/trunk/ocw-ui/backend/processing.py Sat Feb  8 21:00:23 2014
@@ -318,7 +318,9 @@ def _load_metrics(metric_names):
     :raises ValueError: If a metric name cannot be matched.
     '''
     instantiated_metrics = []
-    possible_metrics = _get_valid_metric_options()
+    metrics_map = _get_valid_metric_options()
+    possible_metrics = metrics_map.keys()
+
     for metric in metric_names:
         if metric not in possible_metrics:
             cur_frame = sys._getframe().f_code
@@ -329,28 +331,16 @@ def _load_metrics(metric_names):
             )
             raise ValueError(err)
 
-        metric_class = _load_metric_class_from_name(metric)
-        instantiated_metrics.append(metric_class())
+        instantiated_metrics.append(metrics_map[metric]())
 
     return instantiated_metrics
 
 def _get_valid_metric_options():
-    ''' Get valid metric names from the ocw.metrics module.
+    ''' Get valid metric options from the ocw.metrics module.
 
-    :returns: A dictionary of metric name, object pairs
+    :returns: A dictionary of metric (name, object) pairs
     '''
     invalid_metrics = ['Metric', 'UnaryMetric', 'BinaryMetric']
     return {name:obj
             for name, obj in inspect.getmembers(metrics)
             if inspect.isclass(obj) and name not in invalid_metrics}
-
-def _load_metric_class_from_name(metric_name):
-    ''' Load a metric class by name from ocw.metrics.
-
-    :param metric_name: The name of the metric class to load from ocw.metrics.
-    :type metric_name: String
-
-    :returns: The loaded metric Class
-    '''
-    module = __import__('ocw.metrics', fromlist=[metric_name])
-    return getattr(module, metric_name)



Mime
View raw message