示例#1
0
def single_doc_check_convert(doc):
    item = doc.__dict__
    item_conv = ADict(**item)
    item_conv_id = item_conv.pop("id", None)
    item_conv.pop("payload", None)

    return item_conv, bool(item_conv)
示例#2
0
 def compute_stats_by_dataset(self, name: str) -> StatType:
     """Compute stats for the given world
     Arguments:
         name {str} -- [description]
     Returns:
         Dict[str, Any] -- [description]
     """
     dataset = self.get_dataset_by_name(name)
     stat = ADict()
     stat.num_class = len(get_class(dataset.json_graphs))
     stat.num_des = len(get_descriptors(dataset.json_graphs))
     stat.avg_resolution_length = get_avg_resolution_length(
         dataset.json_graphs)
     stat.num_nodes, stat.num_edges = get_num_nodes_edges(
         dataset.json_graphs)
     stat.split = self.get_dataset_split(name)
     print(f"Data Split : {stat.split},"
           f"Number of Classes : {stat.num_class},"
           f"Number of Descriptors : {stat.num_des},"
           f"Average Resolution Length : {stat.avg_resolution_length},"
           f"Average number of nodes : {stat.num_nodes} and"
           f"edges : {stat.num_edges}"  # noqa: E501
           )
     assert isinstance(stat, dict)
     return stat
示例#3
0
    def delete(self, query: dict, alt={}):
        self.check()
        query = self.setup_query(alt)
        current_settings = ADict()

        self.processor.storage.delete(query, **current_settings)
        self.changed_since_command = False
示例#4
0
 def last(self, alt={}):
     self.check()
     query = self.setup_query(alt)
     current_settings = ADict()
     self.changed_since_command = False
     obj = self.processor.storage.query(query, **current_settings.to_dict())
     return obj
示例#5
0
 def by_version(self, version: str, alt={}):
     """ Get the data by version. """
     self.check()
     query = self.setup_query(alt)
     current_settings = ADict()
     self.processor.storage.query(query, **current_settings.to_dict())
     self.changed_since_command = False
示例#6
0
 def find_sub_dictionaries(self, super_id):
     """ Finds a subdictionary by superid inside of the database. """
     # Should use the find within function for every subkey
     mega_dict = ADict()
     for key, sub in self.subs.items():
         key_dict = ADict()
         try:
             res = sub.client.search(f'"{super_id}"')
             if res.total == 0:
                 continue
             dd = [dictify(doc, False) for doc in res.docs]
             key_dict[key] = dd[0]
         except ResponseError:
             pass
         mega_dict.update(key_dict)
     return mega_dict
示例#7
0
    def pick(self, _id: str):
        """ 
            Given an id find the element with the top level id. We aren't searching lower level_ids. 
            
            After we pull all of the 
        """
        self.set_entity()
        self.keystore.reset()
        doc = self.client.load_document(_id)
        dd = doc.__dict__
        doc = ADict(**dd)
        _id = doc.pop("id", None)
        doc.pop("payload", None)
        doc_z = len(doc) > 0
        if len(self.subs) == 0:
            if not doc_z:
                return None
            doc.update({"id": _id})
            return doc

        if doc_z:
            sub_dicts = self.find_sub_dictionaries(_id)
            # if len(sub_dicts) > 0:
            doc.update(sub_dicts)
            doc.update({"id": _id})
            return doc

        return None
示例#8
0
    def _construct_sfc_conf(self):
        """Construct a addict formatted SFC conf from nested dict"""
        for sec in ('log', 'cloud', 'SFC_manager', 'SFC'):
            if sec not in self._conf_dict:
                raise ConfigError('Missing %s base section!' % sec)
        self._log_conf = ADict(self._conf_dict['log'])
        self._cloud_conf = ADict(self._conf_dict['cloud'])
        self._sfc_conf = ADict(self._conf_dict['SFC'])

        self.sfc_mgr_conf = ADict(self._conf_dict['SFC_manager'])

        self._set_cloud_auth(self._cloud_conf.auth)
        self._set_sfc_function_chain(self._sfc_conf.function_chain)
        self._set_sfc_flow_classifier(self._sfc_conf.flow_classifier)
        self._set_sfc_network(self._sfc_conf.network)
        self._set_sfc_server_chain(self._sfc_conf.server_chain)
        self._set_sample_server(self._sfc_conf.sample_server)
示例#9
0
 def save(self, data: dict, alt={}, is_overwrite=False):
     self.check()
     query = self.setup_query(alt)
     # Put settings here
     current_settings = ADict()
     current_settings.overwrite = is_overwrite
     self.processor.storage.save(query, data, **current_settings.to_dict())
     self.changed_since_command = False
    def set_saved_fields(self, fields: Optional[Iterable[str]] = None) -> None:
        self.saved_data = self.current(fields)

        # preventing mutable fields side effects
        for field, field_value in self.saved_data.items():
            self.saved_data[field] = deepcopy(field_value)

        self.saved_data = ADict(self.saved_data)
示例#11
0
def dictify(doc, is_id=True):
    item = ADict(**doc.__dict__)
    item.pop("super_id", None)
    item.pop("payload", None)
    if is_id == False:
        item.pop("id", None)

    return item
示例#12
0
 def absolute_exists(self, alt={}):
     self.check()
     query = self.setup_query(alt)
     # Put settings here
     current_settings = ADict()
     current_settings.is_force = self.changed_since_command
     avs = self.processor.storage.absolute_exists(
         query, **current_settings.to_dict())
     self.changed_since_command = False
     return avs
示例#13
0
 def _set_sfc_flow_classifier(self, flow_conf):
     self._check_sec_arg('SFC, flow_classifier', flow_conf,
                         ('name', 'description', 'ethertype', 'protocol',
                          'source_port_range_min', 'source_port_range_max',
                          'destination_port_range_min',
                          'destination_port_range_max',
                          'source_ip_prefix',
                          'destination_ip_prefix',
                          'logical_source_port',
                          'logical_destination_port')
                         )
     self._flow_classifier = ADict(flow_conf)
示例#14
0
    def __init__(self):
        self._mod = None
        self._opt = None
        self._crit = None

        self._model_dict = ADict()
        self._model_dict.model = None
        self._model_dict.optimizer = None
        self._model_dict.criteria = None

        self._model_typing = ADict()
        self._model_typing.model = None
        self._model_typing.optimizer = None
        self._model_typing.criteria = None

        self._model_requirements = ADict()
        self._model_requirements.model = True
        self._model_requirements.optimizer = False
        self._model_requirements.criteria = False

        self.changed = False
        self.named_metric_set = NamedModelMetricSet()
示例#15
0
def test_addict():
    game = ADict(MODEL_INSTANCE)
    assert isinstance(game.name, str)
    assert isinstance(game.platform, str)
    assert isinstance(game.score, float)
    assert isinstance(game.resolution_tested, str)
    assert isinstance(game.genre, list)
    assert isinstance(game.rating, dict)
    assert isinstance(game.players, list)
    assert isinstance(game.language, int)
    assert isinstance(game.awesome_city, dict)
    assert isinstance(game.awesome_city.name, str)
    assert isinstance(game.awesome_city.region, str)
示例#16
0
def get_paths(mode: str, rule_folder: str, loc: str) -> ADict:
    paths = ADict()
    paths.mode = mode
    paths.rule_folder = rule_folder
    paths.config_path = path.join(loc, mode, rule_folder, "config.json")
    paths.train_path = path.join(loc, mode, rule_folder, "train.jsonl")
    paths.test_path = path.join(loc, mode, rule_folder, "test.jsonl")
    paths.valid_path = path.join(loc, mode, rule_folder, "valid.jsonl")
    paths.meta_graph_path = path.join(loc, mode, rule_folder,
                                      "meta_graph.jsonl")
    paths.graph_prop_path = path.join(loc, mode, rule_folder,
                                      "graph_prop.json")
    return paths
示例#17
0
def dictify(doc):
    item = ADict(**doc.__dict__)
    item.pop("super_id", None)
    item.pop("payload", None)
    return item
示例#18
0
 def _set_log(self, log_conf):
     self._check_sec_arg('log', log_conf,
                         ('level', ))
     self._log_conf = ADict(log_conf)
示例#19
0
def doc_convert(doc):
    item = doc.__dict__
    item_conv = ADict(**item)
    # item_conv_id = item_conv.pop("id", None)
    item_conv.pop("payload", None)
    return item_conv
示例#20
0
 def _set_sfc_function_chain(self, chn_conf):
     self._check_sec_arg('SFC, function_chain', chn_conf,
                         ('name', 'description', 'placement_algo', 'destination_hypervisor',
                          'availability_zone', 'available_hypervisors')
                         )
     self._function_chain = ADict(chn_conf)
示例#21
0
 def _set_sfc_network(self, net_conf):
     self._check_sec_arg('SFC, network', net_conf,
                         ('pubnet_name', 'net_name', 'subnet_name')
                         )
     self._network = ADict(net_conf)
示例#22
0
def split_doc(doc):
    return doc.id, ADict(**doc.__dict__)
示例#23
0
 def _set_sample_server(self, sample_server):
     self._check_sec_arg('sample server', sample_server,
                         ('image', 'flavor', 'init_script')
                         )
     self._sample_server = ADict(sample_server)
示例#24
0
 def _set_cloud_auth(self, auth_conf):
     self._check_sec_arg('cloud, auth', auth_conf,
                         ('auth_url', 'project_name', 'project_domain_name',
                          'username', 'user_domain_name', 'password')
                         )
     self._auth = ADict(auth_conf)
示例#25
0
    def set_params(self, **params):
        raise NotImplementedError

    def extract(self):
        """ Get a dictionary to save the model. Should be called in close """
        return self.dictionary

    @property
    def metrics(self):
        """ Given the information we have, return a set of metrics"""
        metric_set = self.named_metric_set.metrics(0, 0)
        return metric_set


if __name__ == "__main__":
    model_types = ADict()
    model_vals = ADict()
    model_types.model = bool
    model_types.optimizer = str
    model_types.criteria = str

    model_vals.model = False
    model_vals.optimizer = "str"
    model_vals.criteria = "str"

    base_model_procedure = ModelProcedureAbstract()
    base_model_procedure.mtypes = model_types
    base_model_procedure.mdict = model_vals
    base_model_procedure.verify()

    print(base_model_procedure)