想知道你的贵人啥时候点的赞? 我们可以通过 @arcange ‘s STEEMSQL 得到点赞的时间然后通过 R 语言很轻松的画出来.
比如, 我的好基友 @tumutanzi 至从拿到 @ned 所代理的50万SP 后, 是不是像他所说的, 忙得连X生活都没有了呢? 我们可以先用 STEEMSQL 取出数据来看看:
1 | select DATEPART(hour, timestamp) "hour", count(1) "count" from TxVotes where voter='tumutanzi' and datediff(day, timestamp, GetUTCDate()) between 0 and 30 group by DATEPART(hour, timestamp) |
select DATEPART(hour, timestamp) "hour", count(1) "count" from TxVotes where voter='tumutanzi' and datediff(day, timestamp, GetUTCDate()) between 0 and 30 group by DATEPART(hour, timestamp)
between 0 and 30 是针对过去30天的数据, 然后我们通过 DATEPART(hour, timestamp) 来分组(按UTC时区的小时)
接下来和我们以前做的一样, 在R语言里封装一下.
votes_hour = function(id) { conn <- odbcDriverConnect("Driver=SQL Server Native Client 11.0;Server=sql.steemsql.com;Database=DBSteem;Uid=steemit;Pwd=steemit") x <- sqlQuery(conn, str_c("select DATEPART(hour, timestamp) hour, count(1) count from TxVotes where voter='", id, "' and datediff(day, timestamp, GetUTCDate()) between 0 and 30 group by DATEPART(hour, timestamp)")) close(conn) return(x) }
我们需要传递 ID 给这个函数.
id <- "tumutanzi" vote < - votes_hour(id)
检查一下返回的数据:
hour count 1 1 1 2 2 5 3 3 4 4 4 7 5 5 50 6 6 74 7 7 37 8 8 77 9 9 237 10 10 136 11 11 71 12 12 53 13 13 96 14 14 223 15 15 177 16 16 220 17 17 276 18 18 297 19 19 240 20 20 494 21 21 207 22 22 176 23 23 41
如果我们想计算百分比, 我们需要把每一个次数除于所有.
total = sum(vote$count) vote$count = vote$count / total * 100
然后在R里通过plot_ly 来画出柱状图 (bar plot):
plot_ly(x=vote$hour, y=vote$count, type="bar") %>% layout(autosize = F, xaxis=list(title="Hour"), yaxis=list(title="Percentage"), title=str_c("@", id))
看来, @tumutanzi 的确是连X生活都没有了呢, 哈哈.
英文: R Tutorial – Knowing when a Steem Whale vote?
R语言教程
- R 语言教程 – 蒙特卡罗
- R 语言教程 – Sigmoid
- R 语言教程 – 错位排列
- R 语言教程 – 连接STEEMSQL 数据库
- R 语言教程 – STEEMIT 微信群有多少钱?
- R 语言教程 – STEEMIT 大鲸啥时候点赞的?
- R 语言教程 – 通过 RStudio 来快速连接SteemSQL
强烈推荐
- 英国代购-畅购英伦
- TopCashBack 返现 (英国购物必备, 积少成多, 我2年来一共得了3000多英镑)
- Quidco 返现 (也是很不错的英国返现网站, 返现率高)
- 注册就送10美元, 免费使用2个月的 DigitalOcean 云主机(性价比超高, 每月只需5美元)
- 注册就送10美元, 免费使用4个月的 Vultr 云主机(性价比超高, 每月只需2.5美元)
- 注册就送10美元, 免费使用2个月的 阿里 云主机(性价比超高, 每月只需4.5美元)
- 注册就送20美元, 免费使用4个月的 Linode 云主机(性价比超高, 每月只需5美元) (折扣码: PodCastInit2022)
- PlusNet 英国光纤(超快, 超划算! 用户名 doctorlai)
- 刷了美国运通信用卡一年得到的积分 换了 485英镑
- 注册就送50英镑 – 英国最便宜最划算的电气提供商
- 能把比特币莱特币变现的银行卡! 不需要手续费就可以把虚拟货币法币兑换
微信公众号: 小赖子的英国生活和资讯 JustYYUK