from typing import Counter


def get_log_prefixes(log, activity_key="concept:name"):
    """
    Get trace log prefixes

    Parameters
    ----------
    log
        Trace log
    activity_key
        Activity key (must be provided if different from concept:name)
    """
    prefixes = {}
    prefixCount = Counter()
    for trace in log:
        i = 1
        while i < len(trace) - 1:
            redTrace = trace[0:i]
            prefix = ",".join([x[activity_key] for x in redTrace])
            nextActivity = trace[i][activity_key]
            if not prefix in prefixes:
                prefixes[prefix] = set()
            prefixes[prefix].add(nextActivity)
            prefixCount[prefix] += 1
            i = i + 1
    return prefixes, prefixCount