Skip to content

Instantly share code, notes, and snippets.

@faizaankhan
Created July 30, 2018 08:39
Show Gist options
  • Save faizaankhan/73a11956c8e350aefb6123edc8e19d51 to your computer and use it in GitHub Desktop.
Save faizaankhan/73a11956c8e350aefb6123edc8e19d51 to your computer and use it in GitHub Desktop.
require 'faker'
qp = QuestionPaper.new
qp.name = "QP-Test-React-Exam"
qp.save
4.times do
s = qp.sections.new
s.name = Faker::GameOfThrones.city
s.save
c = Category.new
c.name = Faker::GameOfThrones.house
c.description = Faker::Lorem.paragraph(2)
c.save
60.times do
q = Question.new
q.category_id = c.id
q.text = Faker::GameOfThrones.quote
q.save
4.times do
a = q.answers.new
a.text = Faker::GameOfThrones.character
a.correct_answer = false
a.save
end
q.answers.last.update_attribute(:correct_answer, true)
qpq = qp.question_papers_questions.new
qpq.question_id = q.id
qpq.section_id = s.id
qpq.save
end
end
@faizaankhan
Copy link
Author

faizaankhan commented Aug 10, 2018

require 'faker'
x = 1
70.times do
  c = Candidate.new
  c.name = Faker::GameOfThrones.character
  c.email = Faker::Internet.email
  c.created_at = Time.zone.today - x.hours
  x = x + 1
  c.save
end

qp.save
4.times do
s = qp.sections.new
s.name = Faker::GameOfThrones.city
s.save

c = Category.new
c.name = Faker::GameOfThrones.house
c.description = Faker::Lorem.paragraph(2)
c.save

60.times do
q = Question.new
q.category_id = c.id
q.text = Faker::GameOfThrones.quote
q.save

4.times do
  a = q.answers.new
  a.text = Faker::GameOfThrones.character
  a.correct_answer = false
  a.save
end

q.answers.last.update_attribute(:correct_answer, true)

qpq = qp.question_papers_questions.new
qpq.question_id = q.id
qpq.section_id = s.id
qpq.save

end
end

@faizaankhan
Copy link
Author

faizaankhan commented Aug 10, 2018

require 'csv'
file = "#{Rails.root}/public/data.csv"
CSV.open( file, 'w') do | csv |
 csv << ["Sl No", "Name", "Email Id"]
 Candidate.where(created_at:  Date.new(2018,8,7)..Time.zone.today).find_each(:batch_size => 500).with_index do |candidate, index|
   csv << [index + 1, candidate.name, candidate.email]
 end
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment