def find_sessions_that_need_meshing():
    db_url = 'http://localhost:5984'
    
    find_all_objects = '''
            function(doc)
            {
              emit('tags',doc.tags);
            }
    '''
    
    
    find_all_sessions = '''
            function(doc)
            {
              if(doc.object_id == "%s")
                  emit('session_id',doc.session_id);
            }
    '''
    find_all_meshes = '''
            function(doc)
            {
              if(doc.session_id == "%s")
                  emit('session_id',doc.session_id);
            }
    '''
    objects = object_recognition_db.run_view(db_url, 'objects', find_all_objects)
    
    sessions_to_do = []
    for object in objects:
        print object
        sessions = object_recognition_db.run_view(db_url, 'sessions', find_all_sessions % object[0])
        for session in sessions:
            print session
            meshes = object_recognition_db.run_view(db_url, 'meshes', find_all_meshes % session[0])
            if len(meshes) == 0: #we haven't yet computed a mesh.
                sessions_to_do.append((object[0], session[0]))
    return sessions_to_do
def find_object_id(session_id):
    db_url = 'http://localhost:5984'

    find_object_id = '''
    function(doc)
    {
      if(doc.session_id == "%s")
          emit('object_id',doc.object_id);
    }
    '''
    objects = object_recognition_db.run_view(db_url, 'sessions', find_object_id % session_id)
    print objects
    if len(objects) > 0:
        return objects[0][2].split('"')[1]
    else:
        raise "No object found with the given session:", session_id