def calculate_scores()

in slot_detection/score.py [0:0]


def calculate_scores(slots, media_info, asset_metadata):
    # Sorting by slot time
    slots.sort(key=lambda slot: slot["Timestamp"])

    min_slot_interval = 0.50
    block_ratio = 0.25

    consolidated = []
    prev_slot = {}

    # Getting video duration
    total_duration = float(media_info["DurationMillis"]) / 1000.0

    for slot in slots:
        # Adjusting base slot score
        slot["Score"] = slot["Score"] * SCORE_ADJUSTMENTS[slot["Reasons"][0]]

        # Score adjustment: distance from beginning
        if slot["Timestamp"] / total_duration < block_ratio:
            slot["Score"] = slot["Score"] * math.pow(
                slot["Timestamp"] / total_duration, 0.30)

        if "Timestamp" in prev_slot:
            dist_from_prev = slot["Timestamp"] - prev_slot["Timestamp"]
            # Consolidating with previous slot if distance < min_slot_interval
            if dist_from_prev < min_slot_interval:
                print("Consolidating slots: {}\n{}".format(prev_slot, slot))

                prev_slot["Timestamp"] = slot["Timestamp"]
                if slot["Reasons"][0] not in prev_slot["Reasons"]:
                    prev_slot["Reasons"].append(slot["Reasons"][0])
                prev_slot["Score"] = __disjunction(prev_slot["Score"], slot["Score"])
                continue
            # Score adjustment: distance between slots
            elif dist_from_prev / total_duration < block_ratio:
                if slot["Score"] < prev_slot["Score"]:
                    slot["Score"] = slot["Score"] * math.pow(
                        dist_from_prev / total_duration, 0.05)
                else:
                    prev_slot["Score"] = prev_slot["Score"] * math.pow(
                        dist_from_prev / total_duration, 0.05)

        # Score adjustment: labels before and after
        slot["Context"] = __get_context_metadata(slot["Timestamp"], asset_metadata)
        pre_labels = set(label["Name"] for label in slot["Context"]["Labels"]["Before"])
        post_labels = set(label["Name"] for label in slot["Context"]["Labels"]["After"])
        if pre_labels or post_labels:
            distance = 1.0 - (len(pre_labels.intersection(post_labels)) / len(pre_labels.union(post_labels)))
            slot["Score"] = __disjunction(slot["Score"], math.pow(distance, 4.0))

        consolidated.append(slot)
        prev_slot = slot

    return consolidated