完成了脚本的修改

This commit is contained in:
zhangxunhui 2022-08-28 11:46:32 +08:00
parent bdc4b97a2e
commit b05f05ca69
1 changed files with 65 additions and 40 deletions

View File

@ -1,7 +1,6 @@
from collections import Counter
import re
from typing import Dict, List, Tuple
import GlobalConstants
from FileOperator import FileOperator
from models.RepoInfo import RepoInfo
from MySQLOperator import MySQLOperator
@ -231,27 +230,39 @@ class RiskEvaluator(object):
# get CCR
# Find consistent_changes in all changes
change_pair_id_1 = []
change_pair_id_2 = []
if sum_changes <= 1:
consistent_changes = 0
else:
change_list_1 = []
change_list_2 = []
consistent_changes = 0
for change in result_changes_1:
change_list_1.append((change[2], change[3]))
for change in result_changes_2:
change_list_2.append((change[2], change[3]))
for i in range(len(change_list_1)):
for j in range(len(change_list_2)):
if change_list_1[i] == change_list_2[j]:
change_pair_id_1.append(i)
change_pair_id_2.append(j)
consistent_changes = consistent_changes + 2
consistent_change_list1 = []
consistent_change_list2 = []
consistent_changes = 0
for change_1 in result_changes_1:
for change_2 in result_changes_2:
if change_1[2] == change_2[2] and change_1[3] == change_2[3]:
consistent_change_list1.append(change_1)
consistent_change_list2.append(change_2)
consistent_changes = consistent_changes + 2
# get CCL
# Find Latency in different commits
def get_commit_change_by_method_change(
method_old: int, method_new: int, method_commit_dict: dict
) -> List[Tuple[int, int]]:
"""
Function: get the change of commits via the change of methods
return:
- [(
commit_old,
commit_new
)]
"""
result = []
commits_old = method_commit_dict[method_old]
commits_new = method_commit_dict[method_new]
for commit_old in commits_old:
children_old = commit_children_dict[commit_old]
intersect_commits = set(children_old) & set(commits_new)
for commit_id in intersect_commits:
result.append((commit_old, commit_id))
return result
consistent_change_list1 = []
consistent_change_list2 = []
target_commits = []
@ -259,21 +270,33 @@ class RiskEvaluator(object):
CCL = 0
else:
CCL = 0
for id in change_pair_id_1:
consistent_change_list1.append(result_changes_1[id])
for id in change_pair_id_2:
consistent_change_list2.append(result_changes_2[id])
for i in range(len(consistent_change_list1)):
consistent_changed_method_1 = consistent_change_list1[i]
consistent_changed_method_2 = consistent_change_list2[i]
commit_target_1 = consistent_changed_method_1.get("commmit_id")
commit_target_2 = consistent_changed_method_2.get("commmit_id")
if commit_target_1 == commit_target_2:
CCL = 0
else:
target_commits.append(commit_target_1)
target_commits.append(commit_target_2)
CCL = CCL + 1
change_1 = consistent_change_list1[i]
change_2 = consistent_change_list2[i]
method_old_1 = change_1[0]
method_new_1 = change_1[1]
method_old_2 = change_2[0]
method_new_2 = change_2[1]
commit_changes_1 = get_commit_change_by_method_change(
method_old=method_old_1,
method_new=method_new_1,
method_commit_dict=method_commit_dict_1,
)
commit_changes_2 = get_commit_change_by_method_change(
method_old=method_old_2,
method_new=method_new_2,
method_commit_dict=method_commit_dict_2,
)
consistent_change_commit_paths = list(
set(commit_changes_1) & set(commit_changes_2)
)
CCL += len(consistent_change_commit_paths)
target_commits = list(
set([path[1] for path in consistent_change_commit_paths])
)
# get bug_fix_num
if CCL == 0:
@ -287,13 +310,15 @@ class RiskEvaluator(object):
tablename1=commits, id=commit
)
mysqlOp.cursor.execute(sql_message)
messages = mysqlOp.cursor.fetchall()
for message in messages:
keywords = (
message.get("message").decode().replace("\n", " ").split()
message = mysqlOp.cursor.fetchone()["message"].lower()
if (
re.search(
rb"(close|closes|closed|fix|fixes|fixed|resolve|resolves|resolved)\s+.*?#\d+",
message,
)
if "fix" in keywords or "Fix" in keywords:
bug_fix_num = bug_fix_num + 1
is not None
):
bug_fix_num += 1
def Harmness_Evaluating(CpI: int, CCR: int, CCL: int, bug_fix_num: int) -> int:
"""