-
Notifications
You must be signed in to change notification settings - Fork 13
/
analytics.html
123 lines (106 loc) · 4.79 KB
/
analytics.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
---
title: Analytics
layout: default
permalink: /analytics/
---
{% include breadcrumbs.html %}
<!--Commentary-->
<h2>Dataset Overview</h2>
<p class="lead" style="margin-bottom:0"><span id="stat-distinct-datasets"></span> Distinct datasets</p>
<p class="lead" style="margin-bottom:0"><span id="stat-data-files"></span> Data files</p>
<!--Chart: Unique datasets by org-->
<canvas id="chart-datasets-by-org" width="400" height="200"></canvas>
<!--Chart: Total files by org-->
<canvas id="chart-datafiles-by-org" width="400" height="200"></canvas>
<script>
document.addEventListener('DOMContentLoaded', () => {
// loading the datasets data
$.getJSON('/datasets.json', function (datasets) {
// Getting count of data files
document.getElementById("stat-data-files").innerText = datasets.flatMap(ds => ds.resources).length;
// Getting count of datasets
document.getElementById("stat-distinct-datasets").innerHTML = datasets.length;
// Load charts
chartDatasetsByOrg(datasets);
chartDataFilesByOrg(datasets);
});
});
function chartDatasetsByOrg(datasets) {
let ctx = document.getElementById('chart-datasets-by-org').getContext('2d');
let data = _.chain(datasets)
.groupBy('organization')
.map((value, key) => ({ label: key, count: value.length }))
.orderBy('count', 'desc')
.value();
let labels = _.chain(data)
.map('label')
.value();
let values = _.chain(data)
.map('count')
.value();
var myChart = new Chart(ctx, {
type: 'bar',
data: {
labels: labels,
datasets: [{
label: '# of datasets',
data: values,
backgroundColor: 'rgba(31, 120, 180, 1)',
borderColor: 'rgba(31, 120, 180, 0.5)',
borderWidth: 1
}]
},
options: {
scales: {
yAxes: [{
ticks: {
beginAtZero: true
}
}]
}
}
});
}
function chartDataFilesByOrg(datasets) {
let ctx = document.getElementById('chart-datafiles-by-org').getContext('2d');
let data = _.chain(datasets)
.groupBy('organization')
.map((value, key) => (
{
label: key,
count: value.flatMap(x => x.resources).length
}
))
.filter(function (item) { return item.count > 0 })
.orderBy('count', 'desc')
.value();
let labels = _.chain(data)
.map('label')
.value();
let values = _.chain(data)
.map('count')
.value();
var myChart = new Chart(ctx, {
type: 'bar',
data: {
labels: labels,
datasets: [{
label: '# of data files',
data: values,
backgroundColor: 'rgba(31, 120, 180, 1)',
borderColor: 'rgba(31, 120, 180, 0.5)',
borderWidth: 1
}]
},
options: {
scales: {
yAxes: [{
ticks: {
beginAtZero: true
}
}]
}
}
});
}
</script>