diff --git a/modules/data.js b/modules/data.js index 17985c0..11fb6a9 100644 --- a/modules/data.js +++ b/modules/data.js @@ -104,12 +104,41 @@ function getAltTextStats(callback) { size: 0, q: 'images.alttext:* AND accesslevel:1' }; - const url = makeURL('object', params); + const aggs = { + "by_division": { + "terms": { + "field": "division" + } + }, + "total_images" : { + "value_count" : { + "field" : "images.imageid" + } + } + }; + + const url = makeURL('object', params, aggs); fetch(url) .then(response => response.json()) .then(results => { - callback(null, results['info']['totalrecords']); + let output = { + objects: { + count: results['info']['totalrecords'] + }, + divisions: [] + }; + results.aggregations.by_division.buckets.forEach(division => { + output.divisions.push( + { + name: division.key, + count: division.doc_count, + percent: ((division.doc_count/output.objects.count)*100).toFixed(1) + } + ) + }); + + callback(null, output); }); } @@ -139,7 +168,23 @@ function getActivityStats(callback) { "extended_stats": { "field": "date" } - } + }, + "by_object": { + "terms": { + "field": "objectid", + "size": 5, + "order": { + "totals": "desc" + } + }, + "aggs": { + "totals": { + "sum": { + "field": "activitycount" + } + } + } + } } } }; @@ -164,17 +209,30 @@ function getActivityStats(callback) { singledaymostviews: { date: object['date'], activitycount: object['activitycount'] + }, + alltimemostviews: { + activitycount: pageviews['by_object']['buckets'][0]['totals']['value'] } } }; let objectUrl = makeURL(`object/${object['objectid']}`); + fetch(objectUrl) .then(response => response.json()) .then(results => { output.pageviews.singledaymostviews.object = results; - callback(null, output); + + let objectUrl = makeURL(`object/${pageviews['by_object']['buckets'][0]['key']}`); + + fetch(objectUrl) + .then(response => response.json()) + .then(results => { + output.pageviews.alltimemostviews.object = results; + + callback(null, output); + }); }); }); diff --git a/routes/index.js b/routes/index.js index a6d6d5a..6a480dd 100644 --- a/routes/index.js +++ b/routes/index.js @@ -67,8 +67,10 @@ router.get('/', function(req, res, next) { data.objects.onview.count_as_percent = ((results['objectsOnViewStats']/results['objectStats']['recordcount'])*100).toFixed(2); data.exhibitions.current = results['currentExhibitions']; data.exhibitions.upcoming = results['upcomingExhibitions']; - data.objects.alttext.count = results['alttextStats']; + data.objects.alttext.count = results['alttextStats']['objects']['count']; + data.objects.alttext.count_as_string = data.objects.alttext.count.toLocaleString('en'); data.objects.alttext.count_as_percent = ((data.objects.alttext.count/data.objects.count)*100).toFixed(2); + data.objects.alttext.by_division = results['alttextStats']['divisions']; data.pageviews = results['activityStats']['pageviews']; data.pageviews.objects.count_as_string = data.pageviews.objects.count.toLocaleString('en'); data.pageviews.objects.count_as_percent = ((data.pageviews.objects.count/data.objects.public.count)*100).toFixed(2) diff --git a/views/production.hbs b/views/production.hbs index 924b918..3051687 100644 --- a/views/production.hbs +++ b/views/production.hbs @@ -44,7 +44,12 @@
{{apistats.objects.alttext.count_as_percent}}% of collection images have alt text.
-# of images online with alttext: {{apistats.objects.alttext.count}}
+# of images online with alt text: {{apistats.objects.alttext.count_as_string}}
+ +{{apistats.pageviews.objects.count_as_string}} individual objects have been viewed on our website to date. That's {{apistats.pageviews.objects.count_as_percent}}% of the collection.
-The object with the most views in a single day:
- -{{apistats.pageviews.singledaymostviews.object.title}} was viewed {{apistats.pageviews.singledaymostviews.activitycount}} times on {{apistats.pageviews.singledaymostviews.date}}.
+{{apistats.pageviews.singledaymostviews.object.title}} was viewed {{apistats.pageviews.singledaymostviews.activitycount}} times on {{apistats.pageviews.singledaymostviews.date}}.
+Object with the most views of all time
+{{apistats.pageviews.alltimemostviews.object.title}} has been viewed {{apistats.pageviews.alltimemostviews.activitycount}} times since we started tracking pageviews.
+