예제 #1
0
파일: views.py 프로젝트: dcaulton/thermal
def both_still():
    '''
    Api endpoint for taking one or a series of 'both' stills - that is, Picam and Lepton stills which are then post-processed
      and merged into a single image
    The still/stills will run asynchronously as Celery tasks, the scheduling work is delegated to the camera.tasks module
    Cleaning up files comes in via a GET parameter, note that empty string is the ONLY thing that will force it to false
    Delaying and Repeating info comes in via GET parameters, the rest comes from the current group record.
    '''
    try:
        snap_id = uuid.uuid4()
        group_id = get_settings_document()['current_group_id']
        args_dict = gather_and_enforce_request_args([{'name': 'delay', 'default': 0, 'cast_function': int},
                                                     {'name': 'repeat', 'default': 0, 'cast_function': int},
                                                     {'name': 'clean_up_files', 'default': True, 'cast_function': bool}])
        # TODO specify that is (snap_id, group_id, **args_dict soon)
        both_still_dict = take_both_still(
            snap_id=snap_id,
            group_id=group_id,
            delay=args_dict['delay'],
            repeat=args_dict['repeat'],
            clean_up_files=args_dict['clean_up_files'])

        return Response(json.dumps(both_still_dict), status=202, mimetype='application/json')
    except Exception as e:
        return Response(json.dumps(e.message), status=e.status_code, mimetype='application/json')
예제 #2
0
파일: views.py 프로젝트: ibivibiv/thermal
def call_distort_image(image_id=None):
    '''
    Distorts an image according to the distortion pairs in the specified distortion set
    '''
    try:
        new_image_id = uuid.uuid4()
        picture_dict = get_document_with_exception(image_id,
                                                   document_type='picture')
        args_dict = gather_and_enforce_request_args([{
            'name': 'distortion_set_id',
            'required': True
        }])
        distortion_set_id = args_dict['distortion_set_id']
        distortion_set_dict = get_document_with_exception(
            distortion_set_id, document_type='distortion_set')

        # TODO call this async via distort_image_shepards_task.delay as soon as it's working
        ans.distort_image_shepards(image_id_in=image_id,
                                   image_id_out=new_image_id,
                                   distortion_set_id=distortion_set_id)

        resp_json = {'distorted_image_id': str(new_image_id)}
        return Response(json.dumps(resp_json),
                        status=202,
                        mimetype='application/json')
    except Exception as e:
        return Response(json.dumps(e.message),
                        status=e.status_code,
                        mimetype='application/json')
예제 #3
0
파일: views.py 프로젝트: dcaulton/thermal
def call_edge_detect(image_id=None):
    '''
    Invokes edge detection for a given image
    Accepts a GET parameter for detection threshold.  Allowable values are 'all', 'auto', 'wide' and 'tight'
    '''
    try:
        picture_dict = get_document_with_exception(image_id, document_type='picture')
        auto_id = uuid.uuid4()
        wide_id = uuid.uuid4()
        tight_id = uuid.uuid4()

        args_dict = gather_and_enforce_request_args([{'name': 'detection_threshold', 'default': 'all'}])
        if args_dict['detection_threshold'] not in ['all', 'auto', 'wide', 'tight']:
            error_msg = 'invalid detection threshold specified.  Allowable are all, auto, wide or tight'
            return Response(json.dumps(error_msg), status=409, mimetype='application/json')

        ans.edge_detect_task.delay(img_id_in=image_id,
                                   detection_threshold=args_dict['detection_threshold'],
                                   auto_id=auto_id,
                                   wide_id=wide_id,
                                   tight_id=tight_id)

        resp_json = {}
        if args_dict['detection_threshold'] in ['all', 'auto']:
            resp_json['auto_id'] = str(auto_id)
        if args_dict['detection_threshold'] in ['all', 'wide']:
            resp_json['wide_id'] = str(wide_id)
        if args_dict['detection_threshold'] in ['all', 'tight']:
            resp_json['tight_id'] = str(tight_id)

        return Response(json.dumps(resp_json), status=202, mimetype='application/json')
    except Exception as e:
        return Response(json.dumps(e.message), status=e.status_code, mimetype='application/json')
예제 #4
0
def call_merge_images():
    '''
    Merges two images into a third one
    Accepts merge_type as an optional parameter, see here for valid merge types: http://www.effbot.org/imagingbook/imagechops.htm
    '''
    try:
        args_dict = gather_and_enforce_request_args([{'name': 'img1_id', 'required': True},
                                                     {'name': 'img2_id', 'required': True},
                                                     {'name': 'merge_type'}])
        img1_id = args_dict['img1_id']
        img2_id = args_dict['img2_id']

        test_input_parameters_for_valid_image_ids(args_dict)
        merge_type = check_for_merge_type(args_dict)
        result_id = cast_uuid_to_string(uuid.uuid4())

        merge_images_task.delay(
            img1_primary_id_in=img1_id,
            img1_alternate_id_in=uuid.uuid4(),
            img2_id_in=img2_id,
            img_id_out=result_id,
            group_id='current',
            merge_type=merge_type)
        accept_json = {'result_id': result_id}
        return Response(json.dumps(accept_json), status=202, mimetype='application/json')
    except Exception as e:
        return Response(json.dumps(e.message), status=e.status_code, mimetype='application/json')
예제 #5
0
 def test_gather_and_enforce_request_args_routes_to_gaera_enumerated(
         self, tu_gather_and_enforce_request_args_enumerated):
     tu_gather_and_enforce_request_args_enumerated.return_value = {'c': 'd'}
     with current_app.test_request_context('/whatever'):
         ret_val = tu.gather_and_enforce_request_args([{'name': 'steve'}])
         tu_gather_and_enforce_request_args_enumerated.assert_called_once_with(
             [{
                 'name': 'steve'
             }])
예제 #6
0
 def test_gather_and_enforce_request_args_routes_to_gaera_any_searchable(
         self, tu_gather_and_enforce_request_args_any_searchable):
     tu_gather_and_enforce_request_args_any_searchable.return_value = {
         'a': 'b'
     }
     with current_app.test_request_context('/whatever'):
         ret_val = tu.gather_and_enforce_request_args(['ANY_SEARCHABLE'])
         tu_gather_and_enforce_request_args_any_searchable.assert_called_once_with(
         )
예제 #7
0
파일: views.py 프로젝트: dcaulton/thermal
def clean_up_files(snap_id):
    '''
    Cleans up files for the specified snap
    Defaults to current group (for determining types of files to delete), but can be overridden with a group_id GET parameter
    '''
    try:
        snap_dict = get_document_with_exception(snap_id, document_type='snap')
        args_dict = gather_and_enforce_request_args([{'name': 'group_id', 'default': 'current'}])
        clean_up_files_task.delay(snap_id, args_dict['group_id'])
        return Response(json.dumps(snap_dict), status=202, mimetype='application/json')
    except Exception as e:
        return Response(json.dumps(e.message), status=e.status_code, mimetype='application/json')
예제 #8
0
def search_generic(document_type='', args_dict={}):
    '''
    Finds all documents of the specified type matching the parameters passed in with the wargs dict
    It's just a wrapper around get_documents_from_criteria
    THIS CAN THROW EXCEPTIONS, it needs to run within a try except block
    '''
    if request is not None and 'args' in dir(request): # only gather parms if we have a request context
        the_dict = gather_and_enforce_request_args(['ANY_SEARCHABLE'])
        for key in the_dict:
            args_dict[key] = the_dict[key]
    args_dict['type'] = document_type
    documents_dict = get_documents_from_criteria(args_dict)
    return documents_dict
예제 #9
0
파일: views.py 프로젝트: ibivibiv/thermal
def call_edge_detect(image_id=None):
    '''
    Invokes edge detection for a given image
    Accepts a GET parameter for detection threshold.  Allowable values are 'all', 'auto', 'wide' and 'tight'
    '''
    try:
        picture_dict = get_document_with_exception(image_id,
                                                   document_type='picture')
        auto_id = uuid.uuid4()
        wide_id = uuid.uuid4()
        tight_id = uuid.uuid4()

        args_dict = gather_and_enforce_request_args([{
            'name': 'detection_threshold',
            'default': 'all'
        }])
        if args_dict['detection_threshold'] not in [
                'all', 'auto', 'wide', 'tight'
        ]:
            error_msg = 'invalid detection threshold specified.  Allowable are all, auto, wide or tight'
            return Response(json.dumps(error_msg),
                            status=409,
                            mimetype='application/json')

        ans.edge_detect_task.delay(
            img_id_in=image_id,
            detection_threshold=args_dict['detection_threshold'],
            auto_id=auto_id,
            wide_id=wide_id,
            tight_id=tight_id)

        resp_json = {}
        if args_dict['detection_threshold'] in ['all', 'auto']:
            resp_json['auto_id'] = str(auto_id)
        if args_dict['detection_threshold'] in ['all', 'wide']:
            resp_json['wide_id'] = str(wide_id)
        if args_dict['detection_threshold'] in ['all', 'tight']:
            resp_json['tight_id'] = str(tight_id)

        return Response(json.dumps(resp_json),
                        status=202,
                        mimetype='application/json')
    except Exception as e:
        return Response(json.dumps(e.message),
                        status=e.status_code,
                        mimetype='application/json')
예제 #10
0
def clean_up_files(snap_id):
    '''
    Cleans up files for the specified snap
    Defaults to current group (for determining types of files to delete), but can be overridden with a group_id GET parameter
    '''
    try:
        snap_dict = get_document_with_exception(snap_id, document_type='snap')
        args_dict = gather_and_enforce_request_args([{
            'name': 'group_id',
            'default': 'current'
        }])
        clean_up_files_task.delay(snap_id, args_dict['group_id'])
        return Response(json.dumps(snap_dict),
                        status=202,
                        mimetype='application/json')
    except Exception as e:
        return Response(json.dumps(e.message),
                        status=e.status_code,
                        mimetype='application/json')
예제 #11
0
def thermal_still():
    '''
    Api endpoint for taking one or a series of Lepton stills.
    The still/stills will run asynchronously as Celery tasks, the scheduling work is delegated to the camera.tasks module
    Cleaning up files comes in via a GET parameter, note that empty string is the ONLY thing that will force it to false
    Delaying and Repeating info comes in via GET parameters, the rest comes from the current group record.
    '''
    try:
        snap_id = uuid.uuid4()
        group_id = get_settings_document()['current_group_id']
        args_dict = gather_and_enforce_request_args([{
            'name': 'delay',
            'default': 0,
            'cast_function': int
        }, {
            'name': 'repeat',
            'default': 0,
            'cast_function': int
        }, {
            'name': 'clean_up_files',
            'default': True,
            'cast_function': bool
        }, {
            'name': 'scale_image',
            'default': True,
            'cast_function': bool
        }])
        # TODO specify that is (snap_id, group_id, **args_dict soon)
        ret_dict = take_thermal_still(
            snap_id=snap_id,
            group_id=group_id,
            delay=args_dict['delay'],
            repeat=args_dict['repeat'],
            scale_image=args_dict['scale_image'],
            clean_up_files=args_dict['clean_up_files'])
        return Response(json.dumps(ret_dict),
                        status=202,
                        mimetype='application/json')
    except Exception as e:
        return Response(json.dumps(e.message),
                        status=e.status_code,
                        mimetype='application/json')
예제 #12
0
파일: views.py 프로젝트: dcaulton/thermal
def call_distort_image(image_id=None):
    '''
    Distorts an image according to the distortion pairs in the specified distortion set
    '''
    try:
        new_image_id = uuid.uuid4()
        picture_dict = get_document_with_exception(image_id, document_type='picture')
        args_dict = gather_and_enforce_request_args([{'name': 'distortion_set_id', 'required': True}])
        distortion_set_id = args_dict['distortion_set_id']
        distortion_set_dict = get_document_with_exception(distortion_set_id, document_type='distortion_set')

        # TODO call this async via distort_image_shepards_task.delay as soon as it's working
        ans.distort_image_shepards(image_id_in=image_id,
                                   image_id_out=new_image_id,
                                   distortion_set_id=distortion_set_id)

        resp_json = {
            'distorted_image_id': str(new_image_id)
        }
        return Response(json.dumps(resp_json), status=202, mimetype='application/json')
    except Exception as e:
        return Response(json.dumps(e.message), status=e.status_code, mimetype='application/json')
예제 #13
0
 def test_gather_and_enforce_request_args_routes_to_gaera_enumerated(self,
                                                                     tu_gather_and_enforce_request_args_enumerated):
     tu_gather_and_enforce_request_args_enumerated.return_value = {'c': 'd'}
     with current_app.test_request_context('/whatever'):
         ret_val = tu.gather_and_enforce_request_args([{'name': 'steve'}])
         tu_gather_and_enforce_request_args_enumerated.assert_called_once_with([{'name': 'steve'}])
예제 #14
0
 def test_gather_and_enforce_request_args_routes_to_gaera_any_searchable(self,
                                                                         tu_gather_and_enforce_request_args_any_searchable):
     tu_gather_and_enforce_request_args_any_searchable.return_value = {'a': 'b'}
     with current_app.test_request_context('/whatever'):
         ret_val = tu.gather_and_enforce_request_args(['ANY_SEARCHABLE'])
         tu_gather_and_enforce_request_args_any_searchable.assert_called_once_with()