-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgenerate-report-v3.py
executable file
·215 lines (192 loc) · 7.3 KB
/
generate-report-v3.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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
#!/usr/bin/python
import sys
import os
from operator import attrgetter
from csv import reader
from datetime import datetime
from report.run import Run
from report.commit import Commit
from report.language import Language
import chevron
timestamp = None
default_folders_location = "https://github.com/swagger-api/swagger-codegen-test/tree/main/out"
def multisort(xs, specs):
for key, reverse in reversed(specs):
xs.sort(key=attrgetter(key), reverse=reverse)
return xs
def deserializeRun(row):
row_content = row[0]
cells = row_content.split('|')
run = Run()
run.v2_version = cells[0]
run.v3_version = cells[1]
run.codegen_version = cells[2]
run.timestamp = datetime.strptime(cells[3], "%Y_%m_%d_%H_%M_%S")
run.commit = cells[4]
run.language = cells[5]
run.job = cells[6]
run.spec = cells[7]
run.generate_outcome = cells[8]
run.build_outcome = cells[9]
run.spec_url = cells[10]
run.is_success_generation = run.generate_outcome == "success"
timestamp = run.timestamp.strftime("%Y_%m_%d_%H_%M_%S")
run.generated_folder_link = default_folders_location + "/" + run.v2_version + "_" + run.v3_version + "/" + timestamp + "/" + run.language + "/" + run.job + "/" + run.spec
return run
def generateReport(outFolder, newestSpecV3, oldestSpecV3):
global timestamp
results_file = open("out/results.csv", "r")
csv_reader = reader(results_file)
index = 0
suitesMap = dict()
# iterate all runs
for row in csv_reader:
# skip header
if index == 0:
index = index + 1
continue
# get run
run = deserializeRun(row)
# identify "commit" (todo rename to suite) by timestamp
if run.timestamp in suitesMap: # exists
commit = suitesMap[run.timestamp]
else: # doesn't exist, create
commit = Commit()
commit.languagesv2 = dict()
commit.languagesv3 = dict()
commit.commit = run.commit
commit.short_hash = commit.commit[0:7]
commit.timestamp = run.timestamp
commit.v2_version = run.v2_version
commit.v3_version = run.v3_version
commit.runs = list()
# add to suiteMap
suitesMap[run.timestamp] = commit
# append the current run to suite
commit.runs.append(run)
languagev2 = None
languagev3 = None
# setup languages for each suite
if run.codegen_version == "v3":
run.isV2 = False
if run.language in commit.languagesv3: # use existing
languagev3 = commit.languagesv3[run.language]
else: # create new
languagev3 = Language()
languagev3.codegen_version = run.codegen_version
languagev3.name = run.language
commit.languagesv3[run.language] = languagev3
languagev3.total_runs += 1
else:
run.isV2 = True
index = index + 1
continue
index += 1
# sort by timestamp ascending
suitesKeys = sorted(suitesMap.keys(), reverse = False)
# suitesMap = dict(sorted(suitesMap.items(), None, True))
# commits = sorted(commits, key=lambda sortCommit: sortCommit.timestamp)
# todo now we mandate all 4 parameters, checking only the first
suiteNew = None
suiteOld = None
for suiteKey in suitesKeys:
commit = suitesMap[suiteKey]
print (str(suiteKey) + " " + commit.v2_version + " " + commit.v3_version)
# todo we should be able to run probably separately v2 and v3 to be able to run and compare separately..
if commit.v3_version == newestSpecV3:
suiteNew = commit
if commit.v3_version == oldestSpecV3:
suiteOld = commit
suitesMapFiltered = dict()
suitesMapFiltered[suiteOld.timestamp] = suiteOld
suitesMapFiltered[suiteNew.timestamp] = suiteNew
suitesMap = suitesMapFiltered
suitesKeys = suitesMap.keys()
previous_commit = None
for suiteKey in suitesKeys:
commit = suitesMap[suiteKey]
commit.runs = multisort(list(commit.runs), (('codegen_version', False), ('language', False)))
commit.total_runs = 0
# commit.total_runs = len(commit.runs)
for run in commit.runs:
previous_run = None
if run.codegen_version != "v3":
continue
commit.total_runs += 1
if previous_commit is not None:
previous_run = run.find_match(previous_commit.runs)
if run.generate_outcome != "success":
run.generate_error = True
commit.generate_error_count += 1
if run.codegen_version == "v3":
if run.language in commit.languagesv3: # use existing
commit.languagesv3[run.language].generate_error_count += 1
if previous_run is not None:
if previous_run.generate_outcome == "success":
commit.regression_count += 1
run.is_regression = True
if run.codegen_version == "v3":
if run.language in commit.languagesv3: # use existing
commit.languagesv3[run.language].regression_count += 1
if run.build_outcome != "success":
run.build_error = True
if run.build_outcome == "failure":
commit.build_failure_count += 1
if run.codegen_version == "v3":
if run.language in commit.languagesv3:
commit.languagesv3[run.language].build_failure_count += 1
if previous_run is not None:
if previous_run.build_outcome == "success":
commit.regression_count += 1
run.is_regression = True
if run.codegen_version == "v3":
if run.language in commit.languagesv3:
commit.languagesv3[run.language].regression_count += 1
else:
commit.build_error_count += 1
if run.codegen_version == "v3":
if run.language in commit.languagesv3: # use existing
commit.languagesv3[run.language].build_error_count += 1
if previous_run is not None:
if previous_run.build_outcome == "success":
commit.regression_count += 1
run.is_regression = True
if run.codegen_version == "v3":
if run.language in commit.languagesv3: # use existing
commit.languagesv3[run.language].regression_count += 1
else:
if run.codegen_version == "v3" and run.language in commit.languagesv3:
commit.languagesv3[run.language].successful_runs += 1
previous_commit = commit
# sort by timestamp descending
if newestSpecV3 is None:
suitesKeys = sorted(suitesMap.keys(), reverse = True)
else:
suitesMapFiltered = dict()
suitesMapFiltered[suiteNew.timestamp] = suiteNew
suitesMapFiltered[suiteOld.timestamp] = suiteOld
suitesMap = suitesMapFiltered
suitesKeys = suitesMap.keys()
commits = list()
commit = suiteNew
langKeysv3 = sorted(commit.languagesv3.keys(), reverse = False)
langsv3 = list()
for langKeyv3 in langKeysv3:
langsv3.append(commit.languagesv3[langKeyv3])
commit.languagesv3 = multisort(list(langsv3), (('codegen_version', False), ('name', False)))
commits.append(commit)
if not os.path.exists(outFolder):
os.makedirs(outFolder)
with open('indexmdv3.mustache', 'r') as template:
output = chevron.render(template, {'commits': commits})
file = outFolder + newestSpecV3 + ".md"
result_file = open(file, "wt")
result_file.write(output)
result_file.close()
# main
def main():
global timestamp
timestamp = datetime.now().strftime("%Y_%m_%d_%H_%M_%S")
generateReport("reports/releases/" + sys.argv[1] + "/", sys.argv[1], sys.argv[2])
# here start main
main()