Exemplo n.º 1
0
def calculate_stats(log_file):
    count_saved = defaultdict(int)
    count_total = defaultdict(int)
    with open(log_file) as fd:
        for line in fd.readlines():
            passengers, pedestrians, decision = line.strip().split('|')
            scenario = Scenario.from_string(passengers, pedestrians)

            # add saved population to count_saved
            if decision == 'passengers':
                add_to_count(scenario.passengers, count_saved)
            elif decision == 'pedestrians':
                add_to_count(scenario.pedestrians, count_saved)
            add_to_count(scenario.passengers, count_total)
            add_to_count(scenario.pedestrians, count_total)

    keys = set(count_saved.keys()).union(set(count_total.keys()))
    count_percents = {}
    for key in keys:
        count_percents[key] = count_saved[key] / count_total[key]
    table = []
    for key, percent in sorted(count_percents.items(),
                               key=(lambda kv: kv[1]),
                               reverse=True):
        table.append([key, '{:2.2%}'.format(percent), str(count_total[key])])
    pretty_print_table(table)
Exemplo n.º 2
0
def find_difference(manual_file):
    with open(manual_file) as manual_fd:
        for manual_line in manual_fd.readlines():
            passengers, pedestrians, manual_decision = manual_line.strip().split('|')
            scenario = Scenario.from_string(passengers, pedestrians)
            auto_decision = automatic_decision(scenario)
            if manual_decision != auto_decision:
                print(scenario)
                print()
                print('manual decision: ' + manual_decision)
                print('auto decision: ' + auto_decision)
                print(40 * '-')
Exemplo n.º 3
0
def find_difference(manual_file):
    with open(manual_file) as manual_fd:
        for manual_line in manual_fd.readlines():
            if manual_line.strip(" ") == "":
                break
            passengers, pedestrians, manual_decision = manual_line.strip(
            ).split('|')  #it's broken :'( i tried to fix it but i moved on
            scenario = Scenario.from_string(passengers, pedestrians)
            auto_decision = automatic_decision(scenario)
            if manual_decision != auto_decision:
                print(scenario)
                print()
                print('manual decision: ' + manual_decision)
                print('auto decision: ' + auto_decision)
                print(40 * '-')