Change some labels

This commit is contained in:
Rucknium 2022-05-12 02:10:07 +00:00
parent fcf5507736
commit 64ca3fe43b
4 changed files with 68 additions and 58 deletions

View file

@ -102,61 +102,61 @@ spent.status[, btc.block_time.date := lubridate::date(btc.block_time)]
# {BTC spent status}{BCH spent status}.to.{BTC spent status}{BCH spent status}
# u = unspent; s = spent
spent.status[, uu.to.su := as.Date(ifelse(
spent.status[, ff.to.tf := as.Date(ifelse(
ifelse(is.na(btc.block_time.date), Inf, btc.block_time.date) < ifelse(is.na(bch.block_time.date), Inf, bch.block_time.date),
btc.block_time.date, rep(NA, .N)), origin = "1970-01-01")]
spent.status[, uu.to.us := as.Date(ifelse(
spent.status[, ff.to.ft := as.Date(ifelse(
ifelse(is.na(bch.block_time.date), Inf, bch.block_time.date) < ifelse(is.na(btc.block_time.date), Inf, btc.block_time.date),
bch.block_time.date, rep(NA, .N)), origin = "1970-01-01")]
spent.status[, uu.to.ss := as.Date(ifelse(
spent.status[, ff.to.tt := as.Date(ifelse(
ifelse(is.na(btc.block_time.date), Inf, btc.block_time.date) == ifelse(is.na(bch.block_time.date), Inf, bch.block_time.date),
btc.block_time.date, rep(NA, .N)), origin = "1970-01-01")]
spent.status[, su.to.ss := as.Date(ifelse(
(! is.na(uu.to.su)) &
spent.status[, tf.to.tt := as.Date(ifelse(
(! is.na(ff.to.tf)) &
ifelse(is.na(bch.block_time.date), Inf, bch.block_time.date) > ifelse(is.na(btc.block_time.date), Inf, btc.block_time.date),
bch.block_time.date, rep(NA, .N)), origin = "1970-01-01")]
spent.status[, us.to.ss := as.Date(ifelse(
(! is.na(uu.to.us)) &
spent.status[, ft.to.tt := as.Date(ifelse(
(! is.na(ff.to.ft)) &
ifelse(is.na(btc.block_time.date), Inf, btc.block_time.date) > ifelse(is.na(bch.block_time.date), Inf, bch.block_time.date),
btc.block_time.date, rep(NA, .N)), origin = "1970-01-01")]
uu.to.su <- spent.status[ (! is.na(uu.to.su)),
.(value.uu.to.su = sum(value, na.rm = TRUE), outputs.uu.to.su = .N), by = uu.to.su]
names(uu.to.su)[1] <- "block_time.date"
ff.to.tf <- spent.status[ (! is.na(ff.to.tf)),
.(value.ff.to.tf = sum(value, na.rm = TRUE), outputs.ff.to.tf = .N), by = ff.to.tf]
names(ff.to.tf)[1] <- "block_time.date"
uu.to.us <- spent.status[ (! is.na(uu.to.us)),
.(value.uu.to.us = sum(value, na.rm = TRUE), outputs.uu.to.us = .N), by = uu.to.us]
names(uu.to.us)[1] <- "block_time.date"
ff.to.ft <- spent.status[ (! is.na(ff.to.ft)),
.(value.ff.to.ft = sum(value, na.rm = TRUE), outputs.ff.to.ft = .N), by = ff.to.ft]
names(ff.to.ft)[1] <- "block_time.date"
uu.to.ss <- spent.status[ (! is.na(uu.to.ss)),
.(value.uu.to.ss = sum(value, na.rm = TRUE), outputs.uu.to.ss = .N), by = uu.to.ss]
names(uu.to.ss)[1] <- "block_time.date"
ff.to.tt <- spent.status[ (! is.na(ff.to.tt)),
.(value.ff.to.tt = sum(value, na.rm = TRUE), outputs.ff.to.tt = .N), by = ff.to.tt]
names(ff.to.tt)[1] <- "block_time.date"
su.to.ss <- spent.status[ (! is.na(su.to.ss)),
.(value.su.to.ss = sum(value, na.rm = TRUE), outputs.su.to.ss = .N), by = su.to.ss]
names(su.to.ss)[1] <- "block_time.date"
tf.to.tt <- spent.status[ (! is.na(tf.to.tt)),
.(value.tf.to.tt = sum(value, na.rm = TRUE), outputs.tf.to.tt = .N), by = tf.to.tt]
names(tf.to.tt)[1] <- "block_time.date"
us.to.ss <- spent.status[ (! is.na(us.to.ss)),
.(value.us.to.ss = sum(value, na.rm = TRUE), outputs.us.to.ss = .N), by = us.to.ss]
names(us.to.ss)[1] <- "block_time.date"
ft.to.tt <- spent.status[ (! is.na(ft.to.tt)),
.(value.ft.to.tt = sum(value, na.rm = TRUE), outputs.ft.to.tt = .N), by = ft.to.tt]
names(ft.to.tt)[1] <- "block_time.date"
trans.matrix.prep <-
state.trans.by.day <-
data.table(block_time.date = sort(unique(lubridate::date(c(spent.status$bch.block_time, spent.status$btc.block_time)))))
trans.matrix.prep <- merge(trans.matrix.prep, uu.to.su, all = TRUE)
trans.matrix.prep <- merge(trans.matrix.prep, uu.to.us, all = TRUE)
trans.matrix.prep <- merge(trans.matrix.prep, uu.to.ss, all = TRUE)
trans.matrix.prep <- merge(trans.matrix.prep, su.to.ss, all = TRUE)
trans.matrix.prep <- merge(trans.matrix.prep, us.to.ss, all = TRUE)
state.trans.by.day <- merge(state.trans.by.day, ff.to.tf, all = TRUE)
state.trans.by.day <- merge(state.trans.by.day, ff.to.ft, all = TRUE)
state.trans.by.day <- merge(state.trans.by.day, ff.to.tt, all = TRUE)
state.trans.by.day <- merge(state.trans.by.day, tf.to.tt, all = TRUE)
state.trans.by.day <- merge(state.trans.by.day, ft.to.tt, all = TRUE)
trans.matrix.prep[is.na(trans.matrix.prep)] <- 0
state.trans.by.day[is.na(state.trans.by.day)] <- 0
@ -230,7 +230,10 @@ stopifnot(max(outputs.row.sum.check) - min(outputs.row.sum.check) == 0)
saveRDS(spent.status.by.day, file = paste0(bch.data.dir, "spent_status_by_day.rds"))
saveRDS(trans.matrix.prep, file = paste0(bch.data.dir, "trans_matrix_prep.rds"))
saveRDS(state.trans.by.day, file = paste0(bch.data.dir, "state_trans_by_day.rds"))
write.csv(spent.status.by.day, file = paste0(bch.data.dir, "spent_status_by_day.csv"), row.names = FALSE)
write.csv(state.trans.by.day, file = paste0(bch.data.dir, "state_trans_by_day.csv"), row.names = FALSE)

View file

@ -6,6 +6,12 @@ library(Cairo)
# NOTE: Also need lubridate package installed, but not loading it due to
# it masking functions
bch.data.dir <- ""
spent.status.by.day <- readRDS(paste0(bch.data.dir, "spent_status_by_day.rds"))
state.trans.by.day <- readRDS(paste0(bch.data.dir, "state_trans_by_day.rds"))
sum.value.pre.fork <- sum(spent.status.by.day[1,
@ -69,33 +75,33 @@ spent.status.by.day.outputs.reshaped[, variable :=
trans.matrix.prep.value.reshaped <- melt(trans.matrix.prep[,
.(block_time.date, value.uu.to.su, value.uu.to.us, value.uu.to.ss,
value.su.to.ss, value.us.to.ss)], id.vars = c("block_time.date"),
measure.vars = c("value.uu.to.su", "value.uu.to.us", "value.uu.to.ss",
"value.su.to.ss", "value.us.to.ss"))
state.trans.by.day.value.reshaped <- melt(state.trans.by.day[,
.(block_time.date, value.ff.to.tf, value.ff.to.ft, value.ff.to.tt,
value.tf.to.tt, value.ft.to.tt)], id.vars = c("block_time.date"),
measure.vars = c("value.ff.to.tf", "value.ff.to.ft", "value.ff.to.tt",
"value.tf.to.tt", "value.ft.to.tt"))
trans.matrix.prep.value.reshaped[, block_time.date := as.POSIXct(block_time.date)]
trans.matrix.prep.value.reshaped[, variable :=
factor(variable, levels = c("value.uu.to.su", "value.uu.to.us", "value.uu.to.ss",
"value.su.to.ss", "value.us.to.ss"))]
state.trans.by.day.value.reshaped[, block_time.date := as.POSIXct(block_time.date)]
state.trans.by.day.value.reshaped[, variable :=
factor(variable, levels = c("value.ff.to.tf", "value.ff.to.ft", "value.ff.to.tt",
"value.tf.to.tt", "value.ft.to.tt"))]
trans.matrix.prep.outputs.reshaped <- melt(trans.matrix.prep[,
.(block_time.date, outputs.uu.to.su, outputs.uu.to.us, outputs.uu.to.ss,
outputs.su.to.ss, outputs.us.to.ss)], id.vars = c("block_time.date"),
measure.vars = c("outputs.uu.to.su", "outputs.uu.to.us", "outputs.uu.to.ss",
"outputs.su.to.ss", "outputs.us.to.ss"))
state.trans.by.day.outputs.reshaped <- melt(state.trans.by.day[,
.(block_time.date, outputs.ff.to.tf, outputs.ff.to.ft, outputs.ff.to.tt,
outputs.tf.to.tt, outputs.ft.to.tt)], id.vars = c("block_time.date"),
measure.vars = c("outputs.ff.to.tf", "outputs.ff.to.ft", "outputs.ff.to.tt",
"outputs.tf.to.tt", "outputs.ft.to.tt"))
trans.matrix.prep.outputs.reshaped[, block_time.date := as.POSIXct(block_time.date)]
trans.matrix.prep.outputs.reshaped[, variable :=
factor(variable, levels = c("outputs.uu.to.su", "outputs.uu.to.us", "outputs.uu.to.ss",
"outputs.su.to.ss", "outputs.us.to.ss"))]
state.trans.by.day.outputs.reshaped[, block_time.date := as.POSIXct(block_time.date)]
state.trans.by.day.outputs.reshaped[, variable :=
factor(variable, levels = c("outputs.ff.to.tf", "outputs.ff.to.ft", "outputs.ff.to.tt",
"outputs.tf.to.tt", "outputs.ft.to.tt"))]
@ -206,7 +212,7 @@ dev.off()
ann_text.value <- data.frame(
block_time.date = as.POSIXct("2022-03-15"),
value = 300000,
variable = factor("value.us.to.ss", levels = levels(trans.matrix.prep.value.reshaped$variable)))
variable = factor("value.ft.to.tt", levels = levels(state.trans.by.day.value.reshaped$variable)))
# Due to
# https://stackoverflow.com/questions/11889625/annotating-text-on-individual-facet-in-ggplot2
@ -214,15 +220,15 @@ ann_text.value <- data.frame(
png(paste0(bch.data.dir, "preliminary-pre-fork-BTC-BCH-trans-matrix-by-value.png"), width = 800, height = 2000)
print(
ggplot(trans.matrix.prep.value.reshaped, aes(x = block_time.date, y = value, fill = variable)) +
ggplot(state.trans.by.day.value.reshaped, aes(x = block_time.date, y = value, fill = variable)) +
ggtitle("State Transition of Pre-fork BTC and BCH by Bitcoin Value\nKEY: {BTC Spent}{BCH Spent} to {BTC Spent}{BCH Spent}") +
geom_line(aes(color = variable)) + coord_flip() +
scale_x_continuous(trans = rev_date, labels = date_format("%b-%Y"), expand = c(0, 0),
breaks = date.breaks) +
scale_y_continuous(labels = scales::comma) +
facet_grid(. ~ variable, labeller = labeller(variable =
c(value.uu.to.su = "FF to TF", value.uu.to.us = "FF to FT", value.uu.to.ss = "FF to TT",
value.su.to.ss = "TF to TT", value.us.to.ss = "FT to TT" ))) +
c(value.ff.to.tf = "FF to TF", value.ff.to.ft = "FF to FT", value.ff.to.tt = "FF to TT",
value.tf.to.tt = "TF to TT", value.ft.to.tt = "FT to TT" ))) +
ylab("Quantity of Bitcoin Value Transitioned per Day") +
theme(legend.position = "none", axis.title.y = element_blank(),
strip.text.x = element_text(size = 20), plot.title = element_text(size = 24),
@ -242,20 +248,20 @@ dev.off()
ann_text.output <- data.frame(
block_time.date = as.POSIXct("2022-03-15"),
value = 280000,
variable = factor("outputs.us.to.ss", levels = levels(trans.matrix.prep.outputs.reshaped$variable)))
variable = factor("outputs.ft.to.tt", levels = levels(state.trans.by.day.outputs.reshaped$variable)))
png(paste0(bch.data.dir, "preliminary-pre-fork-BTC-BCH-trans-matrix-by-outputs.png"), width = 800, height = 2000)
print(
ggplot(trans.matrix.prep.outputs.reshaped, aes(x = block_time.date, y = value, fill = variable)) +
ggplot(state.trans.by.day.outputs.reshaped, aes(x = block_time.date, y = value, fill = variable)) +
ggtitle("State Transition of Pre-fork BTC and BCH by Number of Outputs\nKEY: {BTC Spent}{BCH Spent} to {BTC Spent}{BCH Spent}") +
geom_line(aes(color = variable)) + coord_flip() +
scale_x_continuous(trans = rev_date, labels = date_format("%b-%Y"), expand = c(0, 0),
breaks = date.breaks) +
scale_y_continuous(labels = scales::comma) +
facet_grid(. ~ variable, labeller = labeller(variable =
c(outputs.uu.to.su = "FF to TF", outputs.uu.to.us = "FF to FT", outputs.uu.to.ss = "FF to TT",
outputs.su.to.ss = "TF to TT", outputs.us.to.ss = "FT to TT" ))) +
c(outputs.ff.to.tf = "FF to TF", outputs.ff.to.ft = "FF to FT", outputs.ff.to.tt = "FF to TT",
outputs.tf.to.tt = "TF to TT", outputs.ft.to.tt = "FT to TT" ))) +
ylab("Number of Transitioned Outputs per Day") +
theme(legend.position = "none", axis.title.y = element_blank(),
strip.text.x = element_text(size = 20), plot.title = element_text(size = 24),

View file

@ -20,7 +20,7 @@ dir.create(paste0(data.dir, "tx_graphs"))
bch.config <- rbch::conrpc(bitcoin.conf.file)
# current.block.height <- rbch::getblockchaininfo(bch.config)@result$blocks
current.block.height <- 733867
# current.block.height <- 733867
# 733867 is for BCH
# current.block.height <- 729896
# 729896 is for BTC

View file

@ -1,4 +1,5 @@
library(data.table)
library(rbch)
bitcoin.conf.file <- ""
# Input filepath for your bitcoin.conf file
@ -12,7 +13,7 @@ initial.fork.height <- 478558 - 1
# current.block.height <- 733867
# 733867 is for BCH
current.block.height <- 729896
# current.block.height <- 729896
# 729896 is for BTC
block.times <- vector(length(initial.fork.height:current.block.height), mode ="list")