Created
March 26, 2009 15:35
-
-
Save austinfromboston/86159 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
# from lib / import_from_marshal.rb | |
def self.load | |
data = Marshal.load(`bzcat #{Rails.root}/private/rockwood_legacy.marshal.bz2`) | |
t = LegacyTraining.new | |
t.add_questions | |
@@txt_questions = t.text_questions | |
@@num_questions = t.numeric_questions | |
@@answers = 0 | |
# numeric_questions = t.numeric_questions.sort(&:order) | |
# text_questions = t.text_questions.sort(&:order) | |
t.name = 'Legacy' | |
# Do not save yet! | |
t.save! | |
data.each_value do |tr| | |
puts "Training #{tr['training_id']}" | |
if tr['trainee'] and !EXCLUDE.include? tr['name'] | |
e = LegacyEvent.new | |
note = "#{tr['name']} #{tr['location']}" | |
if note.isutf8 | |
e.note = note | |
end | |
tr['trainee'].each do |te| | |
r = LegacyRegistration.new | |
name = te['name'].split | |
r.first_name = name.first | |
r.last_name = name.last | |
r.email = te['email'] | |
r.status = 'accepted' | |
se = LegacyEvaluation.new | |
se.self_eval = true | |
se.state = 'completed' | |
populate_eval(se, te) | |
r.evaluations << se | |
if te['peer'] | |
te['peer'].each do |p| | |
pe = LegacyEvaluation.new | |
pe.self_eval = false | |
populate_eval(pe, p) | |
r.evaluations << pe | |
end | |
end | |
e.registrations << r | |
end | |
t.events << e | |
t = LegacyTraining.find t.id | |
end | |
end | |
end | |
# from app/models/evaluation.rb | |
def access_metadata_table(method_args, name, answer_index, write) | |
if name == 'text' | |
q = find_my_question(answer_index){|t| t.text_questions} | |
if not q | |
if write | |
raise 'no question to save to' | |
else | |
return nil | |
end | |
end | |
answers = q.text_answers | |
a = answers.find_by_evaluation_id(self.id) | |
else | |
q = find_my_question(answer_index){|t| t.numeric_questions} | |
return nil if not q and not write | |
answers = q.numeric_answers | |
a = answers.find_by_evaluation_id(self.id) | |
end | |
if write | |
if a | |
a.value = method_args[0] | |
a.save(false) | |
else | |
if name == 'text' | |
answer = TextAnswer.new | |
else | |
answer = NumericAnswer.new | |
end | |
answer.evaluation_id = id | |
answer.question_id = q.id | |
answer.value = method_args[0] | |
answer.save! | |
end | |
#TODO(adam): Find a more efficent way of doing this; perhaps I | |
#can just append to answers and friends, but if I do that what | |
#other overhead am I begging for? Does << automagically update | |
#for me? | |
reload | |
else | |
if a | |
return a.value | |
else | |
return nil | |
end | |
end | |
end | |
# from app/views/admin/feedbacks/show.pdf.prawn | |
def draw pdf, reg, numeric_questions, text_questions | |
participant_feedback ||= [] | |
peer_feedback ||= [] | |
global_feedback ||= [] | |
pdf.stroke_color = "000000" | |
header(pdf, reg) | |
block_start = @top_of_page - 140 | |
#TODO(adam): This section really needs to be reworked once I add an answer object. | |
@numeric_questions.each_with_index do |question, index| | |
current_question = index | |
if block_start < @bottom_of_page | |
block_start = @top_of_page - 140 | |
start_new_page(pdf, reg) | |
end | |
question = @reg.event.training.numeric_questions.find_by_position(index+1).for_peer | |
line = 12 | |
pdf.text "\n\n#{index+1} #{question}", :style=>:bold | |
pdf.bounding_box [ 0, block_start - 120 ], :width=>@page_width do | |
# pdf.text "#{index + 1}. #{question}\n\n", :style => :bold, :at=>[0, line * 10], :width=>400 | |
scale = 40 | |
pdf.text "Almost Never", :at=>[0, line * 7] | |
pdf.text "Almost Always", :at=>[scale * 9.5, line * 7], :align=>:right | |
histogram = @reg.scores_for_q(index+1).histogram | |
1.upto(10).each do |x| | |
pdf.text x.to_s, :at=>[scale * x, line * 5 ], :align=>'center' | |
if histogram[x] > 0 | |
pdf.text "|" * histogram[x], :at=>[scale * x,line * 6], :align=>'center' | |
end | |
end | |
avg = @reg.event.scores_for_q(index+1) | |
avg.sort! | |
score = @reg.score_for_q(index+1) | |
mean = avg.mean | |
#TODO(adam): Use the statis lib to compute quartile. | |
q = avg.clone | |
q.delete_if{ |e| e>=score} | |
q = ((q.size * 4) / avg.size) + 1 | |
score = "%0.1f" % score | |
mean = "%0.1f" % mean | |
pdf.text "Average score: #{mean}", :at=>[0, line*3] | |
pdf.text "Group quartile: #{q}", :at=>[350, line*3] | |
pdf.text "Self Score: #{score}", :at=>[0, line*2] | |
pdf.text "Rockwood quartile: #{q}", :at=>[350, line*2] | |
block_start -= @block_height | |
end | |
end | |
form_question = 0 | |
@text_questions.each_with_index do |question, index| | |
current_question = index | |
start_new_page(pdf, reg) | |
question = @reg.event.training.text_questions.find_by_position(index+1).for_peer | |
pdf.text "\n#{index + 1}. #{question}\n\n", :style => :bold | |
reg.evaluations.peers.each do |eval| | |
pdf.text "\n" + eval.read_text(index+1).inspect | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment