import datetime
import matplotlib
import matplotlib.pyplot as plt
import numpy as np

md_sizes = [
    3.8173828125,
    10.8671875,
    7.083984375,
    13.4091796875,
    15.06640625,
    9.337890625,
    6.623046875,
    6.2119140625,
    4.470703125,
    20.3232421875,
    12.259765625,
    7.9873046875,
    7.2744140625,
    5.6474609375,
    9.5478515625,
    8.1689453125,
    17.9482421875,
    5.9267578125,
    6.0556640625,
    10.765625,
    8.2451171875,
    7.6875,
    17.7119140625,
    13.568359375,
    12.166015625,
    17.30859375,
    6.47265625,
    6.623046875,
    15.4853515625,
    6.9375,
    0.9736328125,
    13.8369140625,
    8.435546875,
    12.544921875,
    11.2119140625,
    20.0009765625,
    12.8017578125,
    12.15625,
    12.3671875,
    29.0849609375,
    20.5390625,
    31.3427734375,
    22.9462890625,
    30.5078125,
    36.01953125,
    28.529296875,
    46.0244140625,
    33.2939453125,
    30.302734375,
    29.0791015625,
    21.37890625,
    40.5263671875,
    48.51953125,
    34.689453125,
    22.37890625,
    38.1376953125,
    35.68359375,
    29.373046875,
    37.486328125,
    43.837890625,
    53.1962890625,
    34.017578125,
    71.9931640625,
    62.6884765625,
    45.2294921875,
    49.4013671875,
    44.6923828125,
    55.953125,
    75.6044921875,
    65.4794921875,
    69.3857421875,
    48.109375,
    45.1259765625,
    31.837890625,
    49.98828125,
    61.859375,
    44.2939453125,
    57.900390625,
    37.2607421875,
    371.5107421875,
    57.681640625,
    24.0986328125,
    77.046875,
    59.0751953125,
    78.796875,
    75.8759765625,
    49.44921875,
    149.9296875,
    75.1357421875,
    310.6982421875,
    109.3603515625,
    153.6748046875,
    186.8154296875,
    68.775390625,
    151.4208984375,
    175.939453125,
    149.1767578125,
    160.3828125,
    345.29296875,
    186.150390625,
]
dir_sizes = [
    184.53125,
    74.5966796875,
    329.7041015625,
    47.1015625,
    305.4833984375,
    634.8046875,
    135.0361328125,
    140.19921875,
    198.8525390625,
    1778.615234375,
    609.7646484375,
    542.8466796875,
    399.7529296875,
    430.1142578125,
    863.216796875,
    526.02734375,
    1207.99609375,
    607.1162109375,
    712.138671875,
    335.31640625,
    1026.4462890625,
    368.494140625,
    377.65234375,
    663.279296875,
    675.03515625,
    407.05859375,
    582.59765625,
    668.2705078125,
    1060.9091796875,
    456.6630859375,
    690.693359375,
    1115.8369140625,
    948.958984375,
    662.8046875,
    1238.125,
    1452.6826171875,
    1052.357421875,
    1250.24609375,
    1668.0947265625,
    2390.859375,
    1156.1298828125,
    1831.3134765625,
    939.43359375,
    2142.4765625,
    1909.705078125,
    1205.1064453125,
    2810.044921875,
    2683.234375,
    2174.3525390625,
    29.0791015625,
    2145.4970703125,
    2263.0283203125,
    2804.435546875,
    2192.26171875,
    1569.7578125,
    1450.5341796875,
    2564.5615234375,
    2460.349609375,
    2190.951171875,
    1675.943359375,
    1579.9013671875,
    689.876953125,
    2537.48046875,
    3108.2490234375,
    1387.6708984375,
    1285.7451171875,
    1343.9736328125,
    2421.99609375,
    2353.18359375,
    2251.9951171875,
    2092.0615234375,
    1813.2080078125,
    5260.6689453125,
    2387.458984375,
    2796.908203125,
    4337.359375,
    3372.4033203125,
    2783.041015625,
    6667.9794921875,
    17333.916015625,
    7798.830078125,
    3342.6220703125,
    7911.53515625,
    12797.8564453125,
    12986.77734375,
    10606.7080078125,
    6000.919921875,
    14279.271484375,
    12977.1611328125,
    31468.5732421875,
    8471.583984375,
    13809.5908203125,
    6451.2373046875,
    12135.630859375,
    10197.7314453125,
    16632.888671875,
    32360.2001953125,
    11791.36328125,
    40063.5087890625,
    34303.9365234375,
]
creation_dates = [
    0.0,
    0.0,
    0.912349537037037,
    1.1690509259259259,
    1.0186574074074075,
    1.247025462962963,
    2.391412037037037,
    0.4577777777777778,
    2.338252314814815,
    3.197986111111111,
    1.5738425925925925,
    2.065462962962963,
    1.5659837962962964,
    1.0369097222222223,
    1.3342361111111112,
    2.1685300925925928,
    1.4960416666666667,
    1.6909953703703704,
    2.0433680555555553,
    3.2810300925925926,
    1.9123379629629629,
    1.2816550925925927,
    3.2724652777777776,
    1.2615393518518518,
    2.4924537037037036,
    1.1484953703703704,
    2.099224537037037,
    0.9613657407407408,
    2.1582523148148147,
    2.374976851851852,
    1.8224421296296296,
    1.1035069444444445,
    1.8824652777777777,
    3.067858796296296,
    3.255613425925926,
    3.7397222222222224,
    4.882858796296296,
    5.9674652777777775,
    10.689386574074074,
    9.112395833333334,
    4.498414351851852,
    5.3203125,
    4.925081018518519,
    4.12443287037037,
    6.2035532407407405,
    6.0866087962962965,
    10.082222222222223,
    6.142384259259259,
    8.225277777777778,
    3.0336458333333334,
    3.3443171296296295,
    5.30525462962963,
    6.903414351851852,
    6.495671296296297,
    5.4505787037037035,
    5.9379282407407405,
    5.896134259259259,
    9.780138888888889,
    7.525439814814815,
    11.05730324074074,
    8.760497685185186,
    3.901828703703704,
    7.551793981481482,
    10.353935185185184,
    6.514490740740741,
    5.00261574074074,
    6.208900462962963,
    4.8829513888888885,
    9.641886574074075,
    6.357835648148148,
    8.176296296296297,
    8.722708333333333,
    7.8587037037037035,
    8.080729166666666,
    10.6475,
    10.90818287037037,
    9.183854166666666,
    10.098090277777779,
    12.465763888888889,
    36.67619212962963,
    16.74252314814815,
    5.129363425925926,
    21.01247685185185,
    11.610983796296296,
    14.255300925925926,
    19.072407407407407,
    13.17349537037037,
    21.4971875,
    25.723969907407408,
    19.84375,
    34.51599537037037,
    19.415972222222223,
    54.420462962962965,
    14.555659722222222,
    16.684953703703705,
    16.460856481481482,
    24.660462962962963,
    21.460694444444446,
    33.15903935185185,
    14.032430555555555,
]

METADATA = {"Creator": None, "Date": None, "Format": None, "Type": None}

fig, ax = plt.subplots(figsize=(18.0, 6.0), layout="constrained")
ax1 = ax.twinx()  # "twinx": the plural of "twink"
ax2 = ax.twinx()

ax.set_ylim(0, 375)
ax1.set_ylim(0, 40100)
ax2.set_ylim(0, 55)

labels = [
    "Markdown size (KiB)",
    "Total size (KiB)",
    "1ˢᵗ-commit-to-1ˢᵗ-commit time (days)",
]
ax.set_xlabel("rangifer’s diary pt.")
ax.set_ylabel(labels[0])
ax1.set_ylabel(labels[1])
ax2.set_ylabel(labels[2])

x = np.arange(1, 100 + 1)
width = 0.25
colours = plt.cm.viridis([0.0, 0.45, 0.85])

multiplier = 0
handles = []
for attr, colour, values, axes in [
    (labels[0], colours[0], md_sizes, ax),
    (labels[1], colours[1], dir_sizes, ax1),
    (labels[2], colours[2], creation_dates, ax2),
]:
    offset = width * multiplier
    handles.append(
        axes.bar(x + offset, values, width, color=colour, label=attr)
    )
    multiplier += 1

handles = [
    plt.Rectangle((0, 0), 1, 1, color=colours[i]) for i in range(len(labels))
]
ax.legend(handles, labels)

ax2.spines["right"].set_position(("outward", 60))

ax.xaxis.set_ticks(
    [1 + width] + [10 * n + width for n in range(1, 10 + 1)],
    ["i", "x", "xx", "xxx", "xl", "l", "lx", "lxx", "lxxx", "xc", "c"],
)

plt.savefig("plot.svg", format="svg", metadata=METADATA)
