Skip to content

Commit

Permalink
Merge pull request #836 from alliance-genome/SCRUM-4868
Browse files Browse the repository at this point in the history
new endpoint to export mod recently sorted out papers
  • Loading branch information
sweng66 authored Feb 14, 2025
2 parents 18eba3d + 838e087 commit cb97870
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 12 deletions.
55 changes: 49 additions & 6 deletions agr_literature_service/api/crud/reference_crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -1145,14 +1145,18 @@ def add_to_corpus(db: Session, mod_abbreviation: str, reference_curie: str): #
detail=f"Error adding {reference_curie} to {mod_abbreviation} corpus: {e}")


def get_recently_sorted_references(db: Session, mod_abbreviation, days):

datestamp = str(date.today()).replace("-", "")
metaData = get_meta_data(mod_abbreviation, datestamp)

def get_past_to_present_date_range(num_days_ago: int):
current_timestamp = str(date.today()).replace("-", "")
now = datetime.now().date()
start_date = now - timedelta(days=days)
start_date = now - timedelta(days=num_days_ago)
end_date = now + timedelta(days=1) # to cover timezone issue
return current_timestamp, start_date, end_date


def get_recently_sorted_references(db: Session, mod_abbreviation, days):

current_timestamp, start_date, end_date = get_past_to_present_date_range(days)
metaData = get_meta_data(mod_abbreviation, current_timestamp)

refColNmList = ", ".join(get_reference_col_names())

Expand Down Expand Up @@ -1212,3 +1216,42 @@ def get_recently_sorted_references(db: Session, mod_abbreviation, days):
"metaData": metaData,
"data": data
}


def get_recently_deleted_references(db: Session, mod_abbreviation, days):

current_timestamp, start_date, end_date = get_past_to_present_date_range(days)
metaData = get_meta_data(mod_abbreviation, current_timestamp)

sql_query = text(
"SELECT cr.curie, u.email, u.id "
"FROM cross_reference cr, mod_corpus_association mca, mod m, users u "
"WHERE cr.curie_prefix = 'PMID' "
"AND cr.reference_id = mca.reference_id "
"AND mca.corpus = :corpus "
"AND mca.date_updated >= :start_date "
"AND mca.date_updated < :end_date "
"AND mca.mod_id = m.mod_id "
"AND m.abbreviation = :mod_abbreviation "
"AND mca.updated_by = u.id"
)

rows = db.execute(sql_query, {
"corpus": False,
"start_date": start_date,
"end_date": end_date,
"mod_abbreviation": mod_abbreviation
}).fetchall()

data = []
for x in rows:
data.append({
"pmid": x[0],
"updated_by_email": x[1],
"updated_by_okta_id": x[2]
})

return {
"metaData": metaData,
"data": data
}
17 changes: 11 additions & 6 deletions agr_literature_service/api/crud/sort_crud.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import logging
from sqlalchemy.orm import Session
from sqlalchemy import text
from datetime import datetime, timedelta

from agr_literature_service.api.models import ReferenceModel, WorkflowTagModel, CrossReferenceModel,\
ModCorpusAssociationModel, ModModel, ResourceDescriptorModel, ReferencefileModAssociationModel
from agr_literature_service.api.schemas import ReferenceSchemaNeedReviewShow, \
CrossReferenceSchemaShow, ReferencefileSchemaRelated, ReferencefileModSchemaShow
from agr_literature_service.api.crud.reference_crud import get_past_to_present_date_range

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -145,25 +145,30 @@ def get_referencefile_mod(referencefile_id, db: Session):


def get_mod_curators(db: Session, mod_abbreviation):

_, one_month_ago, _ = get_past_to_present_date_range(30)

sql_query_str = """
SELECT u.id, u.email
FROM users u
INNER JOIN mod_corpus_association mca ON mca.updated_by = u.id
INNER JOIN mod m ON mca.mod_id = m.mod_id
WHERE mca.corpus = TRUE
WHERE mca.corpus IS NOT NULL
AND m.abbreviation = :mod_abbreviation
AND u.email is NOT NULL
AND mca.date_updated >= :one_month_ago
"""
sql_query = text(sql_query_str)
result = db.execute(sql_query, {'mod_abbreviation': mod_abbreviation})
result = db.execute(sql_query, {
'mod_abbreviation': mod_abbreviation,
'one_month_ago': one_month_ago
})
return {row[1]: row[0] for row in result}


def get_recently_sorted_reference_ids(db: Session, mod_abbreviation, count, curator_okta_id, day):

now = datetime.now().date()
start_date = now - timedelta(days=day)
end_date = now + timedelta(days=1) # to cover timezone issue
_, start_date, end_date = get_past_to_present_date_range(day)

sql_query_str = """
SELECT DISTINCT mcav.reference_id, mcav.date_updated
Expand Down
10 changes: 10 additions & 0 deletions agr_literature_service/api/routers/reference_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,3 +279,13 @@ def get_recently_sorted_references(mod_abbreviation: str,
references = reference_crud.get_recently_sorted_references(db, mod_abbreviation, days)

return references


@router.get('/get_recently_deleted_references/{mod_abbreviation}',
status_code=status.HTTP_200_OK)
def get_recently_deleted_references(mod_abbreviation: str,
days: int = 7,
db: Session = db_session):
references = reference_crud.get_recently_deleted_references(db, mod_abbreviation, days)

return references

0 comments on commit cb97870

Please sign in to comment.