db/seeds.rb
# load test data
# - mark district/precinct as having protocol
# - add to queue for users (is finished)
# - add to crowd data (set is valid)
# - if both users and valid, then add to raw table
load test data
mark district/precinct as having protocol
add to queue for users (is finished)
add to crowd data (set is valid)
if both users and valid, then add to raw table
load test data mark district / precinct as having protocol add to queue for users ( is finished ) add to crowd data ( set is valid ) if both users and valid then add to raw table
def load_crowd_data(election_id, csv_data, party_ids, u1, u2)
  csv_data.each_with_index do |row, i|
    if i > 0
      district_precinct = DistrictPrecinct.by_ids(election_id, row[1], row[3]).first
      if district_precinct.nil?
        puts "!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
        puts "ROW #{i+1} - THE DISTRICT/PRECINCT COULD NOT BE FOUND FOR THIS ELECTION"
        puts "!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
        return
      end
      district_precinct.has_protocol = true
      district_precinct.save
      if row[-2].present?
        cq = CrowdQueue.new(election_id: election_id, district_id: row[1], precinct_id: row[3], is_finished: true)
        cd = CrowdDatum.new(election_id: election_id, district_id: row[1], precinct_id: row[3],
            possible_voters: row[5],
            special_voters: row[6],
            votes_by_1200: row[7],
            votes_by_1700: row[8],
            ballots_signed_for: row[9],
            ballots_available: row[10],
            invalid_ballots_submitted: row[11]
        )
        party_ids.each_with_index do |party_id, i|
          cd["party_#{party_id}"] = row[19+i]
        end
        is_valid = row[-1] == '1' ? true : row[-1] == '0' ? false : nil
        if row[-2].include?(',')
          cq1 = cq.dup
          cq2 = cq.dup
          cq1.user_id = u1.id
          cq2.user_id = u2.id
          cq1.save
          cq2.save
          cd1 = cd.dup
          cd2 = cd.dup
          cd1.user_id = u1.id
          cd2.user_id = u2.id
          cd1.save
          cd2.save
          district_precinct.is_validated = true
          district_precinct.save
        elsif row[-2] == '1'
          cq1 = cq.dup
          cq1.user_id = u1.id
          cq1.save
          cd1 = cd.dup
          cd1.user_id = u1.id
          cd1.save
        elsif row[-2] == '2'
          cq2 = cq.dup
          cq2.user_id = u2.id
          cq2.save
          cd2 = cd.dup
          cd2.user_id = u2.id
          cd2.save
        end
      end
    end
  end
end
def load_crowd_data ( election_id , csv_data , party_ids , u1 , u2 ) csv_data . each_with_index do | row , i | if i > 0 district_precinct = DistrictPrecinct . by_ids ( election_id , row [ 1 ] , row [ 3 ] ) . first if district_precinct . nil? puts "!!!!!!!!!!!!!!!!!!!!!!!!!!!!" puts "ROW #{i+1} - THE DISTRICT/PRECINCT COULD NOT BE FOUND FOR THIS ELECTION" puts "!!!!!!!!!!!!!!!!!!!!!!!!!!!!" return end district_precinct . has_protocol = true district_precinct . save if row [ - 2 ] . present? cq = CrowdQueue . new ( election_id : election_id , district_id : row [ 1 ] , precinct_id : row [ 3 ] , is_finished : true ) cd = CrowdDatum . new ( election_id : election_id , district_id : row [ 1 ] , precinct_id : row [ 3 ] , possible_voters : row [ 5 ] , special_voters : row [ 6 ] , votes_by_1200 : row [ 7 ] , votes_by_1700 : row [ 8 ] , ballots_signed_for : row [ 9 ] , ballots_available : row [ 10 ] , invalid_ballots_submitted : row [ 11 ] ) party_ids . each_with_index do | party_id , i | cd [ "party_#{party_id}" ] = row [ 19 + i ] end is_valid = row [ - 1 ] == '1' ? true : row [ - 1 ] == '0' ? false : nil if row [ - 2 ] . include? ( ',' ) cq1 = cq . dup cq2 = cq . dup cq1 . user_id = u1 . id cq2 . user_id = u2 . id cq1 . save cq2 . save cd1 = cd . dup cd2 = cd . dup cd1 . user_id = u1 . id cd2 . user_id = u2 . id cd1 . save cd2 . save district_precinct . is_validated = true district_precinct . save elsif row [ - 2 ] == '1' cq1 = cq . dup cq1 . user_id = u1 . id cq1 . save cd1 = cd . dup cd1 . user_id = u1 . id cd1 . save elsif row [ - 2 ] == '2' cq2 = cq . dup cq2 . user_id = u2 . id cq2 . save cd2 = cd . dup cd2 . user_id = u2 . id cd2 . save end end end end end
load test data
 mark district/precinct as having protocol
 add to queue for users (is finished)
 add to crowd data (set is valid)
 if both users and valid, then add to raw table
load test data mark district / precinct as having protocol add to queue for users ( is finished ) add to crowd data ( set is valid ) if both users and valid then add to raw table
# indicate district/precinct has protocol # add to queue of users if have users assigned # both users # user 1 # user 2
election_id
csv_data
party_ids
u1
u2