Example #1
0
 def fetch_data_sparse(self, country_codes, indicator_codes,
                       event_boundaries, wb_pause):
     """
     We fetch data only for the years that we need, specified in event_boundaries
     """
     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(wb_pause)
                 indicator.merge_with_indicator(indicator_part)
             indicator.code = ind_code
             country.set_indicator(ind_code, indicator)
         country_list.append(country)
     self.indicators = indicator_codes
     self.countries = country_list
     return self.countries
Example #2
0
 def fetch_data_sparse(self, country_codes, indicator_codes, event_boundaries, wb_pause):
     """
     We fetch data only for the years that we need, specified in event_boundaries
     """
     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(wb_pause)
                 indicator.merge_with_indicator(indicator_part)
             indicator.code = ind_code
             country.set_indicator(ind_code, indicator)
         country_list.append(country)
     self.indicators = indicator_codes
     self.countries = country_list
     return self.countries
Example #3
0
def parse_single_country(data_list):
    values=[]
    dates=[]
    for entity in data_list:
        try:
            value = float(entity["value"])
            date = int(entity["date"])
        except TypeError: # value wasn't a float 
            pass
        else:
            values.append(value)
            dates.append(date)
    #pprint(dates)
    #pprint(values)
    indicator = Indicator(dates, values)
    return indicator
Example #4
0
 def test_apply_derivative(self):
     indicator = Indicator([1,2,3], [17,16,13])
     indicator.apply_derivative()
     self.assertEqual(indicator.values, [-1,-3])
     self.assertEqual(indicator.dates, [2,3])