import math


def ideal_dcg(query, rankings, n=10):
    """
    Calculate the ideal DCG for a query at N.
    The premise of DCG is that highly relevant documents appearing lower
    in a search result list should be penalized as the graded relevance value is reduced
    logarithmically proportional to the position of the result. This function calculates
    what the ideal DCG would be for a given query.

    :param query: The search query.
    :param rankings: A pre-calculated dictionary of queries with relevance labels (available on request).
    :param n: The position through which to calculate the DCG.
    :return idcg: The ideal DCG through N for a given query.
    """
    ranking = rankings[query.lower()][:n]
    idcg = sum([r["label"]/math.log((i+1)+1) for i, r in enumerate(ranking)])
    return idcg