Skip to content

Commit

Permalink
Provide data size summary endpoint.
Browse files Browse the repository at this point in the history
  Address downstream Bravue issue #4
  Avoid manually coding info about backing data set
  • Loading branch information
grosscol committed Dec 7, 2023
1 parent 8658d22 commit 81cc6f5
Show file tree
Hide file tree
Showing 4 changed files with 2,158 additions and 556 deletions.
27 changes: 25 additions & 2 deletions bravo_api/blueprints/status/status.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import sys
from flask import Blueprint, Response, current_app, jsonify, make_response


bp = Blueprint('status', __name__)
logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -38,11 +39,33 @@ def usage() -> Response:
result = current_app.cache.get('usage')
if result is None:
result = usage_stats(current_app.mmongo.db)
current_app.cache.set('usage', result, timeout=3600)
logger.debug("Usage result updated")
current_app.cache.set('usage', result, timeout=0)
return make_response(jsonify(result))


@bp.route('/counts', methods=['GET'])
def counts() -> Response:
result = current_app.cache.get('counts')
if result is None:
snv_count = count_collection(current_app.mmongo.db.snv)
transcript_count = count_collection(current_app.mmongo.db.transcripts)
gene_count = count_collection(current_app.mmongo.db.genes)

result = {'snvs': snv_count, 'transcripts': transcript_count, 'genes': gene_count}

current_app.cache.set('counts', result, timeout=3600)
logger.debug('variant counts updated')
return make_response(jsonify(result))


def count_collection(collection: pymongo.collection.Collection) -> int:
"""
Count (estimate) the number of snv in backing database
"""
result = collection.estimated_document_count()
return result


def usage_stats(db: pymongo.database.Database) -> dict:
"""
Given a mongo database, run queries to compile statistics about user usage of API.
Expand Down
Loading

0 comments on commit 81cc6f5

Please sign in to comment.