Esempio n. 1
0
def getContainerNameByID(container_id):
    """
    container_id:  required, integer
    """
    c = Container.objects(__raw__={'container_id': container_id})
    return _try0_dict_key(c, 'container', 'container_id', container_id, '',
                           dict_key='containerName')
Esempio n. 2
0
def getCoordsfromSampleID(sample_id):
    """
    returns the container position within the dewar and position in
    that container for a sample with the given id in one of the
    containers in the container named by the global variable
    'primaryDewarName'
    """
    try:
        primary_dewar_item_list = Container.objects(__raw__={'containerName': primaryDewarName}).only('item_list')[0].item_list
    except IndexError, AttributeError:
        return None
Esempio n. 3
0
def getDewarPosfromSampleID(sample_id):

    """
    returns the container_id and position in that container for a sample with the given id
    in one of the containers in the container named by the global variable 'primaryDewarName'
    """
    try:
        cont = Container.objects(__raw__={'containerName': primaryDewarName}).only('item_list')[0]
    except IndexError:
        return None

    for puck_id in cont.item_list:
        if puck_id is not None:
            try:
                puck = Container.objects(__raw__={'container_id': puck_id}).only('item_list')[0]
            except IndexError:
                continue

            for j,samp_id in enumerate(puck.item_list):
                if samp_id == sample_id and samp_id is not None:
                    containerID = puck_id
                    position = j + 1  # most people don't zero index things
                    return (containerID, position)    
Esempio n. 4
0
def getContainersByType(type_name, group_name, as_mongo_obj=False): 

    if isinstance(type_name, unicode) or isinstance(type_name, str):
        type_obj = type_from_name(type_name, as_mongo_obj=True)
    else:
        type_obj = type_name

    # go one level deaper for now?  maybe we should have another field to search on
    # "class" or something?  :(
    container_types = Types.objects(__raw__={'$or': [{'name': type_name},
                                                     {'parent_type': type_name}]})

    #c = Container.objects(container_type=type_obj)
    #c = Container.objects(__raw__={'container_type': {'$in': container_types}})
    c = Container.objects(container_type__in=container_types)
    return _ret_list(c, as_mongo_obj=as_mongo_obj)
Esempio n. 5
0
def getSampleIDfromCoords(puck_num, position):
    """
    given a container position within the dewar and position in
    that container, returns the id for a sample in one of the
    containers in the container named by the global variable
    'primaryDewarName'
    """
    try:
        cont = Container.objects(__raw__={'containerName': primaryDewarName}).only('item_list')[0]
    except IndexError:
        return None

    puck_id = cont.item_list[puck_num]
    puck = getContainerByID(puck_id)
            
    sample_id = puck["item_list"][position - 1]  # most people don't zero index things
    return sample_id
Esempio n. 6
0
def getQueue():
    """
    returns a list of request dicts for all the samples in the container
    named by the global variable 'primaryDewarName'
    """
    
    # seems like this would be alot simpler if it weren't for the Nones?

    ret_list = []

    # try to only retrieve what we need...
    # Use .first() instead of [0] here because when the query returns nothing,
    # .first() returns None while [0] generates an IndexError
    # Nah... [0] is faster and catch Exception...
    try:
        items = Container.objects(__raw__={'containerName': primaryDewarName}).only('item_list')[0].item_list
    except IndexError, AttributeError:
        raise ValueError('could not find container: "{0}"!'.format(primaryDewarName))
Esempio n. 7
0
def find_container():
    ret_list = []

    headers = ['container_name', 'container_type', 'capacity', 'contents']

    #return [c.to_mongo() for c in Container.objects()]
    for cont in Container.objects():
        c = cont.to_mongo()
    #    cont.pop('_id')
    #    cont.pop(

        c['container_type'] = cont.container_type.name
        try:
            c['capacity'] = cont.item_list.__len__()
        except AttributeError:
            c['capacity'] = 'variable'  # indeterminate or variable capacity

        ret_list.append(c)

    return (headers, ret_list)
Esempio n. 8
0
def getContainerByID(container_id, as_mongo_obj=False): 
    c = Container.objects(__raw__={'container_id': container_id})
    return _try0_maybe_mongo(c, 'container', 'container_id', container_id,
                           None, as_mongo_obj=as_mongo_obj)
Esempio n. 9
0
def getContainerByName(container_name, as_mongo_obj=False): 
    c = Container.objects(__raw__={'containerName': container_name})
    return _try0_maybe_mongo(c, 'container', 'containerName', container_name,
                           None, as_mongo_obj=as_mongo_obj)
Esempio n. 10
0
def getContainers(as_mongo_obj=False): 
    """get *all* containers""" 

    c = Container.objects()
    return _ret_list(c, as_mongo_obj=as_mongo_obj)
Esempio n. 11
0
def getContainerIDbyName(container_name):
    c = Container.objects(__raw__={'containerName': container_name})
    return _try0_dict_key(c, 'container', 'containerName', container_name,
                           -99, dict_key='container_id')
Esempio n. 12
0
    ret_list = []

    # try to only retrieve what we need...
    # Use .first() instead of [0] here because when the query returns nothing,
    # .first() returns None while [0] generates an IndexError
    # Nah... [0] is faster and catch Exception...
    try:
        items = Container.objects(__raw__={'containerName': primaryDewarName}).only('item_list')[0].item_list
    except IndexError, AttributeError:
        raise ValueError('could not find container: "{0}"!'.format(primaryDewarName))
    
    items = set(items)
    items.discard(None)  # skip empty positions

    sample_list = []
    for samp in Container.objects(container_id__in=items).only('item_list'):
        sil = set(samp.item_list)
        sil.discard(None)
        sample_list += sil

    for request in Request.objects(sample_id__in=sample_list):
        yield request.to_mongo()

#    
##    for item_id in items.item_list:
##        if item_id is not None:
#    for item_id in items:
#            try:
#                puck_items = Container.objects(__raw__={'container_id': item_id}).only('item_list')[0].item_list
#            except IndexError, AttributeError:
#                raise ValueError('could not find container id: "{0}"!'.format(item_id))