import math


def average_length_in_sentences(groundtruth):
    """
    Returns the average length of all daily summaries (in sentences).

    The average ist first computed over all summaries in each timeline
    in `groundtruth`. Then the average over all averages obtained
    in this way is computed.

    Params:
        groundtruth (Groundtruth): Reference timelines.

    Returns:
        Average daily sumamry length.
    """
    all_avgs = []
    for tl in groundtruth.timelines:
        all_avgs.append(sum(len(x) for x in tl.dates_to_summaries.values()) / len(tl.get_dates()))

    return math.floor(sum(all_avgs) / len(all_avgs))