Skip to content

Commit

Permalink
add a card of api stats
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffsteward committed Aug 7, 2020
1 parent a8df5d6 commit ce6896e
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 2 deletions.
33 changes: 32 additions & 1 deletion modules/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,41 @@ function getActivityStats(callback) {
});
}

function getKeyStats(callback) {
const params = {
size: 0
};
const aggs = {
"date_stats": {
"extended_stats": {
"field": "createdat"
}
}
};
const url = makeURL('key', params, aggs);

fetch(url)
.then(response => response.json())
.then(results => {
let output = {
keys: {
count: results.info.totalrecords,
statsdates: {
start: results.aggregations.date_stats.min_as_string,
end: results.aggregations.date_stats.max_as_string
},
}
};

callback(null, output);
});
}

module.exports = {
getObjectStats: getObjectStats,
getObjectsInGalleryStats: getObjectsInGalleryStats,
getCurrentExhibitions: getCurrentExhibitions,
getAltTextStats: getAltTextStats,
getActivityStats: getActivityStats
getActivityStats: getActivityStats,
getKeyStats: getKeyStats
};
12 changes: 11 additions & 1 deletion routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ let data = {
datafreshness: 0,
dateoflastrefresh: "2000-01-01",
dateoflastexport: "2000-01-01",
keys: {
count: 0,
count_as_string: 0,
statsdates: {}
},
objects: {
count: 0,
public: {
Expand Down Expand Up @@ -44,7 +49,8 @@ router.get('/', function(req, res, next) {
currentExhibitions: stats.getCurrentExhibitions,
alttextStats: stats.getAltTextStats,
objectsOnViewStats: stats.getObjectsInGalleryStats,
activityStats: stats.getActivityStats
activityStats: stats.getActivityStats,
keyStats: stats.getKeyStats
},
function(err, results) {
data.dateoflastrefresh = results['objectStats']['lastrefresh'];
Expand All @@ -63,6 +69,10 @@ router.get('/', function(req, res, next) {
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)
data.keys.count = results['keyStats']['keys']['count'];
data.keys.count_as_string = data.keys.count.toLocaleString('en');
data.keys.statsdates = results['keyStats']['keys']['statsdates'];
data.keys.statsdates.start_short = data.keys.statsdates.start.substr(0, 10);

// calculate the age of the data
// freshness = number of hours old
Expand Down
9 changes: 9 additions & 0 deletions views/production.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,15 @@
</div>
</div>

<div class="card mb-5">
<div class="card-body">
<h2 class="card-title">API Statistics</h2>

<p class="lead">{{apistats.keys.count_as_string}} keys have been issued since {{apistats.keys.statsdates.start_short}}.</p>
<p class="lead">The newest key was cut at precisely {{apistats.keys.statsdates.end}}.</p>

</div>
</div>
</div>

<div class="col-sm-4">
Expand Down

0 comments on commit ce6896e

Please sign in to comment.