compare_solutions.py 文件源码

python
阅读 24 收藏 0 点赞 0 评论 0

项目:Odin 作者: HackSoftware 项目源码 文件源码
def compare_file_solutions(first_solution, second_solution):
    current_code = first_solution.file.read().decode('utf-8').splitlines()
    next_code = second_solution.file.read().decode('utf-8').splitlines()

    # Reset file pointers
    first_solution.file.seek(0)
    second_solution.file.seek(0)

    diff_percentage, unified_diff = calculate_difference_percentage(current_code, next_code)

    result = ""
    if diff_percentage < MIN_ALLOWED_DIFFERENCE_PERCENTAGE:
        result = f"""
        Matching contents in files
        {first_solution.file.name} from {first_solution.student.email} and
        {second_solution.file.name} from {second_solution.student.email}
        on Task: {first_solution.task.name}
        Differences: {diff_percentage}%\n
        """
        for line in unified_diff:
            result += line + '\n'

    return result
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号