Skip to content

Commit

Permalink
Merge pull request #16850 from code-dot-org/randomized_survey_factories
Browse files Browse the repository at this point in the history
Randomized survey factories
  • Loading branch information
mehalshah committed Aug 4, 2017
2 parents 1310c18 + c11a7fb commit 49d3e8a
Showing 1 changed file with 46 additions and 53 deletions.
99 changes: 46 additions & 53 deletions dashboard/test/factories/pd_factories.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
enrolled_and_attending_users 0
enrolled_unattending_users 0
num_completed_surveys 0
randomized_survey_answers false
end
after(:build) do |workshop, evaluator|
# Sessions, one per day starting today
Expand Down Expand Up @@ -62,9 +63,9 @@
evaluator.num_completed_surveys.times do
enrollment = create :pd_enrollment, workshop: workshop
if workshop.teachercon?
create :pd_teachercon_survey, pd_enrollment: enrollment
create :pd_teachercon_survey, pd_enrollment: enrollment, randomized_survey_answers: evaluator.randomized_survey_answers
elsif workshop.local_summer?
create :pd_local_summer_workshop_survey, pd_enrollment: enrollment
create :pd_local_summer_workshop_survey, pd_enrollment: enrollment, randomized_survey_answers: evaluator.randomized_survey_answers
else
raise 'Num_completed_surveys trait unsupported for this workshop type'
end
Expand Down Expand Up @@ -189,13 +190,27 @@
factory :pd_teachercon_survey, class: 'Pd::TeacherconSurvey' do
association :pd_enrollment, factory: :pd_enrollment, strategy: :create

after(:build) do |survey|
transient do
randomized_survey_answers false
end

after(:build) do |survey, evaluator|
if survey.form_data.presence.nil?
enrollment = survey.pd_enrollment
workshop = enrollment.workshop

survey_hash = build :pd_teachercon_survey_hash

if evaluator.randomized_survey_answers
survey_hash.each do |k, _|
if Pd::TeacherconSurvey.options.key? k.underscore.to_sym
survey_hash[k] = Pd::TeacherconSurvey.options[k.underscore.to_sym].sample
else
survey_hash[k] = SecureRandom.hex[0..8]
end
end
end

Pd::TeacherconSurvey.facilitator_required_fields.each do |field|
survey_hash[field] = {}
end
Expand All @@ -204,10 +219,20 @@

workshop.facilitators.each do |facilitator|
Pd::TeacherconSurvey.facilitator_required_fields.each do |field|
if Pd::TeacherconSurvey.options.key? field
answers = Pd::TeacherconSurvey.options.key? field
survey_hash[field][facilitator.name] = evaluator.randomized_survey_answers ? answers.sample : answers.last
else
survey_hash[field][facilitator.name] = evaluator.randomized_survey_answers ? SecureRandom.hex[0..8] : 'Free Response'
end
survey_hash[field][facilitator.name] = 'Free response'
end
end

if Pd::TeacherconSurvey::DISAGREES.include?(survey_hash['personalLearningNeedsMet'])
survey_hash[:how_could_improve] = evaluator.randomized_survey_answers ? SecureRandom.hex[0..8] : 'Rant about how to improve things'
end

survey.update_form_data_hash(survey_hash)
end
end
Expand Down Expand Up @@ -260,53 +285,6 @@
end
end

factory :pd_teachercon_survey_randomized_hash, class: 'Hash' do
initialize_with do
{
"personalLearningNeedsMet": "Strongly Agree",
"haveIdeasAboutFormative": "Strongly Disagree",
"haveIdeasAboutSummative": "Disagree",
"haveConcreteIdeas": "Slightly Disagree",
"toolsWillHelp": "Slightly Agree",
"learnedEnoughToMoveForward": "Agree",
"feelConfidentUsingMaterials": "Strongly Agree",
"feelConfidentCanHelpStudents": "Agree",
"havePlan": "Slightly Agree",
"feelComfortableLeading": "Slightly Disagree",
"haveLessAnxiety": "Disagree",
"whatHelpedMost": "helped learn most",
"whatDetracted": "detracted",
"receivedClearCommunication": "Strongly Agree",
"venueFeedback": "venue feedback",
"knowWhereToGoForHelp": "Strongly Disagree",
"suitableForMyExperience": "Disagree",
"practicingTeachingHelped": "Slightly Disagree",
"seeingOthersTeachHelped": "Slightly Agree",
"facilitatorsPresentedInformationClearly": "Agree",
"facilitatorsProvidedFeedback": "Strongly Agree",
"feltComfortableAskingQuestions": "Agree",
"morePreparedThanBefore": "Slightly Agree",
"lookForwardToContinuing": "Slightly Disagree",
"partOfCommunity": "Disagree",
"allStudentsShouldTake": "Strongly Disagree",
"wouldRecommend": "Disagree",
"bestPdEver": "Slightly Disagree",
"howMuchParticipated": "A tremendous amount",
"howOftenLostTrackOfTime": "Almost always",
"howHappyAfter": "Extremely happy",
"howExcitedBefore": "Extremely excited",
"facilitatorsDidWell": "facilitators did well",
"facilitatorsCouldImprove": "facilitators could improve",
"likedMost": "liked most",
"wouldChange": "would change",
"givePermissionToQuote": "Yes, I give Code.org permission to quote me and use my name.",
"instructionFocus": "Strongly aligned with A",
"teacherResponsibility": "Strongly aligned with A",
"teacherTime": "Strongly aligned with A",
}.stringify_keys
end
end

factory :pd_workshop_survey_hash, class: 'Hash' do
initialize_with do
{
Expand Down Expand Up @@ -359,13 +337,27 @@
factory :pd_local_summer_workshop_survey, class: 'Pd::LocalSummerWorkshopSurvey' do
association :pd_enrollment, factory: :pd_enrollment, strategy: :create

after(:build) do |survey|
transient do
randomized_survey_answers false
end

after(:build) do |survey, evaluator|
if survey.form_data.nil?
enrollment = survey.pd_enrollment
workshop = enrollment.workshop

survey_hash = build :pd_local_summer_workshop_survey_hash

if evaluator.randomized_survey_answers
survey_hash.each do |k, _|
if Pd::LocalSummerWorkshopSurvey.options.key? k.underscore.to_sym
survey_hash[k] = Pd::LocalSummerWorkshopSurvey.options[k.underscore.to_sym].sample
else
survey_hash[k] = SecureRandom.hex[0..8]
end
end
end

Pd::LocalSummerWorkshopSurvey.facilitator_required_fields.each do |field|
survey_hash[field] = {}
end
Expand All @@ -375,9 +367,10 @@
workshop.facilitators.each do |facilitator|
Pd::LocalSummerWorkshopSurvey.facilitator_required_fields.each do |field|
if Pd::LocalSummerWorkshopSurvey.options.key? field
survey_hash[field][facilitator.name] = Pd::LocalSummerWorkshopSurvey.options[field].last
answers = Pd::LocalSummerWorkshopSurvey.options[field]
survey_hash[field][facilitator.name] = evaluator.randomized_survey_answers ? answers.sample : answers.last
else
survey_hash[field][facilitator.name] = 'Free Response'
survey_hash[field][facilitator.name] = evaluator.randomized_survey_answers ? SecureRandom.hex[0..8] : 'Free Response'
end
end
end
Expand Down

0 comments on commit 49d3e8a

Please sign in to comment.