-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rossum DMv2 analyze: add export functionality
This allows downloading of the new results from DMv2.
- Loading branch information
Showing
9 changed files
with
294 additions
and
87 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
use reqwest::{Client, Url}; | ||
use serde::de::DeserializeOwned; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
#[derive(Debug, Serialize, Deserialize)] | ||
pub(crate) struct Document { | ||
pub annotations: Vec<String>, | ||
pub id: u64, | ||
pub mime_type: String, | ||
pub original_file_name: String, | ||
pub s3_name: String, | ||
pub url: String, | ||
} | ||
|
||
#[derive(Debug, Serialize, Deserialize)] | ||
pub(crate) struct Annotations { | ||
pub results: Vec<Annotation>, | ||
pub pagination: Pagination, | ||
} | ||
|
||
/// See: https://elis.rossum.ai/api/docs/#annotation | ||
#[derive(Clone, Debug, Serialize, Deserialize)] | ||
pub(crate) struct Annotation { | ||
pub id: i32, | ||
pub document: String, | ||
} | ||
|
||
#[derive(Debug, Serialize, Deserialize)] | ||
pub(crate) struct Pagination { | ||
pub total: i32, | ||
pub total_pages: i32, | ||
pub next: Option<String>, | ||
pub previous: Option<String>, | ||
} | ||
|
||
pub(crate) async fn get<T: DeserializeOwned>( | ||
http_client: &Client, | ||
url: &String, | ||
) -> reqwest::Result<T> { | ||
http_client.get(url).send().await?.json().await | ||
} | ||
|
||
pub(crate) async fn annotations_get( | ||
http_client: &Client, | ||
queue_id: &str, | ||
current_page: &mut i32, | ||
concurrency: &usize, | ||
annotations_status: &Vec<String>, | ||
) -> anyhow::Result<Annotations> { | ||
Ok(http_client | ||
.get(Url::parse_with_params( | ||
"https://elis.rossum.ai/api/v1/annotations", | ||
&[ | ||
("queue", queue_id.to_string()), | ||
("page", current_page.to_string()), | ||
("page_size", concurrency.to_string()), | ||
("status", annotations_status.join(",").to_string()), | ||
], | ||
)?) | ||
.send() | ||
.await? | ||
.json::<Annotations>() | ||
.await?) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
use csv; | ||
use serde::Serialize; | ||
use std::io; | ||
use tempfile::NamedTempFile; | ||
|
||
#[derive(Serialize)] | ||
pub struct CsvRecord { | ||
pub operation: String, | ||
pub document_original_file_name: String, | ||
pub document_mime_type: String, | ||
pub datapoint_id: String, | ||
pub datapoint_value_content: String, | ||
pub datapoint_value_options: String, | ||
} | ||
|
||
pub struct CsvWriter { | ||
writer: csv::Writer<std::fs::File>, | ||
} | ||
|
||
impl CsvWriter { | ||
pub fn new(file_path: &Option<&String>) -> Result<Self, csv::Error> { | ||
let writer = match file_path { | ||
Some(path) => csv::Writer::from_path(path)?, | ||
None => { | ||
let tmpfile = NamedTempFile::new()?; | ||
csv::Writer::from_path(tmpfile)? | ||
} | ||
}; | ||
Ok(Self { writer }) | ||
} | ||
|
||
pub fn write_record(&mut self, record: &CsvRecord) -> Result<(), csv::Error> { | ||
self.writer.serialize(record) | ||
} | ||
|
||
pub fn flush(&mut self) -> Result<(), io::Error> { | ||
self.writer.flush() | ||
} | ||
} |
Oops, something went wrong.