Ejemplo n.º 1
0
    def reify_anomaly(self, resource_id):
        """Extracts the REST API arguments from the anomaly JSON structure

        """

        child = self.get_resource(resource_id)
        _, parent_id = u.get_origin_info(child)
        parent = self.get_resource(parent_id)

        opts = {"create": {}, "update": {}}

        # options common to all model types
        u.common_model_opts(child, parent, opts)

        # name, exclude automatic naming alternatives
        autonames = [u'']
        autonames.append(
            u'%s\'s anomaly detector' % parent.get('name', ''))
        autonames.append(
            u'%s\' anomaly detector' % parent.get('name', ''))
        autonames.append(
            u'%s\ anomaly detector' % parent.get('name', ''))
        u.non_automatic_name(
            child, opts,
            autonames=autonames)

        calls = u.build_calls(resource_id, [parent_id], opts)
        self.add(resource_id, calls)
Ejemplo n.º 2
0
    def reify_cluster(self, resource_id):
        """Extracts the REST API arguments from the cluster JSON structure

        """
        child = self.get_resource(resource_id)
        _, parent_id = u.get_origin_info(child)
        parent = self.get_resource(parent_id)

        opts = {"create": {}, "update": {}}

        # options common to all model types
        u.common_model_opts(child, parent, opts)

        if child.get('critical_value') is None and  'k' in child:
            opts['create'].update({"k": child['k']})

        # name, exclude automatic naming alternatives
        autonames = [u'']
        autonames.append(
            u'%s\'s cluster' % parent.get('name', ''))
        autonames.append(
            u'%s\' cluster' % parent.get('name', ''))
        autonames.append(
            u'%s\ cluster' % parent.get('name', ''))
        u.non_automatic_name( \
            child, opts, autonames=autonames)

        calls = u.build_calls(resource_id, [parent_id], opts)
        self.add(resource_id, calls)
Ejemplo n.º 3
0
    def _inspect_model(self, resource_id):
        """Auxliliary function to use model JSON structure to define ensembles
           and models

        """
        child = self.get_resource(resource_id)
        origin, parent_id = u.get_origin_info(child)
        parent = self.get_resource(parent_id)
        opts = {"create": {}, "update": {}}
        # as two-steps result from a cluster
        if origin == 'cluster':
            opts['create'].update({"centroid": child['centroid']})
            _, grandparent = u.get_origin_info(parent)
            grandparent = self.get_resource(grandparent)
        elif origin == 'datasets':
            grandparent = parent
            if child.get('objective_field') != \
                    grandparent.get('objective_field').get('id'):
                opts['create'].update(
                    {"objective_field": child.get('objective_field')})
        else:
            grandparent = parent
            if child.get('objective_field') != \
                    grandparent.get('objective_field').get('id'):
                opts['create'].update(
                    {"objective_field": child.get('objective_field')})

        # the objective field name is automatically added to tags
        objective_field_name = child.get('objective_field_name','')
        if objective_field_name in child.get('tags'):
            child['tags'].remove(objective_field_name)
        # options common to all model types
        u.common_model_opts(child, grandparent, opts)

        # name, exclude automatic naming alternatives
        autonames = [u'']
        autonames.append(
            u"%s\'s model" % grandparent.get('name', ''))
        autonames.append(
            u"%s\' model" % grandparent.get('name', ''))
        autonames.append(
            u"%s model" % grandparent.get('name', ''))
        autonames.append(
            u"Cluster %s - %s" % (int(child.get('centroid', "0"), base=16),
                                  parent['name']))

        u.non_automatic_name(child, opts, autonames=autonames)

        if child.get('randomize') == True:
            default_random_candidates = int(
                math.floor(math.sqrt(len(child['input_fields']))))
            opts['create'].update(
                u.default_setting( \
                    child, 'random_candidates', [default_random_candidates]))
        return parent_id, opts
Ejemplo n.º 4
0
    def _inspect_model(self, resource_id):
        """Auxliliary function to use model JSON structure to define ensembles
           and models

        """
        child = self.get_resource(resource_id)
        origin, parent_id = u.get_origin_info(child)
        parent = self.get_resource(parent_id)
        opts = {"create": {}, "update": {}}
        # as two-steps result from a cluster
        if origin == "cluster":
            opts["create"].update({"centroid": child["centroid"]})
            _, grandparent = u.get_origin_info(parent)
            grandparent = self.get_resource(grandparent)
        elif origin == "datasets":
            grandparent = parent
            if child.get("objective_field") != grandparent.get("objective_field").get("id"):
                opts["create"].update({"objective_field": child.get("objective_field")})
        else:
            grandparent = parent
            if child.get("objective_field") != grandparent.get("objective_field").get("id"):
                opts["create"].update({"objective_field": child.get("objective_field")})

        # the objective field name is automatically added to tags
        objective_field_name = child.get("objective_field_name", "")
        if objective_field_name in child.get("tags"):
            child["tags"].remove(objective_field_name)
        # options common to all model types
        u.common_model_opts(child, grandparent, opts)

        # name, exclude automatic naming alternatives
        autonames = [u""]
        autonames.append(u"%s model" % grandparent.get("name", ""))
        autonames.append(u"Cluster %s - %s" % (int(child.get("centroid", "0"), base=16), parent["name"]))

        u.non_automatic_name(child, opts, autonames=autonames)

        if child.get("randomize") == True:
            default_random_candidates = int(math.floor(math.sqrt(len(child["input_fields"]))))
            opts["create"].update(u.default_setting(child, "random_candidates", [default_random_candidates]))
        return parent_id, opts
Ejemplo n.º 5
0
    def reify_cluster(self, resource_id):
        """Extracts the REST API arguments from the cluster JSON structure

        """
        child = self.get_resource(resource_id)
        _, parent_id = u.get_origin_info(child)
        parent = self.get_resource(parent_id)

        opts = {"create": {}, "update": {}}

        # options common to all model types
        u.common_model_opts(child, parent, opts)

        if child.get("critical_value") is None and "k" in child:
            opts["create"].update({"k": child["k"]})

        # name, exclude automatic naming alternatives
        u.non_automatic_name(child, opts, autoname=u"%s cluster" % parent.get("name", ""))

        calls = u.build_calls(resource_id, [parent_id], opts)
        self.add(resource_id, calls)