-
Notifications
You must be signed in to change notification settings - Fork 0
/
stats.html
210 lines (182 loc) · 5.95 KB
/
stats.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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
---
layout: page
---
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.7.2/Chart.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/randomcolor/0.5.2/randomColor.min.js"></script>
<h1>Blog statistics</h1>
<div id="total-posts">Total number of posts:</div>
<div id="total-words">Total number of words:</div>
<div id="words-per-post">Number of words per post:</div>
<h1>Number of posts per month</h1>
<canvas id="postsPerMonth" width="400" height="300"></canvas>
<h1>Number of words per month</h1>
<canvas id="wordsPerMonth" width="400" height="300"></canvas>
<h1>Number of posts per year</h1>
<canvas id="postsPerYear" width="400" height="300"></canvas>
<h1>Tags distribution</h1>
<canvas id="tagsDistr" width="400" height="300"></canvas>
<script>
var accentColor = "#3CA2A2";
var datePostsWords = [
{% for post in site.posts %}
{
"t":"{{post.date | date: '%Y-%-m'}}",
"year":"{{post.date | date: '%Y'}}",
"x":1,
"y":{{ post.content | number_of_words }}
},
{% endfor %}
];
var sy = "{{ site.posts.last.date | date: '%Y'}}",
ey = "{{ site.posts.first.date | date: '%Y'}}";
var datePostsWordsZeros = [];
for (var i = parseInt(sy); i <= parseInt(ey); i++) {
for (var j = 1; j < 13; j++) {
datePostsWordsZeros.push({"t": '' + i + "-" + j, "x": 0, "y": 0});
}
}
var datePostsWords = datePostsWordsZeros.concat(datePostsWords);
var postsPerMonth = datePostsWords.reduce((p, c) => {
var name = c.t;
if (!p.hasOwnProperty(name)) {
p[name] = 0;
}
p[name] = p[name] + c.x;
return p;
}, {});
var postsPerYear = datePostsWords.reduce((p, c) => {
if (c.year === undefined)
return p;
var name = c.year;
if (!p.hasOwnProperty(name)) {
p[name] = 0;
}
p[name] = p[name] + c.x;
return p;
}, {});
var wordsPerMonth = datePostsWords.reduce((p, c) => {
var name = c.t;
if (!p.hasOwnProperty(name)) {
p[name] = 0;
}
p[name] = p[name] + c.y;
return p;
}, {});
var postsPerMonthCtx = document.getElementById("postsPerMonth").getContext('2d');
var postsPerMonthChart = new Chart(postsPerMonthCtx, {
type: 'bar',
data: {
labels: Object.keys(postsPerMonth),
datasets: [{
label: 'Post(s)',
data: Object.values(postsPerMonth),
backgroundColor: accentColor,
borderWidth: 1
}],
},
options: {
scales: {
xAxes: [{
categoryPercentage: 1.0,
barPercentage: 1.0
}]
}
}
});
var wordsPerMonthCtx = document.getElementById("wordsPerMonth").getContext('2d');
var wordsPerMonthChart = new Chart(wordsPerMonthCtx, {
type: 'bar',
data: {
labels: Object.keys(wordsPerMonth),
datasets: [{
label: 'Number of words',
data: Object.values(wordsPerMonth),
backgroundColor: accentColor,
borderWidth: 1
}],
},
options: {
scales: {
xAxes: [{
categoryPercentage: 1.0,
barPercentage: 1.0
}]
}
}
});
var postsPerYearCtx = document.getElementById("postsPerYear").getContext('2d');
var postsPerYearChart = new Chart(postsPerYearCtx, {
type: 'bar',
data: {
labels: Object.keys(postsPerYear),
datasets: [{
label: 'Number of words',
data: Object.values(postsPerYear),
backgroundColor: accentColor,
borderWidth: 1
}],
},
options: {
scales: {
xAxes: [{
categoryPercentage: 1.0,
barPercentage: 1.0
}]
}
}
});
{% capture tags %}
{% for tag in site.tags %}
{{ tag[1].size | plus: 1000 }}#{{ tag[0] }}#{{ tag[1].size }}/
{% endfor %}
{% endcapture %}
{% assign sortedtags = tags | split:'/' | sort %}
var pieLabels = [
{% for tag in sortedtags reversed %}
{% assign tagitems = tag | split: '#' %}
{% for tag in tags %} "{{ tagitems[1] }}", {% endfor %}
{% endfor %}
];
var pieData = [
{% for tag in sortedtags reversed %}
{% assign tagitems = tag | split: '#' %}
{% for tag in tags %} {{ tagitems[2]}}, {% endfor %}
{% endfor %}
];
var tagsDistrCtx = document.getElementById("tagsDistr").getContext('2d');
var tagsDistrChart = new Chart(tagsDistrCtx,{
type: 'pie',
data: {
labels: pieLabels,
datasets: [{
label: "tag",
data: pieData,
borderColor: "#aaa",
backgroundColor: randomColor({
count: pieData.length,
hue: accentColor,
luminosity: 'dark',
})
}],
},
options: {
responsive: true,
}
});
</script>
<script>
var totalWords = [
{% for post in site.posts %}
{{ post.content | number_of_words }},
{% endfor %}
].reduce((a, b) => a + b, 0);
var totalPosts = {{ site.posts.size }};
function concatBoldTextToELement(id, text) {
var abvgd = document.createElement('b');
abvgd.innerText = ' ' + text;
document.getElementById(id).appendChild(abvgd);
}
concatBoldTextToELement('total-words', totalWords);
concatBoldTextToELement('total-posts', totalPosts);
concatBoldTextToELement('words-per-post', totalWords / totalPosts);
</script>