def remove_dataset_to_project(project_id, file_name): """Remove dataset from project """ project_file_path = get_project_file_path(project_id) fp_lock = get_lock_path(project_id) with SQLiteLock(fp_lock, blocking=True, lock_name="active", project_id=project_id): # open the projects file with open(project_file_path, "r") as f_read: project_dict = json.load(f_read) # remove the path from the project file data_fn = project_dict["dataset_path"] del project_dict["dataset_path"] with open(project_file_path, "w") as f_write: json.dump(project_dict, f_write) # files to remove data_path = get_data_file_path(project_id, data_fn) pool_path = get_pool_path(project_id) labeled_path = get_labeled_path(project_id) os.remove(str(data_path)) os.remove(str(pool_path)) os.remove(str(labeled_path))
def read_label_history(project_id): """Get all the newly labeled papers from the file. Make sure to lock the "active" lock. """ try: with open(get_labeled_path(project_id), "r") as fp: labeled = json.load(fp) labeled = [[int(idx), int(label)] for idx, label in labeled] except FileNotFoundError: labeled = [] return labeled
def write_label_history(project_id, label_history): label_fp = get_labeled_path(project_id) with open(label_fp, "w") as f: json.dump(label_history, f)