Last active
July 1, 2017 07:43
-
-
Save sffc/535f04b7cb57bb8da6a45377be67c482 to your computer and use it in GitHub Desktop.
Helper script for counting the recruitment stats in the IRON Recruitment Corps
This file contains hidden or 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 | |
require 'uri' | |
LAST_MONTH_DAN = "2017/april-dan.txt" | |
THIS_MONTH_DAN = "2017/may-dan.txt" | |
THIS_MONTH_RULERS = "2017/may-rulers.txt" | |
THIS_MONTH_THREADS = "2017/may-threads.txt" | |
rulers = File | |
.readlines(THIS_MONTH_RULERS) | |
.map { |l| l.strip() } | |
.select { |l| l != "" } | |
dan = (File.read(LAST_MONTH_DAN) + File.read(THIS_MONTH_DAN)) | |
.split(/\#\d+ \[DAN Recruiting/) | |
.slice(1..-1) | |
.map { |r| r | |
.split("\n") | |
.map { |l| l.strip() } | |
} | |
.group_by { |r| r[1] } | |
.map { |k,v| { k => v.flatten().join("\n") } } | |
.reduce(:merge) | |
recruiters = dan.keys | |
threads = Hash.new("") | |
all_threads = "" | |
File | |
.read(THIS_MONTH_THREADS) | |
.scan(/^(.*)\nStarted by (.*)/) | |
.each { |title,tags| | |
recruiters.each { |recruiter| | |
if tags.downcase.include?(recruiter.downcase) | |
threads[recruiter] += title + "\n" | |
end | |
} | |
all_threads += title + "\n" | |
} | |
parsed_rulers = rulers.map { |ruler| { ruler => | |
{ | |
dan: dan | |
.select { |k,v| v.downcase.include? ruler.downcase } | |
.map { |k,v| k }, | |
threads: threads | |
.select { |k,v| v.downcase.include? ruler.downcase } | |
.map { |k,v| k }, | |
has_thread: all_threads.downcase.include?(ruler.downcase) | |
} | |
}}.reduce(:merge) | |
ghosts_with_recruiter = Hash.new() | |
recruiter_pts = recruiters | |
.map { |recruiter| | |
r = parsed_rulers | |
.select { |name,h| h[:dan].include?(recruiter) or h[:threads].include?(recruiter) } | |
.select { |name,h| | |
if !h[:has_thread] | |
ghosts_with_recruiter[name] = h | |
end | |
h[:has_thread] | |
} | |
.map { |name,h| | |
syms = "" | |
# Add the % symbol (not located in DAN thread) | |
if h[:dan].length == 0 | |
syms += "%" | |
end | |
# Add the # symbol (points split) | |
rcrtrs = (h[:dan] + h[:threads]).uniq | |
if rcrtrs.length > 1 | |
syms += "\#" | |
end | |
pts = 1/rcrtrs.length.to_f | |
{ name: name, syms: syms, pts: pts } | |
} | |
{ recruiter => { | |
rulers: r, | |
pts: r.reduce(0) { |s,h| s + h[:pts] }, | |
names: r.map { |h| "#{h[:name]} #{h[:syms]}" }.join("\n") | |
}} | |
} | |
.reduce(:merge) | |
rulers_with_recruiter = recruiter_pts | |
.map { |_,info| info[:rulers] } | |
.flatten() | |
.map { |h| h[:name] } | |
.uniq | |
leftovers = (rulers - rulers_with_recruiter - ghosts_with_recruiter.map{|name,h| name} ) | |
.map { |name| { name => parsed_rulers[name] } } | |
.reduce(:merge) | |
selfr = leftovers.select { |name,h| h[:has_thread] } | |
ghosts = leftovers.map{ |name,_| name } - selfr.map{ |name,_| name } | |
# puts parsed_rulers.map { |h| "#{h[:name]}: #{h[:dan]}, #{h[:threads]}" }.join("\n") | |
# p recruiter_pts | |
puts recruiter_pts | |
.select { |recruiter,info| info[:pts] > 0 } | |
.sort_by { |recruiter,info| -info[:pts] } | |
.map { |recruiter,info| "[b]#{recruiter}: #{info[:pts]}[/b]\n#{info[:names]}\n\n" } | |
# puts "Rulers with no application thread:" | |
# p parsed_rulers.select { |h| h[:dan].length == 0 and h[:] } | |
links = (ghosts+ghosts_with_recruiter.map{|name,h| name}) | |
.map { |ghost| "http://www.cybernations.net/search.asp?searchstring=Poster&search=#{URI.escape(ghost)}&anyallexact=all&Strength1=&Strength2=" } | |
puts "[b]Self-Recruited: #{selfr.length}[/b]\n#{selfr.map{|name,h| name}.join("\n")}" | |
puts "\n-----\n\n" | |
puts "In DAN but no Welcome Center Thread:\n#{ghosts_with_recruiter.map{|name,h| name}.join("\n")}" | |
puts "\n-----\n\n" | |
puts "Not Found:" | |
puts ghosts | |
if ARGV[0] == "firefox" | |
links.each{ |url| `open -a firefox -g '#{url}'` } | |
else | |
puts "-----" | |
puts "Links:" | |
puts links.join("\n") | |
puts "Re-run as './analyze.rb firefox' to open all of the links in Firefox" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment