-
Notifications
You must be signed in to change notification settings - Fork 0
/
langAnalysis.py
55 lines (51 loc) · 1.98 KB
/
langAnalysis.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
import json
import os
resPath = "cases.json"
# outputPath = "langAnalysis.json"
pyPercentPath = "pyPercent.json"
# typePath="type.json"
dir_name = "cases"
f = open(resPath, encoding='utf-8')
# outputFile = open(outputPath, "w", encoding='utf-8')
pyPercentFile = open(pyPercentPath, "w", encoding='utf-8')
# typeFile=open(typePath,"w",encoding='utf-8')
res = f.read()
data = json.loads(res)
result_dict = {}
pyPercent_dict = {}
type_dict={}
no_py_count = 0
for case in data:
print(case)
result_dict.setdefault(case, {"case_id": int(case)})
case_dict = result_dict[case]
case_dict["case_num"] = 0
case_dict["languages"] = {}
case_dir_str = os.path.join(dir_name, case)
result_dir_str = os.path.join(case_dir_str, "results")
result_dir = os.listdir(result_dir_str)
for result in result_dir:
result_str = os.path.join(result_dir_str, result)
if os.path.isdir(result_str):
properties_str = os.path.join(result_str, "properties")
properties_file = open(properties_str, encoding='utf-8')
properties_json = json.loads(properties_file.read())
lang = properties_json["lang"]
if lang not in case_dict["languages"]:
lang_count = 1
else:
lang_count = case_dict["languages"][lang] + 1
case_dict["languages"][lang] = lang_count
case_dict["case_num"] = case_dict["case_num"] + 1
py_count = 0
for language in case_dict["languages"]:
if language == "Python3" or language == "Python":
py_count = py_count + case_dict["languages"][language]
else:
no_py_count = no_py_count + case_dict["languages"][language]
py_percent = py_count / case_dict["case_num"]
case_dict["py_percent"] = py_percent
pyPercent_dict.setdefault(case, py_percent)
type_dict[case]=data[case]["user_records"][0]["case_type"]
result_dict.setdefault("not_py_count", no_py_count)
json.dump(pyPercent_dict,pyPercentFile,sort_keys=True)