-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathanalytics.html
More file actions
306 lines (281 loc) · 11.6 KB
/
analytics.html
File metadata and controls
306 lines (281 loc) · 11.6 KB
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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
---
layout: default
title: Analytics
---
<div class="analytics">
<h2 class="title is-2">Analytics</h2>
<div class="section">
<h3 class="title is-4">Overview statistics</h3>
<div class="columns is-multiline">
{% assign total_tried = 0 %}
{% assign total_to_try = 0 %}
{% assign total_owned = 0 %}
{% assign total_rating_sum = 0 %}
{% assign rated_whisky_count = 0 %}
{% for region in site.data %}
{% assign total_tried = total_tried | plus: region[1].tried.size %}
{% assign total_to_try = total_to_try | plus: region[1].to_try.size %}
{% for whisky in region[1].tried %}
{% if whisky.rating > 0 %}
{% assign total_rating_sum = total_rating_sum | plus: whisky.rating %}
{% assign rated_whisky_count = rated_whisky_count | plus: 1 %}
{% endif %}
{% if whisky.owned %}
{% assign total_owned = total_owned | plus: 1 %}
{% endif %}
{% endfor %}
{% for whisky in region[1].to_try %}
{% if whisky.owned %}
{% assign total_owned = total_owned | plus: 1 %}
{% endif %}
{% endfor %}
{% endfor %}
{% assign total_backlog = total_tried | plus: total_to_try %}
{% if total_backlog > 0 %}
{% assign completion_pct = total_tried | times: 100 | divided_by: total_backlog %}
{% else %}
{% assign completion_pct = 0 %}
{% endif %}
{% if rated_whisky_count > 0 %}
{% assign avg_rating = total_rating_sum | times: 1000 | divided_by: rated_whisky_count | divided_by: 1000.0 | round: 1 %}
{% else %}
{% assign avg_rating = 0 %}
{% endif %}
<div class="column is-6-mobile is-4-tablet is-3-desktop">
<div class="box has-background-light has-text-centered">
<p class="title is-2">{{ total_tried }}</p>
<p class="heading">Tried</p>
</div>
</div>
<div class="column is-6-mobile is-4-tablet is-3-desktop">
<div class="box has-background-light has-text-centered">
<p class="title is-2">{{ total_to_try }}</p>
<p class="heading">To try</p>
</div>
</div>
<div class="column is-6-mobile is-4-tablet is-3-desktop">
<div class="box has-background-light has-text-centered">
<p class="title is-2">{{ completion_pct }}%</p>
<p class="heading">Completion rate</p>
</div>
</div>
<div class="column is-6-mobile is-4-tablet is-3-desktop">
<div class="box has-background-light has-text-centered">
<p class="title is-2">{{ avg_rating }}</p>
<p class="heading">Average rating</p>
</div>
</div>
<div class="column is-6-mobile is-4-tablet is-3-desktop">
<div class="box has-background-light has-text-centered">
<p class="title is-2">{{ total_owned }}</p>
<p class="heading">Bottles owned</p>
</div>
</div>
<div class="column is-6-mobile is-4-tablet is-3-desktop">
<div class="box has-background-light has-text-centered">
<p class="title is-2">{{ site.data | size }}</p>
<p class="heading">Regions</p>
</div>
</div>
</div>
</div>
<div class="section">
<h3 class="title is-4">Regional progress</h3>
<div class="region-progress">
{% for region in site.data %}
{% assign region_name = region[0] | replace: "-", " " | capitalize %}
{% assign tried = region[1].tried.size | default: 0 %}
{% assign to_try = region[1].to_try.size | default: 0 %}
{% assign total = tried | plus: to_try %}
{% assign pct = tried | times: 100 | divided_by: total %}
<div class="box">
<div class="level is-mobile">
<div class="level-left">
<a href="/{{ region[0] }}" class="is-capitalized has-text-weight-semibold">{{ region_name }}</a>
</div>
<div class="level-right">
<span class="is-size-7 has-text-grey">{{ tried }}/{{ total }} ({{ pct }}%)</span>
</div>
</div>
<progress class="progress is-small" value="{{ pct }}" max="100"></progress>
</div>
{% endfor %}
</div>
</div>
<div class="section">
<h3 class="title is-4">Bottles owned</h3>
<div class="columns">
{% assign owned_tried = 0 %}
{% assign owned_to_try = 0 %}
{% for region in site.data %}
{% for whisky in region[1].tried %}
{% if whisky.owned %}
{% assign owned_tried = owned_tried | plus: 1 %}
{% endif %}
{% endfor %}
{% for whisky in region[1].to_try %}
{% if whisky.owned %}
{% assign owned_to_try = owned_to_try | plus: 1 %}
{% endif %}
{% endfor %}
{% endfor %}
<div class="column is-6">
<h4 class="title is-5">Owned & tried ({{ owned_tried }})</h4>
<table class="table is-narrow is-fullwidth">
<tbody>
{% for region in site.data %}
{% for whisky in region[1].tried %}
{% if whisky.owned %}
<tr>
<td>{{ whisky.name }}</td>
<td class="has-text-right is-narrow">
{% if whisky.rating > 0 %}
<span class="tag is-light">{{ whisky.rating }} ⭐</span>
{% else %}
<span class="tag is-light">unrated</span>
{% endif %}
</td>
<td class="has-text-right is-narrow is-size-7 has-text-grey">
{{ region[0] | replace: "-", " " | capitalize }}
</td>
</tr>
{% endif %}
{% endfor %}
{% endfor %}
</tbody>
</table>
</div>
<div class="column is-6">
<h4 class="title is-5">Owned & to try ({{ owned_to_try }})</h4>
<table class="table is-narrow is-fullwidth">
<tbody>
{% for region in site.data %}
{% for whisky in region[1].to_try %}
{% if whisky.owned %}
<tr>
<td>{{ whisky.name }}</td>
<td class="has-text-right is-narrow is-size-7 has-text-grey">
{{ region[0] | replace: "-", " " | capitalize }}
</td>
</tr>
{% endif %}
{% endfor %}
{% endfor %}
</tbody>
</table>
</div>
</div>
</div>
<div class="section">
<h3 class="title is-4">Highest rated</h3>
<div class="columns">
<div class="column is-6">
<h4 class="title is-5">3-star whiskies</h4>
<table class="table is-narrow is-fullwidth">
<tbody>
{% assign found_3 = false %}
{% for region in site.data %}
{% for whisky in region[1].tried %}
{% if whisky.rating == 3 %}
{% assign found_3 = true %}
<tr>
<td>{{ whisky.name }}</td>
<td class="has-text-right is-narrow is-size-7 has-text-grey">
{{ region[0] | replace: "-", " " | capitalize }}
</td>
</tr>
{% endif %}
{% endfor %}
{% endfor %}
{% unless found_3 %}
<tr><td><em>None yet! Keep exploring...</em></td></tr>
{% endunless %}
</tbody>
</table>
</div>
</div>
</div>
<div class="section">
<h3 class="title is-4">Region comparison</h3>
{% assign global_sum = 0 %}
{% assign global_count = 0 %}
{% for region in site.data %}
{% for whisky in region[1].tried %}
{% assign rating_val = whisky.rating | default: 0 %}
{% assign global_sum = global_sum | plus: rating_val %}
{% assign global_count = global_count | plus: 1 %}
{% endfor %}
{% endfor %}
{% if global_count > 0 %}
{% assign global_mean_x1000 = global_sum | times: 1000 | divided_by: global_count %}
{% else %}
{% assign global_mean_x1000 = 0 %}
{% endif %}
{% assign prior_weight = 10 %}
{% assign global_mean = global_mean_x1000 | divided_by: 1000.0 | round: 1 %}
<p class="is-size-7 has-text-grey mb-3">
Weighted average uses a Bayesian adjustment to compare regions fairly when tried counts differ:
({{ prior_weight }} × global mean + region total) / ({{ prior_weight }} + tried).
Global mean: {{ global_mean }}; prior weight: {{ prior_weight }}.
</p>
<table class="table is-bordered is-striped is-narrow is-hoverable is-fullwidth">
<thead>
<tr>
<th>Region</th>
<th class="has-text-centered">Tried</th>
<th class="has-text-centered">To try</th>
<th class="has-text-centered">Total</th>
<th class="has-text-centered">Average rating</th>
<th class="has-text-centered">Weighted average</th>
<th class="has-text-centered">Owned</th>
</tr>
</thead>
<tbody>
{% for region in site.data %}
{% assign region_name = region[0] | replace: "-", " " | capitalize %}
{% assign tried = region[1].tried.size | default: 0 %}
{% assign to_try = region[1].to_try.size | default: 0 %}
{% assign total = tried | plus: to_try %}
{% assign region_rating_sum = 0 %}
{% for whisky in region[1].tried %}
{% assign rating_value = whisky.rating | default: 0 %}
{% assign region_rating_sum = region_rating_sum | plus: rating_value %}
{% endfor %}
{% assign region_owned = 0 %}
{% for whisky in region[1].tried %}
{% if whisky.owned %}
{% assign region_owned = region_owned | plus: 1 %}
{% endif %}
{% endfor %}
{% for whisky in region[1].to_try %}
{% if whisky.owned %}
{% assign region_owned = region_owned | plus: 1 %}
{% endif %}
{% endfor %}
{% if tried > 0 %}
{% assign avg = region_rating_sum | times: 1000 | divided_by: tried | divided_by: 1000.0 | round: 1 %}
{%- comment -%} Weighted (Bayesian) average: (prior_weight * global_mean + sum) / (prior_weight + tried)
Compute in x1000 space safely: (prior_weight*global_mean_x1000) + (region_sum*1000) {%- endcomment -%}
{% assign weighted_prior_x1000 = prior_weight | times: global_mean_x1000 %}
{% assign region_sum_x1000 = region_rating_sum | times: 1000 %}
{% assign weighted_num_x1000 = weighted_prior_x1000 | plus: region_sum_x1000 %}
{% assign weighted_den = prior_weight | plus: tried %}
{% assign weighted_avg = weighted_num_x1000 | divided_by: weighted_den | divided_by: 1000.0 | round: 1 %}
{% else %}
{% assign avg = 0 %}
{% assign weighted_avg = 0 %}
{% endif %}
<tr>
<td><a href="/{{ region[0] }}">{{ region_name }}</a></td>
<td class="has-text-centered">{{ tried }}</td>
<td class="has-text-centered">{{ to_try }}</td>
<td class="has-text-centered"><strong>{{ total }}</strong></td>
<td class="has-text-centered">{{ avg }}</td>
<td class="has-text-centered">{{ weighted_avg }}</td>
<td class="has-text-centered">{{ region_owned }}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>