Skip to content

Commit

Permalink
expand alttext and web stats
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffsteward committed Sep 13, 2022
1 parent 60c858e commit 72b134a
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 9 deletions.
66 changes: 62 additions & 4 deletions modules/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
}

Expand Down Expand Up @@ -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"
}
}
}
}
}
}
};
Expand All @@ -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);
});
});

});
Expand Down
4 changes: 3 additions & 1 deletion routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
26 changes: 22 additions & 4 deletions views/production.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,12 @@
<h2 class="card-title">Alt Text Statistics</h2>

<p class="lead">{{apistats.objects.alttext.count_as_percent}}% of collection images have alt text.</p>
<p># of images online with alttext: {{apistats.objects.alttext.count}}</p>
<p># of images online with alt text: {{apistats.objects.alttext.count_as_string}}</p>

<ul class="list-group">
{{#each apistats.objects.alttext.by_division}}
<li class="list-group-item">{{percent}}% are {{name}}</li>
{{/each}}
</ul>
</div>
</div>
Expand All @@ -55,9 +60,22 @@

<p class="lead">{{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.</p>

<p>The object with the most views in a single day: </p>
<img class="img-fluid" src="{{apistats.pageviews.singledaymostviews.object.images.[0].iiifbaseuri}}/full/!400,400/0/default.jpg">
<p><a href="{{apistats.pageviews.singledaymostviews.object.url}}">{{apistats.pageviews.singledaymostviews.object.title}}</a> was viewed {{apistats.pageviews.singledaymostviews.activitycount}} times on {{apistats.pageviews.singledaymostviews.date}}.</p>
<div class="card-deck">
<div class="card">
<img class="img-fluid" src="{{apistats.pageviews.singledaymostviews.object.images.[0].iiifbaseuri}}/full/!400,400/0/default.jpg">
<div class="card-body">
<div class="card-title">Object with the most views in a single day</div>
<p><a href="{{apistats.pageviews.singledaymostviews.object.url}}">{{apistats.pageviews.singledaymostviews.object.title}}</a> was viewed <span class="font-weight-bold">{{apistats.pageviews.singledaymostviews.activitycount}}</span> times on {{apistats.pageviews.singledaymostviews.date}}.</p>
</div>
</div>
<div class="card">
<img class="img-fluid" src="{{apistats.pageviews.alltimemostviews.object.images.[0].iiifbaseuri}}/full/!400,400/0/default.jpg">
<div class="card-body">
<p>Object with the most views of all time</p>
<p><a href="{{apistats.pageviews.alltimemostviews.object.url}}">{{apistats.pageviews.alltimemostviews.object.title}}</a> has been viewed <span class="font-weight-bold">{{apistats.pageviews.alltimemostviews.activitycount}}</span> times since we started tracking pageviews.</p>
</div>
</div>
</div>
</div>

<div class="card-footer text-muted">
Expand Down

0 comments on commit 72b134a

Please sign in to comment.