Commit dd7428e1 authored by norvell's avatar norvell
Browse files

Change layout of matplotlib histogram

parent 56e874cc
Loading
Loading
Loading
Loading
+29 −5
Original line number Diff line number Diff line
@@ -4,6 +4,7 @@ import argparse
import re
import math
import numpy as np
import matplotlib.pyplot as plt
from xml.etree import ElementTree

"""
@@ -41,8 +42,10 @@ if __name__ == "__main__":
    count = {'PASS':0,'FAIL':0,'ERROR':0}

    # Formats, categories and MLD histogram limits
    # formats = {'Stereo':r'stereo', 'ISM':r'ISM', 'Multichannel':r'Multi-channel',
    #            'MASA':r'MASA','SBA':r'SBA', 'OSBA':r'OSBA', 'OMASA':r'OMASA','Renderer':r'renderer'}
    formats = {'Stereo':r'stereo', 'ISM':r'ISM', 'Multichannel':r'Multi-channel',
               'MASA':r'MASA','SBA':r'SBA', 'OSBA':r'OSBA', 'OMASA':r'OMASA','Renderer':r'renderer','**Unidentified format**':r'.*'}
               'OSBA':r'OSBA', 'OMASA':r'OMASA','MASA':r'MASA','SBA':r'SBA', 'Renderer':r'renderer'}
    categories = {'Normal operation':r'.*', 'DTX':r'DTX', 'PLC':r'%', 'Bitrate switching':r'br sw|bitrate switching', 'JBM':r'JBM' }
    limits = [0,5,10,20,math.inf]

@@ -109,19 +112,40 @@ if __name__ == "__main__":
                cat = results_sorted[testcase]["Category"]
                tmp[fmt][cat].append(results_sorted[testcase]["MLD"]) # Add MLD score to list

            subplot = 0
            fig, ax = plt.subplots(len(formats)//2, 2)
            for fmt in tmp:
                headerline = f"{fmt};\nCategory;0;" + ";".join([f"{str(a)} -- {str(b)}" for (a,b) in zip(limits[0:-1],limits[1:])]) + ";None\n"
                limits_labels = ["0"] + [f"{str(a)} -- {str(b)}" for (a,b) in zip(limits[0:-1],limits[1:])] + ["None"]
                headerline = f"{fmt};\nCategory;" + ";".join(limits_labels) + "\n"
                fp.write(headerline)
                bottom = np.zeros(len(limits)+1)
                for cat in categories:
                    # CSV output
                    # Separate 0 and None as special cases
                    mld = [float(x) for x in tmp[fmt][cat] if x != 'None' and x != '0']
                    zero = sum([1 for x in tmp[fmt][cat] if x == '0'])
                    none = sum([1 for x in tmp[fmt][cat] if x == 'None'])
                    hist, _ = np.histogram(mld,limits)
                    line = f"{cat}; {str(zero)}; {'; '.join(map(str,hist))}; {str(none)}\n"
                    data = np.array([zero] + list(hist) + [none])
                    line = f"{cat}; {'; '.join(map(str,data))}\n"
                    fp.write(line)

                    # Matplotlib histogram
                    a = subplot % 4
                    b = subplot // 4
                    ax[a][b].bar(limits_labels, data, 0.5, label=cat, bottom=bottom)
                    bottom += data
                fp.write("\n")

                ax[a][b].set_title(fmt)
                ax[a][b].legend(loc="best")
                ax[a][b].set_xlabel("MLD")
                ax[a][b].set_ylabel("Number of test cases")
                subplot += 1
    fig.set_figheight(20)
    fig.set_figwidth(16)
    plt.savefig(summary_file +".png")

    print(
        f"Parsed testsuite with {count['PASS']+count['FAIL']+count['ERROR']} tests: {count['PASS']} passes, {count['FAIL']} failures and {count['ERROR']} errors."
    )