Created
January 12, 2019 23:05
-
-
Save SamSaffron/ef737b3917acd7a1e708caa0da2e4ce8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
fail "API_KEY required" unless key = ENV["API_KEY"] | |
fail "API_USERNAME required" unless username = ENV["API_USERNAME"] | |
require "set" | |
require "date" | |
require "json" | |
json = JSON.parse(`curl -s "https://dev.discourse.org/t/7433.json?include_raw=true&api_username=#{username}&api_key=#{key}"`) | |
map = {} | |
def find_bad_dates(raw) | |
dates = [] | |
raw.split("\n").each { |line| | |
a, b = line.scan(/\w+ \d+/).map { |d| Date.parse(d) } | |
b ||= a | |
(a..b).each { |d| dates << Date.parse(d.to_s) } | |
} | |
dates | |
end | |
json.dig("post_stream", "posts")[1..-1].each do |post| | |
bad_dates = map[post["username"]] ||= [] | |
bad_dates.concat(find_bad_dates(post["raw"])) | |
end | |
puts "#{map.keys.length} users found!" | |
# first of week in august this is the Saturday | |
start_date = Date.parse("03-08-2019") | |
weeks = (1..20).map { | |
[start_date += 1, start_date += 6] | |
} | |
weeks.each do |start,finish| | |
problem_users = [] | |
map.each do |user, dates| | |
found = [] | |
dates.each do |date| | |
if date <= finish && date >= start | |
found << date | |
end | |
end | |
if found.length > 0 | |
problem_users << [user, found] | |
end | |
end | |
problem_text = problem_users.map do |name, dates| | |
days = dates.map do |date| | |
date.strftime('%a')[0..1] | |
end.join(",") | |
"#{name} (#{days})" | |
end.join(" ") | |
puts "#{start} #{finish} : #{problem_users.count} issues. #{problem_text}" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment