-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdouble_pooling_variable.py
190 lines (141 loc) · 4.95 KB
/
double_pooling_variable.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
class WeigtedSmoothing():
def __init__(self,batch):
self.batch=batch
def optimal_size_based_on_failure_rate(self,failure_rate): #pool_testing
if (failure_rate < 0.02):
return 20
elif (failure_rate < 0.03):
return 17
elif (failure_rate < 0.04):
return 12
elif (failure_rate < 0.05):
return 10
elif (failure_rate < 0.06):
return 8
elif (failure_rate < 0.12):
return 6
elif (failure_rate < 0.17):
return 5
elif (failure_rate < 0.3):
return 4
else:
return 20
def run_batch(self,batch):
for element in batch:
if element == False:
return False
break
return True
def double_pooling(self,batch_size, data):
# create sub_batches
test_numbers_in_sub_batch = 0
double_batches = []
for i in range(0, batch_size + 1):
double_batches.append([])
counter = 0
for i in range(0, batch_size):
j = i + 1
while (len(double_batches[i]) < batch_size):
double_batches[i].append(data[counter])
double_batches[j].append(data[counter])
counter = counter + 1
j = j + 1
# print(double_batches)
test_numbers_in_sub_batch = test_numbers_in_sub_batch + batch_size + 1
result = []
for sub_double_batch in double_batches:
result.append(self.run_batch(sub_double_batch))
faild_builds = 0
# print(result)
for flag in result:
if (flag == False):
faild_builds = faild_builds + 1
if (faild_builds <= 2):
return test_numbers_in_sub_batch
else:
num = faild_builds - 1
# print(num)
addition = (num * (num + 1) / 2)
return (test_numbers_in_sub_batch + addition)
def weighted_failure_rate_devide_to_location(self,sub_batch):
denom = 0
number = 0
sub_batch = sub_batch[::-1]
for i in range(0, len(sub_batch)):
denom = denom + (1 / (i + 1))
if (sub_batch[i] == False):
number = number + (1 / (i + 1))
failure_rate = number / denom
try:
failure_rate = failure_rate
except:
failure_rate = 0.07
return failure_rate
@staticmethod
def runbatch(batch):
for test in batch:
if (test == False):
return False
return True
def run(self):
test_number=0
batch_size=9
counter = 100
i = 0
sub_batch_size = int((batch_size * (batch_size + 1)) / 2)
batch_size=9
total_test = 0
mode = "d"
while(counter<len(self.batch)):
a=1
if(mode=="p"):
upper_bound = (counter + sub_batch_size)
sub_batch = self.batch[counter:upper_bound]
if (len(sub_batch) < sub_batch_size):
return total_test
if(self.runbatch(sub_batch)==True):
a=1
else:
a=5
elif(mode=="d"):
upper_bound = (counter + sub_batch_size)
sub_batch = self.batch[counter:upper_bound]
if(len(sub_batch)<int((batch_size * (batch_size + 1)) / 2)):
return total_test
a = self.double_pooling(batch_size, sub_batch)
total_test = total_test + a
counter = counter + sub_batch_size
if(self.weighted_failure_rate_devide_to_location(self.batch[counter - 100:(counter)])<0.1):
batch_size = self.optimal_size_based_on_failure_rate(self.weighted_failure_rate_devide_to_location(self.batch[counter - 100:(counter)]))
sub_batch_size = int((batch_size * (batch_size + 1)) / 2)
mode="d"
else:
batch_size=4
sub_batch_size=4
mode="p"
return total_test
import pandas as pd
import os
projects=(os.listdir("./data/extracted_project_travis"))
def calc_failure_rate(result_list):
failure_count=0
for result in result_list:
if(result==False):
failure_count+=1
return (failure_count/len(result_list))
for project in projects:
project_path='./data/extracted_project_travis/'+project
data = pd.read_csv(project_path)
if(project=='ruby.csv'):
data=data[data.git_branch=="trunk"]
else:
data = data[data.git_branch == "master"]
data = data[100:]
# elif(data_file[i]=='sling.csv'):
# data=data[data.git_branch=="trunk"]
# else:
data = data.build_successful
data = pd.Series.tolist(data)
ws=WeigtedSmoothing(data)
test_number=(ws.run())
print(project,1 - (test_number / (len(data)-100)))