File size: 6,194 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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
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","token_subset_4","token_subset_5","token_subset_6"])


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","line_subset_4","line_subset_5","line_subset_6"])

# 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","CC_subset_4","CC_subset_5","CC_subset_6"])



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
    sum3 = 0
    count3 = 0
    sum4=0
    count4=0
    sum5 = 0
    count5 = 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["token_diff"] == 3:
    #         index, value = item1
    #         print(item2["token_diff"], index, value)
    #         sum3=sum3+value
    #         count3=count3+1
    #     if item2["token_diff"] == 4:
    #         index, value = item1
    #         print(item2["token_diff"], index, value)
    #         sum4 = sum4 + value
    #         count4 = count4 + 1
    #     if item2["token_diff"] ==5:
    #         index, value = item1
    #         print(item2["token_diff"], index, value)
    #         sum5 = sum5 + value
    #         count5 = count5 + 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["line_diff"] == 3:
            index, value = item1
            print(item2["line_diff"], index, value)
            sum3=sum3+value
            count3=count3+1
        if item2["line_diff"] == 4:
            index, value = item1
            print(item2["line_diff"], index, value)
            sum4=sum4+value
            count4=count4+1
        if item2["line_diff"] == 5:
            index, value = item1
            print(item2["line_diff"], index, value)
            sum5 = sum5 + value
            count5 = count5 + 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
        # if item2["CC_diff"] == 3 :
        #     index, value = item1
        #     print(item2["CC_diff"], index, value)
        #     sum3=sum3+value
        #     count3=count3+1
        # if item2["CC_diff"] == 4 :
        #     index, value = item1
        #     print(item2["CC_diff"], index, value)
        #     sum4=sum4+value
        #     count4=count4+1
        # if item2["CC_diff"] == 5 :
        #     index, value = item1
        #     print(item2["CC_diff"], index, value)
        #     sum5=sum5+value
        #     count5=count5+1



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

    mean1=round(sum1/count1*100,2)
    mean2=round(sum2/count2*100,2)
    mean3=round(sum3/count3*100,2)
    mean4=round(sum4/count4*100,2)
    mean5 = round(sum5 / count5 * 100, 2)
    print("count_result!!")
    print(count0,count1,count2,count3,count4,count5)
    print(mean0,mean1,mean2,mean3,count4,mean5)
    # 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,mean3,mean4,mean5])

    with open("line_counts_QS.csv", mode='a', newline='', encoding='utf-8') as file:
        writer = csv.writer(file)
        writer.writerow([model_name,mean0,mean1,mean2,mean3,mean4,mean5])
    #
    # with open("CC_QS.csv", mode='a', newline='', encoding='utf-8') as file:
    #     writer = csv.writer(file)
    #     writer.writerow([model_name,mean0,mean1,mean2,mean3,mean4,mean5])
    #