-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add curation rates stats to JSON output
- Loading branch information
1 parent
0949dfa
commit 3c8f52e
Showing
7 changed files
with
87 additions
and
3 deletions.
There are no files selected for viewing
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,68 @@ | ||
extern crate tokio_postgres; | ||
|
||
use self::tokio_postgres::Client; | ||
|
||
#[derive(Serialize, Deserialize, Clone, Debug)] | ||
pub struct CommunityResponseRate { | ||
pub year: i32, | ||
pub submitted: i64, | ||
pub sent_sessions: i64, | ||
pub response_rate: f32, | ||
} | ||
|
||
#[derive(Serialize, Deserialize, Clone, Debug)] | ||
pub struct ChadoQueries { | ||
pub community_response_rates: Vec<CommunityResponseRate>, | ||
} | ||
|
||
const RESPONSE_RATE_SQL: &str = " | ||
WITH counts as (SELECT year, | ||
(SELECT COUNT (*) | ||
FROM pombase_publication_curation_summary | ||
WHERE canto_curator_role = 'community' | ||
AND (canto_annotation_status = 'NEEDS_APPROVAL' OR canto_annotation_status = 'APPROVAL_IN_PROGRESS' OR canto_annotation_status = 'APPROVED') | ||
AND (canto_session_submitted_date IS NOT NULL | ||
AND canto_session_submitted_date <= (YEAR || '-12-30')::date)) AS submitted, | ||
(SELECT COUNT (*) | ||
FROM pombase_publication_curation_summary | ||
WHERE canto_curator_role = 'community' | ||
AND (canto_approved_date is not null OR canto_first_sent_to_curator_year IS NOT NULL | ||
AND canto_first_sent_to_curator_year <= YEAR)) AS sent_sessions | ||
FROM generate_series(2013, | ||
(SELECT extract(YEAR | ||
FROM CURRENT_DATE))::integer) AS YEAR) | ||
SELECT year, submitted, sent_sessions, trunc(100.0*submitted/sent_sessions,1)::real as response_rate from counts; | ||
"; | ||
|
||
async fn get_community_response_rates(conn: &mut Client) | ||
-> Result<Vec<CommunityResponseRate>, tokio_postgres::Error> | ||
{ | ||
let mut ret = vec![]; | ||
|
||
let result = conn.query(RESPONSE_RATE_SQL, &[]).await?; | ||
|
||
for row in &result { | ||
let el = CommunityResponseRate { | ||
year: row.get(0), | ||
submitted: row.get(1), | ||
sent_sessions: row.get(2), | ||
response_rate: row.get(3), | ||
}; | ||
|
||
ret.push(el); | ||
} | ||
|
||
Ok(ret) | ||
} | ||
|
||
impl ChadoQueries { | ||
pub async fn new(conn: &mut Client) -> Result<ChadoQueries, tokio_postgres::Error> { | ||
let community_response_rates = get_community_response_rates(conn).await?; | ||
Ok(ChadoQueries { | ||
community_response_rates, | ||
}) | ||
} | ||
} |
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 |
---|---|---|
@@ -1,5 +1,7 @@ | ||
pub mod raw; | ||
pub mod processed; | ||
pub mod chado_queries; | ||
|
||
pub use raw::Raw; | ||
pub use processed::Processed; | ||
pub use chado_queries::ChadoQueries; |
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