Recovering support for generating NSF CnPs.

pull/1/head
Oliver Kennedy 2016-06-16 22:47:36 -04:00
parent 042cfdbb53
commit f4a97e2ff8
5 changed files with 136 additions and 4 deletions

View File

@ -5,6 +5,7 @@ require "jdb.rb"
require "lab_metadata.rb"
require "util.rb"
require "cv.rb"
require "nsfcp.rb"
include GemSmith
$db = JDB.new("db")
@ -93,3 +94,10 @@ directory "cvs"
end
task :cv => "cvs/#{who}.pdf"
end
file "cvs/okennedy_current_and_pending.pdf" do
NSFCnP.new("Oliver Kennedy",
$db["cv/okennedy/grants"].select { |r| r["status"] == "accepted" or r["status"] == "submitted" or r["status"] == "planned"}
).render("cvs/okennedy_current_pending.pdf")
end
task :cnp => "cvs/okennedy_current_and_pending.pdf"

Binary file not shown.

View File

@ -43,7 +43,7 @@
"status" : "submitted",
"start" : "08/2016", "end" : "08/2017",
"type" : "grant",
"commitment" : { "summer" : 0.5 }
"commitment" : { "summer" : 0.25 }
},
{ "title" : "Curating Uncertainty and Reliable Exploitation (CURE)",
"agency" : "The US Naval Postgraduate School",
@ -57,7 +57,8 @@
"start" : "05/2016", "end" : "04/2017",
"optional_end" : "04/2017",
"type" : "grant",
"supports" : [ "Jon Logan" ]
"supports" : [ "Jon Logan" ],
"commitment" : { "summer" : 1 }
},
{ "title" : "III: Small: Just in Time Datastructures",
"agency" : "NSF: CISE: IIS: III",
@ -67,7 +68,7 @@
"status" : "submitted",
"start" : "05/2016", "end" : "04/2019",
"type" : "grant",
"commitment" : { "summer" : 1 }
"commitment" : { "summer" : "0.75, 1, 1.25" }
},
{ "title" : "Expressing Uncertainty Using the maybe System",
"agency" : "Google Research Awards",
@ -106,7 +107,7 @@
"role" : "PI",
"amount" : 90455,
"effort" : "100%",
"status" : "accepted",
"status" : "completed",
"start" : "03/2015", "end" : "03/2016",
"type" : "gift",
"urls" : {

BIN
lib/NSFCP.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 305 KiB

123
lib/nsfcp.rb Normal file
View File

@ -0,0 +1,123 @@
require "rubygems"
require "prawn"
require "prawn/measurement_extensions"
class Array
def symbolize_json
map { |v| if v.respond_to? :symbolize_json then v.symbolize_json else v end }
end
end
class Hash
def symbolize_json
self.map do |k,v|
v = v.symbolize_json if v.respond_to? :symbolize_json
case k
when String then [k.to_sym, v]
else [k, v]
end
end.to_h
end
end
class NSFCnP
@@box_heights = [ 8.66.in, 7.085.in, 5.52.in, 3.97.in, 2.42.in ]
@@debug = false
def initialize(me, grants)
@me = me
@grants = grants.symbolize_json
end
def render(target)
grants = @grants
pi_name = @me
Prawn::Document.generate(target,
background: "lib/NSFCP.png",
background_scale: 0.5
) do
stroke_color 'ff0000' if @@debug
grants.take_groups(@@box_heights.length)
.each.with_index do |page_records, page|
puts "Rendering Page #{page}"
start_new_page unless page == 0;
bounding_box([0.8.in, 8.85.in], width: 2.5.in, height: 0.2.in) do
text pi_name
stroke_bounds if @@debug
end
page_records.zip(@@box_heights.take(page_records.length)).
each do |record, height|
bounding_box([-0.17.in, height], width: 7.85.in, height: 1.59.in) do
stroke_bounds if @@debug
######## Support Type ########
offset =
case record.fetch(:status, record.fetch("status", :pending))
when :pending, "submitted" then 2.21.in
when :current, "accepted" then 1.16.in
when :planned, "planned" then 3.32.in
when :transfer then 6.07.in
else raise "Unknown status: #{record[:support]}"
end
# puts "Offset: #{record.fetch(:title)} -> #{offset}; #{record[:status]} -- #{record["status"]}"
### Make the checkbox ###
bounding_box([offset,1.57.in], width: 0.2.in, height: 0.2.in) do
text "X"
end
######## Title ########
bounding_box([0.1.in, 1.20.in], width: 7.6.in, height: 0.38.in) do
stroke_bounds if @@debug
text record.fetch(:title)
end
######## Agency ########
bounding_box([1.23.in, 0.8.in], width: 6.47.in, height: 0.19.in) do
stroke_bounds if @@debug
text record.fetch(:agency)
end
######## Amount ########
bounding_box([1.5.in, 0.6.in], width: 1.4.in, height: 0.19.in) do
stroke_bounds if @@debug
text record.fetch(:amount).to_s
end
######## Period ########
bounding_box([4.7.in, 0.6.in], width: 3.in, height: 0.19.in) do
stroke_bounds if @@debug
text "#{record.fetch(:start)} -- #{record.fetch(:end)}"
end
######## Location ########
bounding_box([1.23.in, 0.4.in], width: 6.47.in, height: 0.19.in) do
stroke_bounds if @@debug
text record.fetch(:location, "University at Buffalo, Buffalo, NY")
end
######## Commitment ########
commitment = record.fetch(:commitment)
bounding_box([4.4.in, 0.2.in], width: 0.6.in, height: 0.19.in) do
stroke_bounds if @@debug
text commitment.fetch(:calendar, 0).to_s, align: :center
end
bounding_box([5.45.in, 0.2.in], width: 0.55.in, height: 0.19.in) do
stroke_bounds if @@debug
text commitment.fetch(:schoolyear, 0).to_s, align: :center
end
bounding_box([6.4.in, 0.2.in], width: 1.in, height: 0.19.in) do
stroke_bounds if @@debug
text commitment.fetch(:summer, 0).to_s, align: :center
end
end
end
end
end
end
end