duangsuse::Echo
#Ruby 弄了半天我才知道 Ruby 里 Enumerator 还可以 with_index... 😂 还可以 map(Enumerator).with_index { |a, i| }...
require 'gnuplot'
xs = []; ys = []
_dataset = r.map { |it| it['published'] }
ps = _dataset.sort_by { |d| d.day }.reverse.each { |k| xs << k.day; ys << _dataset.count { |it| it.day == k.day } }
Gnuplot.open do |p|
Gnuplot::Plot.new(p) do |plot|
plot.title "duangsuse::Echo message publish time (all #{ys.size}, day from #{xs.min} to #{xs.max})"
plot.xlabel "day (1-31)"
plot.ylabel "messages count"
plot.data << Gnuplot::DataSet.new([xs, ys]) do |ds|
ds.with = "points"
ds.notitle
end
end
end
然后就可以画出类似下面的统计折线图: 🤔 #Ruby #Gnu #stat #Learn需要注意的是,gnuplot 比较底层和原始,它不会自动帮你处理好数据集合排序(如果需要的话,比如这里就需要)
弄不好会生成瞎* 🐔 折线图,会包含『反折』的线条角度...
Ruby 的 gnuplot Gem 很简单,之需了解 DataSet 和 Plot、GnuPlot 程序命令行接口的抽象即可
Plot 是图座标系的抽象,包含
title(图表名)、xlabel 和 ylabel,也可以设置初始 xrange,它包含的折线们就是 data 数组DataSet 就是要往 Plot 上画的点集合,每个新画上去的点都有一个 x value 和 y value(可以作为一个 xvalue, yvalue 数组传入
new),并且如果要连线就会和上一个点连接。DataSet 可以指定是
with 'lines' 'points' 还是 'linespoints'可以指定
linewidth 和 title(这条折线的 title)也可以 notitletelegramscanner_with_rb.zip
186.9 KB
好了,那么这周这个工程就这些。( 😃
🤔 所以,我们可以用 echarts 来完成更好的可视化需求(
依然是折线图,还是 187 个数据,我们看看使用 echarts 怎么样,待会发 html.
依然是折线图,还是 187 个数据,我们看看使用 echarts 怎么样,待会发 html.
差点忘了发 #share 结果图,gnuplot 完成度比较... 呃,或者说 GUI 功能有点限制,不好用,只能导出成这样,待会会有好的。
duangsuse::Echo
🤔 所以,我们可以用 echarts 来完成更好的可视化需求( 依然是折线图,还是 187 个数据,我们看看使用 echarts 怎么样,待会发 html.
我们使用条形图。 🤔
条形图的 xAxis 是时间,可缩放,yAxis 是这个时间里的消息条数。
基于这种需求,我们首先拿到数据点集合:
条形图的 xAxis 是时间,可缩放,yAxis 是这个时间里的消息条数。
基于这种需求,我们首先拿到数据点集合:
data = collect { |it| it['published'] }.map.with_index { |p, i| [self[i], p] }.sort_by(&:last)
result data.map(&:last).yield_self { |t| t.map { |s| [s, t.count(s) ] } }
puts result.to_json
这样就拿到了时间和条数的 pair 二维数组 🐱