import matplotlib.pyplot as plt
import matplotlib.patches as pch
import json


def main():
    with open("res.json", 'r') as json_f:
        times = json.load(json_f)
    with open("w_cls.csv", 'r') as cls_f:
        classes = [[], [], [], []]
        for l in cls_f:
            r, c = list(map(int, l.split(',')))
            classes[c - 1].append(r)

    plt.bar(classes[0], [times[r] for r in classes[0]], color="blue")
    plt.bar(classes[1], [times[r] for r in classes[1]], color="red")
    plt.bar(classes[2], [times[r] for r in classes[2]], color="green")
    plt.bar(classes[3], [times[r] for r in classes[3]], color="purple")

    plt.yscale('log')

    cls_1 = pch.Patch(color="blue", label="Class 1")
    cls_2 = pch.Patch(color="red", label="Class 2")
    cls_3 = pch.Patch(color="green", label="Class 3")
    cls_4 = pch.Patch(color="purple", label="Class 4")
    plt.legend(handles=[cls_1, cls_2, cls_3, cls_4])

    plt.xlabel("Wolfram rule")
    plt.ylabel("Average cycle time")
    plt.title("Average cycle time for each Wolfram rule")

    plt.show()


if __name__ == "__main__":
    main()
