def query_es_for_graphs(config):
    now = datetime.utcnow()
    then = (now - timedelta(days=config['days']))
    es = Elasticsearch(**config['elasticsearch'])
    battles_query['query']['bool']['must'][(- 1)]['range']['date']['gte'] = then.strftime('%Y-%m-%d')
    battles_query['query']['bool']['must'][(- 1)]['range']['date']['lte'] = now.strftime('%Y-%m-%d')
    players_query['query']['bool']['must'][(- 1)]['range']['date']['gte'] = then.strftime('%Y-%m-%d')
    players_query['query']['bool']['must'][(- 1)]['range']['date']['lte'] = now.strftime('%Y-%m-%d')
    new_players_query['query']['bool']['must'][(- 1)]['range']['created_at']['gte'] = then.strftime('%Y-%m-%d')
    new_players_query['query']['bool']['must'][(- 1)]['range']['created_at']['lt'] = now.strftime('%Y-%m-%d')
    battles = es.search(index=config['battle index'], body=battles_query)
    players = es.search(index=config['battle index'], body=players_query)
    newplayers = es.search(index='players', body=new_players_query)
    battles_xbox = []
    battles_ps = []
    players_xbox = []
    players_ps = []
    newplayers_xbox = []
    newplayers_ps = []
    averages_xbox = []
    averages_ps = []
    for bucket in battles['aggregations']['2']['buckets']:
        if (not bucket['3']['buckets']):
            battles_xbox.append(0)
            battles_ps.append(0)
            continue
        for subbucket in bucket['3']['buckets']:
            if (subbucket['key'] == 'xbox'):
                battles_xbox.append(subbucket['1']['value'])
            else:
                battles_ps.append(subbucket['1']['value'])
    for bucket in players['aggregations']['2']['buckets']:
        if (not bucket['3']['buckets']):
            players_xbox.append(0)
            players_ps.append(0)
            continue
        for subbucket in bucket['3']['buckets']:
            if (subbucket['key'] == 'xbox'):
                players_xbox.append(subbucket['doc_count'])
            else:
                players_ps.append(subbucket['doc_count'])
    for bucket in newplayers['aggregations']['2']['buckets']:
        if (not bucket['3']['buckets']):
            newplayers_xbox.append(0)
            newplayers_ps.append(0)
        for subbucket in bucket['3']['buckets']:
            if (subbucket['key'] == 'xbox'):
                newplayers_xbox.append(subbucket['doc_count'])
            else:
                newplayers_ps.append(subbucket['doc_count'])
    for (b, p) in zip(battles_xbox, players_xbox):
        averages_xbox.append((b / p))
    for (b, p) in zip(battles_ps, players_ps):
        averages_ps.append((b / p))
    dates = [b['key_as_string'].split('T')[0] for b in players['aggregations']['2']['buckets']]
    newplayers_dates = [b['key_as_string'].split('T')[0] for b in newplayers['aggregations']['2']['buckets']]
    return (dates, battles_xbox, battles_ps, players_xbox, players_ps, newplayers_dates, newplayers_xbox, newplayers_ps, averages_xbox, averages_ps)
def query_es_for_graphs(config):
    now = datetime.utcnow()
    then = (now - timedelta(days=config['days']))
    es = Elasticsearch(**config['elasticsearch'])
    battles_query['query']['bool']['must'][(- 1)]['range']['date']['gte'] = then.strftime('%Y-%m-%d')
    battles_query['query']['bool']['must'][(- 1)]['range']['date']['lte'] = now.strftime('%Y-%m-%d')
    players_query['query']['bool']['must'][(- 1)]['range']['date']['gte'] = then.strftime('%Y-%m-%d')
    players_query['query']['bool']['must'][(- 1)]['range']['date']['lte'] = now.strftime('%Y-%m-%d')
    new_players_query['query']['bool']['must'][(- 1)]['range']['created_at']['gte'] = then.strftime('%Y-%m-%d')
    new_players_query['query']['bool']['must'][(- 1)]['range']['created_at']['lt'] = now.strftime('%Y-%m-%d')
    battles = es.search(index=config['battle index'], body=battles_query)
    players = es.search(index=config['battle index'], body=players_query)
    newplayers = es.search(index='players', body=new_players_query)
    battles_xbox = []
    battles_ps = []
    players_xbox = []
    players_ps = []
    newplayers_xbox = []
    newplayers_ps = []
    averages_xbox = []
    averages_ps = []
    for bucket in battles['aggregations']['2']['buckets']:
        if (not bucket['3']['buckets']):
            battles_xbox.append(0)
            battles_ps.append(0)
            continue
        for subbucket in bucket['3']['buckets']:
            if (subbucket['key'] == 'xbox'):
                battles_xbox.append(subbucket['1']['value'])
            else:
                battles_ps.append(subbucket['1']['value'])
    for bucket in players['aggregations']['2']['buckets']:
        if (not bucket['3']['buckets']):
            players_xbox.append(0)
            players_ps.append(0)
            continue
        for subbucket in bucket['3']['buckets']:
            if (subbucket['key'] == 'xbox'):
                players_xbox.append(subbucket['doc_count'])
            else:
                players_ps.append(subbucket['doc_count'])
    for bucket in newplayers['aggregations']['2']['buckets']:
        if (not bucket['3']['buckets']):
            newplayers_xbox.append(0)
            newplayers_ps.append(0)
        for subbucket in bucket['3']['buckets']:
            if (subbucket['key'] == 'xbox'):
                newplayers_xbox.append(subbucket['doc_count'])
            else:
                newplayers_ps.append(subbucket['doc_count'])
    for (b, p) in zip(battles_xbox, players_xbox):
        averages_xbox.append((b / p))
    for (b, p) in zip(battles_ps, players_ps):
        averages_ps.append((b / p))
    dates = [b['key_as_string'].split('T')[0] for b in players['aggregations']['2']['buckets']]
    newplayers_dates = [b['key_as_string'].split('T')[0] for b in newplayers['aggregations']['2']['buckets']]
    return (dates, battles_xbox, battles_ps, players_xbox, players_ps, newplayers_dates, newplayers_xbox, newplayers_ps, averages_xbox, averages_ps)