-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathall-stats.R
More file actions
223 lines (197 loc) · 7.27 KB
/
all-stats.R
File metadata and controls
223 lines (197 loc) · 7.27 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
require(RPostgreSQL)
require(data.table)
require(lubridate)
require(jsonlite)
require(ggplot2)
require(scales)
drv <- dbDriver("PostgreSQL")
networks = c("mainnet", "preprod", "preview")
marloweStat <- function(network)
data.table(Network=network, dbGetQuery(conns[[network]], "
select distinct
slotno as \"Slot No\"
, sum(created * case when txout.txix = 0 then 1 else 0 end) over (order by slotno) as \"Creations\"
, sum(closed * case when txout.txix = 0 then 1 else 0 end) over (order by slotno) as \"Closures\"
, sum((created - closed) * case when txout.txix = 0 then 1 else 0 end) over (order by slotno) as \"Active\"
, count(txs.txid) over (order by slotno) as \"Transaction\"
, sum(txout.lovelace * case when txout.txix = 0 then 0 else 1 end) over (order by slotno) / 1000000 \"Ada Transacted\"
, addresses as \"Payment Addresses\"
, stakes as \"Stake Addresses\"
from (
select txid, 1 as created, 0 as closed
from marlowe.createtxout
union
select txid, 0, case when outputtxix is null then 1 else 0 end
from marlowe.applytx
) txs
inner join chain.txout
using (txid)
left outer join (
select slotno, max(addresses) as addresses
from (
select slotno, row_number() over (order by slotno) as addresses
from (
select min(slotno) as slotno
from (
select txid
from marlowe.createtxout
union
select txid
from marlowe.applytx
) txs
inner join chain.txout
using (txid)
group by txout.addresspaymentcredential
) u
) v
group by slotno
) w
using (slotno)
left outer join (
select slotno, max(stakes) as stakes
from (
select slotno, row_number() over (order by slotno) as stakes
from (
select min(slotno) as slotno
from (
select txid
from marlowe.createtxout
union
select txid
from marlowe.applytx
) txs
inner join chain.txout
using (txid)
group by addressstakeaddressreference
) u
) v
group by slotno
) x
using (slotno)
order by 1
")
)
offsets <- list(
mainnet = 1685297070 - 93730779,
preprod = 1685297096 - 29613896,
preview = 1685297218 - 18641218
)
to_epoch <- function(network, slotno) {
slotno + offsets[[network]]
}
dbnames <- list(
mainnet="mainnet",
preprod="preprod",
preview="preview"
)
conns <- lapply(networks, function(network) dbConnect(
drv,
dbname = dbnames[[network]]
))
names(conns) <- networks
df <- rbind(
marloweStat("mainnet"),
marloweStat("preprod"),
marloweStat("preview")
)
df[,
`Timestamp` := mapply(to_epoch, `Network`, `Slot No`)
]
ggplot(df, aes(x=as_datetime(`Timestamp`), y=`Creations`, color=`Network`)) +
geom_line() +
geom_label(
aes(label = `Creations`),
data = df[, .(`Timestamp`=max(`Timestamp`), `Creations`=last(`Creations`)), by=.(`Network`)],
hjust=0, show.legend = FALSE
) +
scale_x_datetime(label=date_format(), expand = expand_scale(mult = c(0.05, 0.20))) +
scale_y_sqrt(label=label_number_auto()) +
xlab("Date") +
ylab("Marlowe Contracts") +
theme(axis.text.x = element_text(angle = 0, vjust = 0.5, hjust=0.5))
ggsave("all/contracts.png", width=7, height=5, units="in", dpi=200)
ggplot(df, aes(x=as_datetime(`Timestamp`), y=`Active`, color=`Network`)) +
geom_line() +
geom_label(
aes(label = `Active`),
data = df[, .(`Timestamp`=max(`Timestamp`), `Active`=last(`Active`)), by=.(`Network`)],
hjust=0, show.legend = FALSE
) +
scale_x_datetime(label=date_format(), expand = expand_scale(mult = c(0.05, 0.20))) +
scale_y_sqrt(label=label_number_auto()) +
xlab("Date") +
ylab("Open Marlowe Contracts") +
theme(axis.text.x = element_text(angle = 0, vjust = 0.5, hjust=0.5))
ggsave("all/open.png", width=7, height=5, units="in", dpi=200)
ggplot(df, aes(x=as_datetime(`Timestamp`), y=`Transaction`, color=`Network`)) +
geom_line() +
geom_label(
aes(label = `Transaction`),
data = df[, .(`Timestamp`=max(`Timestamp`), `Transaction`=last(`Transaction`)), by=.(`Network`)],
hjust=0, show.legend = FALSE
) +
scale_x_datetime(label=date_format(), expand = expand_scale(mult = c(0.05, 0.20))) +
scale_y_sqrt(label=label_number_auto()) +
xlab("Date") +
ylab("Marlowe Transactions") +
theme(axis.text.x = element_text(angle = 0, vjust = 0.5, hjust=0.5))
ggsave("all/transactions.png", width=7, height=5, units="in", dpi=200)
ggplot(df, aes(x=as_datetime(`Timestamp`), y=`Ada Transacted`, color=`Network`)) +
geom_line() +
geom_label(
aes(label = `Ada Transacted`),
data = df[, .(`Timestamp`=max(`Timestamp`), `Ada Transacted`=round(last(`Ada Transacted`))), by=.(`Network`)],
hjust=0, show.legend = FALSE
) +
scale_x_datetime(label=date_format(), expand = expand_scale(mult = c(0.05, 0.20))) +
scale_y_sqrt(label=label_number_auto()) +
xlab("Date") +
ylab("Ada Transacted by Marlowe") +
theme(axis.text.x = element_text(angle = 0, vjust = 0.5, hjust=0.5))
ggsave("all/ada.png", width=7, height=5, units="in", dpi=200)
ggplot(df[!is.na(`Payment Addresses`)], aes(x=as_datetime(`Timestamp`), y=`Payment Addresses`, color=`Network`)) +
geom_line() +
geom_label(
aes(label = `Payment Addresses`),
data = df[!is.na(`Payment Addresses`), .(`Timestamp`=max(`Timestamp`), `Payment Addresses`=round(last(`Payment Addresses`))), by=.(`Network`)],
hjust=0, show.legend = FALSE
) +
scale_x_datetime(label=date_format(), expand = expand_scale(mult = c(0.05, 0.20))) +
scale_y_sqrt(label=label_number_auto()) +
xlab("Date") +
ylab("Unique Payment Addresses in Marlowe Transactions") +
theme(axis.text.x = element_text(angle = 0, vjust = 0.5, hjust=0.5))
ggsave("all/payments.png", width=7, height=5, units="in", dpi=200)
ggplot(df[!is.na(`Stake Addresses`)], aes(x=as_datetime(`Timestamp`), y=`Stake Addresses`, color=`Network`)) +
geom_line() +
geom_label(
aes(label = `Stake Addresses`),
data = df[!is.na(`Stake Addresses`), .(`Timestamp`=max(`Timestamp`), `Stake Addresses`=round(last(`Stake Addresses`))), by=.(`Network`)],
hjust=0, show.legend = FALSE
) +
scale_x_datetime(label=date_format(), expand = expand_scale(mult = c(0.05, 0.20))) +
scale_y_sqrt(label=label_number_auto()) +
xlab("Date") +
ylab("Unique Stake Addresses in Marlowe Transactions") +
theme(axis.text.x = element_text(angle = 0, vjust = 0.5, hjust=0.5))
ggsave("all/stakes.png", width=7, height=5, units="in", dpi=200)
lapply(conns, dbDisconnect)
dbUnloadDriver(drv)
write.csv(df, file="marlowe-stats.csv")
f <- file("all/latest.json")
writeLines(toJSON(
df[,
.(
`Slot No`=last(`Slot No`),
`Creations`=last(`Creations`),
`Closures`=last(`Closures`),
`Actives`=last(`Active`),
`Transactions`=last(`Transaction`),
`Ada Transacted`=last(`Ada Transacted`),
`Payment Addresses`=last(na.omit(`Payment Addresses`)),
`Stake Addresses`=last(na.omit(`Stake Addresses`))
),
by=`Network`
]
), f)
close(f)