Created
August 13, 2009 11:03
-
-
Save iMagesh/167105 to your computer and use it in GitHub Desktop.
this is my first ruby script..for rake tasks.. used to populate the database with the students textbook info
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace :sp do | |
authors = %w/Magesh Bala Vikram Abraham Imran Satish Harish Varun Jayamohan Ramesh Raghuvamsan Yogesh Yuvaraja Ranjith Kavitha Safia Surya Priya Shalini Priyanka/ | |
publishers = ["Tamil Nadu TextBook Corporation"] | |
al = authors.length | |
pl = publishers.length | |
task :textbooks => :environment do | |
TextBook.delete_all | |
Lesson.delete_all | |
PrescribedText.delete_all | |
courses = Course.find :all, :conditions => ["grade_level = 12"] | |
puts "Wait..Creating Text Books now.." | |
courses.each do |course| | |
if(course.name =="I" && course.parent.name == "English") | |
tb = TextBook.new(:title => "English Reader", :authors => authors[rand(al)], :publisher => publishers[rand(pl)], :subject =>"#{course.parent.name} #{course.name}", :grade_level => 12) | |
tb.save! | |
else if(course.name =="II" && course.parent.name == "English") | |
tb = TextBook.new(:title => "Communicative English", :authors => authors[rand(al)], :publisher => publishers[rand(pl)], :subject => "#{course.parent.name} #{course.name}", :grade_level => 12) | |
tb.save! | |
end | |
end | |
if(course.name =="I" && course.parent.name == "Mathematics") | |
tb = TextBook.new(:title => "Mathematics-1", :authors => authors[rand(al)], :publisher => publishers[rand(pl)], :subject => "#{course.parent.name} #{course.name}", :grade_level => course.grade_level) | |
tb.save! | |
else if(course.name =="II" && course.parent.name =="Mathematics") | |
tb = TextBook.new(:title => "Mathematics-2", :authors => authors[rand(al)], :publisher => publishers[rand(pl)], :subject => course.name, :grade_level => course.grade_level) | |
tb.save! | |
end | |
end | |
if(course.name == "Physics") | |
tb = TextBook.new(:title => "Physics-Volume 1 & 2", :authors => authors[rand(al)], :publisher => publishers[rand(pl)], :subject => course.name, :grade_level => course.grade_level) | |
tb.save! | |
end | |
if(course.name == "Chemistry") | |
tb = TextBook.new(:title => "Chemistry-Volume 1 & 2", :authors => authors[rand(al)], :publisher => publishers[rand(pl)], :subject => course.name, :grade_level => course.grade_level) | |
tb.save! | |
end | |
if(course.name == "Accountancy") | |
tb = TextBook.new(:title => "Accountancy-Volume 1 & 2", :authors => authors[rand(al)], :publisher => publishers[rand(pl)], :subject => course.name, :grade_level => course.grade_level) | |
tb.save! | |
end | |
end | |
textbooks = TextBook.all | |
count = textbooks.size | |
puts "Created #{count} Textbooks.." | |
textbooks.each do |t| | |
10.times do |l| | |
lesson = Lesson.new(:title => "Chapter #{l+1}",:text_book_id => t.id, :sord => l, :time_slots => 10 + rand(20)) | |
lesson.save! | |
puts "Chapter #{l+1} for Textbook #{t.title} added" | |
end | |
end | |
#textbooks = TextBook.all | |
schoolyr = SchoolYear.all | |
schoolyr.each do |syr| | |
courses.each do |course| | |
# if(course.name == 'English' || course.name == 'Accountancy' || course.name == 'Chemistry' || course.name == 'Computer Science' || course.name == 'Mathematics' || course.name == 'Physics') | |
if(course.parent_id != nil) | |
#2.times do |t| | |
ptext = PrescribedText.new | |
ptext.school_year = syr | |
ptext.course = course | |
textbooks.each do |textbook| | |
if(textbook.subject == "#{course.parent.name} #{course.name}") | |
ptext.text_book = textbook | |
puts " Creating Prescribed TextBooks for #{syr.academic_year}" | |
else | |
end | |
ptext.save! | |
end | |
else | |
#1.times do |t| | |
ptext = PrescribedText.new | |
ptext.school_year = syr | |
ptext.course = course | |
textbooks.each do |textbook| | |
if(textbook.subject == course.name) | |
ptext.text_book = textbook | |
else | |
end | |
ptext.save! | |
end | |
end | |
end | |
end | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment