-
Notifications
You must be signed in to change notification settings - Fork 2
/
html_elements.py
438 lines (398 loc) · 13.3 KB
/
html_elements.py
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
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
from datetime import datetime
from dominate.tags import *
from db_data import InscriptionModel
from db_data_read import (
content_types_with_amounts,
get_biggest_collections,
get_collections_using_most_space,
get_document_count,
get_document_count_for_last_days,
get_document_size_for_last_days,
get_duplicate_content_hashes,
get_entries_from_content_hash,
get_n_biggest_sizes,
get_n_most_expensive,
get_total_content_size,
)
def page_title() -> None:
h1("Ordinals statistics")
p("Obscure statistics about obscure data")
def page_footer() -> None:
with footer():
p(f"Data updated {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}")
with p():
span("Created by ")
a("grdddj", href="https://github.com/grdddj", target="_blank")
span(" in cooperation with ")
a("ChatGPT", href="https://chat.openai.com/chat", target="_blank")
with p():
span("Feel free to")
a(
" create an issue ",
href="https://github.com/grdddj/ordinals-statistics/issues/new",
target="_blank",
)
span("on Github")
def page_resources() -> None:
h3("Useful resources")
with p():
a(
"Dune.com - dashboard",
href="https://dune.com/dgtl_assets/bitcoin-ordinals-analysis",
target="_blank",
)
with p():
a(
"Dune.com - dashboard",
href="https://dune.com/domo/ordinals-marketplaces",
target="_blank",
)
with p():
a(
"Github.com - ord repository",
href="https://github.com/casey/ord",
target="_blank",
)
with p():
a("Ordinals.com - explorer", href="https://ordinals.com/", target="_blank")
with p():
a("Ordinals.com - docs", href="https://docs.ordinals.com/", target="_blank")
with p():
a(
"Ordinalswallet.com - explorer",
href="https://ordinalswallet.com/inscriptions",
target="_blank",
)
with p():
a(
"Ordinalswallet.com - collections",
href="https://ordinalswallet.com/collections",
target="_blank",
)
with p():
a("Ordswap.io - marketplace", href="https://ordswap.io/", target="_blank")
with p():
a("Openordex.org - marketplace", href="https://openordex.org/", target="_blank")
with p():
a("Ordx.io - marketplace", href="https://beta.ordx.io/", target="_blank")
with p():
a(
"Pourteaux.xyz - article",
href="https://read.pourteaux.xyz/p/illegitimate-bitcoin-transactions",
target="_blank",
)
with p():
a(
"Ordinals.wtf - other resources",
href="https://ordinals.wtf",
target="_blank",
)
def document_count() -> None:
doc_count = get_document_count()
h3("Ordinals count")
p(f"Total number of documents: {doc_count:,}")
def _two_y_axes_graph(
x_values: list[str],
y_values: list[int],
title: str,
main_label: str,
secondary_label: str,
chart_id: str,
) -> str:
days_str = ",".join([f"'{x}'" for x in x_values])
counts_str = ",".join([str(x) for x in y_values])
count_running_total = 0
counts_running_total = []
for count in y_values:
count_running_total += count
counts_running_total.append(count_running_total)
running_total_str = ",".join([str(x) for x in counts_running_total])
variables = f"""
const labels = [{days_str}];
const data = [{counts_str}];
const data_running_total = [{running_total_str}];
const main_label = '{main_label}';
const secondary_label = '{secondary_label}';
const title = '{title}';
const chart_id = '{chart_id}';
"""
graph = """\
// Depending on the following variables:
// labels, data, data_running_total, main_label, secondary_label, title, chart_id
const chart = document.getElementById(chart_id);
new Chart(chart, {
type: 'bar',
data: {
labels: labels,
datasets: [
{
type: 'bar',
label: main_label,
data: data,
borderWidth: 1,
yAxisID: 'y_left'
},
{
type: 'line',
label: secondary_label,
data: data_running_total,
borderWidth: 1,
yAxisID: 'y_right'
}
]
},
options: {
plugins: {
title: {
display: true,
text: title,
font: {
size: 18,
weight: 'bold'
}
}
},
scales: {
y_left: {
beginAtZero: true,
type: 'linear',
position: 'left'
},
y_right: {
beginAtZero: true,
type: 'linear',
position: 'right'
}
}
}
});
"""
# Wrapped in a closure to avoid polluting the global namespace
# and avoid name collisions
return "{" + variables + graph + "}"
def document_count_graph() -> None:
canvas(id="document_count_graph")
def document_count_graph_script(last_n_days: int) -> str:
result = get_document_count_for_last_days(last_n_days)
days = [x[0] for x in result]
counts = [x[1] for x in result]
return _two_y_axes_graph(
x_values=days,
y_values=counts,
title=f"Last {last_n_days} days document count",
main_label="Document count",
secondary_label="Running total",
chart_id="document_count_graph",
)
def content_size_graph() -> None:
canvas(id="content_size_graph")
def content_size_graph_script(last_n_days: int) -> str:
result = get_document_size_for_last_days(last_n_days)
days = [x[0] for x in result]
counts = [x[1] for x in result]
return _two_y_axes_graph(
x_values=days,
y_values=counts,
title=f"Last {last_n_days} days document sizes",
main_label="Document size [MB]",
secondary_label="Running total [MB]",
chart_id="content_size_graph",
)
def biggest_inscriptions(n: int) -> None:
biggest = get_n_biggest_sizes(n)
h3("Biggest inscriptions")
with table(cls="table"):
with thead():
with tr(cls="table-light"):
th("ID")
th("TX")
th("Size [bytes]")
th("Type")
th("Date")
th("Fee [sats]")
with tbody():
for entry in biggest:
with tr():
td(a(entry.id, href=entry.ordinals_com_link(), target="_blank"))
td(
a(
entry.tx_id_ellipsis(),
href=entry.mempool_space_link(),
target="_blank",
)
)
td(f"{entry.content_length:,}")
td(entry.content_type)
td(entry.datetime.split()[0])
td(f"{entry.genesis_fee:,}")
def most_expensive_inscriptions(n: int) -> None:
biggest = get_n_most_expensive(n)
h3("Most expensive inscriptions")
with table(cls="table"):
with thead():
with tr(cls="table-light"):
th("ID")
th("TX")
th("Fee [sats]")
th("Type")
th("Date")
th("Size [bytes]")
with tbody():
for entry in biggest:
with tr():
td(a(entry.id, href=entry.ordinals_com_link(), target="_blank"))
td(
a(
entry.tx_id_ellipsis(),
href=entry.mempool_space_link(),
target="_blank",
)
)
td(f"{entry.genesis_fee:,}")
td(entry.content_type.split(";")[0])
td(entry.datetime.split()[0])
td(f"{entry.content_length:,}")
def content_types(n: int) -> None:
content_type_amounts = content_types_with_amounts(n)
h3("Most common content types")
with table():
with thead():
with tr():
th("Type")
th("Amount")
with tbody():
for content_type, amount in content_type_amounts:
with tr():
td(content_type.split(";")[0])
td(f"{amount:,}")
def content_size() -> None:
content_size_bytes = get_total_content_size()
mb_size = int(content_size_bytes / 1024 / 1024)
h3("Total size")
p(f"Total size of documents (without transaction data): {mb_size:,} MB")
def duplicated_content(n: int, examples_n: int) -> None:
most_duplicated_content = get_duplicate_content_hashes(n)
h3("Most duplicated content")
with table():
with thead():
with tr():
th("Amount")
th("Content type")
th("Content length")
th("Examples")
with tbody():
for hash, amount in most_duplicated_content:
examples = get_entries_from_content_hash(hash, examples_n)
content_type = examples[0].content_type
content_length = examples[0].content_length
with tr():
td(f"{amount:,}")
td(content_type.split(";")[0])
td(f"{content_length:,}")
td(
*[
a(
example.id,
href=example.ordinals_com_link(),
target="_blank",
)
for example in examples
]
)
def collections_using_most_space(n: int) -> None:
collections = get_collections_using_most_space(n)
h3("Collections using most space")
with table():
with thead():
with tr():
th("ID")
th("Used space [bytes]")
th("Amount")
th("Description")
with tbody():
for collection, used_space in collections:
with tr():
td(
a(
collection.id,
href=collection.link_ordinalswallet(),
target="_blank",
)
)
td(f"{used_space:,}")
td(f"{int(collection.supply or 0):,}")
td(collection.description)
def biggest_collections(n: int) -> None:
collections = get_biggest_collections(n)
h3("Biggest collections")
with table():
with thead():
with tr():
th("ID")
th("Amount")
th("Description")
with tbody():
for collection, amount in collections:
with tr():
td(
a(
collection.id,
href=collection.link_ordinalswallet(),
target="_blank",
)
)
td(f"{amount:,}")
td(collection.description)
def bizzare() -> None:
tx_ids_descriptions = [
(
"6a415863875f212082dc78d96d27565e97fbc6f1f16a11a5e6dc9850cf6e8d00i0",
"Whole fckin HTML website",
),
(
"0fa05780d91262c22d5b62a4fbebfa5dbed8fbf1e5b169346830ac99d9cebf70i0",
"PDF with a dishwasher (and maybe a virus)",
),
(
"c86d37524b435a440a668f9b2eba85fdad084f451f44950c0650dc2976fd965bi0",
"Holy bible on the blockchain",
),
(
"220e3a7f6c190042194302c0037ac4fa42894d9c87152e7809bb340b1c5dcc02i0",
"ETH whitepaper",
),
("5e92195849607b400d77f01cb1146563ce523fed47f66a044e7a470016e05e59i0", "Fart"),
(
"55a06c90671f1f3a30fe1b49a4fb1b606eebb10c842e29562214d786a645f8dci0",
"BTC whitepaper",
),
(
"db5fa1f5ab30cad822ce0b28a5751617fc1e7cdf07457d2910f9d1bad511d708i0",
"Wanna play some music?",
),
("521f8eccffa4c41a3a7728dd012ea5a4a02feed81f41159231251ecf1e5c79dai0", "DOOM"),
]
h3("Bizzare")
with table():
with thead():
with tr():
th("ID")
th("Description")
th("Date")
th("Size [bytes]")
with tbody():
for tx_id, description in tx_ids_descriptions:
if len(tx_id) == 66:
tx_id = tx_id[:64]
inscription = InscriptionModel.by_tx_id(tx_id)
with tr():
td(
a(
inscription.id,
href=inscription.ordinals_com_content_link(),
target="_blank",
)
)
td(description)
td(inscription.datetime.split()[0])
td(f"{inscription.content_length:,}")