Spaces:
Running
Running
import json | |
with open("sub_mbpp.json","r",encoding="utf-8") as f: | |
data = json.load(f) | |
# token_counts=[25,25,25,25] | |
# token_counts_I=token_counts[0]*0.01*974 | |
# token_counts_II=token_counts[1]*0.01*974 | |
# token_counts_III=token_counts[2]*0.01*974 | |
# token_counts_IV=token_counts[3]*0.01*974 | |
# | |
# | |
# | |
# cyclomatic_complexity=[25,25,25,25] | |
# cyclomatic_complexity_I=cyclomatic_complexity[0]*0.01*974 | |
# cyclomatic_complexity_II=cyclomatic_complexity[1]*0.01*974 | |
# cyclomatic_complexity_III=cyclomatic_complexity[2]*0.01*974 | |
# cyclomatic_complexity_IV=cyclomatic_complexity[3]*0.01*974 | |
token_counts=[25,25,25,25] | |
token_counts_I=token_counts[0]*0.01*500 | |
token_counts_II=token_counts[1]*0.01*500 | |
token_counts_III=token_counts[2]*0.01*500 | |
token_counts_IV=token_counts[3]*0.01*500 | |
cyclomatic_complexity=[25,25,25,25] | |
cyclomatic_complexity_I=cyclomatic_complexity[0]*0.01*500 | |
cyclomatic_complexity_II=cyclomatic_complexity[1]*0.01*500 | |
cyclomatic_complexity_III=cyclomatic_complexity[2]*0.01*500 | |
cyclomatic_complexity_IV=cyclomatic_complexity[3]*0.01*500 | |
data.sort(key=lambda x: x['token']) | |
for i, item in enumerate(data): | |
if i < token_counts_I: | |
item['token_diff'] = 0 | |
elif i < token_counts_I + token_counts_II: | |
item['token_diff'] = 1 | |
elif i < token_counts_I + token_counts_II+token_counts_III: | |
item['token_diff'] = 2 | |
else: | |
item['token_diff'] = 3 | |
data.sort(key=lambda x: x['cc']) | |
for i, item in enumerate(data): | |
if i < cyclomatic_complexity_I: | |
item['CC_diff'] = 0 | |
elif i < cyclomatic_complexity_I + cyclomatic_complexity_II: | |
item['CC_diff'] = 1 | |
elif i < cyclomatic_complexity_I + cyclomatic_complexity_II+cyclomatic_complexity_III: | |
item['CC_diff'] = 2 | |
else: | |
item['CC_diff'] = 3 | |
data.sort(key=lambda x: x['id']) | |
# 将更新后的数据写回JSON文件 | |
with open('QS.json', 'w', encoding='utf-8') as file: | |
json.dump(data, file, ensure_ascii=False, indent=4) | |