def identifier_names(self, min_name_size=0):
     node_id = "Identifier"
     names = []
     nodes = self.all_nodes.get(node_id)
     for node in nodes:
         name = node.name
         if min_name_size < len(name):
             names.append(name)
     return unique(names)
 def var_names(self, min_name_size=0):
     node_id = "VariableDeclarator"
     names = []
     nodes = self.all_nodes.get(node_id)
     for node in nodes:
         name = node.id.get('name')
         if min_name_size < len(name):
             names.append(name)
     return unique(names)
 def literal_names(self, min_name_size=0, starts_with=None):
     node_id = "Literal"
     names = []
     nodes = self.all_nodes.get(node_id)
     for node in nodes:
         name = node.raw
         if min_name_size < len(name):
             if starts_with is None or name.startswith(starts_with):
                 names.append(name)
     return unique(names)
 def function_names(self, min_name_size=0):
     node_id = "FunctionDeclaration"
     names = []
     nodes = self.all_nodes.get(node_id)
     if nodes:
         for node in nodes:
             if node.id:
                 name = node.id.get('name')
                 if min_name_size < len(name):
                     names.append(name)
     return unique(names)
Esempio n. 5
0
    def metric_list(self,
                    namespace,
                    metric_name=None,
                    dimensions=None,
                    recently_active='PT3H',
                    max_results=-1):
        results_paginated = self.metric_list_raw(
            namespace=namespace,
            metric_name=metric_name,
            dimensions=dimensions,
            recently_active=recently_active)
        results = {}
        items_added = 0
        for result in results_paginated:
            #pprint(result)
            _dimensions = result.get('Dimensions')
            _metric_name = result.get('MetricName')
            _namespace = result.get('Namespace')

            if results.get(_namespace) is None:
                results[_namespace] = {}
            result_namespace = results[_namespace]

            if result_namespace.get(_metric_name) is None:
                result_namespace[_metric_name] = {}
            result_metric_name = result_namespace[_metric_name]

            for result_dimension in _dimensions:
                dimension_name = result_dimension.get('Name')
                dimension_value = result_dimension.get('Value')

                if result_metric_name.get(dimension_name) is None:
                    result_metric_name[dimension_name] = []
                result_dimension_name = result_metric_name[dimension_name]

                result_dimension_name.append(dimension_value)
                items_added += 1
            if max_results != -1 and items_added > max_results:
                break

        # sort and unique dimensions data
        for namespace in results.values():
            for metric_name, metric_values in namespace.items():
                for dimension_name, dimension_values in metric_values.items():
                    metric_values[dimension_name] = unique(
                        metric_values[dimension_name])

        return results