Exemple #1
0
def create_practice_sessions(collection_folders, collection_exercises):
    """
    Create a randomized practice session for all folders and corresponding exercises present in the DB.

    :param collection_folders:      The MongoDB 'folders' collection reference.
    :param collection_exercises:    The MongoDB 'exercises' collection reference.
    :return:
    """

    all_folders = Folder.get_all_folders(collection_folders)

    for folder in all_folders:
        folder_exercises = folder['exercises']

        for each_exercise_id in folder_exercises:
            # print "Adding a practice session to %s" % each_exercise_id
            today = datetime.utcnow()

            for i in range(10, -1, -1):
                practice_session_date = today - timedelta(i)
                updated_exercise = Exercise.add_practice_session(collection_exercises,
                                                                 each_exercise_id,
                                                                 practice_session_date)
                ex_latest_session = updated_exercise['history'][-1]
                folder = Folder.update_folder_with_practice_session(collection_folders,
                                                                    folder,
                                                                    ex_latest_session,
                                                                    updated_exercise['lastPracticeTime'])
Exemple #2
0
def create_folders_and_exercises(collection_folders, collection_exercises, folders_exercises_to_create, stack):
    """
    Create all Folders and Exercises in these Folders as specified by the parameters: folders_exercises_to_create & stack

    :param collection_folders:          The MongoDB 'folders' collection reference.
    :param collection_exercises:        The MongoDB 'exercises' collection reference.
    :param folders_exercises_to_create: A dictionary of folders and corresponding exercises to create.
    :param stack:                       The parent stack to which all the folders.
    :return:
    """

    for folder_name in folders_exercises_to_create.keys():
        print "Creating Folder: %s" % folder_name
        folder_created = Folder.create_folder(collection_folders, folder_name, stack)
        print "Done!"

        if folder_created.acknowledged:
            exercises = folders_exercises_to_create.get(folder_name)
            print "-- Creating exercises: %s" % exercises
            Exercise.create_exercises_in_folder(collection_exercises, collection_folders, exercises,
                                                folder_created.inserted_id)
            print "Done!"

        else:
            print "Folder %s was not created successfully." % folder_name