import pandas
import matplotlib.pyplot as plt

def generate(wod, divider):
    data = pandas.read_csv(wod + '.csv')

    data['ScoreWeight'] = data['Score'] / divider
    data = data.astype({'ScoreWeight': 'int32'})
    df = data[['AthleteGender', 'ScoreWeight']].groupby('AthleteGender').quantile([float(i) / 100 for i in range(1, 100)]).reset_index().rename(columns={'level_1': 'quantile'})
    df = df.pivot(index='quantile', columns='AthleteGender', values='ScoreWeight')
    print(df)
    df['Ratio'] = df['M'] / df['F']
    df.plot(secondary_y=['Ratio'])

    plt.savefig(wod + '-strengh-distribution.pdf')

    with open(wod + '.strengh-distribution.html', 'w') as f:
        f.write(df.to_html())

    with open(wod + '.strengh-distribution.csv', 'w') as f:
        f.write(df.to_csv())

for wod, divider in [('21.4', 1000000), ('23.2', 10000)]:
    generate(wod, divider)
