aboutsummaryrefslogtreecommitdiffstats
path: root/python/fatcat_web
diff options
context:
space:
mode:
authorBryan Newbold <bnewbold@robocracy.org>2019-08-12 22:09:10 -0700
committerBryan Newbold <bnewbold@robocracy.org>2019-08-12 22:09:10 -0700
commitedbbecc7607d1e5a1321e6c6b7be6f733db84e99 (patch)
tree7fabfec92f6abed8f5369d937a7389a0f691610e /python/fatcat_web
parentb6d79ead3c0a8d6617628c9e9a4db9d7c081e04c (diff)
downloadfatcat-edbbecc7607d1e5a1321e6c6b7be6f733db84e99.tar.gz
fatcat-edbbecc7607d1e5a1321e6c6b7be6f733db84e99.zip
default container stats by ident, not issnl
Diffstat (limited to 'python/fatcat_web')
-rw-r--r--python/fatcat_web/entity_helpers.py2
-rw-r--r--python/fatcat_web/routes.py20
-rw-r--r--python/fatcat_web/search.py9
3 files changed, 25 insertions, 6 deletions
diff --git a/python/fatcat_web/entity_helpers.py b/python/fatcat_web/entity_helpers.py
index ab5eaea8..4ecd089a 100644
--- a/python/fatcat_web/entity_helpers.py
+++ b/python/fatcat_web/entity_helpers.py
@@ -14,7 +14,7 @@ def enrich_container_entity(entity):
entity._stats = None
if entity.issnl:
try:
- entity._stats = get_elastic_container_stats(entity.issnl)
+ entity._stats = get_elastic_container_stats(entity.ident, issnl=entity.issnl)
except Exception as e:
app.log.error(e)
pass
diff --git a/python/fatcat_web/routes.py b/python/fatcat_web/routes.py
index 393df33e..126bcdd0 100644
--- a/python/fatcat_web/routes.py
+++ b/python/fatcat_web/routes.py
@@ -687,7 +687,25 @@ def stats_json():
@crossdomain(origin='*',headers=['access-control-allow-origin','Content-Type'])
def container_issnl_stats(issnl):
try:
- stats = get_elastic_container_stats(issnl)
+ container = api.lookup_container(issnl=issnl)
+ except Exception as ae:
+ abort(ae.status)
+ try:
+ stats = get_elastic_container_stats(container.ident, issnl=container.issnl)
+ except Exception as ae:
+ app.log.error(ae)
+ abort(503)
+ return jsonify(stats)
+
+@app.route('/container/<ident>/stats.json', methods=['GET', 'OPTIONS'])
+@crossdomain(origin='*',headers=['access-control-allow-origin','Content-Type'])
+def container_ident_stats(ident):
+ try:
+ container = api.get_container(ident)
+ except Exception as ae:
+ abort(ae.status)
+ try:
+ stats = get_elastic_container_stats(container.ident, issnl=container.issnl)
except Exception as ae:
app.log.error(ae)
abort(503)
diff --git a/python/fatcat_web/search.py b/python/fatcat_web/search.py
index 10549a15..709163ec 100644
--- a/python/fatcat_web/search.py
+++ b/python/fatcat_web/search.py
@@ -201,11 +201,11 @@ def get_elastic_entity_stats():
return stats
-def get_elastic_container_stats(issnl):
+def get_elastic_container_stats(ident, issnl=None):
"""
- TODO: container_id, not issnl
-
Returns dict:
+ ident
+ issnl (optional)
total
in_web
preserved
@@ -214,7 +214,7 @@ def get_elastic_container_stats(issnl):
query = {
"size": 0,
"query": {
- "term": { "container_issnl": issnl }
+ "term": { "container_ident": ident }
},
"aggs": { "container_stats": { "filters": { "filters": {
"in_web": { "term": { "in_web": "true" } },
@@ -232,6 +232,7 @@ def get_elastic_container_stats(issnl):
resp = resp.json()
buckets = resp['aggregations']['container_stats']['buckets']
stats = {
+ 'ident': ident,
'issnl': issnl,
'total': resp['hits']['total'],
'in_web': buckets['in_web']['doc_count'],