From ee1448ab1f4cc640e60515b6214c6fde1d98d4cf Mon Sep 17 00:00:00 2001 From: multiple creatures Date: Mon, 30 Sep 2019 23:28:52 -0500 Subject: add `histogram` bangtag --- app/lib/bangtags.rb | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/app/lib/bangtags.rb b/app/lib/bangtags.rb index 31395740d..81aef2807 100644 --- a/app/lib/bangtags.rb +++ b/app/lib/bangtags.rb @@ -700,6 +700,33 @@ class Bangtags next unless @sroff_open @sroff_open = false chunk = "\uf334" + when 'histogram' + @status.content_type = 'text/html' + barchars = " #{(0x2588..0x258F).to_a.reverse.pack('U*')}" + q = cmd[1..-1].join.strip + if q.start_with?('@@') + sql = 'tsv @@ to_tsquery(?)' + q = q[2..-1].lstrip + else + sql = 'tsv @@ plainto_tsquery(?)' + end + next if q.blank? + begin + data = @account.statuses.where(sql, q) + .reorder(:created_at) + .pluck(:created_at) + .map { |d| d.strftime('%Y-%m') } + .reduce(Hash.new(0)) { |h, v| h.store(v, h[v] + 1); h } + rescue ActiveRecord::StatementInvalid + raise Mastodon::ValidationError, 'Your advanced search query has invalid syntax.' + end + highest = data.values.max + data = data.map do |date, count| + fill = count / highest.to_f * 96 + bar = "#{"\u2588" * (fill / 8).to_i}#{barchars[fill % 8]}" + "#{date}: #{bar} #{count}" + end + chunk = "\"#{q.split('').join("\u200c")}\" mentions by post count:
#{data.join("
")}" when 'admin' chunk = nil next unless @user.admin? -- cgit