Skip to content

Commit

Permalink
add a card fro data freshness
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffsteward committed Apr 23, 2020
1 parent 61849b0 commit f95f7aa
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 3 deletions.
28 changes: 25 additions & 3 deletions routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ const API_KEY = process.env['API_KEY'];
const APP_TITLE = 'TMS Dashboard';

let data = {
datafreshness: 0,
dateoflastrefresh: "2000-01-01",
dateoflastexport: "2000-01-01",
objects: {
recordcount: 0,
onview: 0
Expand All @@ -28,11 +31,21 @@ router.get('/', function(req, res, next) {

async.series([
function(callback) {
const url = `https://api.harvardartmuseums.org/object?apikey=${API_KEY}&size=0&q=accesslevel:1`;
const url = `https://api.harvardartmuseums.org/object?apikey=${API_KEY}&size=1&q=accesslevel:1`;
fetch(url)
.then(response => response.json())
.then(results => {
callback(null, results['info']['totalrecords']);
let e = new Date(results['records'][0]['lastupdate']);
let d = new Date(results['records'][0]['lastupdate']);
d.setHours(d.getHours() + 2);

let output = {
lastexport: e.toLocaleString('en-US'),
lastrefresh: d.toLocaleString('en-US'),
recordcount: results['info']['totalrecords']
};

callback(null, output);
});

},
Expand All @@ -56,10 +69,19 @@ router.get('/', function(req, res, next) {
}
],
function(err, results) {
data.objects.recordcount = results[0];
data.dateoflastrefresh = results[0]['lastrefresh'];
data.dateoflastexport = results[0]['lastexport'];
data.objects.recordcount = results[0]['recordcount'];
data.objects.onview = results[1];
data.exhibitions.current = results[2];

// calculate the age of the data
// freshness = number of hours old
const now = new Date();
const exportdate = new Date(data.dateoflastexport);
const freshness = Math.round((now - exportdate)/3600000);
data.datafreshness = freshness;

res.render('production', { title: APP_TITLE, apistats: data });
}
);
Expand Down
11 changes: 11 additions & 0 deletions views/production.hbs
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
<div class="card w-25 mb-5">
<div class="card-body">
<h2 class="card-title">Data Freshness</h2>

<p class="lead">The data is about {{apistats.datafreshness}} hour(s) old.</p>
<p class="">Collections data was last exported around <br/> {{apistats.dateoflastexport}}.</p>
<p class="">Collections online was last refreshed around <br/> {{apistats.dateoflastrefresh}}.</p>

</div>
</div>

<div class="card w-25 mb-5">
<div class="card-body">
<h2 class="card-title">Collection Statistics</h2>
Expand Down

0 comments on commit f95f7aa

Please sign in to comment.