Exemple #1
0
 def get_data(self):
     from caravel.data import countries
     df = self.get_df()
     cols = [self.form_data.get('entity')]
     metric = self.form_data.get('metric')
     secondary_metric = self.form_data.get('secondary_metric')
     if metric == secondary_metric:
         ndf = df[cols]
         ndf['m1'] = df[metric]
         ndf['m2'] = df[metric]
     else:
         cols += [metric, secondary_metric]
         ndf = df[cols]
     df = ndf
     df.columns = ['country', 'm1', 'm2']
     d = df.to_dict(orient='records')
     for row in d:
         country = countries.get(self.form_data.get('country_fieldtype'),
                                 row['country'])
         if country:
             row['country'] = country['cca3']
             row['latitude'] = country['lat']
             row['longitude'] = country['lng']
             row['name'] = country['name']
         else:
             row['country'] = "XXX"
     return d
Exemple #2
0
 def get_data(self):
     from caravel.data import countries
     df = self.get_df()
     cols = [self.form_data.get('entity')]
     metric = self.form_data.get('metric')
     secondary_metric = self.form_data.get('secondary_metric')
     if metric == secondary_metric:
         ndf = df[cols]
         ndf['m1'] = df[metric]
         ndf['m2'] = df[metric]
     else:
         cols += [metric, secondary_metric]
         ndf = df[cols]
     df = ndf
     df.columns = ['country', 'm1', 'm2']
     d = df.to_dict(orient='records')
     for row in d:
         country = countries.get(
             self.form_data.get('country_fieldtype'), row['country'])
         if country:
             row['country'] = country['cca3']
             row['latitude'] = country['lat']
             row['longitude'] = country['lng']
             row['name'] = country['name']
         else:
             row['country'] = "XXX"
     return d