def bar_equal_hashes():
    import plotly.graph_objects as go

    runs = [x for x in range(1, 13)]
    equal = [819, 924, 744, 891, 834, 594, 750, 842, 1083, 864, 846, 746]
    total = [1170, 1290, 1275, 1275, 1275, 1260, 1245, 1245, 1275, 1245, 1230, 1275]

    fig = go.Figure(data=[
        go.Bar(name='Equal hashes', x=runs, y=equal),
        go.Bar(name='Total hashes', x=runs, y=total)
    ])
    fig.update_layout(barmode='group', xaxis_title='Index of successive run', yaxis_title='Number of hashes')
    fig.add_hline(828)
    fig.add_hline(1255)
    fig.show()


def box_equal_hashes():
    equal = [819, 924, 744, 891, 834, 594, 750, 842, 1083, 864, 846, 746]
    total = [1170, 1290, 1275, 1275, 1275, 1260, 1245, 1245, 1275, 1245, 1230, 1275]
    percent = []
    for i in range(0, 12):
        percent.append(equal[i] / total[i] * 100)

    import plotly.express as px
    fig = px.box(percent)
    fig.update_layout(xaxis_title='OpenSSL', yaxis_title='Percentage of equal hashes')
    fig.show()


def box_per_fuzzer():
    percent = {'libFuzzer': [70.0, 71.95402298850576, 57.674418604651166, 70.23255813953489, 64.65116279069767,
                             46.588235294117645, 60.71428571428571, 66.42857142857143, 85.11627906976744,
                             69.76190476190476, 68.67469879518072, 58.6046511627907],
               'Honggfuzz': [70.0, 71.95402298850576, 58.837209302325576, 69.06976744186046, 64.65116279069767,
                             46.588235294117645, 60.71428571428571, 66.42857142857143, 85.11627906976744,
                             69.76190476190476, 68.67469879518072, 58.6046511627907],
               'AFL++': [70.0, 71.95402298850576, 58.837209302325576, 71.3953488372093, 64.65116279069767,
                         46.588235294117645, 60.71428571428571, 67.61904761904762, 85.11627906976744,
                         69.76190476190476, 68.67469879518072, 59.76744186046512]}

    import plotly.express as px
    fig = px.box(percent)
    fig.update_layout(xaxis_title='Fuzzer', yaxis_title='Percentage of equal hashes')
    fig.show()


def box_per_target():
    percent = {'openssl-bignum': [73.07692307692307, 72.41379310344827, 58.91472868217055, 72.09302325581395,
                                  67.44186046511628, 47.05882352941176, 63.095238095238095, 68.25396825396825,
                                  86.04651162790698, 70.23809523809523, 71.08433734939759, 60.85271317829457],
               'openssl-asn1parse': [73.07692307692307, 72.41379310344827, 58.91472868217055, 72.09302325581395,
                                     65.11627906976744, 47.05882352941176, 63.095238095238095, 68.25396825396825,
                                     86.04651162790698, 70.23809523809523, 71.08433734939759, 60.85271317829457],
               'openssl-x509': [73.07692307692307, 72.41379310344827, 58.91472868217055, 72.09302325581395,
                                67.44186046511628, 47.05882352941176, 63.095238095238095, 68.25396825396825,
                                86.04651162790698, 70.23809523809523, 71.08433734939759, 60.85271317829457],
               'openssl-server': [65.38461538461539, 71.26436781609196, 57.751937984496124, 67.44186046511628,
                                  61.627906976744185, 45.88235294117647, 57.14285714285714, 64.68253968253968,
                                  83.72093023255815, 69.04761904761905, 65.06024096385542, 56.201550387596896],
               'openssl-client': [65.38461538461539, 71.26436781609196, 57.751937984496124, 67.44186046511628,
                                  61.627906976744185, 45.88235294117647, 57.14285714285714, 64.68253968253968,
                                  83.72093023255815, 69.04761904761905, 65.06024096385542, 56.201550387596896]}

    import plotly.express as px
    fig = px.box(percent)
    fig.update_layout(xaxis_title='Fuzz Target', yaxis_title='Percentage of equal hashes')
    fig.show()


if __name__ == '__main__':
    bar_equal_hashes()
    box_equal_hashes()
    box_per_fuzzer()
    box_per_target()
