Commit 02958130 authored by Jan Kiene's avatar Jan Kiene
Browse files

add new histogram script

with minimal support for now
parent 32f381eb
Loading
Loading
Loading
Loading
+75 −0
Original line number Diff line number Diff line
#!/usr/bin/env python3

import argparse
import math
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt


BINS_4_COLS = {
    "MLD": [0, 1, 2, 3, 4, 5, 10, 20, math.inf],
    "MAXIMUM ABS DIFF": [0, 16, 256, 1024, 2048, 4096, 8192, 16384, 32769],
    "SSNR": [-math.inf, 0, 10, 20, 30, 40, 40, 50, 60, 100],
    "ODG": [-5, -4, -3, -2, -1, -0.5, -0.4, -0.3, -0.2, -0.1, 0, 0.1, 0.5],
    "DELTA_ODG": [-5, -4, -3, -2, -1, -0.5, -0.4, -0.3, -0.2, -0.1, 0, 0.1, 0.5],
}


if __name__ == "__main__":
    parser = argparse.ArgumentParser(
        description="Parses a CSV report and creates a summary report."
    )
    parser.add_argument(
        "csv_report",
        type=str,
        help="CSV report file of test cases, e.g. report.csv",
    )
    args = parser.parse_args()
    df = pd.read_csv(args.csv_report)

    measures = ["MAXIMUM ABS DIFF"]
    formats = df["format"].unique()
    categories = df["category"].unique()

    for measure in measures:
        bins = BINS_4_COLS[measure]
        x = [f"{x}" for x in bins] + ["", "ERROR"]
        for fmt in formats:
            fig, ax = plt.subplots()
            bottom = np.zeros(len(x))
            for cat in categories:
                data_mask = np.logical_and(df["format"] == fmt, df["category"] == cat)
                df_slice = df[data_mask]
                error_mask = df_slice["result"] == "ERROR"
                n_errors = np.sum(error_mask)
                df_hist = df_slice[np.logical_not(error_mask)]

                counts, _ = np.histogram(df_hist[measure], bins)

                data = np.concat([counts, [0], [n_errors], [0]])
                ax.bar(
                    x,
                    data,
                    1,
                    align="edge",
                    edgecolor="black",
                    linewidth=0.5,
                    label=cat,
                    bottom=bottom,
                )
                bottom += data

            # Histogram layout
            ax.set_title(fmt)
            ax.legend(loc="best")
            ax.set_xlabel(measure)
            if "DIFF" in measure:
                ax.set_xticks(range(len(x)), x, rotation=35)
            ax.set_ylabel("Number of test cases")

            fig.set_figheight(4)
            fig.set_figwidth(6)
            plt.tight_layout()

    plt.show()