Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(cli): collect comments before downloading attachments #299

Merged
merged 2 commits into from
Aug 6, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Unreleased
- Add ability to get email by id
- Add ability to upload attachment content for comments
- fix bug where comment's would not be printed when downloading attachments

# v0.29.0
- Add `config parse-from-url` command for parsing configuration from a URL
Expand Down
99 changes: 49 additions & 50 deletions cli/src/commands/get/comments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -608,12 +608,6 @@ fn download_comments(
let page = page.context("Operation to get comments has failed.")?;
statistics.add_comments(page.len());

if let Some(attachments_dir) = &options.attachments_dir {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't allow downloading attachments when you don't have a dataset

page.iter().try_for_each(|comment| -> Result<()> {
download_comment_attachments(client, attachments_dir, comment, &statistics)
})?;
}

print_resources_as_json(
page.into_iter().map(|comment| AnnotatedComment {
comment,
Expand Down Expand Up @@ -685,43 +679,44 @@ fn get_comments_from_uids(
.context("Operation to get predictions has failed.")?;
// since predict-comments endpoint doesn't return some fields,
// they are set to None or [] here
let mut comments =
page.into_iter()
.zip(predictions.into_iter())
.map(|(comment, prediction)| AnnotatedComment {
comment: comment.comment,
labelling: Some(vec![Labelling {
group: DEFAULT_LABEL_GROUP_NAME.clone(),
assigned: Vec::new(),
dismissed: Vec::new(),
predicted: prediction.labels.map(|auto_threshold_labels| {
auto_threshold_labels
.iter()
.map(|auto_threshold_label| PredictedLabel {
name: PredictedLabelName::String(LabelName(
auto_threshold_label.name.join(" > "),
)),
sentiment: None,
probability: auto_threshold_label.probability,
auto_thresholds: Some(
auto_threshold_label.auto_thresholds.to_vec(),
),
})
.collect()
}),
}]),
entities: Some(Entities {
assigned: Vec::new(),
dismissed: Vec::new(),
predicted: prediction.entities,
let comments: Vec<_> = page
.into_iter()
.zip(predictions.into_iter())
.map(|(comment, prediction)| AnnotatedComment {
comment: comment.comment,
labelling: Some(vec![Labelling {
group: DEFAULT_LABEL_GROUP_NAME.clone(),
assigned: Vec::new(),
dismissed: Vec::new(),
predicted: prediction.labels.map(|auto_threshold_labels| {
auto_threshold_labels
.iter()
.map(|auto_threshold_label| PredictedLabel {
name: PredictedLabelName::String(LabelName(
auto_threshold_label.name.join(" > "),
)),
sentiment: None,
probability: auto_threshold_label.probability,
auto_thresholds: Some(
auto_threshold_label.auto_thresholds.to_vec(),
),
})
.collect()
}),
thread_properties: None,
moon_forms: None,
label_properties: None,
});
}]),
entities: Some(Entities {
assigned: Vec::new(),
dismissed: Vec::new(),
predicted: prediction.entities,
}),
thread_properties: None,
moon_forms: None,
label_properties: None,
})
.collect();

if let Some(attachments_dir) = &options.attachments_dir {
comments.try_for_each(|comment| -> Result<()> {
comments.iter().try_for_each(|comment| -> Result<()> {
download_comment_attachments(
client,
attachments_dir,
Expand All @@ -732,17 +727,20 @@ fn get_comments_from_uids(
}
print_resources_as_json(comments, &mut writer)
} else {
let mut comments = page.into_iter().map(|mut annotated_comment| {
if !include_predictions {
annotated_comment = annotated_comment.without_predictions();
}
if annotated_comment.has_annotations() {
statistics.add_annotated(1);
}
annotated_comment
});
let comments: Vec<_> = page
.into_iter()
.map(|mut annotated_comment| {
if !include_predictions {
annotated_comment = annotated_comment.without_predictions();
}
if annotated_comment.has_annotations() {
statistics.add_annotated(1);
}
annotated_comment
})
.collect();
if let Some(attachments_dir) = &options.attachments_dir {
comments.try_for_each(|comment| -> Result<()> {
comments.iter().try_for_each(|comment| -> Result<()> {
download_comment_attachments(
client,
attachments_dir,
Expand All @@ -751,6 +749,7 @@ fn get_comments_from_uids(
)
})?;
}

print_resources_as_json(comments, &mut writer)
}
})?;
Expand Down
Loading