Example #1
0
def collect_course_forums_data(course_id):
    """
    Given a SlashSeparatedCourseKey course_id, return headers and information
    related to course forums usage such as upvotes, downvotes, and number of posts
    """
    try:
        client = MongoClient(get_mongo_connection_string())
        mongodb = client[FORUMS_MONGO_PARAMS['database']]
        new_threads_query = generate_course_forums_query(course_id, "CommentThread")
        new_responses_query = generate_course_forums_query(course_id, "Comment", False)
        new_comments_query = generate_course_forums_query(course_id, "Comment", True)

        new_threads = mongodb.contents.aggregate(new_threads_query)['result']
        new_responses = mongodb.contents.aggregate(new_responses_query)['result']
        new_comments = mongodb.contents.aggregate(new_comments_query)['result']
    except PyMongoError:
        raise

    for entry in new_responses:
        entry['_id']['type'] = "Response"
    results = merge_join_course_forums(new_threads, new_responses, new_comments)
    parsed_results = [
        [
            "{0}-{1}-{2}".format(result['_id']['year'], result['_id']['month'], result['_id']['day']),
            result['_id']['type'],
            result['posts'],
            result['up_votes'],
            result['down_votes'],
            result['net_points'],
        ]
        for result in results
    ]
    header = ['Date', 'Type', 'Number', 'Up Votes', 'Down Votes', 'Net Points']
    return header, parsed_results
 def setUp(self):
     """
     load a user and comment into the db for testing purposes
     """
     client = MongoClient(get_mongo_connection_string())
     self.db = client[MONGO_PARAMS['database']]
     self.mongo_user_id = None
     self.mongo_comment_id = None
     self.sql_user = UserFactory.create()
     self.rename_cmd = rename_user.Command()
     self.seed_mongo_comment()
     self.seed_mongo_user()
Example #3
0
 def setUp(self):
     """
     load a user and comment into the db for testing purposes
     """
     client = MongoClient(get_mongo_connection_string())
     self.db = client[MONGO_PARAMS['database']]
     self.mongo_user_id = None
     self.mongo_comment_id = None
     self.sql_user = UserFactory.create()
     self.rename_cmd = rename_user.Command()
     self.seed_mongo_comment()
     self.seed_mongo_user()
 def setUp(self):
     """
     loads 2 users and 2 comments (1 per user)
     """
     client = MongoClient(get_mongo_connection_string())
     self.db = client[MONGO_PARAMS['database']]
     # maintain arrays of mongo data so that we can delete them when the tests finish
     self.mongo_user_ids = []
     self.mongo_comment_ids = []
     self.sql_users = []
     self.seed_sql_users()
     self.seed_mongo_comments()
     self.seed_mongo_users()
 def setUp(self):
     """
     loads 2 users and 2 comments (1 per user)
     """
     client = MongoClient(get_mongo_connection_string())
     self.db = client[MONGO_PARAMS['database']]
     # maintain arrays of mongo data so that we can delete them when the tests finish
     self.mongo_user_ids = []
     self.mongo_comment_ids = []
     self.sql_users = []
     self.seed_sql_users()
     self.seed_mongo_comments()
     self.seed_mongo_users()
Example #6
0
def collect_student_forums_data(course_id):
    """
    Given a SlashSeparatedCourseKey course_id, return headers and information
    related to student forums usage
    """
    try:
        client = MongoClient(get_mongo_connection_string())
        mongodb = client[FORUMS_MONGO_PARAMS['database']]
        student_forums_query = generate_student_forums_query(course_id)
        results = mongodb.contents.aggregate(student_forums_query)['result']
    except PyMongoError:
        raise
    parsed_results = [[
        result['_id'],
        result['posts'],
        result['votes'],
    ] for result in results]
    header = ['Username', 'Posts', 'Votes']
    return header, parsed_results
Example #7
0
def collect_student_forums_data(course_id):
    """
    Given a SlashSeparatedCourseKey course_id, return headers and information
    related to student forums usage
    """
    try:
        client = MongoClient(get_mongo_connection_string())
        mongodb = client[FORUMS_MONGO_PARAMS['database']]
        student_forums_query = generate_student_forums_query(course_id)
        results = mongodb.contents.aggregate(student_forums_query)['result']
    except PyMongoError:
        raise

    parsed_results = [
        [
            result['_id'],
            result['posts'],
            result['votes'],
        ] for result in results
    ]
    header = ['Username', 'Posts', 'Votes']
    return header, parsed_results
Example #8
0
def collect_course_forums_data(course_id):
    """
    Given a SlashSeparatedCourseKey course_id, return headers and information
    related to course forums usage such as upvotes, downvotes, and number of posts
    """
    def merge_join_course_forums(threads, responses, comments):
        """
        Performs a merge of sorted threads, responses, comments data
        interleaving the results so the final result is in chronological order
        """
        data = []
        t_index, r_index, c_index = 0, 0, 0
        while (t_index < len(threads) or r_index < len(responses)
               or c_index < len(comments)):
            # checking out of bounds
            if t_index == len(threads):
                thread_date = date.max
            else:
                thread = threads[t_index]['_id']
                thread_date = date(thread["year"], thread["month"],
                                   thread["day"])
            if r_index == len(responses):
                response_date = date.max
            else:
                response = responses[r_index]["_id"]
                response_date = date(response["year"], response["month"],
                                     response["day"])
            if c_index == len(comments):
                comment_date = date.max
            else:
                comment = comments[c_index]["_id"]
                comment_date = date(comment["year"], comment["month"],
                                    comment["day"])

            if thread_date <= comment_date and thread_date <= response_date:
                data.append(threads[t_index])
                t_index += 1
                continue
            elif response_date <= thread_date and response_date <= comment_date:
                data.append(responses[r_index])
                r_index += 1
                continue
            else:
                data.append(comments[c_index])
                c_index += 1
        return data

    try:
        client = MongoClient(get_mongo_connection_string())
        mongodb = client[FORUMS_MONGO_PARAMS['database']]
        new_threads_query = generate_course_forums_query(
            course_id, "CommentThread")
        new_responses_query = generate_course_forums_query(
            course_id, "Comment", False)
        new_comments_query = generate_course_forums_query(
            course_id, "Comment", True)
        new_threads = mongodb.contents.aggregate(new_threads_query)['result']
        new_responses = mongodb.contents.aggregate(
            new_responses_query)['result']
        new_comments = mongodb.contents.aggregate(new_comments_query)['result']
    except PyMongoError:
        raise
    for entry in new_responses:
        entry['_id']['type'] = "Response"
    results = merge_join_course_forums(new_threads, new_responses,
                                       new_comments)
    parsed_results = [[
        "{0}-{1}-{2}".format(result['_id']['year'], result['_id']['month'],
                             result['_id']['day']),
        result['_id']['type'],
        result['posts'],
        result['votes'],
    ] for result in results]
    header = ['Date', 'Activity Type', 'Number New', 'Votes']
    return header, parsed_results
Example #9
0
def collect_course_forums_data(course_id):
    """
    Given a SlashSeparatedCourseKey course_id, return headers and information
    related to course forums usage such as upvotes, downvotes, and number of posts
    """
    def merge_join_course_forums(threads, responses, comments):
        """
        Performs a merge of sorted threads, responses, comments data
        interleaving the results so the final result is in chronological order
        """
        data = []
        t_index, r_index, c_index = 0, 0, 0
        while (t_index < len(threads) or r_index < len(responses) or c_index < len(comments)):
            # checking out of bounds
            if t_index == len(threads):
                thread_date = date.max
            else:
                thread = threads[t_index]['_id']
                thread_date = date(thread["year"], thread["month"], thread["day"])
            if r_index == len(responses):
                response_date = date.max
            else:
                response = responses[r_index]["_id"]
                response_date = date(response["year"], response["month"], response["day"])
            if c_index == len(comments):
                comment_date = date.max
            else:
                comment = comments[c_index]["_id"]
                comment_date = date(comment["year"], comment["month"], comment["day"])

            if thread_date <= comment_date and thread_date <= response_date:
                data.append(threads[t_index])
                t_index += 1
                continue
            elif response_date <= thread_date and response_date <= comment_date:
                data.append(responses[r_index])
                r_index += 1
                continue
            else:
                data.append(comments[c_index])
                c_index += 1
        return data

    try:
        client = MongoClient(get_mongo_connection_string())
        mongodb = client[FORUMS_MONGO_PARAMS['database']]
        new_threads_query = generate_course_forums_query(course_id, "CommentThread")
        new_responses_query = generate_course_forums_query(course_id, "Comment", False)
        new_comments_query = generate_course_forums_query(course_id, "Comment", True)
        new_threads = mongodb.contents.aggregate(new_threads_query)['result']
        new_responses = mongodb.contents.aggregate(new_responses_query)['result']
        new_comments = mongodb.contents.aggregate(new_comments_query)['result']
    except PyMongoError:
        raise
    for entry in new_responses:
        entry['_id']['type'] = "Response"
    results = merge_join_course_forums(new_threads, new_responses, new_comments)
    parsed_results = [
        [
            "{0}-{1}-{2}".format(result['_id']['year'], result['_id']['month'], result['_id']['day']),
            result['_id']['type'],
            result['posts'],
            result['votes'],
        ]
        for result in results
    ]
    header = ['Date', 'Activity Type', 'Number New', 'Votes']
    return header, parsed_results