示例#1
0
def import_csv_file(path_to_file="",
                    has_names=False,
                    has_ids=False,
                    delimiter=','):
    if not os.path.exists(path_to_file):
        return None

    input_file = open(path_to_file)
    csvreader = csv.reader(input_file, delimiter=delimiter)
    if has_names:
        names_row = next(csvreader)
        dataset = maindata.create_dataset_with_names(names_row, has_id=has_ids)
    else:
        first_row = next(csvreader)
        dataset = maindata.create_dataset_without_names(
            len(first_row) - 1 if has_ids else len(first_row), has_id=has_ids)
        if has_ids:
            temp = [float(first_row[i]) for i in range(1, len(first_row))]
            temp.insert(0, first_row[0])
            dataset.add_object(temp)
        else:
            dataset.add_object(
                [float(first_row[i]) for i in range(len(first_row))])

    for row in csvreader:
        if has_ids:
            temp = [float(row[i]) for i in range(1, len(row))]
            temp.insert(0, row[0])
            dataset.add_object(temp)
        else:
            dataset.add_object([float(row[i]) for i in range(len(row))])
    input_file.close()
    return dataset
示例#2
0
 def create_testdataset2(self):
     test_dataset = maindata.create_dataset_with_names(["X", "Y", "Z", "T"],
                                                       has_id=False)
     test_dataset.add_object(self._data_set11)
     test_dataset.add_object(self._data_set12)
     test_dataset.add_object(self._data_set13)
     test_dataset.add_object(self._data_set14)
     return test_dataset
示例#3
0
 def create_functions_test1(self):
     assert maindata.create_dataset_with_names(None) is None
     assert maindata.create_dataset_without_names(0) is None
     assert maindata.create_dataset_without_names(-23) is None
     assert maindata.create_dataset_without_names("asd") is None
     test_dataset = maindata.create_dataset_without_names(4)
     assert test_dataset.add_object(["name", 1, 2, 3, 4])
     assert not test_dataset.add_object(["name", 1, 3, 4])
     assert not test_dataset.add_object(self._data_set_fail1)
     assert not test_dataset.add_object(self._data_set_fail2)
示例#4
0
 def create_functions_test1(self):
     assert maindata.create_dataset_with_names(None, has_id=False) is None
     assert maindata.create_dataset_without_names(0, has_id=False) is None
     assert maindata.create_dataset_without_names(-23, has_id=False) is None
     assert maindata.create_dataset_without_names("asd",
                                                  has_id=False) is None
     test_dataset = maindata.create_dataset_without_names(4, has_id=False)
     assert test_dataset.add_object([1, 2, 3, 4])
     assert not test_dataset.add_object([1, 3, 4])
     assert not test_dataset.add_object(self._data_set_fail1)
     assert not test_dataset.add_object(self._data_set_fail2)