<jupyter_start><jupyter_text>Data Source: https://www.uci.org/mountain-bike/results<jupyter_code>import json
DICIPLINE_ID_MOUNTAIN_BIKE = '7'

RACE_TYPE_ID_DOWNHILL = '19'
RACE_TYPE_ID_ENDURO = '122'
RACE_TYPE_ID_CROSS_COUNTRY_OLYMPIC = '92'

SEASON_ID_YEAR_MAP = {
    2020: '129',
    2019: '128',
    2018: '123',
    2017: '22',
    2016: '12',
    2015: '4',
    2014: '102',
    2013: '103',
    2012: '104',
    2011: '105',
    2010: '106',
    2009: '107',
}

COMPETITION_CLASS_CODE_WORLD_CHAMPS = 'CM'
COMPETITION_CLASS_CODE_WORLD_CUP = 'CDM'
COMPETITION_CLASS_CODE_ENDURO_WORLD_SERIES = '3'

CATEGORY_CODE_MEN_ELITE = 'Men Elite'
CATEGORY_CODE_WOMEN_ELITE = 'Women Elite'

RACE_TYPE_CODE_DHI = 'DHI'
RACE_TYPE_CODE_ENDURO = 'END'
RACE_TYPE_CODE_XCO = 'XCO'

RACE_TYPE_ID_TO_CODE_MAP = {
    RACE_TYPE_ID_DOWNHILL: RACE_TYPE_CODE_DHI,
    RACE_TYPE_ID_ENDURO: RACE_TYPE_CODE_ENDURO,
    RACE_TYPE_ID_CROSS_COUNTRY_OLYMPIC: RACE_TYPE_CODE_XCO
}
with open('../data/competitions_with_races_and_events_and_results.json') as f:
    competitions_with_races_and_events_and_results = json.load(f)
total_age_dh_mens = 0
number_of_items_in_total_age_dh_mens = 0

total_age_enduro_mens = 0
number_of_items_in_total_age_enduro_mens = 0

total_age_xc_mens = 0
number_of_items_in_total_age_xc_mens = 0

total_age_dh_womens = 0
number_of_items_in_total_age_dh_womens = 0

total_age_enduro_womens = 0
number_of_items_in_total_age_enduro_womens = 0

total_age_xc_womens = 0
number_of_items_in_total_age_xc_womens = 0
for race_type in competitions_with_races_and_events_and_results:
    for year in competitions_with_races_and_events_and_results[race_type]:
        for competition in competitions_with_races_and_events_and_results[race_type][year]:
            for race in competition['races']:
                for category_code in [CATEGORY_CODE_MEN_ELITE, CATEGORY_CODE_WOMEN_ELITE]:
                    if category_code in race['events']:
                        age = int(race['events'][category_code]['results'][0]['Age'])
                        if race_type == RACE_TYPE_ID_DOWNHILL:
                            if category_code == CATEGORY_CODE_MEN_ELITE:
                                total_age_dh_mens += age
                                number_of_items_in_total_age_dh_mens += 1
                            elif category_code == CATEGORY_CODE_WOMEN_ELITE:
                                total_age_dh_womens += age
                                number_of_items_in_total_age_dh_womens += 1
                        elif race_type == RACE_TYPE_ID_ENDURO:
                            if category_code == CATEGORY_CODE_MEN_ELITE:
                                total_age_enduro_mens += age
                                number_of_items_in_total_age_enduro_mens += 1
                            elif category_code == CATEGORY_CODE_WOMEN_ELITE:
                                total_age_enduro_womens += age
                                number_of_items_in_total_age_enduro_womens += 1
                        elif race_type == RACE_TYPE_ID_CROSS_COUNTRY_OLYMPIC:
                            if category_code == CATEGORY_CODE_MEN_ELITE:
                                total_age_xc_mens += age
                                number_of_items_in_total_age_xc_mens += 1
                            elif category_code == CATEGORY_CODE_WOMEN_ELITE:
                                total_age_xc_womens += age
                                number_of_items_in_total_age_xc_womens += 1
def round_age(age):
    return round(age, 2)
print('Average Age of Event Winners (years)')
print(f"DH Men's: {round_age(total_age_dh_mens / number_of_items_in_total_age_dh_mens)}")
print(f"DH Women's: {round_age(total_age_dh_womens / number_of_items_in_total_age_dh_womens)}")
print(f"Enduro Men's: {round_age(total_age_enduro_mens / number_of_items_in_total_age_enduro_mens)}")
print(f"Enduro Women's: {round_age(total_age_enduro_womens / number_of_items_in_total_age_enduro_womens)}")
print(f"XCO Men's: {round_age(total_age_xc_mens / number_of_items_in_total_age_xc_mens)}")
print(f"XCO Women's: {round_age(total_age_xc_womens / number_of_items_in_total_age_xc_womens)}")<jupyter_output>Average Age of Event Winners (years)
DH Men's: 26.53
DH Women's: 26.64
Enduro Men's: 26.83
Enduro Women's: 27.72
XCO Men's: 29.11
XCO Women's: 28.0
{'fraction_non_alphanumeric': 0.07605177993527508, 'fraction_numerical': 0.030513176144244106, 'mean_word_length': 2.9372156505914466, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 1, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '445911', 'license': 'MIT', 'n_tokens_mistral': 1771, 'n_tokens_neox': 1620, 'n_words': 228, 'path': 'notebooks/analysis.ipynb', 'repo_name': 'Andrew-Mackay/mountain_bike_athlete_analysis', 'size': '4326'}