Example #1
0
def train(request):
    '''
    Take a physical sample from the spectrometer of the reading type specified via the 'reading_type' get parameter.
    Save the record with no group, and a description as specified with the sample_name get parameter.
    This is intended to be a reference sample across all groups.
    On success return json representing the new Sample
    '''
    valid_sample_types = [
        Sample.SPECTROMETER, Sample.COLOR, Sample.FLUORESCENCE
    ]
    if 'reading_type' in request.query_params and request.query_params[
            'reading_type'] in valid_sample_types:
        if request.query_params['sample_name']:
            try:
                return_data = train_task(request.query_params['reading_type'],
                                         request.query_params['sample_name'])
                return Response(returndata)
            except Exception as e:
                return Response(get_error_string_for_api(e),
                                status=e.status_code)
        else:  # TODO add a test for this condition
            err_message = 'A non-empty sample name must be specified for a reference sample'
            return Response(data=err_message, status=409)
    else:
        # TODO add a test for this condition
        err_message = 'Invalid sample type, must be one of these: ' + str(
            valid_sample_types)
        return Response(data=err_message, status=409)
Example #2
0
def capture_sample(request):
    '''
    Calls the chain of tasks associated with getting a physical sample from the spectrometer according to the parameters
        specified in the current active group from (the settings record)
    Tasks are run asynchronously, relevant ids for created objects are returned
    '''
    group = get_current_group()

    try:
        response_dict = capture_sample_task(group)
        return Response(response_dict)
    except Exception as e:
        return Response(get_error_string_for_api(e), status=e.status_code)
Example #3
0
def capture_sample(request):
    '''
    Calls the chain of tasks associated with getting a physical sample from the spectrometer according to the parameters
        specified in the current active group from (the settings record)
    Tasks are run asynchronously, relevant ids for created objects are returned
    '''
    group = get_current_group()

    try:
        response_dict = capture_sample_task(group)
        return Response(response_dict)
    except Exception as e:
        return Response(get_error_string_for_api(e), status=e.status_code)
Example #4
0
def calibrate(request):
    '''
    Take a sample according to the current group config.
    Compare its data to the reference_sample_id passed in as a get parm
    On success return a SampleDelta object with the differences between the two samples
    '''
    # TODO add logic and tests for null reference_sample_id
    group = get_current_group()

    if 'reference_sample_id' in request.query_params and request.query_params['reference_sample_id']:
        try:
            return_data = calibrate_task(group, request.query_params['reference_sample_id'])
            return Response(return_data)
        except Exception as e:
            return Response(get_error_string_for_api(e), status=e.status_code)
    else:  # TODO add a test for this condition
        err_message = 'An id must be specified for a reference sample'
        return Response(data=err_message, status=409)
Example #5
0
def calibrate(request):
    '''
    Take a sample according to the current group config.
    Compare its data to the reference_sample_id passed in as a get parm
    On success return a SampleDelta object with the differences between the two samples
    '''
    # TODO add logic and tests for null reference_sample_id
    group = get_current_group()

    if 'reference_sample_id' in request.query_params and request.query_params[
            'reference_sample_id']:
        try:
            return_data = calibrate_task(
                group, request.query_params['reference_sample_id'])
            return Response(return_data)
        except Exception as e:
            return Response(get_error_string_for_api(e), status=e.status_code)
    else:  # TODO add a test for this condition
        err_message = 'An id must be specified for a reference sample'
        return Response(data=err_message, status=409)
Example #6
0
def train(request):
    '''
    Take a physical sample from the spectrometer of the reading type specified via the 'reading_type' get parameter.
    Save the record with no group, and a description as specified with the sample_name get parameter.
    This is intended to be a reference sample across all groups.
    On success return json representing the new Sample
    '''
    valid_sample_types = [Sample.SPECTROMETER, Sample.COLOR, Sample.FLUORESCENCE]
    if 'reading_type' in request.query_params and request.query_params['reading_type'] in valid_sample_types:
        if request.query_params['sample_name']:
            try:
                return_data = train_task(request.query_params['reading_type'], request.query_params['sample_name'])
                return Response(returndata)
            except Exception as e:
                return Response(get_error_string_for_api(e), status=e.status_code)
        else:  # TODO add a test for this condition
            err_message = 'A non-empty sample name must be specified for a reference sample'
            return Response(data=err_message, status=409)
    else:
        # TODO add a test for this condition
        err_message = 'Invalid sample type, must be one of these: ' + str(valid_sample_types)
        return Response(data=err_message, status=409)