def group_parsed_lines(lines, field):
    """Aggregates the parsed log lines by a field.  Counts
    the log lines in each group and their average duration.  The return
    value is a dict, where the keys are the unique field values, and the values
    are dicts of count, avg_duration, and the key.
    """
    grouped = {}
    for parsed in lines:
        key = parsed[field]
        summary = grouped.setdefault(key, {'count':0, 'total_duration':0.0})
        summary[field] = key
        summary['count'] += 1
        summary['total_duration'] += parsed['duration']
    # average dat up
    for summary in grouped.values():
        summary['avg_duration'] = summary['total_duration']/summary['count']
        del summary['total_duration']
    return grouped