Skip to content

Commit

Permalink
Added new Docmap queries
Browse files Browse the repository at this point in the history
[Issue: #13]
  • Loading branch information
eidens committed Oct 5, 2021
1 parent df5a070 commit 28910a9
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 28 deletions.
44 changes: 31 additions & 13 deletions neoflask/queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -425,21 +425,18 @@ class DOCMAP_BY_DOI(_DOCMAP):
'''
map_docmap_filtering = {'doi': {'req_param': 'doi', 'default': ''}}

class DOCMAPS_BY_REVSERVICE_AND_INTERVAL(_DOCMAP):
class DOCMAPS_FROM_REVSERVICE_IN_INTERVAL(_DOCMAP):
code_docmap_filtering = '''
MATCH (
col:VizCollection {name: "refereed-preprints"}
)-[:HasSubCol]->(
subcol:VizSubCollection
)-[:HasPaper]->(
paper:VizPaper
)-[:HasReviewDate]->(
revdate:VizReviewDate
)
WHERE DATETIME(revdate.date) >= DATETIME($start_date)
AND DATETIME(revdate.date) < DATETIME($end_date)
MATCH
(col:VizCollection)-[:HasSubCol]->(subcol:VizSubCollection)-[:HasPaper]->(paper:VizPaper),
(preprint:Preprint)-[:inputs]->(Step)<-[:actions]-(Action)<-[:outputs]-(review:RefereeReport)
WHERE col.name = "refereed-preprints"
AND subcol.name = $reviewing_service
WITH COLLECT(DISTINCT paper.doi) AS doiList
AND paper.doi = preprint.doi
WITH preprint, DATETIME(MAX(review.published)) AS publish_date_newest_review
WHERE publish_date_newest_review >= DATETIME($start_date)
AND publish_date_newest_review < DATETIME($end_date)
WITH COLLECT(DISTINCT preprint.doi) AS doiList
UNWIND doiList AS doi
'''
map_docmap_filtering = {
Expand All @@ -457,6 +454,27 @@ class DOCMAPS_BY_REVSERVICE_AND_INTERVAL(_DOCMAP):
},
}

class DOCMAPS_IN_INTERVAL(_DOCMAP):
code_docmap_filtering = '''
MATCH
(preprint:Preprint)-[:inputs]->(Step)<-[:actions]-(Action)<-[:outputs]-(review:RefereeReport)
WITH preprint, DATETIME(MAX(review.published)) AS publish_date_newest_review
WHERE publish_date_newest_review >= DATETIME($start_date)
AND publish_date_newest_review < DATETIME($end_date)
WITH COLLECT(DISTINCT preprint.doi) AS doiList
UNWIND doiList AS doi
'''
map_docmap_filtering = {
'start_date': {
'req_param': 'start_date',
'default': '1900-01-01',
},
'end_date': {
'req_param': 'end_date',
'default': '2900-01-01',
},
}

class SEARCH_REVIEWS(Query):
code = '''
MATCH (
Expand Down
60 changes: 45 additions & 15 deletions neoflask/views.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from datetime import date, timedelta
from flask import (
abort,
jsonify,
Expand All @@ -12,7 +13,8 @@
STATS, BY_DOI, FIG_BY_DOI_IDX,
DESCRIBE_REVIEWING_SERVICES,
REVIEW_PROCESS_BY_DOI, REVIEW_MATERIAL_BY_ID,
DOCMAP_BY_DOI, DOCMAPS_BY_REVSERVICE_AND_INTERVAL,
DOCMAP_BY_DOI, DOCMAPS_FROM_REVSERVICE_IN_INTERVAL,
DOCMAPS_IN_INTERVAL,
BY_AUTO_TOPICS, BY_REVIEWING_SERVICE, AUTOMAGIC,
LUCENE_SEARCH, SEARCH_DOI,
COVID19, REFEREED_PREPRINTS,
Expand Down Expand Up @@ -254,31 +256,59 @@ def docmap_semantic_doi(doi: str):
j = ask_neo(DOCMAP_BY_DOI(), doi=doi, root=root)
return jsonify(j)

@app.route('/api/v2/<reviewing_service>/docmap/<start_date>/<end_date>/<int:pagination>', methods=['GET', 'POST'])
def docmap_search(reviewing_service: str, start_date: str, end_date: str, pagination: int):
app.logger.info(f"Searching for docmaps with parameters {reviewing_service}, {start_date}, {end_date}, {pagination}")
if pagination < 0:
def do_paginated_docmap_query(query, page=0, page_size=100, **kwargs):
if page < 0:
abort(400) # pagination paramater must be 0 or greater
page_size = 100
offset = pagination * page_size

offset = page * page_size
root = url_for('root', _external=True)

result = ask_neo(
DOCMAPS_BY_REVSERVICE_AND_INTERVAL(),
reviewing_service=reviewing_service,
start_date=start_date,
end_date=end_date,
query,
root=root,
offset=offset,
page_size=page_size,
root=root,
**kwargs,
)

return jsonify(result)

# @app.route('/api/v2/docmap/<start_date>/<end_date>/<int:pagination>', methods=['GET', 'POST'])
@app.route('/api/v2/<reviewing_service>/docmap/<start_date>/<end_date>/<int:pagination>', methods=['GET', 'POST'])
def docmaps_from_revservice_in_interval(reviewing_service: str, start_date: str, end_date: str, pagination: int):
app.logger.info(f"Getting docmaps for reviewing service \"{reviewing_service}\" from {start_date} to {end_date}, page {pagination}")
return do_paginated_docmap_query(
DOCMAPS_FROM_REVSERVICE_IN_INTERVAL(),
reviewing_service=reviewing_service,
start_date=start_date,
end_date=end_date,
page=pagination,
)

@app.route('/api/v2/docmap/<start_date>/<end_date>/<int:pagination>', methods=['GET', 'POST'])
def docmaps_in_interval(start_date: str, end_date: str, pagination: int):
app.logger.info(f"Getting docmaps from {start_date} to {end_date}, page {pagination}")
return do_paginated_docmap_query(
DOCMAPS_IN_INTERVAL(),
start_date=start_date,
end_date=end_date,
page=pagination,
)

# @app.route('/api/v2/<reviewing_service>/docmap/<int:N_most_recent>/<int:pagination>', methods=['GET', 'POST'])
@app.route('/api/v2/<reviewing_service>/docmap/<int:days>d/<int:pagination>', methods=['GET', 'POST'])
def docmaps_from_revservice_in_last_days(reviewing_service: str, days: int, pagination: int):
app.logger.info(f"Getting docmaps for reviewing service \"{reviewing_service}\" with reviews in the last {days} days, page {pagination}")
# The Docmap query is exclusive for the end of the interval. We want any reviews published today so add a day here.
end_date = date.today() + timedelta(days=1)
# With this start date we get any reviews published today and in the last n-1 days, so reviews from a total of n days.
start_date = end_date - timedelta(days=days)
return do_paginated_docmap_query(
DOCMAPS_FROM_REVSERVICE_IN_INTERVAL(),
reviewing_service=reviewing_service,
start_date=str(start_date),
end_date=str(end_date),
page=pagination,
)

# @app.route('/api/v2/<reviewing_service>/docmap/<int:days>d/<int:pagination>', methods=['GET', 'POST'])
# @app.route('/api/v2/<reviewing_service>/docmap/<int:n_most_recent>/<int:pagination>', methods=['GET', 'POST'])

# date of docmap creation and date of docmap update. filter on publishing data or on docmap creation date.

0 comments on commit 28910a9

Please sign in to comment.