def query_es_for_active_accounts(config):
    now = datetime.utcnow()
    then = (now - timedelta(days=1))
    es = Elasticsearch(**config['elasticsearch'])
    personal_players_query['query']['bool']['must'][(- 1)]['range']['date']['gt'] = then.strftime('%Y-%m-%d')
    personal_players_query['query']['bool']['must'][(- 1)]['range']['date']['lte'] = now.strftime('%Y-%m-%d')
    hits = []
    response = es.search(index=config['battle index'], body=personal_players_query, scroll='30s')
    while len(response['hits']['hits']):
        hits.extend(response['hits']['hits'])
        response = es.scroll(scroll_id=response['_scroll_id'], scroll='3s')
    flattened = [doc['_source']['account_id'] for doc in hits]
    player_info_extracted = []
    for i in range(0, len(flattened), 10000):
        active_player_info = es.mget(index='players', doc_type='player', body={'ids': flattened[i:(i + 10000)]}, _source=['account_id', 'console', 'created_at'])
        player_info_extracted.extend([doc['_source'] for doc in active_player_info['docs']])
    sorted_player_info = sorted(player_info_extracted, key=(lambda d: d['created_at']))
    buckets = {'xbox': OrderedDict(((v, 0) for v in sorted(config['account age']))), 'ps': OrderedDict(((v, 0) for v in sorted(config['account age']))), 'all': OrderedDict(((v, 0) for v in sorted(config['account age'])))}
    buckets['xbox']['other'] = 0
    buckets['ps']['other'] = 0
    buckets['all']['other'] = 0
    for player in sorted_player_info:
        delta = (now - datetime.strptime(player['created_at'], '%Y-%m-%dT%H:%M:%S'))
        for key in buckets['all'].keys():
            if (not isinstance(key, int)):
                buckets['all'][key] += 1
                buckets[player['console']][key] += 1
                break
            elif (delta.total_seconds() <= (((key * 24) * 60) * 60)):
                buckets['all'][key] += 1
                buckets[player['console']][key] += 1
                break
    return buckets
def query_es_for_active_accounts(config):
    now = datetime.utcnow()
    then = (now - timedelta(days=1))
    es = Elasticsearch(**config['elasticsearch'])
    personal_players_query['query']['bool']['must'][(- 1)]['range']['date']['gt'] = then.strftime('%Y-%m-%d')
    personal_players_query['query']['bool']['must'][(- 1)]['range']['date']['lte'] = now.strftime('%Y-%m-%d')
    hits = []
    response = es.search(index=config['battle index'], body=personal_players_query, scroll='30s')
    while len(response['hits']['hits']):
        hits.extend(response['hits']['hits'])
        response = es.scroll(scroll_id=response['_scroll_id'], scroll='3s')
    flattened = [doc['_source']['account_id'] for doc in hits]
    player_info_extracted = []
    for i in range(0, len(flattened), 10000):
        active_player_info = es.mget(index='players', doc_type='player', body={'ids': flattened[i:(i + 10000)]}, _source=['account_id', 'console', 'created_at'])
        player_info_extracted.extend([doc['_source'] for doc in active_player_info['docs']])
    sorted_player_info = sorted(player_info_extracted, key=(lambda d: d['created_at']))
    buckets = {'xbox': OrderedDict(((v, 0) for v in sorted(config['account age']))), 'ps': OrderedDict(((v, 0) for v in sorted(config['account age']))), 'all': OrderedDict(((v, 0) for v in sorted(config['account age'])))}
    buckets['xbox']['other'] = 0
    buckets['ps']['other'] = 0
    buckets['all']['other'] = 0
    for player in sorted_player_info:
        delta = (now - datetime.strptime(player['created_at'], '%Y-%m-%dT%H:%M:%S'))
        for key in buckets['all'].keys():
            if (not isinstance(key, int)):
                buckets['all'][key] += 1
                buckets[player['console']][key] += 1
                break
            elif (delta.total_seconds() <= (((key * 24) * 60) * 60)):
                buckets['all'][key] += 1
                buckets[player['console']][key] += 1
                break
    return buckets