Skip to content

Commit e9cffe8

Browse files
committed
Switch back to python script for collation.
1 parent c2421da commit e9cffe8

File tree

2 files changed

+57
-112
lines changed

2 files changed

+57
-112
lines changed

.github/workflows/datachannel_echo-test.yml

+11-33
Original file line numberDiff line numberDiff line change
@@ -67,43 +67,21 @@ jobs:
6767
needs: [interoptests]
6868
steps:
6969
- uses: actions/checkout@v2
70+
- uses: actions/setup-python@v2
71+
with:
72+
python-version: "3.x"
7073
- name: Create results file from interop test outputs
7174
run: |
7275
echo "Collating...."
76+
echo "raw results=${{ toJSON(needs.interoptests.outputs) }}"
7377
74-
# Capture the outputs as a JSON string
75-
results='${{ toJSON(needs.interoptests.outputs) }}'
76-
77-
# Print the raw JSON for debugging
78-
echo "The output from interop-test is: $results"
79-
80-
# Define the list of clients
81-
clients=("libdatachannel", "sipsorcery", "werift") # Adjust based on actual client list
82-
83-
# Write the header of the Markdown file
84-
echo "| Server | ${clients[@]} |" > DataChannel_Echo_test_results.md
85-
echo "|--------|${clients[*]// /|}|" >> DataChannel_Echo_test_results.md
86-
87-
# Loop through servers to fill in the matrix
88-
for server in $(echo "$results" | jq -r 'keys[] | capture("result_(?<server>.+)_(?<client>.+)") | .server' | sort -u); do
89-
# Start the row with the server name
90-
row="$server"
91-
92-
# Loop through each client to get the results
93-
for client in "${clients[@]}"; do
94-
# Get the result for this server-client combination
95-
value=$(echo "$results" | jq -r --arg server "$server" --arg client "$client" '.["result_\($server)_\($client)"] // "N/A"') # Default to N/A if no value
96-
97-
# Append the value to the row
98-
row+=" | $value"
99-
done
100-
101-
# Write the row to the Markdown file
102-
echo "| $row |" >> DataChannel_Echo_test_results.md
103-
done
104-
105-
echo "" >> DataChannel_Echo_test_results.md
106-
echo "Timestamp: $(date)" >> DataChannel_Echo_test_results.md
78+
python --version
79+
80+
# Update package list and install weasyprint
81+
sudo apt update
82+
sudo apt install -y weasyprint
83+
84+
echo "${{ toJSON(needs.interoptests.outputs) }}" | python3 test/collate-results.py > DataChannel_Echo_test_results.md
10785
10886
# Display the results file
10987
cat DataChannel_Echo_test_results.md

test/collate-results.py

100644100755
+46-79
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
import os
2424
import glob
25+
import json
2526
import sys
2627
#import pandas as pd
2728
#import dataframe_image as dfi
@@ -32,110 +33,76 @@
3233
from datetime import datetime
3334

3435
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
6148
serverKeys = []
6249
clientKeys = []
6350

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)
7362

74-
sorted(serverKeys)
75-
sorted(clientKeys)
63+
# Sort the server and client keys
64+
serverKeys.sort()
65+
clientKeys.sort()
7666

67+
# HTML for Markdown output
7768
html = """<html>
7869
<body>"""
7970

80-
print('## %s Test Results' % testname)
71+
# Print Markdown table header
72+
print('## Test Results')
8173
print('Test run at %s\n' % datetime.now())
8274

83-
html += "<h3>" + testname + " Test Results</h3>"
75+
html += "<h3>Test Results</h3>"
8476
html += "<p>Test run at %s.</p>" % datetime.now()
8577

8678
# 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)) + '|')
11481

11582
# Print Server rows.
11683
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>"
11986
for clientKey in clientKeys:
120-
if serverKey in results.keys() and clientKey in results[serverKey].keys():
121-
resultChar = '&#9745;' if results[serverKey][clientKey] == '0' else '&#x2612;'
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>"
12491
else:
125-
print(f'| {" ":<{COL_WIDTH}}', end='')
126-
html += "<td/>"
92+
print(f'| {" ":<7}', end='')
93+
html += "<td></td>"
12794
print('|')
12895
html += "</tr>"
12996

130-
html += """ </body
131-
</html"""
97+
html += """ </body>
98+
</html>"""
13299

133100
#df = pd.DataFrame(results, columns=clientKeys)
134101
#print(df)
135102
#dfi.export(df, "results.png")
136103

137104
#html = wsp.HTML(string=df.to_html())
138105
#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

Comments
 (0)