def include_extra(masterdata, year): md_list = [] if year != get_cur_year(): print "SWITCHING years from ", get_cur_year(), " to ", year, ".\n" set_regions(year) set_cur_year(year) for mdrec in masterdata: md = OrderedDict() md['Country_Name'] = mdrec['Country_Name'] md['Country_ISO2'] = str( ISO_countries.ISO2_from_name(md['Country_Name'], csl)) md['Country_ISO3'] = str( ISO_countries.ISO3_from_name(md['Country_Name'], csl)) md['Country_Region'] = str( regions.find_region_from_ISO3(md['Country_ISO3'], regs)) mdreckeys = mdrec.keys() for n in range(1, len(mdrec)): currentkey = mdreckeys[n] md[currentkey] = mdrec[currentkey] #print "new ", currentkey, " value is ", md[currentkey] md_list.append(md) if (md['Country_ISO2'] == "-1"): print " No ISO2 code found for ", md['Country_Name'] if (md['Country_ISO3'] == "-1"): print " No ISO3 code found for ", md['Country_Name'] #if (mdrec['Country_Region'].strip().upper() != md['Country_Region'].strip().upper()): #print "Region mismatch between region information in Tab 5 and Tab 1 for ", mdrec['Country_Name'] #print "Region info from Tab 5 is '", mdrec['Country_Region'],"' and Region info from Tab 1 is '", md['Country_Region'],"'.\n" return md_list
def include_extra(goods_list, yer): result = [] if yer != get_base_year(): set_sectors(yer) set_regions(yer) set_base_year(yer) for good in goods_list: g = OrderedDict() g['Country_Name'] = good['Country_Name'] g['Country_ISO2'] = ISO_countries.ISO2_from_name( g['Country_Name'], csl) g['Country_ISO3'] = ISO_countries.ISO3_from_name( g['Country_Name'], csl) if (g['Country_ISO2'] == utility.get_default_error()): print " No ISO2 was found for ", g['Country_Name'] if (g['Country_ISO3'] == utility.get_default_error()): print " No ISO3 was found for ", g['Country_Name'] g['Country_Region'] = regions.find_region_from_ISO3( g['Country_ISO3'], regs) g['Good_Name'] = good['Good_Name'] g['Good_Sector'] = sectors.find_sector_from_name(g['Good_Name'], secs) g['Child_Labor'] = ("Yes" if (good['Child_Labor'] == present) else "No") g['Forced_Labor'] = ("Yes" if (good['Forced_Labor'] == present) else "No") g['Forced_Child_Labor'] = ("Yes" if (good['Forced_Child_Labor'] == present) else "No") result.append(g) return result
def include_ISO(rlist): result = [] for r in rlist: row = OrderedDict() cn = r['Country_Name'] row['Country_Name'] = cn row['Country_ISO2'] = ISO_countries.ISO2_from_name(cn, isocountries) row['Country_ISO3'] = ISO_countries.ISO3_from_name(cn, isocountries) row['Country_Region'] = r['Country_Region'] result.append(row) return result
def include_extra(masterdata, yr): md_list = [] if (yr != get_current_year()): print "SWITCHING years from ", get_current_year(), " to ", yr, ".\n" set_regions(yr) set_current_year(yr) for mdrec in masterdata: md = OrderedDict() md['Country_Name'] = mdrec['Country_Name'] md['Country_ISO2'] = ISO_countries.ISO2_from_name( md['Country_Name'], csl) md['Country_ISO3'] = ISO_countries.ISO3_from_name( md['Country_Name'], csl) if (md['Country_ISO2'] == utility.get_default_error()): print "There is no ISO2 for ", md['Country_Name'] if (md['Country_ISO3'] == utility.get_default_error()): print "There is no ISO3 for ", md['Country_Name'] md['Country_Region'] = regions.find_region_from_ISO3( md['Country_ISO3'], regs) md[CWS + '_Age_Range'] = mdrec[CWS + '_Age_Range'] md[CWS + '_Total_Percentage_of_Working_Children'] = mdrec[ CWS + '_Total_Percentage_of_Working_Children'] md[CWS + '_Total_Working_Population'] = mdrec[CWS + '_Total_Working_Population'] md[CWS + '_Agriculture'] = mdrec[CWS + '_Agriculture'] md[CWS + '_Services'] = mdrec[CWS + '_Services'] md[CWS + '_Industry'] = mdrec[CWS + '_Industry'] md[ESAS + '_Year'] = mdrec[ESAS + '_Year'] md[ESAS + '_Age_Range'] = mdrec[ESAS + '_Age_Range'] md[ESAS + '_Percentage'] = mdrec[ESAS + '_Percentage'] md[CWAS + '_Year'] = mdrec[CWAS + '_Year'] md[CWAS + '_Age_Range'] = mdrec[CWAS + '_Age_Range'] md[CWAS + '_Total'] = mdrec[CWAS + '_Total'] md[UPCR + '_Year'] = mdrec[UPCR + '_Year'] md[UPCR + '_Rate'] = mdrec[UPCR + '_Rate'] md_list.append(md) return md_list
def add_to_country_profiles(profiles): results = [] cpkeys = profiles[0].keys() for profile in profiles: newrec = OrderedDict() cn = profile['country'].encode('utf8') newrec['Country_ISO3'] = ISO_countries.ISO3_from_name(cn, csl) if (newrec['Country_ISO3'] == utility.get_default_error()): print "Could not find ISO3 for ", cn for n in range(0, len(cpkeys)): cur = cpkeys[n] newrec[cur] = profile[cur] results.append(newrec) return results
def get_master_data_from_name(name, mlist): this_iso3 = ISO_countries.ISO3_from_name(name, csl) stats = get_master_data_from_iso3(this_iso3, mlist) return stats
import special_chars import ISO_countries from collections import OrderedDict csv_2013_target = '../output/2013/extra/master_data_from_XL.csv' xml_2013_target = '../output/2013/extra/master_data_from_XL.xml' json_2013_target = '../output/2013/extra/master_data_from_XL.json' csv_2014_target = '../output/2014/extra/master_data_from_XL.csv' xml_2014_target = '../output/2014/extra/master_data_from_XL.xml' json_2014_target = '../output/2014/extra/master_data_from_XL.json' cur_year = 2014 regs = regions.build(cur_year) csl = ISO_countries.build() sp_chars = special_chars.build() mappings = [ "Country_Name", "Assessment", "C_138_Ratified", "C_182_Ratified", "Convention_on_the_Rights_of_the_Child_Ratified", "CRC_Commercial_Sexual_Exploitation_of_Children_Ratified", "CRC_Armed_Conflict_Ratified", "Palermo_Ratified", "Minimum_Age_for_Work_Estabslished", "Minimum_Age_for_Work", "Minimum_Age_for_Hazardous_Work_Estabslished", "Minimum_Age_for_Hazardous_Work", "Compulsory_Education_Age_Established", "Minimum_Age_for_Compulsory_Education", "Free_Public_Education_Estabslished" ]
import utility import ISO_countries import special_chars from collections import OrderedDict json_2013_target = '../output/2013/extra/country_region_mappings.json' csv_2013_target = '../output/2013/extra/country_region_mappings.csv' xml_2013_target = '../output/2013/extra/country_region_mappings.xml' json_2014_target = '../output/2014/extra/country_region_mappings.json' csv_2014_target = '../output/2014/extra/country_region_mappings.csv' xml_2014_target = '../output/2014/extra/country_region_mappings.xml' mappings = ["Country_Name", "Country_Region"] # Info to be extracted from spreadsheet isocountries = ISO_countries.build() sp_chars = special_chars.build() def include_ISO(rlist): result = [] for r in rlist: row = OrderedDict() cn = r['Country_Name'] row['Country_Name'] = cn row['Country_ISO2'] = ISO_countries.ISO2_from_name(cn, isocountries) row['Country_ISO3'] = ISO_countries.ISO3_from_name(cn, isocountries) row['Country_Region'] = r['Country_Region'] result.append(row) return result def build(year):
import ISO_countries import special_chars from collections import OrderedDict json_2013_target = '../output/2013/extra/country_region_mappings.json' csv_2013_target = '../output/2013/extra/country_region_mappings.csv' xml_2013_target = '../output/2013/extra/country_region_mappings.xml' json_2014_target = '../output/2014/extra/country_region_mappings.json' csv_2014_target = '../output/2014/extra/country_region_mappings.csv' xml_2014_target = '../output/2014/extra/country_region_mappings.xml' mappings = ["Country_Name", "Country_Region"] # Info to be extracted from spreadsheet isocountries = ISO_countries.build() sp_chars = special_chars.build() def include_ISO(rlist): result = [] for r in rlist: row = OrderedDict() cn = r['Country_Name'] row['Country_Name'] = cn row['Country_ISO2'] = ISO_countries.ISO2_from_name(cn, isocountries) row['Country_ISO3'] = ISO_countries.ISO3_from_name(cn, isocountries) row['Country_Region'] = r['Country_Region'] result.append(row) return result
csv_2013_target = '../output/2013/extra/country_stats_from_XL.csv' xml_2013_target = '../output/2013/extra/country_stats_from_XL.xml' json_2013_target = '../output/2013/extra/country_stats_from_XL.json' csv_2014_target = '../output/2014/extra/country_stats_from_XL.csv' xml_2014_target = '../output/2014/extra/country_stats_from_XL.xml' json_2014_target = '../output/2014/extra/country_stats_from_XL.json' CWS = "Children_Work_Statistics" ESAS = "Education_Statistics_Attendance_Statistics" CWAS = "Children_Working_and_Studying_7-14_yrs_old" UPCR = "UNESCO_Primary_Completion_Rate" current_year = 2013 regs = regions.build(current_year) csl = ISO_countries.build() sp_chars = special_chars.build() mappings = [ 'Country_Name', CWS+'_Age_Range', CWS+'_Total_Percentage_of_Working_Children', CWS+'_Total_Working_Population', CWS+'_Agriculture', CWS+'_Services', CWS+'_Industry', ESAS+'_Year', ESAS+'_Age_Range', ESAS+'_Percentage', CWAS+'_Year', CWAS+'_Age_Range', CWAS+'_Total', UPCR+'_Year', UPCR+'_Rate' ] def get_current_year(): return current_year def set_current_year(yr):