def query_es_for_mode_battles_difference(config, long_term=False):
    now = datetime.utcnow()
    then = (now - timedelta(days=(config['days'] if (not long_term) else config['long term'])))
    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')
    cw_popular_tanks_query['query']['bool']['must'][(- 1)]['range']['date']['gte'] = then.strftime('%Y-%m-%d')
    cw_popular_tanks_query['query']['bool']['must'][(- 1)]['range']['date']['lte'] = now.strftime('%Y-%m-%d')
    total_battles_response = es.search(index=config['battle index'], body=battles_query)
    cw_battles_response = es.search(index=config['tank index'], body=cw_popular_tanks_query)
    dates = [b['key_as_string'].split('T')[0] for b in total_battles_response['aggregations']['2']['buckets']]
    ww2_battles_xbox = OrderedDict()
    ww2_battles_ps = OrderedDict()
    cw_battles_xbox = OrderedDict()
    cw_battles_ps = OrderedDict()
    percent_cw_xbox = OrderedDict()
    percent_cw_ps = OrderedDict()
    for d in dates:
        ww2_battles_xbox[d] = 0
        ww2_battles_ps[d] = 0
        cw_battles_xbox[d] = 0
        cw_battles_ps[d] = 0
        percent_cw_xbox[d] = None
        percent_cw_ps[d] = None
    for bucket in total_battles_response['aggregations']['2']['buckets']:
        if (not bucket['3']['buckets']):
            continue
        for subbucket in bucket['3']['buckets']:
            if (subbucket['key'] == 'xbox'):
                ww2_battles_xbox[bucket['key_as_string'].split('T')[0]] = subbucket['1']['value']
            else:
                ww2_battles_ps[bucket['key_as_string'].split('T')[0]] = subbucket['1']['value']
    for bucket in cw_battles_response['aggregations']['2']['buckets']:
        if (not bucket['4']['buckets']):
            continue
        for subbucket in bucket['4']['buckets']:
            if (subbucket['key'] == 'xbox'):
                cw_battles_xbox[bucket['key_as_string'].split('T')[0]] = subbucket['1']['value']
            else:
                cw_battles_ps[bucket['key_as_string'].split('T')[0]] = subbucket['1']['value']
    for i in range(len(dates)):
        percent_cw_xbox[dates[i]] = (cw_battles_xbox[dates[i]] / ww2_battles_xbox[dates[i]])
        percent_cw_ps[dates[i]] = (cw_battles_ps[dates[i]] / ww2_battles_ps[dates[i]])
        ww2_battles_xbox[dates[i]] = (ww2_battles_xbox[dates[i]] - cw_battles_xbox[dates[i]])
        ww2_battles_ps[dates[i]] = (ww2_battles_ps[dates[i]] - cw_battles_ps[dates[i]])
    return (dates, list(ww2_battles_xbox.values()), list(ww2_battles_ps.values()), list(cw_battles_xbox.values()), list(cw_battles_ps.values()), list(percent_cw_xbox.values()), list(percent_cw_ps.values()))
def query_es_for_mode_battles_difference(config, long_term=False):
    now = datetime.utcnow()
    then = (now - timedelta(days=(config['days'] if (not long_term) else config['long term'])))
    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')
    cw_popular_tanks_query['query']['bool']['must'][(- 1)]['range']['date']['gte'] = then.strftime('%Y-%m-%d')
    cw_popular_tanks_query['query']['bool']['must'][(- 1)]['range']['date']['lte'] = now.strftime('%Y-%m-%d')
    total_battles_response = es.search(index=config['battle index'], body=battles_query)
    cw_battles_response = es.search(index=config['tank index'], body=cw_popular_tanks_query)
    dates = [b['key_as_string'].split('T')[0] for b in total_battles_response['aggregations']['2']['buckets']]
    ww2_battles_xbox = OrderedDict()
    ww2_battles_ps = OrderedDict()
    cw_battles_xbox = OrderedDict()
    cw_battles_ps = OrderedDict()
    percent_cw_xbox = OrderedDict()
    percent_cw_ps = OrderedDict()
    for d in dates:
        ww2_battles_xbox[d] = 0
        ww2_battles_ps[d] = 0
        cw_battles_xbox[d] = 0
        cw_battles_ps[d] = 0
        percent_cw_xbox[d] = None
        percent_cw_ps[d] = None
    for bucket in total_battles_response['aggregations']['2']['buckets']:
        if (not bucket['3']['buckets']):
            continue
        for subbucket in bucket['3']['buckets']:
            if (subbucket['key'] == 'xbox'):
                ww2_battles_xbox[bucket['key_as_string'].split('T')[0]] = subbucket['1']['value']
            else:
                ww2_battles_ps[bucket['key_as_string'].split('T')[0]] = subbucket['1']['value']
    for bucket in cw_battles_response['aggregations']['2']['buckets']:
        if (not bucket['4']['buckets']):
            continue
        for subbucket in bucket['4']['buckets']:
            if (subbucket['key'] == 'xbox'):
                cw_battles_xbox[bucket['key_as_string'].split('T')[0]] = subbucket['1']['value']
            else:
                cw_battles_ps[bucket['key_as_string'].split('T')[0]] = subbucket['1']['value']
    for i in range(len(dates)):
        percent_cw_xbox[dates[i]] = (cw_battles_xbox[dates[i]] / ww2_battles_xbox[dates[i]])
        percent_cw_ps[dates[i]] = (cw_battles_ps[dates[i]] / ww2_battles_ps[dates[i]])
        ww2_battles_xbox[dates[i]] = (ww2_battles_xbox[dates[i]] - cw_battles_xbox[dates[i]])
        ww2_battles_ps[dates[i]] = (ww2_battles_ps[dates[i]] - cw_battles_ps[dates[i]])
    return (dates, list(ww2_battles_xbox.values()), list(ww2_battles_ps.values()), list(cw_battles_xbox.values()), list(cw_battles_ps.values()), list(percent_cw_xbox.values()), list(percent_cw_ps.values()))