Example #1
0
def rollback_to_structure_id(course_key, struct_id, verify_in_history=True):
    """
    Rollback a course to a previous structure version.
    Optionally verify that the structure is actually in the course's version history.
    Returns the new active_versions document.
    If no course branch is specified in the course_key, published-branch is assumed.
    If no course is found, raises CourseNotFound.
    If a history check is made and fails, raises VersionNotInHistory.
    If the update fails, raises RollbackFailed.
    """
    branch = course_key.branch or 'published-branch'
    if verify_in_history:
        history = get_structure_history(course_key.for_branch(branch))
        if struct_id not in history:
            raise VersionNotInHistory

    # Grab the current active version (and verify that the course exists).
    course_index = _get_active_versions(course_key)

    # Change the course's active version.
    course_index['versions'][branch] = struct_id
    course_index['last_update'] = datetime.datetime.now(pytz.utc)
    coll = get_collection('modulestore.active_versions')
    result = coll.update({'_id': course_index['_id']}, course_index, upsert=False)
    if result['nModified'] < 1:
        raise RollbackFailed("active_versions update failed.")
    return _get_active_versions(course_key)
Example #2
0
def get(polarity=False, display=False, synonyms=False):
    with mongo.get_collection('sentiments') as collection:
        for label in collection.find():
            result = [label['_id']]
            if polarity: result.append(label['polarity'])
            if display: result.append(label['display'])
            if synonyms: result.append(label['synonyms'])
            yield tuple(result)
Example #3
0
def get_courses():
    """
    Returns a list of CourseKeys for all Split courses from MongoDB.
    """
    coll = get_collection('modulestore.active_versions')
    courses = []
    for course in coll.find():
        courses.append(course)
    return courses
Example #4
0
def _get_active_versions(course_key):
    """
    Get the active versions document for a course.
    """
    coll = get_collection('modulestore.active_versions')
    return coll.find_one({
        'org': course_key.org,
        'course': course_key.course,
        'run': course_key.run,
    })
Example #5
0
def get_course_by_id(course_id):
    """
    Returns a split course from MongoDB.
    """
    coll = get_collection('modulestore.active_versions')
    courses = []
    course = coll.find_one(course_id)
    if not course:
        raise CourseNotFound
    return course
Example #6
0
def get_structure_by_key(course_key):
    """
    Returns structure id of current structure for a course branch.
    If no course branch is specified in the course_key, published-branch is assumed.
    If no course is found, raises CourseNotFound.
    """
    branch = course_key.branch or 'published-branch'
    coll = get_collection('modulestore.active_versions')
    course = coll.find_one({
        'org': course_key.org,
        'course': course_key.course,
        'run': course_key.run,
    })
    if course is None:
        raise CourseNotFound
    else:
        return course['versions'][branch]
Example #7
0
def get_structure_history_graph(course_key):
    """
    Returns a complete structure history graph for a course, including any dead branches.
    The return format is:
    Root structure id, {struct_id1: [child_struct_id1, child_struct_id2], struct_id2: [child_struct_id3], etc...}
    If no course branch is specified in the course_key, published-branch is assumed.
    If no course is found, raises CourseNotFound.
    """
    branch = course_key.branch or 'published-branch'
    history = get_structure_history(course_key.for_branch(branch))
    # Now iterate through the history and find all structures which claim each
    # structure as its previous version.
    coll = get_collection('modulestore.structures')
    nodes = {}
    for struct_id in history:
        all_children = coll.find({'previous_version': ObjectId(struct_id)}, projection=['_id'])
        nodes[str(struct_id)] = [str(c['_id']) for c in all_children]
    return {
        'root': [str(history[0])],
        'current': [str(history[-1])],
        'nodes': nodes,
    }
Example #8
0
    def grabAudioInfo(self, file_num):
        'grab audio file characteristics from db'

        if INTERNAL_ANIMATIONS_DB_INTER_DEBUG:
            print "grabbing audioInfo for TRACK: " + file_num

        if not RETURN_MOCK:
            files = mongo.get_collection()
            audioInfo = mongo.grab_audio_info(files, file_num)

            if INTERNAL_ANIMATIONS_DB_INTER_DEBUG:
                print "grab result: " + str(audioInfo)

            return audioInfo
        else:
            # MOCKED return vals
            if RETURN_MOCK_NEW_PROCESSING:
                if int(file_num) == 1:
                    audioInfo = None
                    audioInfo = AudioFileInfo("rain", 1, "MID")

                    e2 = AudioEvent(407, 3.9, "amplitude", "MID")
                    e4 = AudioEvent(7000, 4.6, "amplitude", "MID")

                    audioInfo.addEvent(e2)
                    audioInfo.addEvent(e4)
                elif int(file_num) == 2:
                    audioInfo = None
                    audioInfo = AudioFileInfo("thunder", 2, "LOW")

                    e2 = AudioEvent(450, 3.2, "amplitude", "LOW")
                    e4 = AudioEvent(2450, 5.4, "amplitude", "LOW")

                    audioInfo.addEvent(e2)
                    audioInfo.addEvent(e4)
                else:
                    audioInfo = None
                    audioInfo = AudioFileInfo("wind", 9, "MID")

                    e2 = AudioEvent(1450, 4.1, "amplitude", "MID")
                    e4 = AudioEvent(2450, 6.0, "amplitude", "MID")
                    e1 = AudioEvent(8450, 4.1, "amplitude", "MID")
                    e3 = AudioEvent(17450, 6.0, "amplitude", "MID")

                    audioInfo.addEvent(e1)
                    audioInfo.addEvent(e2)
                    audioInfo.addEvent(e3)
                    audioInfo.addEvent(e4)
            else:
                if int(file_num) == 1:
                    audioInfo = AudioFileInfo("rain", 1, "MID")

                    e1 = AudioEvent(4, -3, "freqband", "MID")
                    e2 = AudioEvent(47, 900, "amplitude", "MID")
                    e3 = AudioEvent(640, 1, "freqband", "MID")
                    e4 = AudioEvent(700, -1300, "amplitude", "MID")

                    audioInfo.addEvent(e1)
                    audioInfo.addEvent(e2)
                    audioInfo.addEvent(e3)
                    audioInfo.addEvent(e4)
                elif int(file_num) == 2:
                    audioInfo = AudioFileInfo("thunder", 2, "LOW")

                    e2 = AudioEvent(45, 2200, "amplitude", "LOW")
                    e1 = AudioEvent(60, 2, "freqband", "LOW")
                    e3 = AudioEvent(240, -3, "freqband", "LOW")
                    e4 = AudioEvent(245, -800, "amplitude", "LOW")

                    audioInfo.addEvent(e1)
                    audioInfo.addEvent(e2)
                    audioInfo.addEvent(e3)
                    audioInfo.addEvent(e4)
                else:
                    audioInfo = AudioFileInfo("wind", 9, "MID")
                    #    def __init__(self, time, degree, magnitude, kind):
                    e1 = AudioEvent(1, -6, "freqband", "MID")
                    e2 = AudioEvent(145, 800, "amplitude", "MID")
                    e3 = AudioEvent(240, 3, "freqband", "MID")
                    e4 = AudioEvent(245, -1600, "amplitude", "MID")

                    audioInfo.addEvent(e1)
                    audioInfo.addEvent(e2)
                    audioInfo.addEvent(e3)
                    audioInfo.addEvent(e4)

            return audioInfo
Example #9
0
def get_collection():
    return mongo.get_collection('terms')
Example #10
0
 def get_collection():
     return mongo.get_collection('administrators')
Example #11
0
def get_collection():
    return mongo.get_collection('subscriptions')
Example #12
0
 def __init__(self):
     self._col = mongo.get_collection("Report")
Example #13
0
 def get_collection():
     return mongo.get_collection('organizations')
Example #14
0
def get_collection():
    return mongo.get_collection('users')
Example #15
0
 def get_collection():
     return mongo.get_collection('system')
Example #16
0
 def get_collection():
     return mongo.get_collection('servers')
Example #17
0
def get_structure(struct_id):
    """
    Return the entire course structure as a dict.
    """
    coll = get_collection('modulestore.structures')
    return coll.find_one({'_id' : ObjectId(struct_id)})
Example #18
0
def init():
    with mongo.get_collection('sentiments') as collection:
        for doc in map(to_dict, models):
            collection.save(doc)