-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstatistics.py
executable file
·60 lines (49 loc) · 1.59 KB
/
statistics.py
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
import torch
import random
import numpy as np
import re
import subprocess
import gzip
import json
import os
import argparse
from codegeex.data.data_utils import write_jsonl
from tqdm import tqdm
'''def extract_generation_code(message):
if re.findall(f'(?is)```(.*)```', message):
raw_code = re.findall(f'(?is)```(.*)```', message)[0]
start = raw_code.find('{')
end = raw_code.rfind('}')
code = raw_code[start+1:end+1]+'\n'
else:
code = message
return code'''
def extract_generation_code(raw_code):
if not raw_code:
return " "
start = raw_code.find('{')
end = raw_code.rfind('}')
code = raw_code[start+1:end+1]+'\n'
if "int main()" in code:
main_start = code.index("int main()")
code = code[:main_start]
return code
def main(path):
passed = []
failed = []
with open(os.path.join(path, 'samples_results.jsonl'), 'r') as f:
for line in tqdm(f):
line = json.loads(line)
state = line['result']
task_id = line['task_id']
if state == "passed":
passed.append(task_id)
else:
failed.append(failed)
write_jsonl(os.path.join(path, 'samples_new.jsonl'), samples)
if __name__=="__main__":
parser = argparse.ArgumentParser(description="Using different models to generate function")
parser.add_argument("--lang", default="c++", choices=['c++','python','java'])
parser.add_argument("--path", default="../output", help="output path")
args = parser.parse_args()
main(args.path)