def PEFM(country_name_list, country_and_percentile_rank_list): Pres_2011_percentile_rank_list = [] Pres_2012_percentile_rank_list = [] Pres_2013_percentile_rank_list = [] Pres_2014_percentile_rank_list = [] Pres_2015_percentile_rank_list = [] Pres_2016_percentile_rank_list = [] Pres_2017_percentile_rank_list = [] Total_Pres_percentile_rank_list = [] for country in country_name_list: country = int(country_numberifier(country)) Pres_2011 = (country_and_percentile_rank_list['Pres_2011'][country]) number_of_nan = int(sum([pd.isnull(i) for i in Pres_2011])) real_len = int(len(Pres_2011) / 2) dvisible_number = int(real_len - number_of_nan) biz_sum = np.nansum(Pres_2011[1::2]) Pres_2011 = biz_sum / dvisible_number Pres_2011_percentile_rank_list.append(Pres_2011) #2012 Pres_2012 = (country_and_percentile_rank_list['Pres_2012'][country]) number_of_nan = int(sum([pd.isnull(i) for i in Pres_2012])) real_len = int(len(Pres_2012) / 2) dvisible_number = int(real_len - number_of_nan) biz_sum = np.nansum(Pres_2012[1::2]) Pres_2012 = biz_sum / dvisible_number Pres_2012_percentile_rank_list.append(Pres_2012) #2013 Pres_2013 = (country_and_percentile_rank_list['Pres_2013'][country]) number_of_nan = int(sum([pd.isnull(i) for i in Pres_2013])) real_len = int(len(Pres_2013) / 2) dvisible_number = int(real_len - number_of_nan) biz_sum = np.nansum(Pres_2013[1::2]) Pres_2013 = biz_sum / dvisible_number Pres_2013_percentile_rank_list.append(Pres_2013) #2014 Pres_2014 = (country_and_percentile_rank_list['Pres_2014'][country]) number_of_nan = int(sum([pd.isnull(i) for i in Pres_2014])) real_len = int(len(Pres_2014) / 2) dvisible_number = int(real_len - number_of_nan) biz_sum = np.nansum(Pres_2014[1::2]) Pres_2014 = biz_sum / dvisible_number Pres_2014_percentile_rank_list.append(Pres_2014) #2015 Pres_2015 = (country_and_percentile_rank_list['Pres_2015'][country]) number_of_nan = int(sum([pd.isnull(i) for i in Pres_2015])) real_len = int(len(Pres_2015) / 2) dvisible_number = int(real_len - number_of_nan) biz_sum = np.nansum(Pres_2015[1::2]) Pres_2015 = biz_sum / dvisible_number Pres_2015_percentile_rank_list.append(Pres_2015) #2016 Pres_2016 = (country_and_percentile_rank_list['Pres_2016'][country]) number_of_nan = int(sum([pd.isnull(i) for i in Pres_2016])) real_len = int(len(Pres_2016) / 2) dvisible_number = int(real_len - number_of_nan) biz_sum = np.nansum(Pres_2016[1::2]) Pres_2016 = biz_sum / dvisible_number Pres_2016_percentile_rank_list.append(Pres_2016) #2017 Pres_2017 = (country_and_percentile_rank_list['Pres_2017'][country]) number_of_nan = int(sum([pd.isnull(i) for i in Pres_2017])) real_len = int(len(Pres_2017) / 2) dvisible_number = int(real_len - number_of_nan) biz_sum = np.nansum(Pres_2017[1::2]) Pres_2017 = biz_sum / dvisible_number Pres_2017_percentile_rank_list.append(Pres_2017) #TOTAL Total_Pres = (country_and_percentile_rank_list['Pres_2017'][country] + country_and_percentile_rank_list['Pres_2016'][country] + country_and_percentile_rank_list['Pres_2015'][country] + country_and_percentile_rank_list['Pres_2014'][country] + country_and_percentile_rank_list['Pres_2013'][country] + country_and_percentile_rank_list['Pres_2012'][country] + country_and_percentile_rank_list['Pres_2011'][country]) number_of_nan = int(sum([pd.isnull(i) for i in Total_Pres])) real_len = int(len(Total_Pres) / 2) dvisible_number = int(real_len - number_of_nan) biz_sum = np.nansum(Total_Pres[1::2]) Total_Pres = biz_sum / dvisible_number Total_Pres_percentile_rank_list.append(Total_Pres) #PERCENTILING COMPOSITES AND FACTORIZATION Pres_2011_percentile_rank_list_factored = [] Pres_2012_percentile_rank_list_factored = [] Pres_2013_percentile_rank_list_factored = [] Pres_2014_percentile_rank_list_factored = [] Pres_2015_percentile_rank_list_factored = [] Pres_2016_percentile_rank_list_factored = [] Pres_2017_percentile_rank_list_factored = [] Total_Pres_percentile_rank_list_factored = [] for a in Pres_2011_percentile_rank_list: Pres_2011_percentile_rank_list_factored.append( stats.percentileofscore(Pres_2011_percentile_rank_list, a, kind='rank')) for b in Pres_2012_percentile_rank_list: Pres_2012_percentile_rank_list_factored.append( stats.percentileofscore(Pres_2012_percentile_rank_list, b, kind='rank')) for c in Pres_2013_percentile_rank_list: Pres_2013_percentile_rank_list_factored.append( stats.percentileofscore(Pres_2013_percentile_rank_list, c, kind='rank')) for d in Pres_2014_percentile_rank_list: Pres_2014_percentile_rank_list_factored.append( stats.percentileofscore(Pres_2014_percentile_rank_list, d, kind='rank')) for e in Pres_2015_percentile_rank_list: Pres_2015_percentile_rank_list_factored.append( stats.percentileofscore(Pres_2015_percentile_rank_list, e, kind='rank')) for f in Pres_2016_percentile_rank_list: Pres_2016_percentile_rank_list_factored.append( stats.percentileofscore(Pres_2016_percentile_rank_list, f, kind='rank')) for h in Pres_2017_percentile_rank_list: Pres_2017_percentile_rank_list_factored.append( stats.percentileofscore(Pres_2017_percentile_rank_list, h, kind='rank')) for g in Total_Pres_percentile_rank_list: Total_Pres_percentile_rank_list_factored.append( stats.percentileofscore(Total_Pres_percentile_rank_list, g, kind='rank')) # Weighting of Age more heavily Pres_2012_percentile_rank_list_factored = [ i * 1.1 for i in Pres_2012_percentile_rank_list_factored ] Pres_2013_percentile_rank_list_factored = [ i * 1.2 for i in Pres_2013_percentile_rank_list_factored ] Pres_2014_percentile_rank_list_factored = [ i * 1.3 for i in Pres_2014_percentile_rank_list_factored ] Pres_2015_percentile_rank_list_factored = [ i * 1.4 for i in Pres_2015_percentile_rank_list_factored ] Pres_2016_percentile_rank_list_factored = [ i * 1.5 for i in Pres_2016_percentile_rank_list_factored ] Pres_2017_percentile_rank_list_factored = [ i * 1.6 for i in Pres_2017_percentile_rank_list_factored ] Total_Pres_percentile_rank_list_factored = [ i * 1.7 for i in Total_Pres_percentile_rank_list_factored ] total_Pres_rank = {} for country in country_name_list: country_num = int(country_numberifier(country)) Pres_rank_data_together = ( Pres_2011_percentile_rank_list_factored[country_num], Pres_2012_percentile_rank_list_factored[country_num], Pres_2013_percentile_rank_list_factored[country_num], Pres_2014_percentile_rank_list_factored[country_num], Pres_2015_percentile_rank_list_factored[country_num], Pres_2016_percentile_rank_list_factored[country_num], Pres_2017_percentile_rank_list_factored[country_num], Total_Pres_percentile_rank_list_factored[country_num]) total_Pres_rank[str(country)] = Pres_rank_data_together Pres_rank_aggregate_factored = [] for country in country_name_list: tbr = total_Pres_rank[country] #Factoring for number of missing data Fields and averaging the raw score number_of_nan = int(sum([pd.isnull(i) for i in tbr])) real_len = len(tbr) dvisible_number = int(real_len - number_of_nan) num_sum = np.nansum(tbr) tbr = num_sum / dvisible_number Pres_rank_aggregate_factored.append(tbr) return {'Pres_rank_aggregate_factored': Pres_rank_aggregate_factored}
def PFM(country_name_list, country_and_percentile_rank_list): summer_olympics_percentile_rank_list = [] winter_olympics_percentile_rank_list = [] total_olympics_percentile_rank_list = [] miscellany_percentile_rank_list = [] for country in country_name_list: country = int(country_numberifier(country)) Summer_Olympics = ( country_and_percentile_rank_list[ 'Games Attended Total Summer Olympics'][country] + country_and_percentile_rank_list['Medals Total Summer Olympics'] [country]) #Factoring for number of missing data Fields and averaging the raw score number_of_nan = int(sum([pd.isnull(i) for i in Summer_Olympics])) real_len = int(len(Summer_Olympics) / 2) dvisible_number = int(real_len - number_of_nan) biz_sum = np.nansum(Summer_Olympics[1::2]) Summer_Olympics = biz_sum / dvisible_number summer_olympics_percentile_rank_list.append(Summer_Olympics) Winter_Olympics = ( country_and_percentile_rank_list['Winter Olympics Attended Total'] [country] + country_and_percentile_rank_list['Winter Olympics Medals Total'] [country]) #Factoring for number of missing data Fields and averaging the raw score number_of_nan = int(sum([pd.isnull(i) for i in Winter_Olympics])) real_len = int(len(Winter_Olympics) / 2) dvisible_number = int(real_len - number_of_nan) num_sum = np.nansum(Winter_Olympics[1::2]) Winter_Olympics = num_sum / dvisible_number winter_olympics_percentile_rank_list.append(Winter_Olympics) Total_Olympics = ( country_and_percentile_rank_list['Combined Olympics Attended'] [country] + country_and_percentile_rank_list['Combined Medals Total Olympics'] [country]) #Factoring for number of missing data Fields and averaging the raw score number_of_nan = int(sum([pd.isnull(i) for i in Total_Olympics])) real_len = int(len(Total_Olympics) / 2) dvisible_number = int(real_len - number_of_nan) num_sum = np.nansum(Total_Olympics[1::2]) Total_Olympics = num_sum / dvisible_number total_olympics_percentile_rank_list.append(Total_Olympics) Miscellany = ( country_and_percentile_rank_list['Number Of Billionaires'][country] + country_and_percentile_rank_list['Nobel Prizes'][country]) #Factoring for number of missing data Fields and averaging the raw score number_of_nan = int(sum([pd.isnull(i) for i in Miscellany])) real_len = int(len(Miscellany) / 2) dvisible_number = int(real_len - number_of_nan) num_sum = np.nansum(Miscellany[1::2]) Miscellany = num_sum / dvisible_number miscellany_percentile_rank_list.append(Miscellany) #PERCENTILING COMPOSITES AND FACTORIZATION summer_olympics_percentile_rank_list_factored = [] winter_olympics_percentile_rank_list_factored = [] total_olympics_percentile_rank_list_factored = [] miscellany_percentile_rank_list_factored = [] for a in summer_olympics_percentile_rank_list: summer_olympics_percentile_rank_list_factored.append( stats.percentileofscore(summer_olympics_percentile_rank_list, a, kind='rank')) for c in winter_olympics_percentile_rank_list: winter_olympics_percentile_rank_list_factored.append( stats.percentileofscore(winter_olympics_percentile_rank_list, c, kind='rank')) for d in total_olympics_percentile_rank_list: total_olympics_percentile_rank_list_factored.append( stats.percentileofscore(total_olympics_percentile_rank_list, d, kind='rank')) for e in miscellany_percentile_rank_list: miscellany_percentile_rank_list_factored.append( stats.percentileofscore(miscellany_percentile_rank_list, e, kind='rank')) # Weighting of Size more heavily ''' miscellany_percentile_rank_list_factored = [i * 2 for i in miscellany_percentile_rank_list_factored] ''' total_prestige_rank = {} for country in country_name_list: country_num = int(country_numberifier(country)) prestige_rank_data_together = ( summer_olympics_percentile_rank_list_factored[country_num], winter_olympics_percentile_rank_list_factored[country_num], total_olympics_percentile_rank_list_factored[country_num], miscellany_percentile_rank_list_factored[country_num]) total_prestige_rank[str(country)] = prestige_rank_data_together prestige_rank_aggregate_factored = [] for country in country_name_list: tbr = total_prestige_rank[country] #Factoring for number of missing data Fields and averaging the raw score number_of_nan = int(sum([pd.isnull(i) for i in tbr])) real_len = len(tbr) dvisible_number = int(real_len - number_of_nan) num_sum = np.nansum(tbr) tbr = num_sum / dvisible_number prestige_rank_aggregate_factored.append(tbr) return { 'prestige_rank_aggregate_factored': prestige_rank_aggregate_factored }
def CDFM(country_name_list, country_and_percentile_rank_list): ease_of_travel_percentile_rank_list = [] americana_abroad_percentile_rank_list = [] immigration_percentile_rank_list = [] ulterior_interaction_percentile_rank_list = [] for country in country_name_list: country = int(country_numberifier(country)) Ease_Of_Travel = ( country_and_percentile_rank_list[ 'Visa_Requirements_for_US_Citizens'][country] + country_and_percentile_rank_list[ 'Total_Non_Immigrant_Arrivals_Visitation_to_the_US_FY_2014'] [country]) #Factoring for number of missing data Fields and averaging the raw score number_of_nan = int(sum([pd.isnull(i) for i in Ease_Of_Travel])) real_len = int(len(Ease_Of_Travel) / 2) dvisible_number = int(real_len - number_of_nan) biz_sum = np.nansum(Ease_Of_Travel[1::2]) Ease_Of_Travel = biz_sum / dvisible_number ease_of_travel_percentile_rank_list.append(Ease_Of_Travel) Americana_Abroad = ( country_and_percentile_rank_list['McDonald_Locations_in_country'] [country] + country_and_percentile_rank_list['Starbucks'][country]) #Factoring for number of missing data Fields and averaging the raw score number_of_nan = int(sum([pd.isnull(i) for i in Americana_Abroad])) real_len = int(len(Americana_Abroad) / 2) dvisible_number = int(real_len - number_of_nan) num_sum = np.nansum(Americana_Abroad[1::2]) Americana_Abroad = num_sum / dvisible_number americana_abroad_percentile_rank_list.append(Americana_Abroad) Immigration = ( country_and_percentile_rank_list['Immigration_to_the_US_2010'] [country] + country_and_percentile_rank_list['Immigration_to_the_US_2011'] [country] + country_and_percentile_rank_list['Immigration_to_the_US_2012'] [country] + country_and_percentile_rank_list['Immigration_to_the_US_2013'] [country] + country_and_percentile_rank_list['Immigration_to_the_US_2014'] [country]) #Factoring for number of missing data Fields and averaging the raw score number_of_nan = int(sum([pd.isnull(i) for i in Immigration])) real_len = int(len(Immigration) / 2) dvisible_number = int(real_len - number_of_nan) num_sum = np.nansum(Immigration[1::2]) Immigration = num_sum / dvisible_number immigration_percentile_rank_list.append(Immigration) Ulterior_Interaction = ( country_and_percentile_rank_list[ 'Total_Tourists_and_Business_Arrival_Visitation_to_the_US_FY_201'] [country] + country_and_percentile_rank_list[ 'Students_and_exchange_visitors_Visitation_to_the_US_FY_2014'] [country] + country_and_percentile_rank_list[ 'Temporary_workers_and_families_Visitation_to_the_US_FY_2014'] [country]) #Factoring for number of missing data Fields and averaging the raw score number_of_nan = int(sum([pd.isnull(i) for i in Ulterior_Interaction])) real_len = int(len(Ulterior_Interaction) / 2) dvisible_number = int(real_len - number_of_nan) num_sum = np.nansum(Ulterior_Interaction[1::2]) Ulterior_Interaction = num_sum / dvisible_number ulterior_interaction_percentile_rank_list.append(Ulterior_Interaction) #PERCENTILING COMPOSITES AND FACTORIZATION ease_of_travel_percentile_rank_list_factored = [] americana_abroad_percentile_rank_list_factored = [] immigration_percentile_rank_list_factored = [] ulterior_interaction_percentile_rank_list_factored = [] for a in ease_of_travel_percentile_rank_list: ease_of_travel_percentile_rank_list_factored.append( stats.percentileofscore(ease_of_travel_percentile_rank_list, a, kind='rank')) for b in americana_abroad_percentile_rank_list: americana_abroad_percentile_rank_list_factored.append( stats.percentileofscore(americana_abroad_percentile_rank_list, b, kind='rank')) for c in immigration_percentile_rank_list: immigration_percentile_rank_list_factored.append( stats.percentileofscore(immigration_percentile_rank_list, c, kind='rank')) for d in ulterior_interaction_percentile_rank_list: ulterior_interaction_percentile_rank_list_factored.append( stats.percentileofscore(ulterior_interaction_percentile_rank_list, d, kind='rank')) cultural_diffusion_rank = {} for country in country_name_list: country_num = int(country_numberifier(country)) cultural_diffusion_rank_data_together = ( ease_of_travel_percentile_rank_list_factored[country_num], americana_abroad_percentile_rank_list_factored[country_num], immigration_percentile_rank_list_factored[country_num], ulterior_interaction_percentile_rank_list_factored[country_num]) cultural_diffusion_rank[str( country)] = cultural_diffusion_rank_data_together cultural_diffusion_aggregate_factored = [] for country in country_name_list: tbr = cultural_diffusion_rank[country] #Factoring for number of missing data Fields and averaging the raw score number_of_nan = int(sum([pd.isnull(i) for i in tbr])) real_len = len(tbr) dvisible_number = int(real_len - number_of_nan) num_sum = np.nansum(tbr) tbr = num_sum / dvisible_number cultural_diffusion_aggregate_factored.append(tbr) return { 'cultural_diffusion_aggregate_factored': cultural_diffusion_aggregate_factored }
def TRFM(country_name_list, country_and_percentile_rank_list): #Total Business Score total_trade_rank_percentile_list = [] rankings_trade_percentile_rank_list = [] data_trade_percentile_rank_list = [] for country in country_name_list: country_name = country country = int(country_numberifier(country)) Rankings_Trade = ( country_and_percentile_rank_list['FDI Inflow in Millions'][country] + country_and_percentile_rank_list['Trading Across Borders'][country] + country_and_percentile_rank_list['GDP Growth Rate in pencentage'] [country] + zero_or_nan(country, country_and_percentile_rank_list)['score'] + country_and_percentile_rank_list['Trade Freedom'][country] + country_and_percentile_rank_list[ 'Change in Trade Freedom from 2015'][country] + country_and_percentile_rank_list[ 'Stock Market Capitalization in billions'][country]) #Factoring for number of missing data Fields and averaging the raw score number_of_nan = int(sum([pd.isnull(i) for i in Rankings_Trade])) real_len = int(len(Rankings_Trade) / 2) dvisible_number = int(real_len - number_of_nan) biz_sum = np.nansum(Rankings_Trade[1::2]) Rankings_Trade = biz_sum / dvisible_number rankings_trade_percentile_rank_list.append(Rankings_Trade) Data_Trade = (trade_data_multiplier( country, country_and_percentile_rank_list)['new_import_score'] + trade_data_multiplier( country, country_and_percentile_rank_list)['new_export_score'] + country_and_percentile_rank_list[ 'Exports from the United States in 2014'][country] + country_and_percentile_rank_list[ 'Imports to the United States in 2014'][country] + country_and_percentile_rank_list[ 'Exports from the United States in 2013'][country] + country_and_percentile_rank_list[ 'Imports to the United States in 2013'][country] + country_and_percentile_rank_list[ 'Exports from the United States in 2012'][country] + country_and_percentile_rank_list[ 'Imports to the United States in 2012'][country] + country_and_percentile_rank_list[ 'Exports from the United States in 2011'][country] + country_and_percentile_rank_list[ 'Imports to the United States in 2011'][country] + country_and_percentile_rank_list[ 'Exports from the United States in 2010'][country] + country_and_percentile_rank_list[ 'Imports to the United States in 2010'][country] + country_and_percentile_rank_list[ 'Exports from the United States in 2009'][country] + country_and_percentile_rank_list[ 'Imports to the United States in 2009'][country]) #Factoring for number of missing data Fields and averaging the raw score number_of_nan = int(sum([pd.isnull(i) for i in Data_Trade])) real_len = int(len(Data_Trade) / 2) dvisible_number = int(real_len - number_of_nan) num_sum = np.nansum(Data_Trade[1::2]) Data_Trade = num_sum / dvisible_number data_trade_percentile_rank_list.append(Data_Trade) #PERCENTILING COMPOSITES AND FACTORIZATION rankings_trade_percentile_rank_list_factored = [] data_trade_percentile_rank_list_factored = [] for a in rankings_trade_percentile_rank_list: rankings_trade_percentile_rank_list_factored.append( stats.percentileofscore(rankings_trade_percentile_rank_list, a, kind='rank')) for b in data_trade_percentile_rank_list: data_trade_percentile_rank_list_factored.append( stats.percentileofscore(data_trade_percentile_rank_list, b, kind='rank')) #Weighting The Trade Rankings By a factor of 8 for Data_Trade rankings_trade_percentile_rank_list_factored = [ i * .25 for i in rankings_trade_percentile_rank_list_factored ] data_trade_percentile_rank_list_factored = [ i * 1.75 for i in data_trade_percentile_rank_list_factored ] total_trade_rank = {} for country in country_name_list: country_num = int(country_numberifier(country)) trade_rank_data_together = ( rankings_trade_percentile_rank_list_factored[country_num], data_trade_percentile_rank_list_factored[country_num]) total_trade_rank[str(country)] = trade_rank_data_together trade_relations_aggregate_factored = [] for country in country_name_list: tbr = total_trade_rank[country] #Factoring for number of missing data Fields and averaging the raw score number_of_nan = int(sum([pd.isnull(i) for i in tbr])) real_len = len(tbr) dvisible_number = int(real_len - number_of_nan) num_sum = np.nansum(tbr) tbr = num_sum / dvisible_number trade_relations_aggregate_factored.append(tbr) return { 'trade_relations_aggregate_factored': trade_relations_aggregate_factored }
def CPFM(country_name_list, country_and_percentile_rank_list): people_power_percentile_rank_list = [] financial_power_percentile_rank_list = [] global_climate_percentile_rank_list = [] for country in country_name_list: country = int(country_numberifier(country)) People_Power = (country_and_percentile_rank_list['Power Status and Relationship'][country] + country_and_percentile_rank_list['Population in Millions'][country] + country_and_percentile_rank_list['Geographic Area including water'][country]) #Factoring for number of missing data Fields and averaging the raw score number_of_nan = int(sum([pd.isnull(i) for i in People_Power])) real_len = int(len(People_Power)/2) dvisible_number = int(real_len - number_of_nan) biz_sum = np.nansum(People_Power[1::2]) People_Power = biz_sum / dvisible_number people_power_percentile_rank_list.append(People_Power) Financial_Climate = (country_and_percentile_rank_list['GDP in Billions at PPP'][country] + country_and_percentile_rank_list['5 Year GDP Growth Rate in Percentage'][country] + country_and_percentile_rank_list['GDP per Capita in PPP'][country] + country_and_percentile_rank_list['Unemployment in Percent'][country] + country_and_percentile_rank_list['Public Debt as Percentage of GDP'][country] + country_and_percentile_rank_list['HDI'][country]) #Factoring for number of missing data Fields and averaging the raw score number_of_nan = int(sum([pd.isnull(i) for i in Financial_Climate])) real_len = int(len(Financial_Climate)/2) dvisible_number = int(real_len - number_of_nan) num_sum = np.nansum(Financial_Climate[1::2]) Financial_Climate = num_sum / dvisible_number financial_power_percentile_rank_list.append(Financial_Climate) Global_Climate = (country_and_percentile_rank_list['Same language'][country] + country_and_percentile_rank_list['Opinion of the US'][country] + country_and_percentile_rank_list['Free Trade Agreements'][country] + country_and_percentile_rank_list['Shared Currency'][country]) #Factoring for number of missing data Fields and averaging the raw score number_of_nan = int(sum([pd.isnull(i) for i in Global_Climate])) real_len = int(len(Global_Climate)/2) dvisible_number = int(real_len - number_of_nan) num_sum = np.nansum(Global_Climate[1::2]) Global_Climate = num_sum / dvisible_number global_climate_percentile_rank_list.append(Global_Climate) #PERCENTILING COMPOSITES AND FACTORIZATION people_power_percentile_rank_list_factored = [] financial_power_percentile_rank_list_factored = [] global_climate_percentile_rank_list_factored = [] for a in people_power_percentile_rank_list: people_power_percentile_rank_list_factored.append(stats.percentileofscore(people_power_percentile_rank_list, a, kind='rank')) for b in financial_power_percentile_rank_list: financial_power_percentile_rank_list_factored.append(stats.percentileofscore(financial_power_percentile_rank_list, b, kind='rank')) for c in global_climate_percentile_rank_list: global_climate_percentile_rank_list_factored.append(stats.percentileofscore(global_climate_percentile_rank_list, c, kind='rank')) # Weighting of Size more heavily people_power_percentile_rank_list_factored = [i * 3 for i in people_power_percentile_rank_list_factored] total_profile_rank = {} for country in country_name_list: country_num = int(country_numberifier(country)) profile_rank_data_together = (people_power_percentile_rank_list_factored[country_num], financial_power_percentile_rank_list_factored[country_num], global_climate_percentile_rank_list_factored[country_num]) total_profile_rank[str(country)] = profile_rank_data_together country_profile_aggregate_factored = [] for country in country_name_list: tbr = total_profile_rank[country] #Factoring for number of missing data Fields and averaging the raw score number_of_nan = int(sum([pd.isnull(i) for i in tbr])) real_len = len(tbr) dvisible_number = int(real_len - number_of_nan) num_sum = np.nansum(tbr) tbr = num_sum / dvisible_number tbr = tbr / 2 country_profile_aggregate_factored.append(tbr) return {'country_profile_aggregate_factored':country_profile_aggregate_factored}
def VPFM(country_name_list, country_and_percentile_rank_list): VP_2011_percentile_rank_list = [] VP_2012_percentile_rank_list = [] VP_2013_percentile_rank_list = [] VP_2014_percentile_rank_list = [] VP_2015_percentile_rank_list = [] VP_2016_percentile_rank_list = [] Total_VP_percentile_rank_list = [] for country in country_name_list: country = int(country_numberifier(country)) VP_2011 = (country_and_percentile_rank_list['VP_2011'][country]) number_of_nan = int(sum([pd.isnull(i) for i in VP_2011])) real_len = int(len(VP_2011) / 2) dvisible_number = int(real_len - number_of_nan) biz_sum = np.nansum(VP_2011[1::2]) VP_2011 = biz_sum / dvisible_number VP_2011_percentile_rank_list.append(VP_2011) #2012 VP_2012 = (country_and_percentile_rank_list['VP_2012'][country]) number_of_nan = int(sum([pd.isnull(i) for i in VP_2012])) real_len = int(len(VP_2012) / 2) dvisible_number = int(real_len - number_of_nan) biz_sum = np.nansum(VP_2012[1::2]) VP_2012 = biz_sum / dvisible_number VP_2012_percentile_rank_list.append(VP_2012) #2013 VP_2013 = (country_and_percentile_rank_list['VP_2013'][country]) number_of_nan = int(sum([pd.isnull(i) for i in VP_2013])) real_len = int(len(VP_2013) / 2) dvisible_number = int(real_len - number_of_nan) biz_sum = np.nansum(VP_2013[1::2]) VP_2013 = biz_sum / dvisible_number VP_2013_percentile_rank_list.append(VP_2013) #2014 VP_2014 = (country_and_percentile_rank_list['VP_2014'][country]) number_of_nan = int(sum([pd.isnull(i) for i in VP_2014])) real_len = int(len(VP_2014) / 2) dvisible_number = int(real_len - number_of_nan) biz_sum = np.nansum(VP_2014[1::2]) VP_2014 = biz_sum / dvisible_number VP_2014_percentile_rank_list.append(VP_2014) #2015 VP_2015 = (country_and_percentile_rank_list['VP_2015'][country]) number_of_nan = int(sum([pd.isnull(i) for i in VP_2015])) real_len = int(len(VP_2015) / 2) dvisible_number = int(real_len - number_of_nan) biz_sum = np.nansum(VP_2015[1::2]) VP_2015 = biz_sum / dvisible_number VP_2015_percentile_rank_list.append(VP_2015) #2016 VP_2016 = (country_and_percentile_rank_list['VP_2016'][country]) number_of_nan = int(sum([pd.isnull(i) for i in VP_2016])) real_len = int(len(VP_2016) / 2) dvisible_number = int(real_len - number_of_nan) biz_sum = np.nansum(VP_2016[1::2]) VP_2016 = biz_sum / dvisible_number VP_2016_percentile_rank_list.append(VP_2016) #TOTAL Total_VP = (country_and_percentile_rank_list['VP_2016'][country] + country_and_percentile_rank_list['VP_2015'][country] + country_and_percentile_rank_list['VP_2014'][country] + country_and_percentile_rank_list['VP_2013'][country] + country_and_percentile_rank_list['VP_2012'][country] + country_and_percentile_rank_list['VP_2011'][country]) number_of_nan = int(sum([pd.isnull(i) for i in Total_VP])) real_len = int(len(Total_VP) / 2) dvisible_number = int(real_len - number_of_nan) biz_sum = np.nansum(Total_VP[1::2]) Total_VP = biz_sum / dvisible_number Total_VP_percentile_rank_list.append(Total_VP) #PERCENTILING COMPOSITES AND FACTORIZATION VP_2011_percentile_rank_list_factored = [] VP_2012_percentile_rank_list_factored = [] VP_2013_percentile_rank_list_factored = [] VP_2014_percentile_rank_list_factored = [] VP_2015_percentile_rank_list_factored = [] VP_2016_percentile_rank_list_factored = [] Total_VP_percentile_rank_list_factored = [] for a in VP_2011_percentile_rank_list: VP_2011_percentile_rank_list_factored.append( stats.percentileofscore(VP_2011_percentile_rank_list, a, kind='rank')) for b in VP_2012_percentile_rank_list: VP_2012_percentile_rank_list_factored.append( stats.percentileofscore(VP_2012_percentile_rank_list, b, kind='rank')) for c in VP_2013_percentile_rank_list: VP_2013_percentile_rank_list_factored.append( stats.percentileofscore(VP_2013_percentile_rank_list, c, kind='rank')) for d in VP_2014_percentile_rank_list: VP_2014_percentile_rank_list_factored.append( stats.percentileofscore(VP_2014_percentile_rank_list, d, kind='rank')) for e in VP_2015_percentile_rank_list: VP_2015_percentile_rank_list_factored.append( stats.percentileofscore(VP_2015_percentile_rank_list, e, kind='rank')) for f in VP_2016_percentile_rank_list: VP_2016_percentile_rank_list_factored.append( stats.percentileofscore(VP_2016_percentile_rank_list, f, kind='rank')) for g in Total_VP_percentile_rank_list: Total_VP_percentile_rank_list_factored.append( stats.percentileofscore(Total_VP_percentile_rank_list, g, kind='rank')) # Weighting of Age more heavily VP_2012_percentile_rank_list_factored = [ i * 1.1 for i in VP_2012_percentile_rank_list_factored ] VP_2013_percentile_rank_list_factored = [ i * 1.2 for i in VP_2013_percentile_rank_list_factored ] VP_2014_percentile_rank_list_factored = [ i * 1.3 for i in VP_2014_percentile_rank_list_factored ] VP_2015_percentile_rank_list_factored = [ i * 1.4 for i in VP_2015_percentile_rank_list_factored ] VP_2016_percentile_rank_list_factored = [ i * 1.5 for i in VP_2016_percentile_rank_list_factored ] Total_VP_percentile_rank_list_factored = [ i * 1.6 for i in Total_VP_percentile_rank_list_factored ] total_VP_rank = {} for country in country_name_list: country_num = int(country_numberifier(country)) VP_rank_data_together = ( VP_2011_percentile_rank_list_factored[country_num], VP_2012_percentile_rank_list_factored[country_num], VP_2013_percentile_rank_list_factored[country_num], VP_2014_percentile_rank_list_factored[country_num], VP_2015_percentile_rank_list_factored[country_num], VP_2016_percentile_rank_list_factored[country_num], Total_VP_percentile_rank_list_factored[country_num]) total_VP_rank[str(country)] = VP_rank_data_together VP_rank_aggregate_factored = [] for country in country_name_list: tbr = total_VP_rank[country] #Factoring for number of missing data Fields and averaging the raw score number_of_nan = int(sum([pd.isnull(i) for i in tbr])) real_len = len(tbr) dvisible_number = int(real_len - number_of_nan) num_sum = np.nansum(tbr) tbr = num_sum / dvisible_number VP_rank_aggregate_factored.append(tbr) return {'VP_rank_aggregate_factored': VP_rank_aggregate_factored}
def GRFM(country_name_list, country_and_percentile_rank_list): outlook_climate_percentile_rank_list = [] political_climate_percentile_rank_list = [] financial_climate_percentile_rank_list = [] global_climate_percentile_rank_list = [] UN_climate_percentile_rank_list = [] for country in country_name_list: country = int(country_numberifier(country)) Outlook = ( country_and_percentile_rank_list['World Giving Index'][country] + country_and_percentile_rank_list['Science and Technology'][country] + country_and_percentile_rank_list['Culture'][country] + country_and_percentile_rank_list['Prosperity and Equality'] [country] + country_and_percentile_rank_list['Health and Wellbeing'][country]) #Factoring for number of missing data Fields and averaging the raw score number_of_nan = int(sum([pd.isnull(i) for i in Outlook])) real_len = int(len(Outlook) / 2) dvisible_number = int(real_len - number_of_nan) biz_sum = np.nansum(Outlook[1::2]) Outlook = biz_sum / dvisible_number outlook_climate_percentile_rank_list.append(Outlook) Political_Climate = ( country_and_percentile_rank_list['Political Freedom'][country] + country_and_percentile_rank_list['Civil Liberties'][country] + country_and_percentile_rank_list['Freedom Status'][country] + country_and_percentile_rank_list['Freedom from Corruption'] [country] + country_and_percentile_rank_list['Political Terror Scale'][country] + country_and_percentile_rank_list['Press Freedom Rank'][country]) #Factoring for number of missing data Fields and averaging the raw score number_of_nan = int(sum([pd.isnull(i) for i in Political_Climate])) real_len = int(len(Political_Climate) / 2) dvisible_number = int(real_len - number_of_nan) num_sum = np.nansum(Political_Climate[1::2]) Political_Climate = num_sum / dvisible_number political_climate_percentile_rank_list.append(Political_Climate) Financial_Climate = ( country_and_percentile_rank_list['Gini Coefficent'][country] + country_and_percentile_rank_list['Labor Freedom'][country] + country_and_percentile_rank_list['Tariff Rate in Percentage'] [country] + country_and_percentile_rank_list['Income Tax Rate in Percentage'] [country] + country_and_percentile_rank_list['Tax Burden as Percent of GDP'] [country]) #Factoring for number of missing data Fields and averaging the raw score number_of_nan = int(sum([pd.isnull(i) for i in Financial_Climate])) real_len = int(len(Financial_Climate) / 2) dvisible_number = int(real_len - number_of_nan) num_sum = np.nansum(Financial_Climate[1::2]) Financial_Climate = num_sum / dvisible_number financial_climate_percentile_rank_list.append(Financial_Climate) Global_Climate = ( country_and_percentile_rank_list['Good Country Overall Score'] [country] + country_and_percentile_rank_list[ 'International Peace and Security'][country] + country_and_percentile_rank_list['World Order'][country] + country_and_percentile_rank_list['Planet and Climate'][country]) #Factoring for number of missing data Fields and averaging the raw score number_of_nan = int(sum([pd.isnull(i) for i in Global_Climate])) real_len = int(len(Global_Climate) / 2) dvisible_number = int(real_len - number_of_nan) num_sum = np.nansum(Global_Climate[1::2]) Global_Climate = num_sum / dvisible_number global_climate_percentile_rank_list.append(Global_Climate) UN_Rank = (country_and_percentile_rank_list[ 'Voting correlation in Percentage at UN with the US'][country]) #Factoring for number of missing data Fields and averaging the raw score number_of_nan = int(sum([pd.isnull(i) for i in UN_Rank])) real_len = int(len(UN_Rank) / 2) dvisible_number = int(real_len - number_of_nan) num_sum = np.nansum(UN_Rank[1::2]) UN_Rank = num_sum / dvisible_number UN_climate_percentile_rank_list.append(UN_Rank) #PERCENTILING COMPOSITES AND FACTORIZATION outlook_climate_percentile_rank_list_factored = [] political_climate_percentile_rank_list_factored = [] financial_climate_percentile_rank_list_factored = [] global_climate_percentile_rank_list_factored = [] UN_climate_percentile_rank_list_factored = [] for a in outlook_climate_percentile_rank_list: outlook_climate_percentile_rank_list_factored.append( stats.percentileofscore(outlook_climate_percentile_rank_list, a, kind='rank')) for b in political_climate_percentile_rank_list: political_climate_percentile_rank_list_factored.append( stats.percentileofscore(political_climate_percentile_rank_list, b, kind='rank')) for c in financial_climate_percentile_rank_list: financial_climate_percentile_rank_list_factored.append( stats.percentileofscore(financial_climate_percentile_rank_list, c, kind='rank')) for d in global_climate_percentile_rank_list: global_climate_percentile_rank_list_factored.append( stats.percentileofscore(global_climate_percentile_rank_list, d, kind='rank')) for e in UN_climate_percentile_rank_list: UN_climate_percentile_rank_list_factored.append( stats.percentileofscore(UN_climate_percentile_rank_list, e, kind='rank')) total_governmental_rank = {} for country in country_name_list: country_num = int(country_numberifier(country)) governmental_rank_data_together = ( outlook_climate_percentile_rank_list_factored[country_num], political_climate_percentile_rank_list_factored[country_num], financial_climate_percentile_rank_list_factored[country_num], global_climate_percentile_rank_list_factored[country_num], UN_climate_percentile_rank_list_factored[country_num]) total_governmental_rank[str(country)] = governmental_rank_data_together governmental_relations_aggregate_factored = [] for country in country_name_list: tbr = total_governmental_rank[country] #Factoring for number of missing data Fields and averaging the raw score number_of_nan = int(sum([pd.isnull(i) for i in tbr])) real_len = len(tbr) dvisible_number = int(real_len - number_of_nan) num_sum = np.nansum(tbr) tbr = num_sum / dvisible_number governmental_relations_aggregate_factored.append(tbr) return { 'governmental_relations_aggregate_factored': governmental_relations_aggregate_factored }
def SSFM(country_name_list, country_and_percentile_rank_list): Sec_of_State_2011_percentile_rank_list = [] Sec_of_State_2012_percentile_rank_list = [] Sec_of_State_2013_percentile_rank_list = [] Sec_of_State_2014_percentile_rank_list = [] Sec_of_State_2015_percentile_rank_list = [] Sec_of_State_2016_percentile_rank_list = [] Sec_of_State_2017_percentile_rank_list = [] Total_Sec_of_State_percentile_rank_list = [] for country in country_name_list: country = int(country_numberifier(country)) Sec_of_State_2011 = ( country_and_percentile_rank_list['Sec_of_State_2011'][country]) number_of_nan = int(sum([pd.isnull(i) for i in Sec_of_State_2011])) real_len = int(len(Sec_of_State_2011) / 2) dvisible_number = int(real_len - number_of_nan) biz_sum = np.nansum(Sec_of_State_2011[1::2]) Sec_of_State_2011 = biz_sum / dvisible_number Sec_of_State_2011_percentile_rank_list.append(Sec_of_State_2011) #2012 Sec_of_State_2012 = ( country_and_percentile_rank_list['Sec_of_State_2012'][country]) number_of_nan = int(sum([pd.isnull(i) for i in Sec_of_State_2012])) real_len = int(len(Sec_of_State_2012) / 2) dvisible_number = int(real_len - number_of_nan) biz_sum = np.nansum(Sec_of_State_2012[1::2]) Sec_of_State_2012 = biz_sum / dvisible_number Sec_of_State_2012_percentile_rank_list.append(Sec_of_State_2012) #2013 Sec_of_State_2013 = ( country_and_percentile_rank_list['Sec_of_State_2013'][country]) number_of_nan = int(sum([pd.isnull(i) for i in Sec_of_State_2013])) real_len = int(len(Sec_of_State_2013) / 2) dvisible_number = int(real_len - number_of_nan) biz_sum = np.nansum(Sec_of_State_2013[1::2]) Sec_of_State_2013 = biz_sum / dvisible_number Sec_of_State_2013_percentile_rank_list.append(Sec_of_State_2013) #2014 Sec_of_State_2014 = ( country_and_percentile_rank_list['Sec_of_State_2014'][country]) number_of_nan = int(sum([pd.isnull(i) for i in Sec_of_State_2014])) real_len = int(len(Sec_of_State_2014) / 2) dvisible_number = int(real_len - number_of_nan) biz_sum = np.nansum(Sec_of_State_2014[1::2]) Sec_of_State_2014 = biz_sum / dvisible_number Sec_of_State_2014_percentile_rank_list.append(Sec_of_State_2014) #2015 Sec_of_State_2015 = ( country_and_percentile_rank_list['Sec_of_State_2015'][country]) number_of_nan = int(sum([pd.isnull(i) for i in Sec_of_State_2015])) real_len = int(len(Sec_of_State_2015) / 2) dvisible_number = int(real_len - number_of_nan) biz_sum = np.nansum(Sec_of_State_2015[1::2]) Sec_of_State_2015 = biz_sum / dvisible_number Sec_of_State_2015_percentile_rank_list.append(Sec_of_State_2015) #2016 Sec_of_State_2016 = ( country_and_percentile_rank_list['Sec_of_State_2016'][country]) number_of_nan = int(sum([pd.isnull(i) for i in Sec_of_State_2016])) real_len = int(len(Sec_of_State_2016) / 2) dvisible_number = int(real_len - number_of_nan) biz_sum = np.nansum(Sec_of_State_2016[1::2]) Sec_of_State_2016 = biz_sum / dvisible_number Sec_of_State_2016_percentile_rank_list.append(Sec_of_State_2016) #2017 Sec_of_State_2017 = ( country_and_percentile_rank_list['Sec_of_State_2017'][country]) number_of_nan = int(sum([pd.isnull(i) for i in Sec_of_State_2017])) real_len = int(len(Sec_of_State_2017) / 2) dvisible_number = int(real_len - number_of_nan) biz_sum = np.nansum(Sec_of_State_2017[1::2]) Sec_of_State_2017 = biz_sum / dvisible_number Sec_of_State_2017_percentile_rank_list.append(Sec_of_State_2017) #TOTAL Total_Sec_of_State = ( country_and_percentile_rank_list['Sec_of_State_2017'][country] + country_and_percentile_rank_list['Sec_of_State_2016'][country] + country_and_percentile_rank_list['Sec_of_State_2015'][country] + country_and_percentile_rank_list['Sec_of_State_2014'][country] + country_and_percentile_rank_list['Sec_of_State_2013'][country] + country_and_percentile_rank_list['Sec_of_State_2012'][country] + country_and_percentile_rank_list['Sec_of_State_2011'][country]) number_of_nan = int(sum([pd.isnull(i) for i in Total_Sec_of_State])) real_len = int(len(Total_Sec_of_State) / 2) dvisible_number = int(real_len - number_of_nan) biz_sum = np.nansum(Total_Sec_of_State[1::2]) Total_Sec_of_State = biz_sum / dvisible_number Total_Sec_of_State_percentile_rank_list.append(Total_Sec_of_State) #PERCENTILING COMPOSITES AND FACTORIZATION Sec_of_State_2011_percentile_rank_list_factored = [] Sec_of_State_2012_percentile_rank_list_factored = [] Sec_of_State_2013_percentile_rank_list_factored = [] Sec_of_State_2014_percentile_rank_list_factored = [] Sec_of_State_2015_percentile_rank_list_factored = [] Sec_of_State_2016_percentile_rank_list_factored = [] Sec_of_State_2017_percentile_rank_list_factored = [] Total_Sec_of_State_percentile_rank_list_factored = [] for a in Sec_of_State_2011_percentile_rank_list: Sec_of_State_2011_percentile_rank_list_factored.append( stats.percentileofscore(Sec_of_State_2011_percentile_rank_list, a, kind='rank')) for b in Sec_of_State_2012_percentile_rank_list: Sec_of_State_2012_percentile_rank_list_factored.append( stats.percentileofscore(Sec_of_State_2012_percentile_rank_list, b, kind='rank')) for c in Sec_of_State_2013_percentile_rank_list: Sec_of_State_2013_percentile_rank_list_factored.append( stats.percentileofscore(Sec_of_State_2013_percentile_rank_list, c, kind='rank')) for d in Sec_of_State_2014_percentile_rank_list: Sec_of_State_2014_percentile_rank_list_factored.append( stats.percentileofscore(Sec_of_State_2014_percentile_rank_list, d, kind='rank')) for e in Sec_of_State_2015_percentile_rank_list: Sec_of_State_2015_percentile_rank_list_factored.append( stats.percentileofscore(Sec_of_State_2015_percentile_rank_list, e, kind='rank')) for f in Sec_of_State_2016_percentile_rank_list: Sec_of_State_2016_percentile_rank_list_factored.append( stats.percentileofscore(Sec_of_State_2016_percentile_rank_list, f, kind='rank')) for j in Sec_of_State_2017_percentile_rank_list: Sec_of_State_2017_percentile_rank_list_factored.append( stats.percentileofscore(Sec_of_State_2017_percentile_rank_list, j, kind='rank')) for g in Total_Sec_of_State_percentile_rank_list: Total_Sec_of_State_percentile_rank_list_factored.append( stats.percentileofscore(Total_Sec_of_State_percentile_rank_list, g, kind='rank')) # Weighting of Age more heavily Sec_of_State_2012_percentile_rank_list_factored = [ i * 1.1 for i in Sec_of_State_2012_percentile_rank_list_factored ] Sec_of_State_2013_percentile_rank_list_factored = [ i * 1.2 for i in Sec_of_State_2013_percentile_rank_list_factored ] Sec_of_State_2014_percentile_rank_list_factored = [ i * 1.3 for i in Sec_of_State_2014_percentile_rank_list_factored ] Sec_of_State_2015_percentile_rank_list_factored = [ i * 1.4 for i in Sec_of_State_2015_percentile_rank_list_factored ] Sec_of_State_2016_percentile_rank_list_factored = [ i * 1.5 for i in Sec_of_State_2016_percentile_rank_list_factored ] Sec_of_State_2017_percentile_rank_list_factored = [ i * 1.6 for i in Sec_of_State_2017_percentile_rank_list_factored ] Total_Sec_of_State_percentile_rank_list_factored = [ i * 1.7 for i in Total_Sec_of_State_percentile_rank_list_factored ] total_sec_state_rank = {} for country in country_name_list: country_num = int(country_numberifier(country)) sec_state_rank_data_together = ( Sec_of_State_2011_percentile_rank_list_factored[country_num], Sec_of_State_2012_percentile_rank_list_factored[country_num], Sec_of_State_2013_percentile_rank_list_factored[country_num], Sec_of_State_2014_percentile_rank_list_factored[country_num], Sec_of_State_2015_percentile_rank_list_factored[country_num], Sec_of_State_2016_percentile_rank_list_factored[country_num], Sec_of_State_2017_percentile_rank_list_factored[country_num], Total_Sec_of_State_percentile_rank_list_factored[country_num]) total_sec_state_rank[str(country)] = sec_state_rank_data_together sec_state_rank_aggregate_factored = [] for country in country_name_list: tbr = total_sec_state_rank[country] #Factoring for number of missing data Fields and averaging the raw score number_of_nan = int(sum([pd.isnull(i) for i in tbr])) real_len = len(tbr) dvisible_number = int(real_len - number_of_nan) num_sum = np.nansum(tbr) tbr = num_sum / dvisible_number sec_state_rank_aggregate_factored.append(tbr) return { 'sec_state_rank_aggregate_factored': sec_state_rank_aggregate_factored }
def SPFM(country_name_list, country_and_percentile_rank_list): military_power_percentile_rank_list = [] foreign_power_percentile_rank_list = [] nuclear_power_percentile_rank_list = [] alliance_climate_percentile_rank_list = [] rank_percentile_rank_list = [] for country in country_name_list: country = int(country_numberifier(country)) Military_Power = (country_and_percentile_rank_list['TOTAL US MILITARY Personnel Abroad'][country] + country_and_percentile_rank_list['US Military Bases Abroad'][country]) #Factoring for number of missing data Fields and averaging the raw score number_of_nan = int(sum([pd.isnull(i) for i in Military_Power])) real_len = int(len(Military_Power)/2) dvisible_number = int(real_len - number_of_nan) biz_sum = np.nansum(Military_Power[1::2]) Military_Power = biz_sum / dvisible_number military_power_percentile_rank_list.append(Military_Power) Foreign_Power = (country_and_percentile_rank_list['Foreign Military Finance'][country] + country_and_percentile_rank_list['Personel in Standing Army'][country]) #Factoring for number of missing data Fields and averaging the raw score number_of_nan = int(sum([pd.isnull(i) for i in Foreign_Power])) real_len = int(len(Foreign_Power)/2) dvisible_number = int(real_len - number_of_nan) num_sum = np.nansum(Foreign_Power[1::2]) Foreign_Power_num = num_sum / dvisible_number foreign_power_percentile_rank_list.append(Foreign_Power_num) Nuclear_Technology = (country_and_percentile_rank_list['Nuclear Technology'][country]) #Factoring for number of missing data Fields and averaging the raw score number_of_nan = int(sum([pd.isnull(i) for i in Nuclear_Technology])) real_len = int(len(Nuclear_Technology)/2) dvisible_number = int(real_len - number_of_nan) num_sum = np.nansum(Nuclear_Technology[1::2]) Nuclear_Technology = num_sum / dvisible_number nuclear_power_percentile_rank_list.append(Nuclear_Technology) Alliance_Climate = (country_and_percentile_rank_list['Alliances'][country] + country_and_percentile_rank_list['Shared Multilateral Organizations'][country]) #Factoring for number of missing data Fields and averaging the raw score number_of_nan = int(sum([pd.isnull(i) for i in Alliance_Climate])) real_len = int(len(Alliance_Climate)/2) dvisible_number = int(real_len - number_of_nan) num_sum = np.nansum(Alliance_Climate[1::2]) Alliance_Climate = num_sum / dvisible_number alliance_climate_percentile_rank_list.append(Alliance_Climate) Rankings = (country_and_percentile_rank_list['Composite Index of National Capability'][country] + country_and_percentile_rank_list['Global Peace Index Raw Score'][country]) #Factoring for number of missing data Fields and averaging the raw score number_of_nan = int(sum([pd.isnull(i) for i in Rankings])) real_len = int(len(Rankings)/2) dvisible_number = int(real_len - number_of_nan) num_sum = np.nansum(Rankings[1::2]) Rankings = num_sum / dvisible_number rank_percentile_rank_list.append(Rankings) #PERCENTILING COMPOSITES AND FACTORIZATION military_power_percentile_rank_list_factored = [] alliance_climate_percentile_rank_list_factored = [] rank_percentile_rank_list_factored = [] foreign_power_percentile_rank_list_factored = [] for a in military_power_percentile_rank_list: military_power_percentile_rank_list_factored.append(stats.percentileofscore(military_power_percentile_rank_list, a, kind='rank')) for c in alliance_climate_percentile_rank_list: alliance_climate_percentile_rank_list_factored.append(stats.percentileofscore(alliance_climate_percentile_rank_list, c, kind='rank')) for d in rank_percentile_rank_list: rank_percentile_rank_list_factored.append(stats.percentileofscore(rank_percentile_rank_list, d, kind='rank')) for j in foreign_power_percentile_rank_list: foreign_power_percentile_rank_list_factored.append(stats.percentileofscore(foreign_power_percentile_rank_list, j, kind='rank')) # Weighting of Size more heavily """ people_power_percentile_rank_list_factored = [i * 3 for i in people_power_percentile_rank_list_factored] """ nuclear_power_percentile_rank_list = [i * 4 for i in nuclear_power_percentile_rank_list] total_security_rank = {} for country in country_name_list: country_num = int(country_numberifier(country)) security_rank_data_together = (military_power_percentile_rank_list_factored[country_num], nuclear_power_percentile_rank_list[country_num], alliance_climate_percentile_rank_list_factored[country_num], rank_percentile_rank_list_factored[country_num], foreign_power_percentile_rank_list_factored[country_num]) total_security_rank[str(country)] = security_rank_data_together security_rank_aggregate_factored = [] for country in country_name_list: tbr = total_security_rank[country] #Factoring for number of missing data Fields and averaging the raw score number_of_nan = int(sum([pd.isnull(i) for i in tbr])) real_len = len(tbr) dvisible_number = int(real_len - number_of_nan) num_sum = np.nansum(tbr) tbr = num_sum / dvisible_number new_tbr = float(tbr) / 1.51 security_rank_aggregate_factored.append(new_tbr) return {'security_rank_aggregate_factored':security_rank_aggregate_factored}
def main(): todays_date = datetime.fromtimestamp(int(time.time())).strftime('%B-%d-%Y') #To add prior to adding any of the data conn = engine.connect() table_list = [ 'Business_Relations', 'Trade_Relations', 'Governmental_Perspective', 'Country_Profile', 'Security', 'Cultural_Diffusion', 'Prestige', 'Sec_State_Bureaucratic_Exchange', 'Presidential_Exchange' ] for tab in table_list: table_name = tab country_name_list = getting_all_the_column_names_from_the_table( table_name)['country_name_list'] column_name_list = getting_all_the_column_names_from_the_table( table_name)['column_name_list'] country_and_percentile_rank_list = percentile_ranking( column_name_list, country_name_list, table_name)['country_and_percentile_rank_list'] formula(country_name_list, country_and_percentile_rank_list, table_name) country_exceptions_list = [ 'Nauru', 'Vatican City', 'Somalia', 'Andorra', 'Monaco', 'Cook Islands' ] ####################################################################################################### ##### ROW INITIALIZATION ####################################################################################################### conn.execute( '''DELETE FROM "Sec_State_SCORE2" WHERE "Date" = '{}';'''.format( todays_date)) conn.execute('''INSERT INTO "Sec_State_SCORE2" VALUES ('{}');'''.format( todays_date)) ####################################################################################################### conn.execute( '''DELETE FROM "Presidential_SCORE2" WHERE "Date" = '{}';'''.format( todays_date)) conn.execute('''INSERT INTO "Presidential_SCORE2" VALUES ('{}');'''.format( todays_date)) ####################################################################################################### conn.execute( '''DELETE FROM "BR_SCORE2" WHERE "Date" = '{}';'''.format(todays_date)) conn.execute( '''INSERT INTO "BR_SCORE2" VALUES ('{}');'''.format(todays_date)) ####################################################################################################### conn.execute('''DELETE FROM "Trade_SCORE2" WHERE "Date" = '{}';'''.format( todays_date)) conn.execute( '''INSERT INTO "Trade_SCORE2" VALUES ('{}');'''.format(todays_date)) ####################################################################################################### conn.execute( '''DELETE FROM "GP_SCORE2" WHERE "Date" = '{}';'''.format(todays_date)) conn.execute( '''INSERT INTO "GP_SCORE2" VALUES ('{}');'''.format(todays_date)) ####################################################################################################### conn.execute( '''DELETE FROM "Prestige_SCORE2" WHERE "Date" = '{}';'''.format( todays_date)) conn.execute( '''INSERT INTO "Prestige_SCORE2" VALUES ('{}');'''.format(todays_date)) ####################################################################################################### conn.execute( '''DELETE FROM "Security_SCORE2" WHERE "Date" = '{}';'''.format( todays_date)) conn.execute( '''INSERT INTO "Security_SCORE2" VALUES ('{}');'''.format(todays_date)) ####################################################################################################### conn.execute( '''DELETE FROM "CD_SCORE2" WHERE "Date" = '{}';'''.format(todays_date)) conn.execute( '''INSERT INTO "CD_SCORE2" VALUES ('{}');'''.format(todays_date)) ####################################################################################################### conn.execute( '''DELETE FROM "CProfile_SCORE2" WHERE "Date" = '{}';'''.format( todays_date)) conn.execute( '''INSERT INTO "CProfile_SCORE2" VALUES ('{}');'''.format(todays_date)) ####################################################################################################### QP_Final_Value_not_ranked = [] for country in country_name_list: temp_value_list = [] for tab in table_list: count_num = country_numberifier(country) table_name = tab #print(country, float(QP_value[table_name][count_num])) if table_name == 'Sec_State_Bureaucratic_Exchange': conn.execute( '''UPDATE "Sec_State_SCORE2" SET "{}" = '{}' WHERE "Date" = '{}';''' .format(country, float(QP_value[table_name][count_num]), todays_date)) #print('Sec_State_Bureaucratic_Exchange', country, QP_value[table_name][count_num]) temp_value_list.append( float(QP_value[table_name][count_num]) * 1.8) if table_name == 'Presidential_Exchange': conn.execute( '''UPDATE "Presidential_SCORE2" SET "{}" = '{}' WHERE "Date" = '{}';''' .format(country, float(QP_value[table_name][count_num]), todays_date)) #print('Presidential_Exchange', country, QP_value[table_name][count_num]) temp_value_list.append( float(QP_value[table_name][count_num]) * 1.7) if table_name == 'Business_Relations': #Some Small countries don't have a BR Score if country in country_exceptions_list: pass else: conn.execute( '''UPDATE "BR_SCORE2" SET "{}" = '{}' WHERE "Date" = '{}';''' .format(country, float(QP_value[table_name][count_num]), todays_date)) #print('Business_Relations', country, QP_value[table_name][count_num]) temp_value_list.append( float(QP_value[table_name][count_num]) * 1.6) if table_name == 'Trade_Relations': conn.execute( '''UPDATE "Trade_SCORE2" SET "{}" = '{}' WHERE "Date" = '{}';''' .format(country, float(QP_value[table_name][count_num]), todays_date)) #print('Trade_Relations', country, QP_value[table_name][count_num]) temp_value_list.append( float(QP_value[table_name][count_num]) * 1.5) if table_name == 'Governmental_Perspective': conn.execute( '''UPDATE "GP_SCORE2" SET "{}" = '{}' WHERE "Date" = '{}';''' .format(country, float(QP_value[table_name][count_num]), todays_date)) #print('Governmental_Perspective', country, QP_value[table_name][count_num]) temp_value_list.append( float(QP_value[table_name][count_num]) * 1.4) if table_name == 'Prestige': conn.execute( '''UPDATE "Prestige_SCORE2" SET "{}" = '{}' WHERE "Date" = '{}';''' .format(country, float(QP_value[table_name][count_num]), todays_date)) #print('Prestige', country, QP_value[table_name][count_num]) temp_value_list.append( float(QP_value[table_name][count_num]) * 1.3) if table_name == 'Security': conn.execute( '''UPDATE "Security_SCORE2" SET "{}" = '{}' WHERE "Date" = '{}';''' .format(country, float(QP_value[table_name][count_num]), todays_date)) #print('Security', country, QP_value[table_name][count_num]) temp_value_list.append( float(QP_value[table_name][count_num]) * 1.2) if table_name == 'Cultural_Diffusion': conn.execute( '''UPDATE "CD_SCORE2" SET "{}" = '{}' WHERE "Date" = '{}';''' .format(country, float(QP_value[table_name][count_num]), todays_date)) #print('Cultural_Diffusion', country, QP_value[table_name][count_num]) temp_value_list.append( float(QP_value[table_name][count_num]) * 1.1) if table_name == 'Country_Profile': conn.execute( '''UPDATE "CProfile_SCORE2" SET "{}" = '{}' WHERE "Date" = '{}';''' .format(country, float(QP_value[table_name][count_num]), todays_date)) #print('Country_Profile', country, QP_value[table_name][count_num]) temp_value_list.append(QP_value[table_name][count_num]) if len(temp_value_list) == 9: number_of_nan = int( sum([pd.isnull(i) for i in temp_value_list])) real_len = int(len(temp_value_list) / 2) dvisible_number = int(real_len - number_of_nan) num_sum = np.nansum(temp_value_list) temp_value_list = num_sum / dvisible_number QP_Final_Value_not_ranked.append(temp_value_list) new_rank_percentile_rank_list_factored = [] for v in QP_Final_Value_not_ranked: new_rank_percentile_rank_list_factored.append( stats.percentileofscore(QP_Final_Value_not_ranked, v, kind='rank')) ########################################################################## #Current_Military_Engagement AKA ARE WE BOMBING YOU AND IF SO, HOW LONG AGO? ########################################################################## hostilities_query = conn.execute( '''SELECT "Current_Military_Engagement" FROM "Security" ORDER BY "Country_Name";''' ) hostilities_query_list = hostilities_query.cursor.fetchall() country_name_query = conn.execute( '''SELECT "Country_Name" FROM "Security" ORDER BY "Country_Name";''') cnl = country_name_query.cursor.fetchall() date_format = '%B-%d-%Y' todays_date = datetime.fromtimestamp(int(time.time())).strftime('%B-%d-%Y') score_to_subtract_dict = {} for index, value in enumerate(hostilities_query_list): if len(value[0]) > 2: a = datetime.strptime(value[0], date_format) b = datetime.strptime(todays_date, date_format) delta = b - a days_til_penalty_removed = 1000 - int(delta.days) days_til_penalty_removed_as_percentage = days_til_penalty_removed / 1000 score_to_subtract = days_til_penalty_removed_as_percentage * 50 score_to_subtract_dict[cnl[index][0]] = score_to_subtract QP_Final_Value = {} for country in country_name_list: count_num = country_numberifier(country) QP_Final_Value[country] = ( new_rank_percentile_rank_list_factored[count_num] * 4) - 200 #print(country, score_to_subtract_dict.get(country)) if score_to_subtract_dict.get(country) != None: current_score = QP_Final_Value[country] QP_Final_Value[ country] = current_score - score_to_subtract_dict[country] ########################################################################## #End Current_Military_Engagement ########################################################################## conn.execute( '''DELETE FROM "QP_SCORE2" WHERE "Date" = '{}';'''.format(todays_date)) conn.execute( '''INSERT INTO "QP_SCORE2" VALUES ('{}');'''.format(todays_date)) for w in sorted(QP_Final_Value, key=QP_Final_Value.get, reverse=True): print(w, QP_Final_Value[w]) conn.execute( '''UPDATE "QP_SCORE2" SET "{}" = '{}' WHERE "Date" = '{}';'''. format(w, float(QP_Final_Value[w]), todays_date)) time2 = time.time() print("Total time to run ", int(time2 - time1), "seconds")
def formula(country_name_list, country_and_percentile_rank_list, table_name): if table_name == 'Business_Relations': from Business_Relations_Formula_Maker import BRFM business_relations_aggregate_factored = BRFM( country_name_list, country_and_percentile_rank_list )['business_relations_aggregate_factored'] QP_value['Business_Relations'] = business_relations_aggregate_factored print(table_name, 'imported') if table_name == 'Trade_Relations': from Trade_Relations_Formula_Maker import TRFM trade_relations_aggregate_factored = TRFM( country_name_list, country_and_percentile_rank_list )['trade_relations_aggregate_factored'] QP_value['Trade_Relations'] = trade_relations_aggregate_factored print(table_name, 'imported') if table_name == 'Governmental_Perspective': from Governmental_Perspective_Formula_Maker import GRFM, UN_Grabber governmental_relations_aggregate_factored = GRFM( country_name_list, country_and_percentile_rank_list )['governmental_relations_aggregate_factored'] QP_value[ 'Governmental_Perspective'] = governmental_relations_aggregate_factored print(table_name, 'imported') if table_name == 'Country_Profile': from Country_Profile import CPFM country_profile_aggregate_factored = CPFM( country_name_list, country_and_percentile_rank_list )['country_profile_aggregate_factored'] QP_value['Country_Profile'] = country_profile_aggregate_factored print(table_name, 'imported') if table_name == 'Security': from Security_Formula_Maker import SPFM security_rank_aggregate_factored = SPFM( country_name_list, country_and_percentile_rank_list )['security_rank_aggregate_factored'] QP_value['Security'] = security_rank_aggregate_factored print(table_name, 'imported') if table_name == 'Cultural_Diffusion': from Cultural_Diffusion_Formula_Maker import CDFM cultural_diffusion_aggregate_factored = CDFM( country_name_list, country_and_percentile_rank_list )['cultural_diffusion_aggregate_factored'] QP_value['Cultural_Diffusion'] = cultural_diffusion_aggregate_factored print(table_name, 'imported') if table_name == 'Prestige': from Prestige_Formula_Maker import PFM prestige_rank_aggregate_factored = PFM( country_name_list, country_and_percentile_rank_list )['prestige_rank_aggregate_factored'] QP_value['Prestige'] = prestige_rank_aggregate_factored print(table_name, 'imported') if table_name == 'Sec_State_Bureaucratic_Exchange': from Sec_State_Formula_Maker import SSFM sec_state_rank_aggregate_factored = SSFM( country_name_list, country_and_percentile_rank_list )['sec_state_rank_aggregate_factored'] QP_value[ 'Sec_State_Bureaucratic_Exchange'] = sec_state_rank_aggregate_factored print(table_name, 'imported') if table_name == 'Presidential_Exchange': from Presidential_Exchange_Formula_Maker import PEFM pres_rank_aggregate_factored = PEFM( country_name_list, country_and_percentile_rank_list)['Pres_rank_aggregate_factored'] from Vice_Presidential_Exchange_Formula_Maker import VPFM vp_rank_aggregate_factored = VPFM( country_name_list, country_and_percentile_rank_list)['VP_rank_aggregate_factored'] from Joint_Meetings_List import JMFM jm_rank_aggregate_factored = JMFM( country_name_list, country_and_percentile_rank_list)['JM_rank_aggregate_factored'] Pres_VP_Joint_BEX = [] for country in country_name_list: count_num = country_numberifier(country) Pres_VP_Joint_BEX.append( float( float(pres_rank_aggregate_factored[count_num] * 3) + float(vp_rank_aggregate_factored[count_num] * 2) + jm_rank_aggregate_factored[count_num])) Pres_VP_Joint_BEX_factored = [] for a in Pres_VP_Joint_BEX: Pres_VP_Joint_BEX_factored.append( stats.percentileofscore(Pres_VP_Joint_BEX, a, kind='rank')) QP_value['Presidential_Exchange'] = Pres_VP_Joint_BEX_factored print(table_name, 'imported')