-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
77 lines (60 loc) · 1.82 KB
/
test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# # import subprocess
# # import tempfile
# # import os
# # import re
# # import myers
# # def get_similarity_index(old: str, new: str) -> tuple[str, float]:
# # def get_lines(text: str) -> list[str]:
# # return text.replace('\r\n', '\n').strip().splitlines()
# # def get_changes(old: list[str], new: list[str]) -> list[tuple[str, str]]:
# # changes = myers.diff(old, new)
# # return changes
# # old_lines = get_lines(old)
# # new_lines = get_lines(new)
# # changes = get_changes(old_lines, new_lines)
# # print(changes)
# # num_unchanged_lines = sum(1 for op, _ in changes if op == 'k')
# # # Calculate similarity
# # total_lines = len(old_lines) + len(new_lines)
# # if total_lines == 0:
# # similarity = 100.0
# # else:
# # similarity = round(2 * num_unchanged_lines / total_lines * 100, 2)
# # return similarity
# # # Example usage
# # code1 = """
# # def hello():
# # print("Hello, World!")
# # return True
# # """
# # code2 = """
# # def hello():
# # print("Hello, Python!")
# # return True
# # """
# # similarity = get_similarity_index(code1, code2)
# # print(f"Similarity index: {similarity}%")
# # # Test with more different codes
# # code3 = """
# # def calculate(x, y):
# # return x + y
# # """
# # code4 = """
# # def multiply(a, b):
# # return a * b
# # """
# # similarity2 = get_similarity_index(code3, code4)
# # print(f"Similarity index for different functions: {similarity2}%")
# import pandas as pd
# df = pd.read_csv("data/migrations_36_file_version.csv")
# print(df.info())
# import difflib
# # Example usage:
# old_code = """def hello():
# print("Hello")
# return True"""
# new_code = """def hello():
# print("Hello, World!")
# return True
# """
# compare_code_snippets(old_code, new_code)