File size: 3,838 Bytes
dfe37be
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
import json
import os
import csv
# 定义文件所在的目录
input_dir = 'E:\python-testn\pythonProject3\hh_1\evaluate_result'

# 获取目录中的所有文件
files = os.listdir(input_dir)

# with open("token_counts_QS.csv","w", newline='') as csvfile:
#     writer = csv.writer(csvfile)
#     writer.writerow(["Model", "token_subset_1", "token_subset_2","token_subset_3"])


# with open("line_counts_QS.csv","w", newline='') as csvfile:
#     writer = csv.writer(csvfile)
#     writer.writerow(["Model", "line_subset_1", "line_subset_2","line_subset_3"])

with open("CC_QS.csv", "w", newline='') as csvfile:
    writer = csv.writer(csvfile)
    writer.writerow(["Model", "CC_subset_1", "CC_subset_2","CC_subset_3"])



for file_name in files:
    # 构建完整的文件路径
    input_file_path = os.path.join(input_dir, file_name)
    first_underscore_index = file_name.find('_')

    # 找到最后一个 - 的位置
    last_dash_index = file_name.rfind('-')
    model_name = file_name[first_underscore_index + 1:last_dash_index]
    print(model_name)
    with open(input_file_path,"r",encoding="utf-8") as file:
        data1=json.load(file)

    with open("QS.json", "r", encoding="utf-8") as file:
        data2=json.load(file)
    sum0=0
    count0=0
    sum1=0
    count1=0
    sum2=0
    count2=0

    for (item1,item2) in zip(data1["humaneval"]["pass@1"],data2):
    #     #按照token个数划分后的评估结果
    #     if item2["token_diff"] == 0:
    #         index, value = item1
    #         print(item2["token_diff"],index,value)
    #         sum0=sum0+value
    #         count0=count0+1
    #     if item2["token_diff"] == 1:
    #         index, value = item1
    #         print(item2["token_diff"], index, value)
    #         sum1=sum1+value
    #         count1=count1+1
    #     if item2["token_diff"] == 2:
    #         index, value = item1
    #         print(item2["token_diff"], index, value)
    #         sum2=sum2+value
    #         count2=count2+1


        #按照行数划分后的评估结果
        # if item2["line_diff"] == 0:
        #     index, value = item1
        #     print(item2["line_diff"],index,value)
        #     sum0=sum0+value
        #     count0=count0+1
        # if item2["line_diff"] == 1:
        #     index, value = item1
        #     print(item2["line_diff"], index, value)
        #     sum1=sum1+value
        #     count1=count1+1
        # if item2["line_diff"] == 2:
        #     index, value = item1
        #     print(item2["line_diff"], index, value)
        #     sum2=sum2+value
        #     count2=count2+1

        #按照圈复杂度划分后的评估结果
        if item2["CC_diff"] == 0:
            index, value = item1
            print(item2["CC_diff"],index,value)
            sum0=sum0+value
            count0=count0+1
        if item2["CC_diff"] == 1:
            index, value = item1
            print(item2["CC_diff"], index, value)
            sum1=sum1+value
            count1=count1+1
        if item2["CC_diff"] == 2:
            index, value = item1
            print(item2["CC_diff"], index, value)
            sum2=sum2+value
            count2=count2+1



    mean0=round(sum0/count0*100,2)

    mean1=round(sum1/count1*100,2)
    mean2=round(sum2/count2*100,2)
    print("count_result!!")
    print(count0,count1,count2)
    print(mean0,mean1,mean2)
    # with open("token_counts_QS.csv", mode='a', newline='', encoding='utf-8') as file:
    #     writer = csv.writer(file)
    #     writer.writerow([model_name,mean0,mean1,mean2])
    with open("CC_QS.csv", mode='a', newline='', encoding='utf-8') as file:
        writer = csv.writer(file)
        writer.writerow([model_name,mean0,mean1,mean2])