from pathlib import Path
import csv


def fill_tabular_tempdir(root_dir):
    """
    Creates the sample files to be read and returns the data we should find
    :param root_dir: The root directory
    :return: Good data in a dict of label -> dict of x -> y
    """
    results = {0: {}, 1: {}}

    # Directory, filename, val_range
    dir_struct = [
        ['myworkspace', 'ws.csv', list(range(0, 4))],
        ['mydataroot', 'dr.csv', list(range(4, 8))],
        ['myrelative', 'rel.csv', list(range(8, 12))]
    ]

    for dir_name, file_name, data in dir_struct:
        dir_path = Path(root_dir) / dir_name
        dir_path.mkdir()

        csv_path = dir_path / file_name
        with open(csv_path, "w") as csv_file:
            csv_writer = csv.writer(csv_file, delimiter=',')
            csv_writer.writerow('x,y,label')
            for idx, val in enumerate(data):
                results[idx % 2][val] = val + 10
                csv_writer.writerow([val, val + 10, idx % 2])

    return results