#!/usr/bin/env python3
# Writes one HTML image gallery per design under reports/, one column per
# platform and one row per view, from the images the flow saved under
# reports////. The metrics comparison table this
# script used to write next to the galleries was removed: the QoR gate is the
# dashboard check in `make metadata`, and the table judged runs against
# committed golden files that are gone.
import os
from collections import defaultdict
# make sure the working dir is flow/
os.chdir(os.path.join(os.path.dirname(os.path.abspath(__file__)), ".."))
cssOutput = "reports/table.css"
cssStyle = """/* gallery styles */
table {
border-collapse: collapse;
margin: 25px 0;
font-size: 0.9em;
font-family: sans-serif;
min-width: 400px;
box-shadow: 0 0 20px rgba(0, 0, 0, 0.15);
}
table thead tr {
background-color: #009879;
color: #ffffff;
text-align: left;
}
table th,
table td {
padding: 12px 15px;
}
table tbody tr {
border-bottom: 1px solid #dddddd;
}
table tbody tr:nth-of-type(even) {
background-color: #f3f3f3;
}
table td:nth-child(n+2) {
text-align: center;
}
table tbody tr:last-of-type {
border-bottom: 2px solid #009879;
}
table th,
table td:nth-child(1),
.image-table td {
border-right: solid 2px;
border-left: solid 2px;
}
table th {
border-top: solid 2px;
}
div.gallery {
margin: 5px;
float: left;
height: 300px;
}
div.gallery:hover {
border: 1px solid #777;
}
div.gallery img {
max-height: 300px;
width: auto;
}
div.desc {
padding: 10px;
text-align: center;
}
"""
head = """
"""
tail = """
"""
def add_image(path, platform, view):
return f"""
{platform} - {view}
"""
# save_images.tcl asks OpenROAD for .webp, but the GUI silently falls back to
# .png when the Qt build has no webp writer, which used to leave the gallery
# empty. Accept either, and derive the view name by stripping whatever image
# extensions the file ended up with rather than a fixed number of characters.
IMAGE_EXTENSIONS = (".webp", ".png")
def image_view_name(file):
view, ext = os.path.splitext(file)
while ext.lower() in IMAGE_EXTENSIONS:
file = view
view, ext = os.path.splitext(file)
return file
def collect_images():
"""Map design -> platform -> view -> image path, relative to reports/."""
images = defaultdict(lambda: defaultdict(dict))
for parents, dirs, files in sorted(os.walk("reports", topdown=False)):
for file in files:
if file.lower().endswith(IMAGE_EXTENSIONS):
path = os.path.join(parents, file).replace("reports", ".")
platform, design = path.split(os.sep)[1:3]
images[design][platform][image_view_name(file)] = path
return images
def write_gallery(design, images, platforms, views):
htmlGallery = f"reports/report-gallery-{design}.html"
with open(htmlGallery, "w") as f:
gallery = "
Image Gallery
\n"
gallery += '
\n'
gallery += "
\n"
for key in platforms:
gallery += f"
{key}
\n"
gallery += "
\n"
for view in views:
gallery += "
\n"
for platform in platforms:
if platform in images[design] and view in images[design][platform]:
gallery += add_image(images[design][platform][view], platform, view)
else:
gallery += "
\n
\n"
gallery += "
\n"
gallery += "
\n"
f.writelines(head + gallery + tail)
images = collect_images()
platforms = sorted({p for d in images.values() for p in d})
views = sorted({v for d in images.values() for p in d.values() for v in p})
os.makedirs("reports", exist_ok=True)
with open(cssOutput, "w") as f:
f.writelines(cssStyle)
for design in sorted(images):
write_gallery(design, images, platforms, views)