@grumpy @rt It's easy! There's some fiddly stuff to fill in, but off the top of my head:
def avg_stddev a
avg = a.sum.to_f/a.size
stddev =
Math.sqrt(a.map { |i| (i-avg)*(i-avg) }.sum/a.size)
[avg, stddev]
end
# You could do this with sqlite3 or whatever.
timestamps_file = '/wherever/you/wanna/put/it/timestamps.yaml'
timestamps = if File.exist?(timestamps_file)
YAML.parse(File.read(timestamps_file))
else
{}
end
now =
Time.now # We wanna freeze "now" so it doesn't skew as time advances.
avg, stddev = if timestamps.any?
avg_stddev
timestamps.values.map { |t| now - t }
else
[0, 0]
end
# 99.7% of the posts will be within average±3*stddev:
#
https://en.wikipedia.org/wiki/68%E2%80%9395%E2%80%9399.7_rule# Anything higher than that will be the top 0.15% of whatever metric,
# and lower will be in the bottom 0.15%, assuming a normal distribution.
# For post frequency, we can assume that.
threshold = avg + (stddev * 3)
hostname = 'your-hostname-here.biz'
posts = `curl -s https://#{hostname}/api/v1/timelines/public?local=false`
repost_queue = []
JSON.parse(posts.reverse).each { |post|
account = post['account']['acct']
if timestamps.has_key? account
next if post['account']['note'].include?('#nobot') # Be polite
if (now - timestamps[account]) > threshold
reposts << post
end
end
timestamps[account] = now
}
File.write(timestamps_file, timestamps.to_yaml)
reposts.each { |post|
# I forget the endpoint you hit to repost, but do that here.
# You'll need post['id'], that's how your server identifies the post.
# (Unfortunately, Pleroma expects you to construct the URL.)
# Maybe it's something like POST /api/v1/notes/$id
}