Skip to content

Commit

Permalink
Fix various small issues with data uploading
Browse files Browse the repository at this point in the history
  • Loading branch information
J535D165 committed Jan 5, 2024
1 parent bc8558d commit 8ff40a7
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
5 changes: 3 additions & 2 deletions asreview/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,10 +330,9 @@ def add_dataset(self, file_name):
Add file to data subfolder and fill the pool of iteration 0.
"""
self.update_config(dataset_path=file_name)

# fill the pool of the first iteration
fp_data = Path(self.project_path, "data", self.config["dataset_path"])
fp_data = Path(self.project_path, "data", file_name)
as_data = ASReviewData.from_file(fp_data)

if self.config["mode"] == PROJECT_MODE_SIMULATE and as_data.labels is None:
Expand All @@ -342,6 +341,8 @@ def add_dataset(self, file_name):
if self.config["mode"] == PROJECT_MODE_EXPLORE and as_data.labels is None:
raise ValueError("Import partially or fully labeled dataset")

self.update_config(dataset_path=file_name)

with open_state(self.project_path, read_only=False) as state:
# save the record ids in the state file
state.add_record_table(as_data.record_ids)
Expand Down
8 changes: 7 additions & 1 deletion asreview/webapp/api/projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,13 @@ def api_upload_data_to_project(project): # noqa: F401
project.add_dataset(data_path.name)

# Bad format. TODO{Jonathan} Return informative message with link.
except BadFileFormatError as err:
except Exception as err:

try:
project.remove_dataset()
except Exception:
pass

message = f"Failed to import file '{filename}'. {err}"
return jsonify(message=message), 400

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,10 @@ const AddDataset = (props) => {
};

React.useEffect(() => {
if (props.mode === projectModes.EXPLORATION) {
setDatasetSource("file");
}
if (props.mode !== projectModes.EXPLORATION) {
if (props.mode === projectModes.SIMULATION) {
setDatasetSource("benchmark");
} else {
setDatasetSource("file");
}
}, [props.mode]);

Expand Down Expand Up @@ -231,7 +230,7 @@ const AddDataset = (props) => {
</Link>
</Typography>
)}
{datasetSource === "file" && fetchReadersSuccess && (
{datasetSource === "file" && datasetReaders !== null && (
<ImportFromFile
acceptFormat={datasetReaders
.map((reader) => reader.extension)
Expand Down

0 comments on commit 8ff40a7

Please sign in to comment.