def upload_dataset():
     if "file" in request.files:
         file = request.files["file"]
         if file.filename == "":
             abort(400)
         filename = secure_filename(file.filename)
         path = DATASETS_DIRECTORY / filename
         file.save(path)
         Dataset.create_from_path(path).save()
         return {"status": "ok"}, 201
     else:
         abort(400)
def load_all_datasets(datasets_directory):
    """Load all unknown datasets into the database """
    datasets_already_loaded = [Path(d.path) for d in Dataset.objects]

    for path in map(Path, os.listdir(datasets_directory)):
        path = (datasets_directory / path).resolve()
        path = datasets_directory / path
        if path.suffix == ".csv" and path not in datasets_already_loaded:
            log.info(f"Loading {path}")
            d = Dataset.create_from_path(path).save()
            log.info(f"Created entry for dataset {path}: {d.to_json()}")
        else:
            log.info(f"Not loading {path}")