Beispiel #1
0
def main():
    while len(images_to_show):
        if get_new_image():
            break

    # Store results.
    utils.write_bounding_boxes(
        bounding_boxes,
        labels_directory + args.file_name + '_bounding_box.json')
    utils.write_labels(labels, labels_directory + args.file_name + '.csv')
from os import listdir

from autowebcompat import utils

labels_directory = 'label_persons/'
all_file_names = [f for f in listdir(labels_directory)]

labels_voted = {}
ydn_map = {'y': 0, 'd': 1, 'n': 2}
ydn_reverse_map = {0: 'y', 1: 'd', 2: 'n'}

for file_name in all_file_names:
    labels = utils.read_labels(labels_directory + file_name)
    for key, value in labels.items():
        if key not in labels_voted.keys():
            labels_voted[key] = [0, 0, 0]
        labels_voted[key][ydn_map[value]] += 1

labels = {}
for key, values in labels_voted.items():
    labels[key] = ydn_reverse_map[values.index(max(values))]

utils.write_labels(labels)
Beispiel #3
0
# The image are basically the same, except for advertisement or content.
def callback_d(e):
    labels[current_image] = 'd'
    get_new_image()


# The images are not the same.
def callback_n(e):
    labels[current_image] = 'n'
    get_new_image()


def callback_skip(e):
    get_new_image()


def close(e):
    root.quit()


get_new_image()
root.bind('y', callback_y)
root.bind('d', callback_d)
root.bind('n', callback_n)
root.bind('<Return>', callback_skip)
root.bind('<Escape>', close)
root.mainloop()

# Store results.
utils.write_labels(labels, labels_directory + args.file_name)
Beispiel #4
0
def test_write_labels(tmpdir):
    label = {1: 1, 2: 2}
    file_path = tmpdir.join("test.csv")
    utils.write_labels(label, file_name=file_path)
    assert (os.path.exists(file_path))
Beispiel #5
0
def test_write_labels():
    label = {1: 1, 2: 2}
    d = TemporaryDirectory()
    file_path = d.name + "/test.csv"
    utils.write_labels(label, file_name=file_path)
    assert (os.path.exists(file_path))
Beispiel #6
0
def migrate_v1_to_v2():

    def read_sequence(bug_id):
        with open('data/%d.txt' % bug_id) as f:
            return f.readlines()

    def write_sequence(bug_id, data):
        with open('./data/%d.txt' % bug_id, 'w') as f:
            for i in range(len(data)):
                for j in range(i + 1):
                    f.write(data[j])
                f.write('\n')

    all_data_files = os.listdir('data')
    label_files = os.listdir('label_persons')
    map_names = {}
    for i in range(7):
        map_names[i] = str(int((i + 1) * (i + 2) / 2 - 1))

    for f in all_data_files:
        if '.png' not in f:
            continue
        parts = f.split('_')

        if len(parts) <= 2:
            continue
        bug_id = parts[0]
        seq_no = int(parts[1])
        browser = parts[2]

        seq_no = map_names[seq_no]
        new_name = utils.create_file_name(bug_id=bug_id, browser=browser, seq_no=seq_no)
        os.rename(os.path.join('data', f), os.path.join('data', new_name))

    for f in all_data_files:
        if '.txt' not in f:
            continue
        bug_id = os.path.splitext(f)[0]
        data = read_sequence(int(bug_id))
        write_sequence(int(bug_id), data)

    for f in label_files:
        if 'csv' not in f:
            continue
        labels = utils.read_labels(os.path.join('label_persons', f))
        new_labels = {}

        for key, value in labels.items():
            key_info = utils.parse_file_name(key)

            if 'seq_no' not in key_info:
                new_labels[key] = value
                continue
            key = key.replace('_%d' % key_info['seq_no'], '_%s' % map_names[key_info['seq_no']])
            new_labels[key] = value
        utils.write_labels(new_labels, os.path.join('label_persons', f))

    for f in label_files:
        if 'json' not in f:
            continue

        bounding_boxes = utils.read_bounding_boxes(os.path.join('label_persons', f))
        new_bounding_boxes = {}

        for key, value in bounding_boxes.items():
            parts = key.split('_')

            if len(parts) <= 2:
                new_bounding_boxes[key] = value
                continue
            bug_id = parts[0]
            seq_no = int(parts[1])
            browser = parts[2]
            seq_no = map_names[seq_no]

            key = utils.create_file_name(bug_id=bug_id, browser=browser, seq_no=seq_no)
            new_bounding_boxes[key] = value
        utils.write_bounding_boxes(new_bounding_boxes, os.path.join('label_persons', f))
Beispiel #7
0
def test_write_labels(tmpdir):
    label = {'1': '1', '2': '2'}
    file_path = tmpdir.join('test.csv')
    utils.write_labels(label, file_name=file_path)
    assert (os.path.exists(file_path))
    assert (label == utils.read_labels(file_name=file_path))