Commit 77531abb authored by Kamlesh Todai's avatar Kamlesh Todai
Browse files

Changes to allow varying of number of collections during creating the summary report.

parent 4b5f0d46
Pipeline #8767 failed with stages
in 10 seconds
......@@ -14,9 +14,16 @@ import datetime
# OSDU Platform Validation CI_CD_Notes.md of "Platform Validation project"
# At present it is assuming 11 collections being run each of the four platforms
# AWS, AZURE, GCP, IBM
# In future work will be done where it should be able handle n number of collections instead of fix 11
# At present this restriction is because of the way the writing of the excel file is implemented,
# specially the writing of the last summary part, after all the collections are processed.
# AT present
# Number of collection can vary, but number of platforms is fixed.
# Also it expects to have the collection report for each platform.
# The Collection run date is extracted from the first collection report processed.
# Also environment file is extracted from the first collection processed for each platform
#
# In future work can be done to make the number of platforms also variable
# At present this restriction is there because
# of the way the writing of the excel file is implemented.
# Also the Columns for each platform are fixed
#=======================================================================================================
# Method to process html report file and summarize the results in Excel file
def processFile(fnm, platform, rowNo, colOffset, envFileNamesPopulated):
......@@ -25,11 +32,11 @@ def processFile(fnm, platform, rowNo, colOffset, envFileNamesPopulated):
# print("Row: ", rowNo)
# print("Total Rows: ", totRows)
# print("Column offset", colOffset)
# return()
#
# Open the html file for reading
html = open(fnm, 'r').read() # local html
bs = BeautifulSoup(html, features="html.parser")
#
bs = BeautifulSoup(html, features="html.parser") # parse the file
# Find the desired section of the file, extract the text and split to extract required information
mydivs = bs.findAll("div", {"class": "col-sm-12 mb-3"})
txt = mydivs[0].get_text()
fileInfo = txt.split("\n")
......@@ -52,7 +59,7 @@ def processFile(fnm, platform, rowNo, colOffset, envFileNamesPopulated):
#
print(collectionName)
print(enviornmentName)
# Save/Collect environment file name
# Save/Collect environment file names (only once, not for each collection)
if (envFileNamesPopulated == False):
if (colOffset == 0):
env_file_names.append(enviornmentName)
......@@ -89,7 +96,7 @@ def processFile(fnm, platform, rowNo, colOffset, envFileNamesPopulated):
elif (count == 20):
skippedTests = info
count += 1
#
# Compute the pass rate (percentage of test that passed for the collection)
passRate = (100 * float(totalAssertionPassed ) / (float(totalAssertionPassed) + float(totalAssertionFailed)) )
# print("totalRequestsPassed: " + totalRequestsPassed)
......@@ -98,12 +105,13 @@ def processFile(fnm, platform, rowNo, colOffset, envFileNamesPopulated):
# print("totalAssertionFailed: " + totalAssertionFailed)
# print("skippedTests: " + skippedTests)
# print(passRate)
#
# save the information
records.append((collectionName, totalRequestsPassed, totalAssertionPassed, totalAssertionFailed, passRate ))
curRow = len(records) - 1
# print(records[curRow])
# write the data to Excel file
for col_num, data in enumerate(records[curRow]):
l_colNum = col_num
......@@ -113,7 +121,7 @@ def processFile(fnm, platform, rowNo, colOffset, envFileNamesPopulated):
worksheet.write(rowNo, l_colNum, data, collection_cell_format)
elif (l_colNum == 1):
worksheet.write(rowNo, l_colNum, int(data), request_cell_format)
elif ( (l_colNum == 4) or (l_colNum == 8) or (l_colNum == 12) or (l_colNum == 16 ) ):
elif (l_colNum in pctColList):
if (passRate >= 100.0):
worksheet.write(rowNo, l_colNum, data, greenPct_cell_format)
elif (passRate < 60.0):
......@@ -122,7 +130,8 @@ def processFile(fnm, platform, rowNo, colOffset, envFileNamesPopulated):
worksheet.write(rowNo, l_colNum, data, pct_cell_format)
else:
worksheet.write(rowNo, l_colNum, int(data), cell_format)
#Extract run Date Info
#
#Extract run Date Info only once from the first collection
if (len(collection_run_date) == 0):
mydivs3 = bs.findAll("div", {"class": "col-md-9 col-lg-12 main"})
txt3 = mydivs3[0].get_text()
......@@ -145,19 +154,28 @@ records.append(("Collection Name", "#of Requests", "Pass", "Fail", "PassRate",""
#Create and initialize the excel file
workbook = xlsxwriter.Workbook('NewmanHtmlReportsSummary.xlsx')
worksheet = workbook.add_worksheet()
worksheet.set_column(0, 0, 40)
worksheet.set_column(1, 1, 12)
# set the column width
worksheet.set_column(0, 0, 40) # Column for Collection Name
worksheet.set_column(1, 1, 12) # Column for number of request
# set variaous formats that will be used to wirte the data to the Excel file
cell_format = workbook.add_format({'align': 'center', 'bold': True})
#
summ_cell_format = workbook.add_format({'align': 'left', 'bold': True})
summ_right_cell_format = workbook.add_format({'align': 'right', 'bold': True})
#
request_cell_format = workbook.add_format({'align': 'center', 'bg_color': '#D8E4BC'})
#
collection_cell_format = workbook.add_format({'align': 'center', 'bold': True})
collection_cell_format.set_font_color('blue')
#
total_cell_format = workbook.add_format({'align': 'center', 'bold': True, 'bg_color': 'orange', 'font_color': 'blue'})
#
total_num_cell_format = workbook.add_format({'align': 'center', 'bold': True, 'bg_color': 'orange', 'font_color': 'blue'})
total_num_cell_format.set_num_format('0')
#
total_pct_cell_format = workbook.add_format({'align': 'center', 'bold': True, 'bg_color': 'orange', 'font_color': 'blue'})
total_pct_cell_format.set_num_format('0.00')
#
pct_cell_format = workbook.add_format({'align': 'center', 'bold': True})
pct_cell_format.set_num_format('0.00')
#
......@@ -171,15 +189,20 @@ redPct_cell_format.set_num_format('0.00')
#
head_cell_format = workbook.add_format({'align': 'center', 'bold': True, 'bg_color': '#78B0DE'})
head_cell_format.set_font_size(14)
#
head2_cell_format = workbook.add_format({'align': 'center', 'bold': True, 'bg_color': '#BBD7EF', 'font_color': 'black'})
head2_cell_format.set_font_size(12)
#
head2_green_cell_format = workbook.add_format({'align': 'center', 'bold': True, 'bg_color': '#BBD7EF', 'font_color': 'green'})
head2_green_cell_format.set_font_size(12)
head2_red_cell_format = workbook.add_format({'align': 'center', 'bold': True, 'bg_color': '#BBD7EF', 'font_color': 'red'})
head2_red_cell_format.set_font_size(12)
#
fillColList = [5,9,13] # column list that are acting as separator between platforms
pctColList = [4,8,12,16] # column list that hold passRate (percent) values
passColList = [2,6,10,14] # column list that hold number of request pass values
failColList = [3,7,11,15] # column list that hold number of request fail values
#
#Write the header records to excel file
rowNum = 0
col_offset = 0
......@@ -190,9 +213,9 @@ for row_num in records:
else:
# print("rowNum: ", rowNum, " col_num: ", col_num)
if (rowNum == 1):
if ( (col_num == 2) or (col_num == 6) or (col_num == 10) or (col_num == 14) ):
if (col_num in passColList):
worksheet.write(rowNum, col_num, data, head2_green_cell_format)
elif ((col_num == 3) or (col_num == 7) or (col_num == 11) or (col_num == 15)):
elif (col_num in failColList):
worksheet.write(rowNum, col_num, data, head2_red_cell_format)
else:
worksheet.write(rowNum, col_num, data, head2_cell_format)
......@@ -210,6 +233,8 @@ for file in os.listdir("."):
continue
else:
# print(file)
# Extract platform from the filename and set the start column offset value for the platform
# First platform (AWS) start column offset also accomodates number of request column
if (fileParts[0] != curPlatform):
#
localRowNo = rowNum
......@@ -226,79 +251,83 @@ for file in os.listdir("."):
else:
print("Invalid platform: " + fileParts[0])
continue
env_file_names_populated = False
env_file_names_populated = False # platform changed, save environment file
else:
env_file_names_populated = True
env_file_names_populated = True # want to save environment file only once for each platform
if (fileParts[0] == "aws"):
collName.append(fileParts[1])
# Process, extract and write the information to the Excel file
processFile(file, fileParts[0], localRowNo, col_offset, env_file_names_populated) # process html report file
localRowNo += 1
print("")
#
# Summarize the results
print("Total number of collections: ", len(collName) )
print("Total number of reports summarized: ", (len(records)-2) )
print("Total number of platforms", ((len(records) - 2)/len(collName)) )
# Populate the Separator columns
fill_cell_format = workbook.add_format({'bg_color': '#FFE1E5'})
total_row_num = len(collName) + 2
colList = [5,9,13]
for i in range(2, total_row_num):
for j in range(len(colList)):
worksheet.write(i, colList[j], "", fill_cell_format)
#
# Write the summary data to the Excel file, Values for the Total row, Collection run and summary report date and list of environment files
total_cols = 17
rowIndx = total_row_num
rowIndxStr = str(rowIndx+1)
sumStartIdx =3
sumEndIdx = rowIndx
sumStartIdxStr = str(sumStartIdx)
sumEndIdxStr = str(sumEndIdx)
# popluate the arrays to sum the pass, fail and passRate values for each platform as well as total number of requests
# e.g. [ ['B14', '{=SUM(B3:B13)}'],...,[...]]
col_lables = [["B"+rowIndxStr, "{=SUM(B"+sumStartIdxStr+":B"+sumEndIdxStr+")}"], ["C"+rowIndxStr, "{=SUM(C"+sumStartIdxStr+":C"+sumEndIdxStr+")}"],
["D"+rowIndxStr, "{=SUM(D"+sumStartIdxStr+":D"+sumEndIdxStr+")}"], ["E"+rowIndxStr, "{=SUM(E"+sumStartIdxStr+":E"+sumEndIdxStr+")}"],
["G"+rowIndxStr, "{=SUM(G"+sumStartIdxStr+":G"+sumEndIdxStr+")}"], ["H"+rowIndxStr, "{=SUM(H"+sumStartIdxStr+":H"+sumEndIdxStr+")}"], ["I"+rowIndxStr, "{=SUM(I"+sumStartIdxStr+":I"+sumEndIdxStr+")}"],
["K"+rowIndxStr, "{=SUM(K"+sumStartIdxStr+":K"+sumEndIdxStr+")}"], ["L"+rowIndxStr, "{=SUM(L"+sumStartIdxStr+":L"+sumEndIdxStr+")}"], ["M"+rowIndxStr, "{=SUM(M"+sumStartIdxStr+":M"+sumEndIdxStr+")}"],
["O"+rowIndxStr, "{=SUM(O"+sumStartIdxStr+":O"+sumEndIdxStr+")}"], ["P"+rowIndxStr, "{=SUM(P"+sumStartIdxStr+":P"+sumEndIdxStr+")}"], ["Q"+rowIndxStr, "{=SUM(Q"+sumStartIdxStr+":Q"+sumEndIdxStr+")}"]]
col_label_indx = 0
# Populate/write the Total Row
for j in range(total_cols):
if (j == 0):
worksheet.write(13, j, "Total", total_cell_format)
elif ( (j == 5) or (j == 9) or (j == 13) ):
worksheet.write(rowIndx, j, "Total", total_cell_format)
elif (j in fillColList):
worksheet.write(total_row_num, j, "", total_cell_format)
# continue
elif (j == 1):
worksheet.write_formula('B14', '{=SUM(B3:B13)}', total_cell_format)
elif (j == 2):
worksheet.write_formula('C14', '{=SUM(C3:C13)}', total_cell_format)
elif (j == 3):
worksheet.write_formula('D14', '{=SUM(D3:D13)}', total_cell_format)
elif (j == 4):
worksheet.write_formula('E14', '{=SUM(E3:E13)}', total_cell_format)
elif (j == 6):
worksheet.write_formula('G14', '{=SUM(G3:G13)}', total_cell_format)
elif (j == 7):
worksheet.write_formula('H14', '{=SUM(H3:H13)}', total_cell_format)
elif (j == 8):
worksheet.write_formula('I14', '{=SUM(I3:I13)}', total_cell_format)
elif (j == 10):
worksheet.write_formula('K14', '{=SUM(K3:K13)}', total_cell_format)
elif (j == 11):
worksheet.write_formula('L14', '{=SUM(L3:L13)}', total_cell_format)
elif (j == 12):
worksheet.write_formula('M14', '{=SUM(M3:M13)}', total_cell_format)
elif (j == 14):
worksheet.write_formula('O14', '{=SUM(O3:O13)}', total_cell_format)
elif (j == 15):
worksheet.write_formula('P14', '{=SUM(P3:P13)}', total_cell_format)
elif (j == 16):
worksheet.write_formula('Q14', '{=SUM(Q3:Q13)}', total_cell_format)
#
else:
colIndx = col_lables[col_label_indx]
if (j in pctColList):
worksheet.write_formula(colIndx[0], colIndx[1], total_pct_cell_format)
else:
worksheet.write_formula(colIndx[0], colIndx[1], total_num_cell_format)
col_label_indx += 1
# Write the collection run date
date_time_obj = datetime.datetime.strptime(collection_run_date[0], '%A, %d %B %Y %H:%M:%S')
str1 = "Collection run date: " + date_time_obj.strftime('%m/%d/%Y, %H:%M:%S')
worksheet.write(15, 0, str1, summ_cell_format)
rowIndx += 2
worksheet.write(rowIndx, 0, str1, summ_cell_format)
# Write the summary report date
# str1 = "Summary report run date:\t " + (datetime.datetime.now().strftime('%A, %d %B %Y %H:%M:%S'))
str1 = "Summary report date: " + (datetime.datetime.now().strftime('%m/%d/%Y, %H:%M:%S'))
worksheet.write(16, 0, str1, summ_cell_format)
#
worksheet.write(18, 0, "Environment Files:", summ_cell_format)
rowIndx += 1
worksheet.write(rowIndx, 0, str1, summ_cell_format)
# Wrtie the list of environment files
rowIndx += 1
worksheet.write(rowIndx, 0, "Environment Files:", summ_cell_format)
numOfEnvs = len(env_file_names)
rowIndx += 1
for i in range(numOfEnvs):
worksheet.write((19+i), 0, env_file_names[i], cell_format)
#
worksheet.write(rowIndx, 0, env_file_names[i], cell_format)
rowIndx += 1
# Close the Excel file
workbook.close()
# Log some summary data
print(env_file_names)
print(collection_run_date)
print("Summary Report Date: ", datetime.datetime.now())
print("Done")
exit()
#
# End
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment