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
评论列表
文章目录