import matplotlib.pyplot as plt

plt.rcParams.update({'font.size':35})

def single_listener():
    fig, ((ax1,ax2),(ax3,ax4)) = plt.subplots(2,2)

    x = [1,10,100,1000]

    y11 = [0.61,  4.8,   46,   422]
    y12 = [  16, 3053, 7233, 37598]
    y13 = [ 2.2,  135, 1230,  8853]

    ax1.plot(x, y12, label="Maximum", linewidth=5)
    ax1.plot(x, y13, label="Average", linewidth=5)
    ax1.plot(x, y11, label="Minimum", linewidth=5)

    ax1.legend(bbox_to_anchor=(0.2,1.4))
    ax1.grid(linewidth=2)
    ax1.set_title("Laptop")

    ax1.set_xlabel("Event count")
    ax1.set_ylabel("Total time (ms)")

    ax1.set_xscale("log")
    ax1.set_yscale("log")

    ax1.set_ylim([0.1,100_000])
    ax1.set_xlim([1,1000])

    ###

    y21 = [0.4, 2.9,   27,   272]
    y22 = [3.5,2036, 6223, 26828]
    y23 = [1.5, 149,  683,  5437]

    ax2.plot(x, y22, label="Maximum", linewidth=5)
    ax2.plot(x, y23, label="Average", linewidth=5)
    ax2.plot(x, y21, label="Minimum", linewidth=5)

    ax2.grid(linewidth=2)
    ax2.set_title("Desktop")

    ax2.set_xlabel("Event count")
    ax2.set_ylabel("Total time (ms)")

    ax2.set_xscale("log")
    ax2.set_yscale("log")

    ax2.set_ylim([0.1,100_000])
    ax2.set_xlim([1,1000])

    ###

    y31 = [0.61, 0.48, 0.46, 0.42]
    y32 = [  16,  305,   72,   37]
    y33 = [ 2.2,   14,   12,  8.9]

    ax3.plot(x, y32, label="Maximum", linewidth=5)
    ax3.plot(x, y33, label="Average", linewidth=5)
    ax3.plot(x, y31, label="Minimum", linewidth=5)

    ax3.grid(linewidth=2)
    # ax3.set_title("Laptop")

    ax3.set_xlabel("Event count")
    ax3.set_ylabel("Time per event (ms)")

    ax3.set_xscale("log")
    ax3.set_yscale("log")

    ax3.set_ylim([0.1,1_000])
    ax3.set_xlim([1,1000])

    ###

    y41 = [0.4,0.29, 0.27, 0.27]
    y42 = [3.5, 203,   62,   26]
    y43 = [1.5,  14,  6.8,  5.4]

    ax4.plot(x, y42, label="Maximum", linewidth=5)
    ax4.plot(x, y43, label="Average", linewidth=5)
    ax4.plot(x, y41, label="Minimum", linewidth=5)

    ax4.grid(linewidth=2)

    ax4.set_xlabel("Event count")
    ax4.set_ylabel("Time per event (ms)")

    ax4.set_xscale("log")
    ax4.set_yscale("log")

    ax4.set_ylim([0.1,1_000])
    ax4.set_xlim([1,1000])

    ###

    fig.set_figheight(25)
    fig.set_figwidth(35)
    fig.set_dpi(100)

    fig.savefig("performance_results/single_listener.png",bbox_inches='tight')

def multiple_listeners():
    fig, (ax1,ax2) = plt.subplots(1,2)

    x = [1,10,100,250,500,1000]

    y11 = [  443,   446,   477,   534,  663,  893]
    y12 = [20614, 20624, 31026, 12485, 3321, 3592]
    y13 = [ 8649,  7764,  7310,  2355,  928, 1163]

    ax1.plot(x, y12, label="Maximum", linewidth=5)
    ax1.plot(x, y13, label="Average", linewidth=5)
    ax1.plot(x, y11, label="Minimum", linewidth=5)

    ax1.legend(bbox_to_anchor=(0.2,1.4))
    ax1.grid(linewidth=2)
    ax1.set_title("Laptop")

    ax1.set_xlabel("Listener count")
    ax1.set_ylabel("Total time (ms)")

    ax1.set_xscale("log")
    ax1.set_yscale("log")

    ax1.set_ylim([200,60_000])
    ax1.set_xlim([1,1000])

    ###

    y21 = [  269,   283,  289,  321, 361, 441]
    y22 = [24828, 19655, 7911, 5890, 475, 613]
    y23 = [ 8090,  5193, 2114, 1002, 386, 462]

    ax2.plot(x, y22, label="Maximum", linewidth=5)
    ax2.plot(x, y23, label="Average", linewidth=5)
    ax2.plot(x, y21, label="Minimum", linewidth=5)

    ax2.grid(linewidth=2)
    ax2.set_title("Desktop")

    ax2.set_xlabel("Listener count")
    ax2.set_ylabel("Total time (ms)")

    ax2.set_xscale("log")
    ax2.set_yscale("log")

    ax2.set_ylim([200,60_000])
    ax2.set_xlim([1,1000])

    ###

    fig.set_figheight(12)
    fig.set_figwidth(35)
    fig.set_dpi(100)

    fig.savefig("performance_results/multiple_listeners.png",bbox_inches='tight')

def multiple_monitors():
    fig, (ax1,ax2) = plt.subplots(1,2)

    x = [1,10,100,250,500,1000]

    y11 = [  468,  521,  444,  469, 508, 601]
    y12 = [20683,48645,12311,13828,2282,2893]
    y13 = [ 8137, 8929, 4520, 1944, 867,1197]

    ax1.plot(x, y12, label="Maximum", linewidth=5)
    ax1.plot(x, y13, label="Average", linewidth=5)
    ax1.plot(x, y11, label="Minimum", linewidth=5)

    ax1.legend(bbox_to_anchor=(0.2,1.4))
    ax1.grid(linewidth=2)
    ax1.set_title("Laptop")

    ax1.set_xlabel("Monitor count")
    ax1.set_ylabel("Total time (ms)")

    ax1.set_xscale("log")
    ax1.set_yscale("log")

    ax1.set_ylim([200,60_000])
    ax1.set_xlim([1,1000])

    ###

    y21 = [  288,  289,  292,  297, 314, 342]
    y22 = [13259, 9542, 7703, 5563, 424, 466]
    y23 = [ 5370, 2615, 1833, 1037, 328, 357]

    ax2.plot(x, y22, label="Maximum", linewidth=5)
    ax2.plot(x, y23, label="Average", linewidth=5)
    ax2.plot(x, y21, label="Minimum", linewidth=5)

    ax2.grid(linewidth=2)
    ax2.set_title("Desktop")

    ax2.set_xlabel("Monitor count")
    ax2.set_ylabel("Total time (ms)")

    ax2.set_xscale("log")
    ax2.set_yscale("log")

    ax2.set_ylim([200,60_000])
    ax2.set_xlim([1,1000])

    ###

    fig.set_figheight(12)
    fig.set_figwidth(35)
    fig.set_dpi(100)

    fig.savefig("performance_results/multiple_monitors.png",bbox_inches='tight')

def standard_deviation():
    fig, (ax1,ax2) = plt.subplots(1,2)

    x = [1,10,100,1000]

    y11 = [4.6,495,1273,5034]
    y12 = [0.8,330,1225,6543]

    ax1.plot(x, y11, label="50 tests", linewidth=5)
    ax1.plot(x, y12, label="1000 tests", linewidth=5)

    ax1.legend(bbox_to_anchor=(0.2,1.4))
    ax1.grid(linewidth=2)
    ax1.set_title("Laptop")

    ax1.set_xlabel("Event count")
    ax1.set_ylabel("Standard deviation (ms)")

    ax1.set_xscale("log")
    ax1.set_yscale("log")

    ###
    ###

    fig.set_figheight(12)
    fig.set_figwidth(35)
    fig.set_dpi(100)

    fig.savefig("performance_results/standard_deviation.png",bbox_inches='tight')

if __name__ == "__main__":
    single_listener()
    multiple_listeners()
    multiple_monitors()
    # standard_deviation()
