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]) #