HCE Project Python language Distributed Tasks Manager Application, Distributed Crawler Application and client API bindings.  2.0.0-chaika
Hierarchical Cluster Engine Python language binding
Metrics.py
Go to the documentation of this file.
1 """@package app
2  @file Metrics.py
3  @author scorp <developers.hce@gmail.com>
4  @link http://hierarchical-cluster-engine.com/
5  @copyright Copyright &copy; 2013 IOIX Ukraine
6  @license http://hierarchical-cluster-engine.com/license/
7  @package HCE project node API
8  @since 0.1
9  """
10 
11 import app.Utils as Utils # pylint: disable=F0401
12 from algorithms.MetricTagsCount import MetricTagsCount
13 from algorithms.MetricWCount import MetricWCount
14 from algorithms.MetricContentSize import MetricContentSize
15 
16 # Logger initialization
18 
19 
20 # #The Metrics static class, is a interface for Metrics precalculating and estimation
21 #
22 class Metrics(object):
23 
24  AVAILABLE_METRICS = {}
25 
26 
27  # # fillMetricModulesList internam method, that fills Metrics dict of one Metric class instance
28  #
29  # @param metricClass - type of metrics class
30  # @param names - metric names, asssotiated with class
31  @staticmethod
32  def addMetricClassMetrics(metricClass, names):
33  metricInstance = metricClass(names)
34  for name in metricInstance.names:
35  Metrics.AVAILABLE_METRICS[name] = metricInstance
36 
37 
38  # # fillMetricModulesList fills dict of available Metrics objects
39  #
40  # @param additionFiller - incoming callback function, which extends of AVAILABLE_METRICS field with user metrics
41  @staticmethod
42  def fillMetricModulesList(additionFiller=None):
43  Metrics.addMetricClassMetrics(MetricTagsCount, ["TAGS_NUMBER", "TAGS_NUMBER_PERCENT"])
44  Metrics.addMetricClassMetrics(MetricWCount, ["WORDS_NUMBER", "WORDS_NUMBER_PERCENT"])
45  Metrics.addMetricClassMetrics(MetricContentSize, ["CONTENT_SIZE", "CONTENT_SIZE_PERCENT"])
46  if additionFiller is not None:
47  additionFiller(Metrics.AVAILABLE_METRICS)
48 
49 
50  # # metricsPrecalculate makes metrics precalculate and fills incoming requestMetrics dics
51  #
52  # @param requestMetrics - incoming dcis with needed metric names
53  # @param result - param, that content calculating data in common format
54  @staticmethod
55  def metricsPrecalculate(requestMetrics, result):
56  for key in requestMetrics:
57  if key in Metrics.AVAILABLE_METRICS:
58  try:
59  requestMetrics[key] = Metrics.AVAILABLE_METRICS[key].precalculate(result, key)
60  except Exception as excp:
61  logger.debug(">>> Somthing wrong in metric precalculating, err = " + str(excp) + " key = " + str(key))
62  else:
63  logger.debug(">>> metricsPrecalculate. No request metric in available metrics dict, metric is = " + str(key))
64 
65 
66  # # sortElementsByMetric resort incoming elements list, by precalculated metric data
67  #
68  # @param elements - incoming elements
69  # @param metricName - name of using metric
70  # @param metricParam - name of using metric param
71  # @return - return resorted elements
72  @staticmethod
73  def sortElementsByMetric(elements, metricName):
74  ret = elements
75  if metricName in Metrics.AVAILABLE_METRICS:
76  ret = Metrics.AVAILABLE_METRICS[metricName].sortElementsByMetric(elements, metricName)
77  else:
78  logger.debug(">>> sortElementsByMetric. No request metric in available metrics dict, metric is = " + metricName)
79  return ret
80 
81 
82  # # selectElementsByMetric selects elements that fit for metric limit value
83  #
84  # @param elements - incoming elements
85  # @param metricName - name of using metric
86  # @param metricParam - name of using metric param
87  # @param metricParamLimit - limit value of using metric param
88  # @return - return reselected elements
89  @staticmethod
90  def selectElementsByMetric(elements, metricName, metricLimitMax, metricLimitMin):
91  ret = elements
92  if metricName in Metrics.AVAILABLE_METRICS:
93  ret = Metrics.AVAILABLE_METRICS[metricName].selectElementsByMetric(elements, metricName, metricLimitMax,
94  metricLimitMin)
95  else:
96  logger.debug(">>> selectElementsByMetric. No request metric in available metrics dict, metric is = " + metricName)
97  return ret
def selectElementsByMetric(elements, metricName, metricLimitMax, metricLimitMin)
Definition: Metrics.py:90
def metricsPrecalculate(requestMetrics, result)
Definition: Metrics.py:55
def addMetricClassMetrics(metricClass, names)
Definition: Metrics.py:32
def fillMetricModulesList(additionFiller=None)
Definition: Metrics.py:42
def sortElementsByMetric(elements, metricName)
Definition: Metrics.py:73