def get_top_submissions(course_id, item_id, item_type, number_of_top_scores, use_cache=True, read_replica=True):
if number_of_top_scores < <NUM_LIT:1> or number_of_top_scores > MAX_TOP_SUBMISSIONS:<EOL><INDENT>error_msg = (<EOL>u"<STR_LIT>".format(MAX_TOP_SUBMISSIONS)<EOL>)<EOL>logger.exception(error_msg)<EOL>raise SubmissionRequestError(msg=error_msg)<EOL><DEDENT>cache_key = "<STR_LIT>".format(<EOL>course=course_id,<EOL>item=item_id,<EOL>type=item_type,<EOL>number=number_of_top_scores<EOL>)<EOL>top_submissions = cache.get(cache_key) if use_cache else None<EOL>if top_submissions is None:<EOL><INDENT>try:<EOL><INDENT>query = ScoreSummary.objects.filter(<EOL>student_item__course_id=course_id,<EOL>student_item__item_id=item_id,<EOL>student_item__item_type=item_type,<EOL>latest__points_earned__gt=<NUM_LIT:0><EOL>).select_related('<STR_LIT>', '<STR_LIT>').order_by("<STR_LIT>")<EOL>if read_replica:<EOL><INDENT>query = _use_read_replica(query)<EOL><DEDENT>score_summaries = query[:number_of_top_scores]<EOL><DEDENT>except DatabaseError:<EOL><INDENT>msg = u"<STR_LIT>".format(<EOL>course_id, item_id, item_type<EOL>)<EOL>logger.exception(msg)<EOL>raise SubmissionInternalError(msg)<EOL><DEDENT>top_submissions = [<EOL>{<EOL>"<STR_LIT>": score_summary.latest.points_earned,<EOL>"<STR_LIT:content>": SubmissionSerializer(score_summary.latest.submission).data['<STR_LIT>']<EOL>}<EOL>for score_summary in score_summaries<EOL>]<EOL>cache.set(cache_key, top_submissions, TOP_SUBMISSIONS_CACHE_TIMEOUT)<EOL><DEDENT>return top_submissions<EOL>
Get a number of top scores for an assessment based on a particular student item

    This function will return top scores for the piece of assessment.
    It will consider only the latest and greater than 0 score for a piece of assessment.
    A score is only calculated for a student item if it has completed the workflow for
    a particular assessment module.

    In general, users of top submissions can tolerate some latency
    in the search results, so by default this call uses
    a cache and the read replica (if available).

    Args:
        course_id (str): The course to retrieve for the top scores
        item_id (str): The item within the course to retrieve for the top scores
        item_type (str): The type of item to retrieve
        number_of_top_scores (int): The number of scores to return, greater than 0 and no
        more than 100.

    Kwargs:
        use_cache (bool): If true, check the cache before retrieving querying the database.
        read_replica (bool): If true, attempt to use the read replica database.
            If no read replica is available, use the default database.

    Returns:
        topscores (dict): The top scores for the assessment for the student item.
            An empty array if there are no scores or all scores are 0.

    Raises:
        SubmissionNotFoundError: Raised when a submission cannot be found for
            the associated student item.
        SubmissionRequestError: Raised when the number of top scores is higher than the
            MAX_TOP_SUBMISSIONS constant.

    Examples:
        >>> course_id = "TestCourse"
        >>> item_id = "u_67"
        >>> item_type = "openassessment"
        >>> number_of_top_scores = 10
        >>>
        >>> get_top_submissions(course_id, item_id, item_type, number_of_top_scores)
        [{
            'score': 20,
            'content': "Platypus"
        },{
            'score': 16,
            'content': "Frog"
        }]