-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcount_control.py
More file actions
58 lines (52 loc) · 1.66 KB
/
count_control.py
File metadata and controls
58 lines (52 loc) · 1.66 KB
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
import json
with open("./data/testset_staticsliced_hop3.json") as f:
data = json.load(f)
with open("./data/testset_transformed.json") as f:
simple_data = json.load(f)
def count_occurrences(main_string, sub_string):
count = 0
start_index = 0
while True:
# Find the next occurrence of sub_string starting from start_index
index = main_string.find(sub_string, start_index)
# If sub_string is found
if index != -1:
# Increment count
count += 1
# Update start_index to search for next occurrence
start_index = index + 1
else:
# If sub_string is not found, break the loop
break
return count
total = 0
total_dayuer = 0
zero = 0
for r, value in data.items():
r1 = r
zero = zero + 1
#if zero == 500:
#break;
split_info = r.rsplit(".py", 1)
r = {
"file": split_info[0] + ".py",
"loc": split_info[1][2:].split("--")[0],
"name": split_info[1][2:].split("--")[1],
"scope": split_info[1][2:].split("--")[2]
}
key = '{}--{}--{}--{}'.format(r["file"], r["loc"], r["name"], r["scope"])
name = r["name"]
scope = r["scope"]
loc = r["loc"]
filename = r["file"]
#if simple_data[r1][2]!= 'user-defined' and simple_data[r1][2]!= 'simple':
try:
#occurrences = count_occurrences(value, name + ' =')
occurrences = count_occurrences(value, " if ")
if occurrences >=1:
#print(r1)
total_dayuer = total_dayuer + 1
total = total + 1
except:
pass
print(total_dayuer/total)