def get_timer(self, needed_captures): """ Get generator used to wait between captures :param needed_captures: number of images needed to capture :rtype: generator """ countdown_time = pkConfig['session']['countdown-time'] extra_wait_time = pkConfig['session']['extra-wait-time'] return timing_generator(countdown_time, needed_captures, countdown_time + extra_wait_time)
def test_normal(self): exp = [(False, 2), (False, 2), (False, 2), (True, 2)] res = list(timing_generator(2, 4)) self.assertEqual(exp, res)
def start(self, camera, root): """ new session Take 4 photos Each photo has 3 attempts to take a photo If we get 4 photos, or 3 failed attempts, then exit :param root: template graph :param camera: camera object """ logger.debug('starting new session') self.start_workers() # each worker is a separate python process self.started = True paths = pkConfig['paths'] needed_captures = root.needed_captures() session_id = self.determine_initial_capture_id() capture_id = 0 # TODO: handle camera errors errors = 0 timing = timing_generator(self.countdown_time, needed_captures, self.countdown_time + self.extra_wait_time) for final, wait_time in timing: logger.debug('waiting %s seconds', wait_time) yield from self.countdown(wait_time) try: image = yield from camera.download_capture() except: errors += 1 traceback.print_exc(file=sys.stdout) logger.debug('failed capture %s/3', errors) continue self.finished = final # indicate that the session has all required photos errors = 0 # reset errors after each successful capture capture_id += 1 if final: bell1.play() # sound to indicate that session is closed else: finished.play() # sound to indicate that photo was taken self.idle = True # indicate that picture is taken, getting ready for next root.push_image(image) # add images to the template for rendering path = join(paths['event_originals'], 'original', self.name_image('original', session_id, capture_id)) self.queue_image_save(image, path) # add this image to the worker queue # give camera some fixed time to process exposure (may not be needed) yield from asyncio.sleep(self.time_to_wait_after_capture) self.idle = False # indicate that the camera is now busy composite = yield from self.render_template(root) composites_folder = paths['event_composites'] composite_filename = self.name_composite('composite', session_id) composite_path = join(composites_folder, 'original', composite_filename) composite_small_path = join(composites_folder, 'small', composite_filename) print_path = join(paths['event_prints'], composite_filename) self.queue_image_save(composite, composite_path) self.queue_image_thumbnail(composite, composite_small_path) self.queue_image_double(composite, print_path) self.wait_for_workers() # blocking! # print the double # TODO: not use the http service? url = 'http://localhost:5000/print/' + composite_filename requests.get(url) self.mark_session_complete(composite_filename) return root
def test_with_initial_len0(self): # TODO: raise error exp = [] res = list(timing_generator(2, 0, 10)) self.assertEqual(exp, res)
def test_normal_len0(self): # TODO: raise error exp = [] res = list(timing_generator(2, 0)) self.assertEqual(exp, res)
def test_with_initial_len1(self): exp = [(True, 10)] res = list(timing_generator(2, 1, 10)) self.assertEqual(exp, res)
def test_normal_len1(self): exp = [(True, 2)] res = list(timing_generator(2, 1)) self.assertEqual(exp, res)
def test_with_initial(self): exp = [(False, 10), (False, 2), (False, 2), (True, 2)] res = list(timing_generator(2, 4, 10)) self.assertEqual(exp, res)