def remove_block(self, block): r = get_redis_instance() block_key = ExpKeys.get_block_key(block.uuid) pipe = r.pipeline(transaction=True) if block.create_new_scope: for sub_block_uuid in block.children_blocks: sub_block = self.get_block(sub_block_uuid) self.remove_block(sub_block) pipe.hdel(ExpKeys.get_scope_creating_block_uuid_keys(self.pk), block.sub_scope_name) block.on_remove(exp=self) # find all bound variables, that provided by this block for other_uuid, other_block in self.get_blocks(self.get_all_block_uuids()): if other_uuid == block.uuid: continue for f_name, bound_var in other_block.bound_inputs.items(): if bound_var.block_uuid == block.uuid: other_block.bound_inputs.pop(f_name) self.store_block(other_block) # Remove information related to block from redis pipe.lrem(ExpKeys.get_exp_blocks_list_key(self.pk), 0, block.uuid) pipe.srem(ExpKeys.get_all_exp_keys_key(self.pk), block_key) pipe.hdel(ExpKeys.get_blocks_uuid_by_alias(self.pk), block.base_name) scope = Scope(self, block.scope_name) scope.remove_vars_from_block(block) pipe.execute()
def remove_block(self, block): r = get_redis_instance() block_key = ExpKeys.get_block_key(block.uuid) pipe = r.pipeline(transaction=True) if block.create_new_scope: for sub_block_uuid in block.children_blocks: sub_block = self.get_block(sub_block_uuid) self.remove_block(sub_block) pipe.hdel(ExpKeys.get_scope_creating_block_uuid_keys(self.pk), block.sub_scope_name) block.on_remove(exp=self) # find all bound variables, that provided by this block for other_uuid, other_block in self.get_blocks( self.get_all_block_uuids()): if other_uuid == block.uuid: continue for f_name, bound_var in other_block.bound_inputs.items(): if bound_var.block_uuid == block.uuid: other_block.bound_inputs.pop(f_name) self.store_block(other_block) # Remove information related to block from redis pipe.lrem(ExpKeys.get_exp_blocks_list_key(self.pk), 0, block.uuid) pipe.srem(ExpKeys.get_all_exp_keys_key(self.pk), block_key) pipe.hdel(ExpKeys.get_blocks_uuid_by_alias(self.pk), block.base_name) scope = Scope(self, block.scope_name) scope.remove_vars_from_block(block) pipe.execute()
return HttpResponseBadRequest() new_block = add_block_to_exp_from_dict(exp, received_block) # TODO: Move to model logic blocks_uuids = exp.get_all_block_uuids(redis_instance=r) blocks = exp.get_blocks(blocks_uuids, redis_instance=r) blocks_by_bscope = defaultdict(list) for uuid, block in blocks: blocks_by_bscope[block.scope_name].append(uuid) aliases_map = exp.get_block_aliases_map(redis_instance=r) variables = [] for scope_name, _ in exp.get_all_scopes_with_block_uuids(redis_instance=r).iteritems(): scope = Scope(exp, scope_name) scope.load(redis_instance=r) scope.update_scope_vars_by_block_aliases(aliases_map) variables.extend(scope.scope_vars) result = { "blocks_uuids": blocks_uuids, "blocks_by_bscope": blocks_by_bscope, "blocks_by_group": blocks_by_group, "vars": [var.to_dict() for var in variables], "vars_by_key": {var.pk: var.to_dict() for var in variables}, "new_block_uuid": new_block.uuid if new_block else "",
def get_sub_scope(self): exp = Experiment.get_exp_by_id(self.exp_id) return Scope(exp, self.sub_scope_name)
new_block = add_block_to_exp_from_dict(exp, received_block) # TODO: Move to model logic blocks_uuids = exp.get_all_block_uuids(redis_instance=r) blocks = exp.get_blocks(blocks_uuids, redis_instance=r) blocks_by_bscope = defaultdict(list) for uuid, block in blocks: blocks_by_bscope[block.scope_name].append(uuid) aliases_map = exp.get_block_aliases_map(redis_instance=r) variables = [] for scope_name, _ in exp.get_all_scopes_with_block_uuids( redis_instance=r).iteritems(): scope = Scope(exp, scope_name) scope.load(redis_instance=r) scope.update_scope_vars_by_block_aliases(aliases_map) variables.extend(scope.scope_vars) result = { "blocks_uuids": blocks_uuids, "blocks_by_bscope": blocks_by_bscope, "blocks_by_group": blocks_by_group, "vars": [var.to_dict() for var in variables], "vars_by_key": {var.pk: var.to_dict() for var in variables}, "new_block_uuid": new_block.uuid if new_block else "", }