def find_all_sessions_for_object(db_params, object_id): db = dbtools.db_params_to_db(db_params) sessions = Session.by_object_id(db, key=object_id) sessions_by_date_added = [] for x in sessions: sess = db[x.id] sessions_by_date_added.append((sess['added'], x.id)) sessions_by_date_added = sorted(sessions_by_date_added) return zip(*sessions_by_date_added)[1]
def find_all_observations_for_session(db_params, session_id): ''' Finds all of the observations associated with a session, and returns a list of their ids. These are sorted by the frame number, so they should be in chronological ordering. ''' db = dbtools.db_params_to_db(db_params) #run the view, keyed on the session id. results = Observation.by_session_id(db, key=session_id) if len(results) == 0 : return [] #create a list of tuples, so that they can be sorted by frame number obs_tuples = [ (obs.frame_number, obs.id) for obs in results] # sort by frame_number, helps preserve chronological order obs_ids = zip(*sorted(obs_tuples, key=lambda obs: obs[0]))[1] return obs_ids
def parse_arguments(obj, db_params, object_ids): if type(obj).__name__ == 'dict': dic = obj else: dic = obj.__dict__ if 'sink_type' in dic: dic['type'] = dic.pop('sink_type') sink = None mapping = object_to_models_mapping(db_params_to_db(db_params), object_ids) if 'type' in dic: sink = Sink.create_sink(sink_type=dic['type'], mapping=mapping, db_params=db_params) else: raise RuntimeError("Could not create a sink from the given args! %s" % str(dic)) return _assert_sink_interface(sink)
def read_arguments(parser=None, argv=sys.argv): """ Returns: params, pipeline_params, db_dict, db params: all the pipeline parameters specified in the config file or command line pipeline_params: an array of parameters for each pipeline db_dict: the dictionary of the db parameters db: a db object created from those parameters """ if parser is None: parser = ObjectRecognitionParser() parser.add_argument('-c', '--config_file', help='Config file') parser.add_argument('--object_ids', help='If set, it overrides the list of object_ids in the config file') parser.add_argument('--object_names', help='If set, it overrides the list of object names in the config file') parser.add_argument('--visualize', help='If set, it will display some windows with temporary results', default=False, action='store_true') dbtools.add_db_options(parser) try: import ecto_ros ecto_ros.strip_ros_args(argv) except: pass if '--help' in sys.argv or '-h' in sys.argv: args = parser.parse_args() else: args = parser.parse_args()#args=argv) # define the input if args.config_file is None or not os.path.exists(args.config_file): print >>sys.stderr, "The option file does not exist. --help for usage." sys.exit(-1) params = yaml.load(open(args.config_file)) # read some parameters db_params = args_to_db_params(args, params.get('db', {})) # initialize the DB db = dbtools.db_params_to_db(db_params) # read the object_ids object_ids = set() for obj in (args.__dict__, params): ids = obj.get('object_ids', None) names = obj.get('object_names', None) if 'all' in (ids, names): object_ids = set([ str(x.id) for x in models.Object.all(db) ]) #unicode without the str() break if 'missing' in (ids, names): tmp_object_ids = set([ str(x.id) for x in models.Object.all(db) ]) tmp_object_ids_from_names = set([ str(x.object_id) for x in models.Model.all(db) ]) object_ids.update(tmp_object_ids.difference(tmp_object_ids_from_names)) if ids and ids != 'missing': object_ids.update(ids[1:-1].split(',')) if names and names != 'missing': for object_name in names[1:-1].split(','): object_ids.update([str(x.id) for x in models.objects_by_name(db, object_name)]) # if we got some ids through the command line, just stop here if object_ids: break object_ids = list(object_ids) params['object_ids'] = object_ids pipeline_params = [] for key , value in params.iteritems(): if key.startswith('pipeline'): pipeline_params.append(value) args = vars(args) return params, args, pipeline_params, args['visualize'], db_params
def read_arguments(parser=None, argv=sys.argv): """ Returns: params, pipeline_params, db_dict, db params: all the pipeline parameters specified in the config file or command line pipeline_params: an array of parameters for each pipeline db_dict: the dictionary of the db parameters db: a db object created from those parameters """ if parser is None: parser = ObjectRecognitionParser() parser.add_argument('-c', '--config_file', help='Config file') parser.add_argument( '--object_ids', help='If set, it overrides the list of object_ids in the config file') parser.add_argument( '--object_names', help='If set, it overrides the list of object names in the config file' ) parser.add_argument( '--visualize', help='If set, it will display some windows with temporary results', default=False, action='store_true') dbtools.add_db_options(parser) try: import ecto_ros ecto_ros.strip_ros_args(argv) except: pass if '--help' in sys.argv or '-h' in sys.argv: args = parser.parse_args() else: args = parser.parse_args() #args=argv) # define the input if args.config_file is None or not os.path.exists(args.config_file): print >> sys.stderr, "The option file does not exist. --help for usage." sys.exit(-1) params = yaml.load(open(args.config_file)) # read some parameters db_params = args_to_db_params(args, params.get('db', {})) # initialize the DB db = dbtools.db_params_to_db(db_params) # read the object_ids object_ids = set() for obj in (args.__dict__, params): ids = obj.get('object_ids', None) names = obj.get('object_names', None) if 'all' in (ids, names): object_ids = set([str(x.id) for x in models.Object.all(db) ]) #unicode without the str() break if 'missing' in (ids, names): tmp_object_ids = set([str(x.id) for x in models.Object.all(db)]) tmp_object_ids_from_names = set( [str(x.object_id) for x in models.Model.all(db)]) object_ids.update( tmp_object_ids.difference(tmp_object_ids_from_names)) if ids and ids != 'missing': object_ids.update(ids[1:-1].split(',')) if names and names != 'missing': for object_name in names[1:-1].split(','): object_ids.update([ str(x.id) for x in models.objects_by_name(db, object_name) ]) # if we got some ids through the command line, just stop here if object_ids: break object_ids = list(object_ids) params['object_ids'] = object_ids pipeline_params = [] for key, value in params.iteritems(): if key.startswith('pipeline'): pipeline_params.append(value) args = vars(args) return params, args, pipeline_params, args['visualize'], db_params