2017-02-15 17:56:03 -05:00
|
|
|
require "rubygems"
|
|
|
|
require "prawn"
|
|
|
|
require "prawn/measurement_extensions"
|
|
|
|
require "util.rb"
|
|
|
|
|
|
|
|
class NSFConflicts
|
2017-02-16 02:02:48 -05:00
|
|
|
include Text
|
|
|
|
|
|
|
|
## The NSF considers collaborators from within the past 48 months
|
|
|
|
## Be conservative and add a few extra days in
|
|
|
|
## Track this in seconds (because time deltas are given in seconds)
|
|
|
|
@@time_to_consider_collabs = 60*60*24*365.25*2
|
|
|
|
|
2017-02-15 17:56:03 -05:00
|
|
|
def initialize(me, data)
|
|
|
|
@me = me
|
|
|
|
@data = data
|
|
|
|
@meta =
|
|
|
|
@data["people"].
|
|
|
|
merge(
|
|
|
|
@data["lab/members"].
|
|
|
|
map { |k,m|
|
2017-02-16 02:02:48 -05:00
|
|
|
[k, {
|
|
|
|
"institution" => "University at Buffalo",
|
|
|
|
"email" => "#{m["ubit"]}@buffalo.edu"
|
|
|
|
}.merge(m)]
|
2017-02-15 17:56:03 -05:00
|
|
|
}.to_h
|
|
|
|
).merge(
|
|
|
|
@data["lab/alumni"].
|
|
|
|
map { |k,m|
|
2017-02-16 02:02:48 -05:00
|
|
|
[k, {
|
|
|
|
"name" => k,
|
|
|
|
"institution" => m["company"],
|
|
|
|
"email" => "#{m["ubit"]}@buffalo.edu"
|
|
|
|
}.merge(m)]
|
2017-02-15 17:56:03 -05:00
|
|
|
}.to_h
|
|
|
|
)
|
2017-02-16 02:02:48 -05:00
|
|
|
@shortname = full_details(@me)["ubit"]
|
2017-07-13 00:15:37 -04:00
|
|
|
@my_data = @data["cv"][@shortname]
|
2017-02-15 17:56:03 -05:00
|
|
|
end
|
|
|
|
def grant_co_pis
|
2017-02-16 02:02:48 -05:00
|
|
|
@data["cv/okennedy/grants"].
|
|
|
|
where { |grant|
|
|
|
|
case grant["status"]
|
|
|
|
when "accepted", "submitted", "completed" then true
|
|
|
|
when "rejected", "retired" then false
|
|
|
|
else raise "Unknown grant status #{grant["status"]} for #{grant["title"]}"
|
|
|
|
end
|
|
|
|
}.
|
|
|
|
where { |grant| Time.now - to_date(grant["end"]) < @@time_to_consider_collabs }.
|
|
|
|
map do |grant|
|
|
|
|
co_pis = grant.fetch("copis", [])
|
|
|
|
grant.fetch("collaborative", []).each do |inst|
|
|
|
|
co_pis = co_pis + inst["pis"]
|
|
|
|
end
|
|
|
|
last_active = to_date(grant["end"])
|
|
|
|
last_active = Time.now if last_active > Time.now
|
2022-02-22 11:09:41 -05:00
|
|
|
co_pis.flatten.map { |name| [name, "#{last_active.year}-#{last_active.month}-#{last_active.day}"] }
|
2017-02-16 02:02:48 -05:00
|
|
|
end.
|
|
|
|
flatten(1)
|
2017-02-15 17:56:03 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def paper_coauthors
|
2017-02-16 02:02:48 -05:00
|
|
|
start_year = (Time.now - @@time_to_consider_collabs).year
|
2017-02-15 17:56:03 -05:00
|
|
|
@data["publications"].
|
|
|
|
where { |paper| paper["authors"].include? @me }.
|
2017-02-16 02:02:48 -05:00
|
|
|
where { |paper| paper["year"].to_i >= start_year }.
|
|
|
|
|
|
|
|
map { |paper|
|
|
|
|
paper["authors"].
|
|
|
|
where { |name| name != @me }.
|
2022-02-22 11:09:41 -05:00
|
|
|
map { |name| [name, "#{paper["year"].to_i}-01-01"] }
|
2017-02-16 02:02:48 -05:00
|
|
|
}.
|
|
|
|
flatten(1)
|
|
|
|
end
|
|
|
|
|
|
|
|
def advisors
|
2019-02-03 17:24:12 -05:00
|
|
|
@data["cv/#{@shortname}/education"]
|
|
|
|
.where { |inst| inst["degree"] == "PhD" }
|
|
|
|
.map { |inst| inst["Advisor"] }
|
|
|
|
end
|
|
|
|
|
|
|
|
def committee
|
|
|
|
@data["cv/#{@shortname}/education"]
|
|
|
|
.where { |inst| inst["degree"] == "PhD" }
|
|
|
|
.map { |inst| inst["Committee"] }
|
|
|
|
.flatten(1)
|
2017-02-15 17:56:03 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def phd_students
|
2019-02-03 17:24:12 -05:00
|
|
|
@data["lab/members"]
|
|
|
|
.values
|
|
|
|
.where { |person| person["status"] == "PhD" }
|
|
|
|
.map { |person| person["name"] }
|
2017-02-15 17:56:03 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def phd_alumni
|
2019-02-03 17:24:12 -05:00
|
|
|
@data["lab/alumni"]
|
|
|
|
.values
|
|
|
|
.where { |person| person["degree"] == "PhD" }
|
|
|
|
.map { |person| person["name"] }
|
2017-02-15 17:56:03 -05:00
|
|
|
end
|
|
|
|
|
2017-02-16 02:02:48 -05:00
|
|
|
def canonicalize(person)
|
2018-11-20 15:56:58 -05:00
|
|
|
@meta.fetch(person, {"canonical" => person})
|
|
|
|
.fetch("canonical", person)
|
2017-02-16 02:02:48 -05:00
|
|
|
end
|
|
|
|
|
2017-02-15 17:56:03 -05:00
|
|
|
def full_details(person)
|
2017-02-16 02:02:48 -05:00
|
|
|
return person.map { |x| full_details(x) } if person.is_a? Array
|
|
|
|
meta = @meta[person] or raise "Unknown Person: #{person}"
|
|
|
|
{
|
|
|
|
"name" => person,
|
|
|
|
"name_parts" => split_name(person)
|
|
|
|
}.merge(meta)
|
2017-02-15 17:56:03 -05:00
|
|
|
end
|
|
|
|
|
2017-02-16 02:02:48 -05:00
|
|
|
def render_name(person)
|
|
|
|
person["name_parts"].reverse.join(", ")
|
2017-02-15 17:56:03 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def render(target)
|
|
|
|
all_collabs = (
|
2017-02-16 02:02:48 -05:00
|
|
|
(grant_co_pis + paper_coauthors).map { |x| x[0] } +
|
2019-02-03 17:24:12 -05:00
|
|
|
(phd_students + phd_alumni + advisors + committee)
|
2017-02-15 17:56:03 -05:00
|
|
|
).uniq.sort
|
|
|
|
|
|
|
|
missing_collabs =
|
|
|
|
all_collabs.select { |person| not (@meta.has_key? person) }
|
|
|
|
|
|
|
|
unless missing_collabs.empty?
|
|
|
|
puts ("You are missing collaborator details. Here's a template to add to /db/people.json:")
|
|
|
|
missing_collabs.each do |collab|
|
|
|
|
puts " \"#{collab}\" : {"
|
|
|
|
puts " \"institution\" : \"\","
|
|
|
|
puts " \"updated\" : \"#{Time.now.year}\""
|
|
|
|
puts " },"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
File.open(target, "w+") do |f|
|
2017-07-13 00:15:37 -04:00
|
|
|
f.puts("==== TABLE A ====")
|
|
|
|
f.puts("\t#{@my_data["name"]}\t#{@my_data["work"]["employer"]}")
|
2017-02-16 02:02:48 -05:00
|
|
|
f.puts("==== TABLE B ====")
|
|
|
|
full_details(advisors).each do |adv|
|
2017-12-15 19:16:07 -05:00
|
|
|
f.puts "G:\t#{render_name(adv)}\t#{adv["institution"]}\t#{adv["email"]}"
|
2017-02-16 02:02:48 -05:00
|
|
|
end
|
2019-02-03 17:24:12 -05:00
|
|
|
full_details((committee + phd_students + phd_alumni).uniq.sort).each do |stud|
|
2017-02-16 02:02:48 -05:00
|
|
|
f.puts "T:\t#{render_name(stud)}\t#{stud["institution"]}\t#{stud["email"]}"
|
|
|
|
end
|
|
|
|
f.puts("==== TABLE C ====")
|
|
|
|
all_collabs = (
|
|
|
|
grant_co_pis.map { |name, y| [canonicalize(name), [:grant, y]] } +
|
|
|
|
paper_coauthors.map { |name, y| [canonicalize(name), [:pub, y]] }
|
|
|
|
)
|
2017-08-27 23:52:29 -04:00
|
|
|
all_collabs
|
2018-10-09 08:32:28 -04:00
|
|
|
.my_reduce
|
2017-08-27 23:52:29 -04:00
|
|
|
.to_a
|
|
|
|
.sort_by { |name, collabs| render_name(full_details(name)) }
|
|
|
|
.each { |name, collabs|
|
|
|
|
categories, years = collabs.unzip
|
|
|
|
category = "C:"
|
|
|
|
category = "A:" if(categories.include? :pub)
|
|
|
|
details = full_details(name)
|
|
|
|
f.puts("#{category}\t#{render_name(details)}\t#{details["institution"]}\t#{details["email"]}\t#{years.max}")
|
|
|
|
}
|
2017-02-15 17:56:03 -05:00
|
|
|
end
|
|
|
|
end
|
2017-02-16 02:02:48 -05:00
|
|
|
|
2017-02-15 17:56:03 -05:00
|
|
|
end
|