Beispiel #1
0
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')
Beispiel #2
0
 def test_take_both_still_calls_all_chained_tasks_multiple_times_when_repeat_specified(self,
                                                                                       cs_take_picam_still,
                                                                                       cs_take_thermal_still,
                                                                                       ans_scale_image,
                                                                                       ans_distort_image_shepards_fixed,
                                                                                       ms_merge_image,
                                                                                       ads_clean_up_files,
                                                                                       ads_send_mail):
     snap_id = uuid.uuid4()
     group_id = get_group_document('current')['_id']
     ct.take_both_still(snap_id=snap_id, group_id=group_id, delay=0, repeat=1)
     cs_take_thermal_still.assert_has_calls([call(snap_id, group_id, ANY), call(ANY, group_id, ANY)])
     cs_take_picam_still.assert_has_calls([call(snap_id, group_id, ANY, ANY), call(ANY, group_id, ANY, ANY)])
     ans_scale_image.assert_has_calls([call(ANY, ANY, group_id), call(ANY, ANY, group_id)])
     ans_distort_image_shepards_fixed.assert_has_calls([call(ANY, ANY, group_id), call(ANY, ANY, group_id)])
     ms_merge_image.assert_has_calls([call(ANY, ANY, ANY, ANY, group_id), call(ANY, ANY, ANY, ANY, group_id)])
     ads_send_mail.assert_has_calls([call(snap_id, group_id), call(ANY, group_id)])
     ads_clean_up_files.assert_has_calls([call(snap_id, group_id), call(ANY, group_id)])
Beispiel #3
0
 def test_take_both_still_calls_all_chained_tasks(self,
                                                  cs_take_picam_still,
                                                  cs_take_thermal_still,
                                                  ans_scale_image,
                                                  ans_distort_image_shepards_fixed,
                                                  ms_merge_image,
                                                  ads_clean_up_files,
                                                  ads_send_mail):
     snap_id = uuid.uuid4()
     group_id = get_group_document('current')['_id']
     ct.take_both_still(snap_id=snap_id, group_id=group_id, delay=0, repeat=0)
     cs_take_thermal_still.assert_called_once_with(snap_id, group_id, ANY)
     cs_take_picam_still.assert_called_once_with(snap_id, group_id, ANY, ANY)
     ans_scale_image.assert_called_once_with(ANY, ANY, group_id)
     ans_distort_image_shepards_fixed.assert_called_once_with(ANY, ANY, group_id)
     ms_merge_image.assert_called_once_with(ANY, ANY, ANY, ANY, group_id)
     ads_send_mail.assert_called_once_with(snap_id, group_id)
     ads_clean_up_files.assert_called_once_with(snap_id, group_id)
Beispiel #4
0
    def test_take_both_still_calls_expected_methods(self):
        camera.services.take_picam_still = Mock()
        camera.services.take_thermal_still = Mock()
        analysis.services.scale_image = Mock()
        analysis.services.distort_image_shepards = Mock()
        merging.services.merge_images = Mock()
        admin.services.send_mail = Mock()
        admin.services.upload_files_to_s3 = Mock()
        admin.services.clean_up_files = Mock()

        return_value = ct.take_both_still('some_snap_id', 'some_group_id')

        camera.services.take_thermal_still.assert_called_once_with('some_snap_id',
                                                                   'some_group_id',
                                                                   ANY,
                                                                   False)
        camera.services.take_picam_still.assert_called_once_with('some_snap_id',
                                                                 'some_group_id',
                                                                 ANY,
                                                                 ANY,
                                                                 False)
        analysis.services.scale_image.assert_called_once_with(ANY,
                                                              ANY,
                                                              'some_group_id')
        analysis.services.distort_image_shepards.assert_called_once_with(image_id_in=ANY,
                                                                         image_id_out=ANY,
                                                                         distortion_set_id=None)
        merging.services.merge_images.assert_called_once_with(img1_primary_id_in=ANY,
                                                              img1_alternate_id_in=ANY,
                                                              img2_id_in=ANY,
                                                              img_id_out=ANY,
                                                              group_id='some_group_id')
        admin.services.send_mail.assert_called_once_with('some_snap_id',
                                                         'some_group_id')
        admin.services.upload_files_to_s3.assert_called_once_with('some_snap_id',
                                                                  'some_group_id')
        admin.services.clean_up_files.assert_called_once_with('some_snap_id',
                                                              'some_group_id')
        assert return_value == {'snap_ids': ['some_snap_id'],
                                'group_id': 'some_group_id',
                                'normal_exposure_picam_ids': [ANY],
                                'long_exposure_picam_ids': [ANY],
                                'thermal_ids': [ANY],
                                'scaled_for_thermal_merge_ids': [ANY],
                                'distorted_for_thermal_merge_ids': [ANY],
                                'merged_ids': [ANY]}
Beispiel #5
0
    def test_take_both_still_calls_expected_methods(self):
        camera.services.take_picam_still = Mock()
        camera.services.take_thermal_still = Mock()
        analysis.services.scale_image = Mock()
        analysis.services.distort_image_shepards = Mock()
        merging.services.merge_images = Mock()
        admin.services.send_mail = Mock()
        admin.services.upload_files_to_s3 = Mock()
        admin.services.clean_up_files = Mock()

        return_value = ct.take_both_still('some_snap_id', 'some_group_id')

        camera.services.take_thermal_still.assert_called_once_with(
            'some_snap_id', 'some_group_id', ANY, False)
        camera.services.take_picam_still.assert_called_once_with(
            'some_snap_id', 'some_group_id', ANY, ANY, False)
        analysis.services.scale_image.assert_called_once_with(
            ANY, ANY, 'some_group_id')
        analysis.services.distort_image_shepards.assert_called_once_with(
            image_id_in=ANY, image_id_out=ANY, distortion_set_id=None)
        merging.services.merge_images.assert_called_once_with(
            img1_primary_id_in=ANY,
            img1_alternate_id_in=ANY,
            img2_id_in=ANY,
            img_id_out=ANY,
            group_id='some_group_id')
        admin.services.send_mail.assert_called_once_with(
            'some_snap_id', 'some_group_id')
        admin.services.upload_files_to_s3.assert_called_once_with(
            'some_snap_id', 'some_group_id')
        admin.services.clean_up_files.assert_called_once_with(
            'some_snap_id', 'some_group_id')
        assert return_value == {
            'snap_ids': ['some_snap_id'],
            'group_id': 'some_group_id',
            'normal_exposure_picam_ids': [ANY],
            'long_exposure_picam_ids': [ANY],
            'thermal_ids': [ANY],
            'scaled_for_thermal_merge_ids': [ANY],
            'distorted_for_thermal_merge_ids': [ANY],
            'merged_ids': [ANY]
        }
Beispiel #6
0
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
    Delaying and Repeating info comes in via GET parameters, the rest comes from the current group record.
    '''
    snap_id = uuid.uuid4()
    group_id = get_settings_document()['current_group_id']
    delay = get_delay_parameter()
    repeat = get_repeat_parameter()

    both_still_dict = take_both_still(
        snap_id=snap_id,
        group_id=group_id,
        delay=delay,
        repeat=repeat
    )

    return Response(json.dumps(both_still_dict), status=202, mimetype='application/json')
Beispiel #7
0
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
    Delaying and Repeating info comes in via GET parameters, the rest comes from the current group record.
    '''
    snap_id = uuid.uuid4()
    group_id = get_settings_document()['current_group_id']
    delay = get_delay_parameter()
    repeat = get_repeat_parameter()

    both_still_dict = take_both_still(snap_id=snap_id,
                                      group_id=group_id,
                                      delay=delay,
                                      repeat=repeat)

    return Response(json.dumps(both_still_dict),
                    status=202,
                    mimetype='application/json')
Beispiel #8
0
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')