示例#1
0
文件: endpoint.py 项目: l3p-cv/lost
 def post(self, visibility):
     args = create_label_parser.parse_args()
     dbm = access.DBMan(LOST_CONFIG)
     identity = get_jwt_identity()
     user = dbm.get_user_by_id(identity)
     default_group = dbm.get_group_by_name(user.user_name)
     if visibility == VisLevel().ALL:
         if not user.has_role(roles.DESIGNER):
             dbm.close_session()
             return "You are not authorized.", 401
         else:
             label = model.LabelLeaf(name=args.get('name'),abbreviation=args.get('abbreviation'), \
             description=args.get('description'),external_id=args.get('external_id'),
             is_root=args.get('is_root'),color=args.get('color'), group_id=default_group.idx)
             if args.get('parent_leaf_id'):
                 label.parent_leaf_id = args.get('parent_leaf_id'),
             dbm.save_obj(label)
             dbm.close_session()
             return "success"
     if visibility == VisLevel().GLOBAL:
         if not user.has_role(roles.ADMINISTRATOR):
             dbm.close_session()
             return "You are not authorized.", 401
         else:
             label = model.LabelLeaf(name=args.get('name'),abbreviation=args.get('abbreviation'), \
             description=args.get('description'),external_id=args.get('external_id'),
             is_root=args.get('is_root'),color=args.get('color'))
             if args.get('parent_leaf_id'):
                 label.parent_leaf_id = args.get('parent_leaf_id'),
             dbm.save_obj(label)
             dbm.close_session()
             return "success"
     dbm.close_session()
     return "You are not authorized.", 401
示例#2
0
 def post(self):
     args = create_label_parser.parse_args()
     dbm = access.DBMan(LOST_CONFIG)
     identity = get_jwt_identity()
     user = dbm.get_user_by_id(identity)
     if not user.has_role(roles.DESIGNER):
         dbm.close_session()
         return "You are not authorized.", 401
     else:
         label = model.LabelLeaf(name=args.get('name'),abbreviation=args.get('abbreviation'), \
         description=args.get('description'),external_id=args.get('external_id'),
         is_root=args.get('is_root'))
         if args.get('parent_leaf_id'):
             label.parent_leaf_id = args.get('parent_leaf_id'),
         dbm.save_obj(label)
         dbm.close_session()
         return "success"
示例#3
0
文件: label.py 项目: kengggg/lost
    def create_child(self, parent_id, name, external_id=None):
        '''Create a new leaf in label tree.

        Args:
            parent_id (int): Id of the parend leaf.
            name (str): Name of the leaf e.g the class name.
            external_id (str): Some id of an external label system.
        
        Retruns:
            :class:`lost.db.model.LabelLeaf`: The the created child leaf.
        '''
        leaf = model.LabelLeaf(name=name, 
            external_id=external_id, parent_leaf_id=parent_id)
        self.dbm.add(leaf)
        self.dbm.commit()
        self.tree[leaf.idx] = leaf
        self.logger.info('Created child leaf: {}'.format(name))
        return leaf
示例#4
0
文件: label.py 项目: kengggg/lost
    def create_root(self, name, external_id=None):
        '''Create the root of a label tree.

        Args:
            name (str): Name of the root leaf.
            external_id (str): Some id of an external label system.
        
        Retruns:
            :class:`lost.db.model.LabelLeaf` or None: 
                The created root leaf or None if a root leaf with same
                name is already present in database.
        '''
        root_leafs = self.dbm.get_all_label_trees(global_only=True)
        if root_leafs is not None:
            for leaf in root_leafs:
                if name == leaf.name:
                    return None
        self.root = model.LabelLeaf(name=name, 
            external_id=external_id, is_root=True)
        self.dbm.add(self.root)
        self.dbm.commit()
        self.tree[self.root.idx] = self.root
        self.logger.info('Created root leaf: {}'.format(name))
        return self.root
示例#5
0
from lost.logic.label import LabelTree
import logging
logger = logging.getLogger(__name__)


# Adding initial label tree if it doesn't exist
dbm = access.DBMan(LOST_CONFIG)
root_leaves = dbm.get_all_label_trees()
foundcovid = False
for root_leaf in root_leaves:
    if LabelTree(dbm, root_leaf.idx).to_hierarchical_dict().get('name') == 'Covid19':
        foundcovid = True
if not foundcovid:
    rootlabel = model.LabelLeaf(name='Covid19',
                                abbreviation=None,
                                description='Covid19 dataset labels contains 5 labels',
                                external_id=None,
                                is_root=True)
    rootlabel.parent_leaf_id = None
    dbm.save_obj(rootlabel)
    for l in ['Parenchyma', 'Emphysema', 'Ground glass', 'Crazy Paving', 'Consolidation']:
        label = model.LabelLeaf(name=l,
                                abbreviation=None,
                                description=None,
                                external_id=None,
                                parent_leaf_id=rootlabel.idx,
                                is_root=False)
        dbm.save_obj(label)

dbm.close_session()