def add_dataset_to_project(project_id, file_name): """Add file path to the project file. Add file to data subfolder and fill the pool of iteration 0. """ 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"): # open the projects file with open(project_file_path, "r") as f_read: project_dict = json.load(f_read) # add path to dict (overwrite if already exists) project_dict["dataset_path"] = file_name with open(project_file_path, "w") as f_write: json.dump(project_dict, f_write) # fill the pool of the first iteration as_data = read_data(project_id) if as_data.labels is not None: unlabeled = np.where(as_data.labels == LABEL_NA)[0] pool_indices = as_data.record_ids[unlabeled] label_indices_included = \ [[int(x), 1] for x in np.where(as_data.labels == 1)[0]] label_indices_excluded = \ [[int(x), 0] for x in np.where(as_data.labels == 0)[0]] label_indices = label_indices_included + label_indices_excluded else: pool_indices = as_data.record_ids label_indices = [] np.random.shuffle(pool_indices) write_pool(project_id, pool_indices.tolist()) # make a empty qeue for the items to label write_label_history(project_id, label_indices)
def api_get_progress_info(project_id): # noqa: F401 """Get progress info on the article""" project_file_path = get_project_file_path(project_id) try: # open the projects file with open(project_file_path, "r") as f_read: project_dict = json.load(f_read) statistics = get_statistics(project_id) except Exception as err: logging.error(err) return jsonify(message="Failed to load pie chart."), 500 response = jsonify({**project_dict, **statistics}) response.headers.add('Access-Control-Allow-Origin', '*') # return a success response to the client. return response
def init_project(project_id, project_name=None, project_description=None, project_authors=None): """Initialize the necessary files specific to the web app.""" if not project_id and not isinstance(project_id, str) \ and len(project_id) >= 3: raise ValueError("Project name should be at least 3 characters.") if is_project(project_id): raise ValueError("Project already exists.") try: get_project_path(project_id).mkdir() get_data_path(project_id).mkdir() project_config = { 'version': asreview_version, # todo: Fail without git? 'id': project_id, 'name': project_name, 'description': project_description, 'authors': project_authors, 'created_at_unix': int(time.time()), # project related variables 'projectInitReady': False, 'reviewFinished': False, } # create a file with project info with open(get_project_file_path(project_id), "w") as fp: json.dump(project_config, fp) return project_config except Exception as err: # remove all generated folders and raise error shutil.rmtree(get_project_path()) raise err
def api_get_project_info(project_id): # noqa: F401 """Get info on the article""" try: # read the file with project info with open(get_project_file_path(project_id), "r") as fp: project_info = json.load(fp) # check if there is a dataset try: get_data_file_path(project_id) project_info["projectHasDataset"] = True except Exception: project_info["projectHasDataset"] = False # check if there is a prior knowledge (check if there is a model set), # if this is the case, the reviewer past the prior knowledge screen. project_info["projectHasPriorKnowledge"] = \ get_kwargs_path(project_id).exists() # check if there is a prior knowledge (check if there is a model set), # if this is the case, the reviewer past the prior knowledge screen. project_info["projectHasAlgorithms"] = \ get_kwargs_path(project_id).exists() # backwards support <0.10 if "projectInitReady" not in project_info: if project_info["projectHasPriorKnowledge"]: project_info["projectInitReady"] = True else: project_info["projectInitReady"] = False except FileNotFoundError: raise ProjectNotFoundError() return jsonify(project_info)
def init_project(project_id, project_name=None, project_description=None, project_authors=None): """Initialize the necessary files specific to the web app.""" if not project_id and not isinstance(project_id, str) \ and len(project_id) >= 3: raise ValueError("Project name can't be None or empty string") # get the directory with the projects project_dir = asreview_path() / project_id if project_dir.exists(): raise ValueError("Project already exists") try: project_dir.mkdir() fp_data = project_dir / "data" fp_data.mkdir() # create a file with project info with open(get_project_file_path(project_id), "w") as fp: json.dump( { 'version': asreview_version, # todo: Fail without git? 'id': project_id, 'name': project_name, 'description': project_description, 'authors': project_authors }, fp) except Exception as err: # remove all generated folders and raise error shutil.rmtree(project_dir) raise err