22
22
23
23
import os
24
24
import glob
25
+ import json
25
26
import sys
26
27
#import pandas as pd
27
28
#import dataframe_image as dfi
32
33
from datetime import datetime
33
34
34
35
testname = "PeerConnection"
35
- if len (sys .argv ) > 1 :
36
- testname = sys .argv [1 ]
37
-
38
- #print("Test name=%s.\n" % testname)
39
-
40
- # The character width of each cell in the results markdown table.
41
- COL_WIDTH = 12
42
- RESULTS_FILE_PATH = testname + "_test_results.png"
43
-
44
- #print("results file path=%s.\n" % RESULTS_FILE_PATH)
45
-
46
- def trim (source_filepath , target_filepath = None , background = None ):
47
- if not target_filepath :
48
- target_filepath = source_filepath
49
- img = pil .Image .open (source_filepath )
50
- if background is None :
51
- background = img .getpixel ((0 , 0 ))
52
- border = pil .Image .new (img .mode , img .size , background )
53
- diff = pil .ImageChops .difference (img , border )
54
- bbox = diff .getbbox ()
55
- img = img .crop (bbox ) if bbox else img
56
- img .save (target_filepath )
57
-
58
- resultFiles = glob .glob ("./*.csv" )
59
-
60
- results = defaultdict (dict )
36
+
37
+ # Read JSON input from stdin (for GitHub Actions)
38
+ input_data = sys .stdin .read ()
39
+
40
+ # Parse the input JSON
41
+ try :
42
+ results = json .loads (input_data )
43
+ except json .JSONDecodeError as e :
44
+ print (f"Failed to parse JSON: { e } " )
45
+ sys .exit (1 )
46
+
47
+ # Initialize data structures
61
48
serverKeys = []
62
49
clientKeys = []
63
50
64
- for resFile in resultFiles :
65
- with open (resFile ) as f :
66
- for line in f :
67
- cols = line .strip ().split (',' )
68
- if not cols [0 ] in serverKeys :
69
- serverKeys .append (cols [0 ])
70
- if not cols [1 ] in clientKeys :
71
- clientKeys .append (cols [1 ])
72
- results [cols [0 ]][cols [1 ]] = cols [2 ]
51
+ # Prepare the results structure
52
+ results_dict = defaultdict (dict )
53
+
54
+ # Populate the results_dict with data from the parsed JSON
55
+ for key , value in results .items ():
56
+ server , client = key .split ("_" )[1 :] # Assuming keys are formatted as "result_<server>_<client>"
57
+ results_dict [server ][client ] = value
58
+ if server not in serverKeys :
59
+ serverKeys .append (server )
60
+ if client not in clientKeys :
61
+ clientKeys .append (client )
73
62
74
- sorted (serverKeys )
75
- sorted (clientKeys )
63
+ # Sort the server and client keys
64
+ serverKeys .sort ()
65
+ clientKeys .sort ()
76
66
67
+ # HTML for Markdown output
77
68
html = """<html>
78
69
<body>"""
79
70
80
- print ('## %s Test Results' % testname )
71
+ # Print Markdown table header
72
+ print ('## Test Results' )
81
73
print ('Test run at %s\n ' % datetime .now ())
82
74
83
- html += "<h3>" + testname + " Test Results</h3>"
75
+ html += "<h3>Test Results</h3>"
84
76
html += "<p>Test run at %s.</p>" % datetime .now ()
85
77
86
78
# Print Table header row.
87
- print (f'| { "Server" : <{COL_WIDTH }} | { "Client" : <{COL_WIDTH }} ' , end = '' )
88
- html += """<table>
89
- <tr>
90
- <th>Server</th>
91
- <th colspan='%d'>Client</th>
92
- </tr>
93
- """ % COL_WIDTH
94
-
95
- for i in range (0 , (len (clientKeys ) - 1 )):
96
- print (f'| { " " :<{COL_WIDTH }} ' , end = '' )
97
- print ('|' )
98
-
99
- # Print end of header line.
100
- sep = '-' * (COL_WIDTH + 1 )
101
- for i in range (len (clientKeys ) + 1 ):
102
- print (f'|{ sep } ' , end = '' )
103
- print ('|' )
104
-
105
- # Print Client column headings.
106
- print (f'| { " " :<{COL_WIDTH }} ' , end = '' )
107
- html += """<tr>
108
- <td/>"""
109
- for clientKey in clientKeys :
110
- print (f'| { clientKey : <{COL_WIDTH }} ' , end = '' )
111
- html += "<td>%s</td>" % clientKey
112
- print ('|' )
113
- html += "</tr>"
79
+ print (f'| { "Server" : <12} | { " | " .join (clientKeys )} |' )
80
+ print ('|--------|' + '|' .join (['--------' ] * len (clientKeys )) + '|' )
114
81
115
82
# Print Server rows.
116
83
for serverKey in serverKeys :
117
- print (f'| { serverKey : <{ COL_WIDTH } } ' , end = '' )
118
- html += "<tr><td>%s </td>" % serverKey
84
+ print (f'| { serverKey : <12 } ' , end = '' )
85
+ html += f "<tr><td>{ serverKey } </td>"
119
86
for clientKey in clientKeys :
120
- if serverKey in results . keys () and clientKey in results [serverKey ]. keys () :
121
- resultChar = '☑ ' if results [serverKey ][clientKey ] == '0' else '☒ '
122
- print (f'| { resultChar :<{ COL_WIDTH } } ' , end = '' )
123
- html += "<td>%s </td>" % resultChar
87
+ if clientKey in results_dict [serverKey ]:
88
+ resultChar = '✔ ' if results_dict [serverKey ][clientKey ] == '0' else '✘ '
89
+ print (f'| { resultChar : <7 } ' , end = '' )
90
+ html += f "<td>{ resultChar } </td>"
124
91
else :
125
- print (f'| { " " :<{ COL_WIDTH } } ' , end = '' )
126
- html += "<td/ >"
92
+ print (f'| { " " :<7 } ' , end = '' )
93
+ html += "<td></td >"
127
94
print ('|' )
128
95
html += "</tr>"
129
96
130
- html += """ </body
131
- </html"""
97
+ html += """ </body>
98
+ </html> """
132
99
133
100
#df = pd.DataFrame(results, columns=clientKeys)
134
101
#print(df)
135
102
#dfi.export(df, "results.png")
136
103
137
104
#html = wsp.HTML(string=df.to_html())
138
105
#print(html)
139
- html = wsp .HTML (string = html )
140
- html .write_png (RESULTS_FILE_PATH )
141
- trim (RESULTS_FILE_PATH )
106
+ # html = wsp.HTML(string=html)
107
+ # html.write_png(RESULTS_FILE_PATH)
108
+ # trim(RESULTS_FILE_PATH)
0 commit comments