def read_results(results_fpath, lamb):
    
    last = {}
    classes = {}
    objs = set()
    users = set()
    
    joint = defaultdict(lambda: defaultdict(int))
    glob = defaultdict(lambda: defaultdict(int))
    
    with open(results_fpath) as results_file:
        results_file.readline()
        for line in results_file:
            spl = line.strip().split()
            user = spl[0]
            class_ = spl[1]

            last_stage = spl[-1].split('-')[-1]
            last[user] = last_stage
            classes[user] = class_

            for item in spl[2:]:
                obj, stage = item.split('-')
                joint[class_][stage, obj] += 1
                glob[class_][stage] += 1
                objs.add(obj)
            users.add(user)

    probs = {}
    for u in last:
        probs[u] = {}
        class_ = classes[u]
        for o in objs:
            probs[u][o] = (lamb + joint[class_][last[u], o]) / \
                    (len(objs) * lamb + glob[class_][last[u]])

    for u in probs:
        sum_ = sum(probs[u].values())
        for o in objs:
            probs[u][o] = probs[u][o] / sum_ if sum_ > 0 else 0

    sorted_probs = {}
    for u in probs:
        sorted_probs[u] = sorted([(v, o) for o, v in probs[u].items()],
                reverse=True)
    return sorted_probs, users, objs
dataset/ETHPy150Open flaviovdf/tribeflow/scripts/mrr_stages.py/read_results/original