Ejemplo n.º 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
Ejemplo n.º 2
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
Ejemplo n.º 3
0
 def test_apply_slope(self):
         indicator = Indicator(dates=[1,3,4], values=[17,16,13])
         indicator.apply_slope(2)
         self.assertEqual(indicator.values, [-0.5,-3.0])
         self.assertEqual(indicator.dates, [3,4])
Ejemplo n.º 4
0
 def test_apply_derivative(self):
     indicator = Indicator(dates=[1,2,3], values=[17,16,13])
     indicator.apply_derivative()
     self.assertEqual(indicator.values, [-1,-3])
     self.assertEqual(indicator.dates, [2,3])