def test_get_active_experiments_returns_active_experiment(self): """ Test that get_active_experiments works correctly indeed. """ e = Experiment(name = "e1", file = 'file2.txt', since = datetime.now()) e.save() active = Experiment.get_active_experiments() eq_(active.count(), 1, "There should be exactly one active experiment") e.active = False e.save() active = Experiment.get_active_experiments() eq_(active.count(), 0, "There should be no active experiments")
def process_message(self, message): # Route messages towards mongo-writer # created_at should be normally set as close to the data generation # as possible and should be the timestamp that the measurement # was phisically generated. Since this is not always possible, the # default is the time of entry in the pipeline. message['created_at'] = message.get('created_at', int(time.time())) self.send_to('mongo-writer', message) self.log('sensor type %s' % message['sensor_type']) # Images & skeletons should be sent to head-crop if message['type'] in ['image_rgb', 'skeleton']: self.send_to('head-crop', message) # If there is at least one active experiment, send them to # recorder. Otherwise, prevent bandwidth waste :) active_experiments = Experiment.get_active_experiments() if len(active_experiments) > 0: self.send_to('recorder', message) # Only send to room position if it's a Kinect skeleton if (message['sensor_type'] == 'kinect' and message['type'] == 'skeleton'): self.send_to('room-position', message) self.send_to('posture-classifier', message) # Only send to dashboard if it's a Kinect RGB image if (message['sensor_type'] == 'kinect' and message['type'] in ['image_rgb', 'skeleton']): self.send_to('dashboard', message)
def purge_files(self): ''' Compare the list of active exercises with the list of open files to determine which are to be closed''' self.logger.info("Starting to purge files ...") active_ids = set([e.id for e in Experiment.get_active_experiments()]) self.logger.info("Active experiment IDs: %r" % active_ids) open_files = {} for (ident, efile) in self._open_files.iteritems(): if ident not in active_ids: efile.close() self.logger.info("Closing down file for experiment %s," "because its experiment is no longer active" %\ str(ident)) else: open_files[ident] = efile self._open_files = open_files