Exemple #1
0
 def fetch_data_sparse(self,
                       country_codes,
                       indicator_codes,
                       event_boundaries,
                       pause=0):
     """
     We fetch data only for the years that we need, specified in event_boundaries
     @deprecated: this method makes a lot of queries - it is generally better to make fewer queries, even if it means fetching some data we don't need.
     """
     country_list = []
     for cnt_code in country_codes:
         country = Country(cnt_code)
         for ind_code in indicator_codes:
             indicator = Indicator()
             for event in event_boundaries[cnt_code]:
                 begin, end = event
                 indicator_part = self.fetch_indicator(
                     country.code, ind_code, begin, end)
                 time.sleep(pause)
                 indicator.merge_with_indicator(indicator_part)
             indicator.code = ind_code
             country.set_indicator(indicator)
         country_list.append(country)
     self.indicators = indicator_codes
     self.countries = country_list
     return self.countries
Exemple #2
0
 def fetch_data_separate_queries(self, country_codes, indicator_codes, start_date, end_date, pause=0):
     """
     Fetch indicator values stored in country objects,
     doesn't care of the crises conditions etc.
     gets all the years!!! (which can be a lot of data for many countries)
     
     @param country_codes: a list of country codes to fetch
     @param indicator_codes: a list of indicator codes to fetch
     @param start_date: a year from which indicators that we want to fetch should start
     @param end_date: a year from which indicators that we want to fetch should end
     @param pause: a pause in number of seconds between two queries (to ease the load on the World Bank API)
     
     @return: a list of country objects
     @deprecated: this method makes a separate query for each country, fetch_data should be used
     """
     # 
     
     country_list = []
     for cnt_code in country_codes:
         country = Country(cnt_code)
         for ind_code in indicator_codes:
             indicator = self.fetch_indicator(country.code,
                                              ind_code,
                                              start_date,
                                              end_date)
             time.sleep(pause)
             indicator.code = ind_code
             country.set_indicator(indicator)
         country_list.append(country)
     self.indicators = indicator_codes
     self.countries = country_list
     return self.countries
Exemple #3
0
    def fetch_data_separate_queries(self,
                                    country_codes,
                                    indicator_codes,
                                    start_date,
                                    end_date,
                                    pause=0):
        """
        Fetch indicator values stored in country objects,
        doesn't care of the crises conditions etc.
        gets all the years!!! (which can be a lot of data for many countries)
        
        @param country_codes: a list of country codes to fetch
        @param indicator_codes: a list of indicator codes to fetch
        @param start_date: a year from which indicators that we want to fetch should start
        @param end_date: a year from which indicators that we want to fetch should end
        @param pause: a pause in number of seconds between two queries (to ease the load on the World Bank API)
        
        @return: a list of country objects
        @deprecated: this method makes a separate query for each country, fetch_data should be used
        """
        #

        country_list = []
        for cnt_code in country_codes:
            country = Country(cnt_code)
            for ind_code in indicator_codes:
                indicator = self.fetch_indicator(country.code, ind_code,
                                                 start_date, end_date)
                time.sleep(pause)
                indicator.code = ind_code
                country.set_indicator(indicator)
            country_list.append(country)
        self.indicators = indicator_codes
        self.countries = country_list
        return self.countries
Exemple #4
0
 def fetch_data_sparse(self, country_codes, indicator_codes, event_boundaries, pause=0):
     """
     We fetch data only for the years that we need, specified in event_boundaries
     @deprecated: this method makes a lot of queries - it is generally better to make fewer queries, even if it means fetching some data we don't need.
     """
     country_list = []
     for cnt_code in country_codes:
         country = Country(cnt_code)
         for ind_code in indicator_codes:
             indicator = Indicator()
             for event in event_boundaries[cnt_code]:
                 begin, end = event
                 indicator_part = self.fetch_indicator(country.code,
                                                  ind_code,
                                                  begin,
                                                  end)
                 time.sleep(pause)
                 indicator.merge_with_indicator(indicator_part)
             indicator.code = ind_code
             country.set_indicator(indicator)
         country_list.append(country)
     self.indicators = indicator_codes
     self.countries = country_list
     return self.countries