コード例 #1
0
def get_pp_breakdown(user, start=0, end=100):
    cursor = connection.cursor()
    cursor.execute(
        '''
        SELECT max_points_table.problem_code,
               max_points_table.problem_name,
               max_points_table.max_points,
               judge_submission.date,
               judge_submission.case_points,
               judge_submission.case_total,
               judge_submission.result,
               judge_language.short_name,
               judge_language.key
        FROM judge_submission
        JOIN (SELECT judge_problem.id problem_id,
                     judge_problem.name problem_name,
                     judge_problem.code problem_code,
                     MAX(judge_submission.points) AS max_points
            FROM judge_problem
            INNER JOIN judge_submission ON (judge_problem.id = judge_submission.problem_id)
            WHERE (judge_problem.is_public = True AND
                   judge_submission.points IS NOT NULL AND
                   judge_submission.user_id = %s)
            GROUP BY judge_problem.id
            HAVING MAX(judge_submission.points) > 0.0) AS max_points_table
        ON (judge_submission.problem_id = max_points_table.problem_id AND
            judge_submission.points = max_points_table.max_points AND
            judge_submission.user_id = %s)
        JOIN judge_language
        ON judge_submission.language_id = judge_language.id
        GROUP BY max_points_table.problem_id
        ORDER BY max_points DESC, judge_submission.date DESC
    ''', (user.id, user.id))
    data = cursor.fetchall()
    cursor.close()

    breakdown = []
    for weight, contrib in zip(PP_WEIGHT_TABLE[start:end], data[start:end]):
        code, name, points, date, case_points, case_total, result, lang_short_name, lang_key = contrib

        # Replicates a lot of the logic usually done on Submission objects
        lang_short_display_name = lang_short_name or lang_key
        result_class = Submission.result_class_from_code(
            result, case_points, case_total)
        long_status = Submission.USER_DISPLAY_CODES.get(result, '')

        breakdown.append(
            PPBreakdown(points=points,
                        weight=weight * 100,
                        scaled_points=points * weight,
                        problem_name=name,
                        problem_code=code,
                        sub_date=date,
                        sub_points=case_points,
                        sub_total=case_total,
                        sub_short_status=result,
                        sub_long_status=long_status,
                        sub_result_class=result_class,
                        sub_lang=lang_short_display_name))
    has_more = end < min(len(PP_WEIGHT_TABLE), len(data))
    return breakdown, has_more
コード例 #2
0
ファイル: performance_points.py プロジェクト: DMOJ/site
def get_pp_breakdown(user, start=0, end=PP_ENTRIES):
    with connection.cursor() as cursor:
        cursor.execute('''
            SELECT max_points_table.problem_code,
                   max_points_table.problem_name,
                   max_points_table.max_points,
                   judge_submission.id,
                   judge_submission.date,
                   judge_submission.case_points,
                   judge_submission.case_total,
                   judge_submission.result,
                   judge_language.short_name,
                   judge_language.key
            FROM judge_submission
            JOIN (SELECT judge_problem.id problem_id,
                         judge_problem.name problem_name,
                         judge_problem.code problem_code,
                         MAX(judge_submission.points) AS max_points
                FROM judge_problem
                INNER JOIN judge_submission ON (judge_problem.id = judge_submission.problem_id)
                WHERE (judge_problem.is_public = True AND
                       judge_problem.is_organization_private = False AND
                       judge_submission.points IS NOT NULL AND
                       judge_submission.user_id = %s)
                GROUP BY judge_problem.id
                HAVING MAX(judge_submission.points) > 0.0) AS max_points_table
            ON (judge_submission.problem_id = max_points_table.problem_id AND
                judge_submission.points = max_points_table.max_points AND
                judge_submission.user_id = %s)
            JOIN judge_language
            ON judge_submission.language_id = judge_language.id
            GROUP BY max_points_table.problem_id
            ORDER BY max_points DESC, judge_submission.date DESC
            LIMIT %s OFFSET %s
        ''', (user.id, user.id, end - start + 1, start))
        data = cursor.fetchall()

    breakdown = []
    for weight, contrib in zip(PP_WEIGHT_TABLE[start:end], data):
        code, name, points, id, date, case_points, case_total, result, lang_short_name, lang_key = contrib

        # Replicates a lot of the logic usually done on Submission objects
        lang_short_display_name = lang_short_name or lang_key
        result_class = Submission.result_class_from_code(result, case_points, case_total)
        long_status = Submission.USER_DISPLAY_CODES.get(result, '')

        breakdown.append(PPBreakdown(
            points=points,
            weight=weight * 100,
            scaled_points=points * weight,
            problem_name=name,
            problem_code=code,
            sub_id=id,
            sub_date=from_database_time(date),
            sub_points=case_points,
            sub_total=case_total,
            sub_short_status=result,
            sub_long_status=long_status,
            sub_result_class=result_class,
            sub_lang=lang_short_display_name,
        ))
    has_more = end < min(len(PP_WEIGHT_TABLE), start + len(data))
    return breakdown, has_more