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.62,  6.7,    44,   550]
    y12 = [  24, 4000, 10000, 22000]
    y13 = [ 2.5,  200,  1200,  6800]

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

    ###

    y21 = [0.4,    3,   25,   240]
    y22 = [2.2, 1000, 2200, 16000]
    y23 = [1.6,   56,  440,  5200]

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

    ###

    y31 = [0.62, 0.67, 0.44, 0.55]
    y32 = [  24,  400,  100,   22]
    y33 = [ 2.5,   20,   12,  6.8]

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

    ###

    y41 = [0.40, 0.30, 0.25, 0.24]
    y42 = [ 2.2,  100,   22,   16]
    y43 = [ 1.6,  5.6,  4.4,  5.2]

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

    ###

    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 = [630,460,420,510,590,920]
    y12 = [17000,25000,20000,7900,1600,3200]
    y13 = [5600,7600,7100,2900,720,1500]

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

    ###

    y21 = [240,240,250,270,310,380]
    y22 = [16000,19000,10000,12000,330,420]
    y23 = [5200,4000,1000,900,310,400]

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

    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 = [630, 450, 380, 400, 440, 520]
    y12 = [17000, 25000, 18000, 13000, 2900, 2300]
    y13 = [5600, 6600, 4400, 1800, 720, 700]

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

    ###

    y21 = [240,230,240,250,260,290]
    y22 = [16000,20000,18000,7600,300,300]
    y23 = [5200,6500,2900,800,270,290]

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

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

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

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