Skip to content

Commit

Permalink
update seed file
Browse files Browse the repository at this point in the history
  • Loading branch information
alepbloyd committed Nov 25, 2024
1 parent c665893 commit 819f499
Showing 1 changed file with 113 additions and 85 deletions.
198 changes: 113 additions & 85 deletions db/seeds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,125 +12,153 @@

puts 'Seeding development database...'

# Create an admin user
admin =
FactoryBot.create(
:facilitator,
email: 'admin@example.com',
password: 'pjassword'
)

# Create 4 other facilitators
facilitators = []
4.times { facilitators << FactoryBot.create(:facilitator) }

current_workshop = FactoryBot.create(:current_workshop)

past_workshops = []
10.times { past_workshops << FactoryBot.create(:past_workshop) }
past_workshops_registration_required = []
5.times do
past_workshops_registration_required << FactoryBot.create(
:past_registration_workshop
)
end

future_workshops = []
10.times { future_workshops << FactoryBot.create(:future_workshop) }
past_workshops_application_required = []
5.times do
past_workshops_application_required << FactoryBot.create(
:past_application_workshop
)
end

participants = []
30.times { participants << FactoryBot.create(:participant) }
past_workshops_open = []
5.times { past_workshops_open << FactoryBot.create(:past_open_workshop) }

WorkshopFacilitator.create(
facilitator_id: admin.id,
workshop_id: current_workshop.id
)

past_workshops.each do |pw|
participants
.sample(rand(participants.count))
.each do |part|
WorkshopParticipant.create(
workshop_id: pw.id,
participant_id: part.id,
in_attendance: [true, false].sample
)
end
future_workshops_registration_required = []
5.times do
future_workshops_registration_required << FactoryBot.create(
:future_registration_workshop
)
end

facilitators
.sample(rand(facilitators.count))
.each do |fac|
WorkshopFacilitator.create(workshop_id: pw.id, facilitator_id: fac.id)
end
future_workshops_application_required = []
5.times do
future_workshops_application_required << FactoryBot.create(
:future_application_workshop
)
end

future_workshops.each do |fw|
participants
.sample(rand(participants.count))
.each do |part|
WorkshopParticipant.create(
workshop_id: fw.id,
participant_id: part.id,
in_attendance: [true, false].sample
)
end
future_workshops_open = []
5.times { future_workshops_open << FactoryBot.create(:future_open_workshop) }

# Assign two facilitators to each workshop
Workshop.all.each do |workshop|
facilitators
.sample(rand(facilitators.count))
.each do |fac|
WorkshopFacilitator.create(workshop_id: fw.id, facilitator_id: fac.id)
.sample(2)
.each do |facilitator|
WorkshopFacilitator.create(
workshop_id: workshop.id,
facilitator_id: facilitator.id
)
end
end

tracks = []
5.times { tracks << FactoryBot.create(:track) }

tracks.each do |t|
past_workshops
.sample(rand(past_workshops.count))
.each { |pw| TrackWorkshop.create(track_id: t.id, workshop_id: pw.id) }

future_workshops
.sample(rand(future_workshops.count))
.each { |fw| TrackWorkshop.create(track_id: t.id, workshop_id: fw.id) }
end

5.times { FactoryBot.create(:non_finalized_workshop) }
# Create 30 participants
participants = []
30.times { participants << FactoryBot.create(:participant) }

Workshop
.where(registration_modality: 'application_required')
.each do |workshop|
at = ApplicationTemplate.create
wat =
WorkshopApplicationTemplate.create(
application_template_id: at.id,
workshop_id: workshop.id
)
end
# Add application_templates to workshops that require an application
[
past_workshops_application_required,
future_workshops_application_required
].flatten.each do |workshop|
at = ApplicationTemplate.create

ApplicationTemplate.all.each do |at|
questions = []
2.times do
q = FactoryBot.create(:true_false_question)

ApplicationTemplateQuestion.create(
question_id: q.id,
application_template_id: at.id
)
questions << FactoryBot.create(:short_answer_question)
questions << FactoryBot.create(:long_answer_question)
questions << FactoryBot.create(:likert_question)
questions << FactoryBot.create(:true_false_question)
end
2.times do
q = FactoryBot.create(:short_answer_question)

questions.each do |q|
ApplicationTemplateQuestion.create(
question_id: q.id,
application_template_id: at.id
)
end
2.times do
q = FactoryBot.create(:long_answer_question)

ApplicationTemplateQuestion.create(
question_id: q.id,
application_template_id: at.id
wat =
WorkshopApplicationTemplate.create(
application_template_id: at.id,
workshop_id: workshop.id
)
end
2.times do
q = FactoryBot.create(:likert_question)
end

ApplicationTemplateQuestion.create(
question_id: q.id,
application_template_id: at.id
future_workshops_application_required.each do |workshop|
questions = workshop.application_templates.first.questions

participants = []
10.times { participants << FactoryBot.create(:participant) }

participants.each do |participant|
application_responses = {}
questions.each do |q|
application_responses[q.prompt] = Faker::Lorem.sentence
end
WorkshopParticipant.create(
workshop_id: workshop.id,
participant_id: participant.id,
application_status: 'pending',
application_responses: application_responses
)
end
end

# Add participants to past workshops, randomize if they are marked as in_attendance or not
# Add random selection of facilitators to past workshops
# past_workshops.each do |pw|
# participants
# .sample(rand(participants.count))
# .each do |part|
# WorkshopParticipant.create(
# workshop_id: pw.id,
# participant_id: part.id,
# in_attendance: [true, false].sample
# )
# end
# end

# Add participants to future workshops, mark as not in_attendance by default
# Add random selection of facilitators to future workshops
# future_workshops.each do |fw|
# participants
# .sample(rand(participants.count))
# .each do |part|
# WorkshopParticipant.create(
# workshop_id: fw.id,
# participant_id: part.id,
# in_attendance: false
# )
# end
# end

# future_workshops.each do |workshop|
# if workshop.registration_modality == 'application_required'
# questions = workshop.application_templates.first.questions
# workshop.workshop_participants.each do |wp|
# responses = {}
# questions.each { |q| responses[q.prompt] = Faker::Lorem.sentence }
# wp.application_responses = responses
# wp.application_status = 'pending'
# end
# end
# end

0 comments on commit 819f499

Please sign in to comment.