def _get_installs(app_id):
 POPULARITY_PERIOD = 90
 client = get_monolith_client()
 popular = {'filter': {'range': {'date': {'gte': days_ago(POPULARITY_PERIOD).date().isoformat(), 'lte': days_ago(1).date().isoformat()}}}, 'aggs': {'total_installs': {'sum': {'field': 'app_installs'}}}}
 query = {'query': {'filtered': {'query': {'match_all': {}}, 'filter': {'term': {'app-id': app_id}}}}, 'aggregations': {'popular': popular, 'region': {'terms': {'field': 'region', 'size': len(mkt.regions.ALL_REGIONS)}, 'aggregations': {'popular': popular}}}, 'size': 0}
 try:
  res = client.raw(query)
 except ValueError as e:
  task_log.error('Error response from Monolith: {0}'.format(e))
  return {}
 if ('aggregations' not in res):
  task_log.error('No installs for app {}'.format(app_id))
  return {}
 results = {'all': res['aggregations']['popular']['total_installs']['value']}
 if ('region' in res['aggregations']):
  for regional_res in res['aggregations']['region']['buckets']:
   region_slug = regional_res['key']
   popular = regional_res['popular']['total_installs']['value']
   results[region_slug] = popular
 return results

def _get_installs ( app_id ) : POPULARITY_PERIOD = 90 client = get_monolith_client ( ) popular = { 'filter' : { 'range' : { 'date' : { 'gte' : days_ago ( POPULARITY_PERIOD ) . date ( ) . isoformat ( ) , 'lte' : days_ago ( 1 ) . date ( ) . isoformat ( ) } } } , 'aggs' : { 'total_installs' : { 'sum' : { 'field' : 'app_installs' } } } } query = { 'query' : { 'filtered' : { 'query' : { 'match_all' : { } } , 'filter' : { 'term' : { 'app-id' : app_id } } } } , 'aggregations' : { 'popular' : popular , 'region' : { 'terms' : { 'field' : 'region' , 'size' : len ( mkt . regions . ALL_REGIONS ) } , 'aggregations' : { 'popular' : popular } } } , 'size' : 0 } try : res = client . raw ( query ) except ValueError as e : task_log . error ( 'Error response from Monolith: {0}' . format ( e ) ) return { } if ( 'aggregations' not in res ) : task_log . error ( 'No installs for app {}' . format ( app_id ) ) return { } results = { 'all' : res [ 'aggregations' ] [ 'popular' ] [ 'total_installs' ] [ 'value' ] } if ( 'region' in res [ 'aggregations' ] ) : for regional_res in res [ 'aggregations' ] [ 'region' ] [ 'buckets' ] : region_slug = regional_res [ 'key' ] popular = regional_res [ 'popular' ] [ 'total_installs' ] [ 'value' ] results [ region_slug ] = popular return results
calculate popularity of app for all regions and per region .