Exemple #1
0
def loaded_sample_changed(sample):
    if not isinstance(sample, Pin):
        return
    
    if sample is not None:
        address = sample.getAddress()
        barcode = sample.getID()
    else:
        address = ''
        barcode = ''

    logging.getLogger("HWR").info('loaded sample changed now is: ' + address)
 
    try:
        # recreate the dict with the sample info
        q = queue_to_dict()
        sampleID = sample.getAddress()
        sample_data = q.get(sampleID, {})
    
        scutils.set_current_sample(sample_data)
        msg = {'signal': 'loadReady', 'location': address}
        socketio.emit('sc', msg, namespace='/hwr')
        socketio.emit("loaded_sample_changed", {'address': address, 'barcode': barcode}, namespace="/hwr")
    except Exception, msg:
        logging.getLogger("HWR").error('error setting loaded sample: %s' + str(msg))
Exemple #2
0
def get_method(sample_id, method_id):
    """
    Get the information of the given task, beloging to the given sample
        :parameter sampleid: sample identifier, integer
        :parameter methodid: task identifier, integer
        :response Content-Type: application/json, object containing the
            parameter(s) of the task. Example without parameters
            {"QueueId": 52,  "Type": 'Centring'...}
        :statuscode: 200: no error
        :statuscode: 409: task could not be added to the sample
    """
    sample = qutils.queue_to_dict().get(int(id), None)

    if not sample:
        msg = "[QUEUE] sample info could not be retrieved"
        logging.getLogger('HWR').error(msg)
        return Response(status=409)
    else:
        # Find task with queue id method_id
        for task in sample.tasks:
            if task['queueID'] == int(method_id):
                resp = jsonify(task)
                resp.status_code = 200
                return resp

    msg = "[QUEUE] method info could not be retrieved, it does not exits for"
    msg += " the given sample"

    logging.getLogger('HWR').exception(msg)
    return Response(status=409)
Exemple #3
0
def get_method(sample_id, method_id):
    """
    Get the information of the given task, beloging to the given sample
        :parameter sampleid: sample identifier, integer
        :parameter methodid: task identifier, integer
        :response Content-Type: application/json, object containing the
            parameter(s) of the task. Example without parameters
            {"QueueId": 52,  "Type": 'Centring'...}
        :statuscode: 200: no error
        :statuscode: 409: task could not be added to the sample
    """
    sample = qutils.queue_to_dict().get(int(id), None)

    if not sample:
        msg = "[QUEUE] sample info could not be retrieved"
        logging.getLogger('HWR').error(msg)
        return Response(status=409)
    else:
        # Find task with queue id method_id
        for task in sample.tasks:
            if task['queueID'] == int(method_id):
                resp = jsonify(task)
                resp.status_code = 200
                return resp

    msg = "[QUEUE] method info could not be retrieved, it does not exits for"
    msg += " the given sample"

    logging.getLogger('HWR').exception(msg)
    return Response(status=409)
Exemple #4
0
def queue_start():
    """
    Start execution of the queue.

    :returns: Respons object, status code set to:
              200: On success
              409: Queue could not be started
    """
    logging.getLogger('HWR').info('[QUEUE] Queue going to start')

    try:
        queue = qutils.queue_to_dict()
        sample_id = queue["sample_order"][0]

        # If auto mount sample is false, just run the first one
        if not qutils.get_auto_mount_sample():
            sid = scutils.get_current_sample() or sample_id
            qutils.execute_entry_with_id(sid)
        else:
            mxcube.queue.queue_hwobj.set_pause(False)
            mxcube.queue.queue_hwobj.execute()

    except Exception as ex:
        signals.queue_execution_failed(ex)
    
    logging.getLogger('HWR').info('[QUEUE] Queue started')
    return Response(status=200)
Exemple #5
0
def loaded_sample_changed(sample):
    # If sample is a "No sample loaded value" None or ''
    if sample in [None, '']:
        msg = {'signal': 'loadReady', 'location': ''}
        socketio.emit('sc', msg, namespace='/hwr')
        socketio.emit("loaded_sample_changed", {'address': '', 'barcode': ''}, namespace="/hwr")
    
    # If sample is not Pin, Sample pin just return
    if not (isinstance(sample, Pin) or isinstance(sample, Sample)):
        return

    if sample is not None:
        address = sample.getAddress()
        barcode = sample.getID()
    else:
        address = ''
        barcode = ''

    logging.getLogger("HWR").info('loaded sample changed now is: ' + address)
 
    try:
        # recreate the dict with the sample info
        q = queue_to_dict()
        sampleID = sample.getAddress()
        sample_data = q.get(sampleID, {})
    
        scutils.set_current_sample(sample_data)
        msg = {'signal': 'loadReady', 'location': address}
        socketio.emit('sc', msg, namespace='/hwr')
        socketio.emit("loaded_sample_changed", {'address': address, 'barcode': barcode}, namespace="/hwr")
    except Exception, msg:
        logging.getLogger("HWR").error('error setting loaded sample: %s' + str(msg))
Exemple #6
0
def get_current_sample():
    current_queue = qutils.queue_to_dict()

    if mxcube.CURRENTLY_MOUNTED_SAMPLE and \
       mxcube.CURRENTLY_MOUNTED_SAMPLE["sampleID"] in  current_queue:
        return mxcube.CURRENTLY_MOUNTED_SAMPLE
    else:
        return {}
Exemple #7
0
def get_current_sample():
    current_queue = qutils.queue_to_dict()
    
    if mxcube.CURRENTLY_MOUNTED_SAMPLE and \
       mxcube.CURRENTLY_MOUNTED_SAMPLE["sampleID"] in  current_queue:
        return mxcube.CURRENTLY_MOUNTED_SAMPLE
    else:
        return {}
Exemple #8
0
def queue_update_item(sid, tindex):
    data = request.get_json()
    current_queue = qutils.queue_to_dict()

    if tindex in ['undefined']:
        node_id = current_queue[sid]["queueID"]
    else:
        node_id = current_queue[sid]["tasks"][int(tindex)]["queueID"]

    model, entry = qutils.get_entry(node_id)

    if data["type"] == "DataCollection":
        qutils.set_dc_params(model, entry, data)
    elif data["type"] == "Characterisation":
        qutils.set_char_params(model, entry, data)

    logging.getLogger('HWR').info('[QUEUE] is:\n%s ' % qutils.queue_to_json())
    return Response(status=200)
Exemple #9
0
def get_sample(id):
    """
    Get the information of the given sample.
        :parameter id: sample identifier, integer
        :response Content-Type: application/json, object containing the
            parameter(s) of the sample. Example without parameters
            {"QueueId": 22, "SampleId": "3:02", "methods": []}
        :statuscode: 200: no error
        :statuscode: 409: sample could not be retrieved
    """
    sample = qutils.queue_to_dict().get(int(id), None)

    if not sample:
        logging.getLogger('HWR').error('[QUEUE] sample info could not be retrieved')
        return Response(status=409)
    else:
        resp = jsonify(sample)
        resp.status_code = 200
        return resp
Exemple #10
0
def synch_sample_list_with_queue(current_queue=None):
    if not current_queue:
        current_queue = qutils.queue_to_dict(include_lims_data=True)

    sample_order = current_queue.get("sample_order", [])

    for loc, data in mxcube.SAMPLE_LIST["sampleList"].iteritems():
        if loc in current_queue:
            sample = current_queue[loc]

            # Don't synchronize, lims attributes from queue sample, if
            # they are already set by sc or lims
            if data.get("sampleName", ""):
                sample.pop("sampleName")

            if data.get("proteinAcronym", ""):
                sample.pop("proteinAcronym")

            sample_list_update_sample(loc, sample)
Exemple #11
0
def get_sample(id):
    """
    Get the information of the given sample.
        :parameter id: sample identifier, integer
        :response Content-Type: application/json, object containing the
            parameter(s) of the sample. Example without parameters
            {"QueueId": 22, "SampleId": "3:02", "methods": []}
        :statuscode: 200: no error
        :statuscode: 409: sample could not be retrieved
    """
    sample = qutils.queue_to_dict().get(int(id), None)

    if not sample:
        logging.getLogger('HWR').error('[QUEUE] sample info could not be retrieved')
        return Response(status=409)
    else:
        resp = jsonify(sample)
        resp.status_code = 200
        return resp
Exemple #12
0
def synch_sample_list_with_queue(current_queue=None):

    if not current_queue:
        current_queue = qutils.queue_to_dict()

    sample_order = current_queue.get("sample_order", [])

    for loc, data in mxcube.SAMPLE_LIST["sampleList"].iteritems():
        if loc in current_queue:
            sample = current_queue[loc]

            # Don't synchronize, lims attributes from queue sample, if
            # they are already set by sc or lims
            if data.get("sampleName", ""):
                sample.pop("sampleName")

            if  data.get("proteinAcronym", ""):
                sample.pop("proteinAcronym")

            sample_list_update_sample(loc, sample)
Exemple #13
0
def queue_delete_item():
    item_pos_list = request.get_json()
    current_queue = qutils.queue_to_dict() 

    for (sid, tindex) in item_pos_list:
        if tindex in ['undefined', None]:
            node_id = current_queue[sid]["queueID"]
            model, entry = qutils.get_entry(node_id)
        else:
            node_id = current_queue[sid]["tasks"][int(tindex)]["queueID"]
            model, entry = qutils.get_entry(node_id)

            # Get the TaskGroup of the item, there is currently only one
            # task per TaskGroup so we have to remove the entire TaskGroup
            # with its task.
            entry = entry.get_container()

        qutils.delete_entry(entry)

    logging.getLogger('HWR').info('[QUEUE] is:\n%s ' % qutils.queue_to_json())
    return Response(status=200)
Exemple #14
0
def toggle_node(node_id):
    '''
    Toggle a sample or a method checked status
        :parameter id: node identifier, integer
        :statuscode: 200: no error
        :statuscode: 409: node could not be toggled
    '''
    node_id = int(node_id)  # params['QueueId']
    node = mxcube.queue.get_node(node_id)
    entry = mxcube.queue.queue_hwobj.get_entry_with_model(node)
    queue = qutils.queue_to_dict()

    if isinstance(entry, qe.SampleQueueEntry):
        # this is a sample entry, thus, go through its checked children and toggle those
        if entry.is_enabled():
            entry.set_enabled(False)
            node.set_enabled(False)
        else:
            entry.set_enabled(True)
            node.set_enabled(True)

        new_state = entry.is_enabled()
        for elem in queue[node_id]:
            child_node = mxcube.queue.get_node(elem['queueID'])
            child_entry = mxcube.queue.queue_hwobj.get_entry_with_model(child_node)
            if new_state:
                child_entry.set_enabled(True)
                child_node.set_enabled(True)
            else:
                child_entry.set_enabled(False)
                child_node.set_enabled(False)

    else:
        # not a sample so find the parent and toggle directly
        logging.getLogger('HWR').info('[QUEUE] toggling entry with id: %s' % node_id)
        parent_node = node.get_parent()  # this is a TaskGroup, so it is not in the parsed queue
        # go a level up,
        parent_node = parent_node.get_parent()  # this is a TaskGroup for a Char, a sampleQueueEntry if DataCol
        if isinstance(parent_node, qmo.TaskGroup):
            parent_node = parent_node.get_parent()
        parent = parent_node._node_id
        parent_entry = mxcube.queue.queue_hwobj.get_entry_with_model(parent_node)
        # now that we know the sample parent no matter what is the entry (char, dc)
        # check if the brother&sisters are enabled (and enable the parent)
        checked = 0

        for i in queue[parent]:
            if i['queueID'] != node_id and i['checked'] == 1:  # at least one brother is enabled, no need to change parent
                checked = 1
                break
        if entry.is_enabled():
            entry.set_enabled(False)
            node.set_enabled(False)

        else:
            entry.set_enabled(True)
            node.set_enabled(True)

        new_state = entry.is_enabled()
        for met in queue[parent]:
            if int(met.get('queueID')) == node_id:
                if new_state == 0 and checked == 0:
                    parent_entry.set_enabled(False)
                    parent_node.set_enabled(False)
                elif new_state == 1 and checked == 0:
                    parent_entry.set_enabled(True)
                    parent_node.set_enabled(True)

    return Response(status=200)
Exemple #15
0
def toggle_node(node_id):
    '''
    Toggle a sample or a method checked status
        :parameter id: node identifier, integer
        :statuscode: 200: no error
        :statuscode: 409: node could not be toggled
    '''
    node_id = int(node_id)  # params['QueueId']
    node = mxcube.queue.get_node(node_id)
    entry = mxcube.queue.queue_hwobj.get_entry_with_model(node)
    queue = qutils.queue_to_dict()

    if isinstance(entry, qe.SampleQueueEntry):
        # this is a sample entry, thus, go through its checked children and toggle those
        if entry.is_enabled():
            entry.set_enabled(False)
            node.set_enabled(False)
        else:
            entry.set_enabled(True)
            node.set_enabled(True)

        new_state = entry.is_enabled()
        for elem in queue[node_id]:
            child_node = mxcube.queue.get_node(elem['queueID'])
            child_entry = mxcube.queue.queue_hwobj.get_entry_with_model(child_node)
            if new_state:
                child_entry.set_enabled(True)
                child_node.set_enabled(True)
            else:
                child_entry.set_enabled(False)
                child_node.set_enabled(False)

    else:
        # not a sample so find the parent and toggle directly
        logging.getLogger('HWR').info('[QUEUE] toggling entry with id: %s' % node_id)
        parent_node = node.get_parent()  # this is a TaskGroup, so it is not in the parsed queue
        # go a level up,
        parent_node = parent_node.get_parent()  # this is a TaskGroup for a Char, a sampleQueueEntry if DataCol
        if isinstance(parent_node, qmo.TaskGroup):
            parent_node = parent_node.get_parent()
        parent = parent_node._node_id
        parent_entry = mxcube.queue.queue_hwobj.get_entry_with_model(parent_node)
        # now that we know the sample parent no matter what is the entry (char, dc)
        # check if the brother&sisters are enabled (and enable the parent)
        checked = 0

        for i in queue[parent]:
            if i['queueID'] != node_id and i['checked'] == 1:  # at least one brother is enabled, no need to change parent
                checked = 1
                break
        if entry.is_enabled():
            entry.set_enabled(False)
            node.set_enabled(False)

        else:
            entry.set_enabled(True)
            node.set_enabled(True)

        new_state = entry.is_enabled()
        for met in queue[parent]:
            if int(met.get('queueID')) == node_id:
                if new_state == 0 and checked == 0:
                    parent_entry.set_enabled(False)
                    parent_node.set_enabled(False)
                elif new_state == 1 and checked == 0:
                    parent_entry.set_enabled(True)
                    parent_node.set_enabled(True)

    return Response(status=200)