<jupyter_start><jupyter_text>Run Monte Carlo model in six month intervals, for each interval:1.) Extrapolate country trends for all countries2.) For each country, if 70% or more hens projected to be cage-free in that country, immediately become a NATIONAL law in that country3.) Each year, expect a scientific report sometime between December 2022 and 2024… when report happens, there is a 36% chance of EU law after 2 years (+/-)4.) The EU Presidency rotates through a known sequence (Germany now, Portugal in Jan 2021, Slovenia in July 2021, France, Czech Republic, Sweden, etc.) - if it hits a country that has a national law, 57% chance it becomes EU law after 12-36 months<jupyter_code>N_SCENARIOS = 10000
scenario_results = []
scenario_reasons = []
scenario_countries = []

for n in range(N_SCENARIOS):
    EU_PRESIDENCIES = ['Portugal', 'Slovenia', 'France', 'Czechia', 'Sweden', 'Spain', 'Belgium',
                       'Hungary', 'Poland', 'Denmark', 'Cyprus', 'Ireland', 'Lithuania', 'Greece',
                       'Italy', 'Latvia', 'Luxembourg', 'Netherlands', 'Slovakia', 'Malta']
    COUNTRIES_W_BANS = ['Germany', 'Czechia', 'Luxembourg']
    COUNTRY_RATES = {'Portugal': 0.138,
                     'Slovenia': 0.607,
                     'France': 0.459,
                     'Czechia': 0.26,
                     'Sweden': 0.908,
                     'Spain': 0.232,
                     'Belgium': 0.628,
                     'Hungary': 0.297,
                     'Poland': 0.179,
                     'Denmark': 0.87,
                     'Cyprus': 0.412,
                     'Germany': 0.94,
                     'Ireland': 0.485,
                     'Lithuania': 0.111,
                     'Greece': 0.227,
                     'Italy': 0.506,
                     'Latvia': 0.183,
                     'Luxembourg': 1,
                     'Netherlands': 0.859,
                     'Slovakia': 0.167,
                     'Malta': 0.06}
    report = False
    ban_presidency = False
    done = False
    i = 1
    verbose = (n % 500 == 0)
    if verbose:
        print('## SCENARIO {}/{} ##'.format(n + 1, N_SCENARIOS))
    for year in range(2021, 10000):
        for season in ['H1', 'H2']:
            if not done:
                tick = '{} {}'.format(year, season)
                if verbose:
                    print('{}: {}'.format(i, tick))

                # Extrapolate country trends for all countries
                for country in COUNTRY_RATES.keys():
                    COUNTRY_RATES[country] += 0.03 # TODO: Country-specific trends
                    if COUNTRY_RATES[country] > 1:
                        COUNTRY_RATES[country] = 1

                # For each country, if 70% or more hens projected to be cage-free in that country,
                # immediately become a NATIONAL law in that country
                for country in COUNTRY_RATES.keys():
                    if COUNTRY_RATES[country] >= 0.7:
                        if country not in COUNTRIES_W_BANS:
                            if verbose:
                                print('...{} passed a national ban!'.format(country))
                            COUNTRIES_W_BANS.append(country)

                # Each year, expect a scientific report sometime between December 2022 and 2024
                if not report and year >= 2023:
                    if random.random() < 0.25:
                        if verbose:
                            print('...The scientific report arrived!')
                        report = True
                        report_on_tick = i

                # when report happens, there is a 36% chance of EU law after 12-36 months
                if report:
                    if (i == report_on_tick + 2 and random.random() < 0.5) or (i > report_on_tick + 6):
                        if random.random() < 0.36:
                            if verbose:
                                print('...EU BAN ACHIEVED (by scientific report)! 🎉🎉🎉')
                            scenario_results.append(year)
                            scenario_reasons.append('report')
                            scenario_countries.append('report')
                            done = True
                        else:
                            if verbose:
                                print('...Scientific report didn\'t lead to ban')
                
                if not done:
                    # The EU Presidency rotates...
                    president = EU_PRESIDENCIES[(i - 1) % len(EU_PRESIDENCIES)]
                    if verbose:
                        print('...{} is President'.format(president))

                    # TODO: if it hits a country that has a national law, 57% chance it becomes EU law after 12-36 months
                    if president in COUNTRIES_W_BANS and not ban_presidency:
                        if verbose:
                            print('...The EU Presidency has a national ban, attempting EU ban')
                        ban_presidency = True
                        ban_presidency_on_tick = i
                        ban_country = president

                    if ban_presidency:
                        if (i >= ban_presidency_on_tick + 2 and random.random() < 0.5) or (i > ban_presidency_on_tick + 6):
                            if random.random() < 0.57:
                                if verbose:
                                    print('...EU BAN ACHIEVED (by {} EU Presidency)! 🎉🎉🎉'.format(ban_country))
                                scenario_results.append(year)
                                scenario_reasons.append('presidency')
                                scenario_countries.append(ban_country)
                                done = True
                            else:
                                if verbose:
                                    print('...attempted EU ban by Presidency failed')
                                ban_presidency = False

                    i += 1
                
    if verbose:
        print('-')
for y in range(2021, 2036):
    print('% chance by {}: {}'.format(y, print_pct(np.sum([s <= y for s in scenario_results]) / len(scenario_results), digits=1)))
pd.Series(scenario_reasons).value_counts(normalize=True) * 100
pd.Series(scenario_countries).value_counts(normalize=True) * 100
# TODO: Can calculate chickens saved by EU ban by looking at delta with existing state at time of ban
# TODO: Can calculate highest-leverage opportunities<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.09448455984022124, 'fraction_numerical': 0.030265785834997696, 'mean_word_length': 1.345100864553314, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '232438', 'license': 'MIT', 'n_tokens_mistral': 1960, 'n_tokens_neox': 1657, 'n_words': 524, 'path': 'EU Cage Free Model.ipynb', 'repo_name': 'NeiloDull/eu_cage_free_model', 'size': '6509'}