Refactor Poll Officer Assignment creation into Poll Shift creation section

This commit is contained in:
Bertocq
2017-11-09 13:05:47 +01:00
parent 896f91e249
commit af460b3eea

View File

@@ -587,32 +587,25 @@ section "Creating Poll Booths & BoothAssignments" do
end
end
# section "Creating Poll Officer Assignments" do
# (1..15).to_a.sample.times do |i|
# Poll::BoothAssignment.all.sample(i).each do |booth_assignment|
# Poll::OfficerAssignment.create(officer: poll_officer.poll_officer,
# booth_assignment: booth_assignment,
# date: booth_assignment.poll.starts_at)
# end
# end
# end
section "Creating Poll Shifts for Poll Officers" do
Poll::BoothAssignment.all.each do |booth_assignment|
# TODO: Create vote_collection on correct date ranges
Poll::Shift.create(booth_id: booth_assignment.booth_id,
officer: Poll::Officer.first,
date: Date.current,
officer_name: Poll::Officer.first.name,
officer_email: Poll::Officer.first.email,
task: :vote_collection)
# TODO: Create recount_scrutiny shifts on correct date ranges
# Poll::Shift.create(booth_id: booth_assignment.booth_id,
# officer_id: poll_officer.poll_officer.id,
# date: Date.current,
# officer_name: poll_officer.poll_officer.name,
# officer_email: poll_officer.poll_officer.email,
# task: 1)
Poll.all.each do |poll|
Poll::BoothAssignment.where(poll: poll).each do |booth_assignment|
Poll::Officer.all.each do |poll_officer|
{
vote_collection: (poll.starts_at.to_datetime..poll.ends_at.to_datetime),
recount_scrutiny: (poll.ends_at.to_datetime..poll.ends_at.to_datetime + Poll::RECOUNT_DURATION)
}.each do |task_name, task_dates|
task_dates.each do |shift_date|
Poll::Shift.create(booth: booth_assignment.booth,
officer: poll_officer,
date: shift_date,
officer_name: poll_officer.name,
officer_email: poll_officer.email,
task: task_name)
end
end
end
end
end
end