Skip to content
Browse files

added priority steps

  • Loading branch information...
1 parent 62de008 commit dabfc7e6cdca1fb50a9b3e3bc9ec0b0b84c41d7b @munya committed
View
14 app/models/cell.rb
@@ -1,4 +1,7 @@
-class Cell < ActiveRecord::Base
+class Cell < ActiveRecord::Base
+ PRIORITY = [1, 10, 100]
+ DEEP = 2 #max value could be 9
+
belongs_to :group_reader_subject
belongs_to :lesson
belongs_to :classroom
@@ -11,10 +14,11 @@ def start
@cells << cell
end
- #select all data
- # minutes - most important subject for this group
- #than reader has a priority
- grs = GroupReaderSubject.joins(:group, :reader, :subject).order('minutes desc, readers.ravity desc')
+ #select all data
+ (0..1).each do |step|
+ # step priority will be different every select
+ grs = GroupReaderSubject.joins(:group, :reader, :subject).order('priority desc, minutes desc, readers.ravity desc').sort_by{|grs| -grs.step_priority}
+ end
end
def take_next
View
16 app/models/group_reader_subject.rb
@@ -3,11 +3,15 @@ class GroupReaderSubject < ActiveRecord::Base
belongs_to :reader
belongs_to :subject
- attr_accessible :group, :reader, :subject, :minutes
- attr_accessor :hours
+ attr_accessible :group, :reader, :subject, :minutes, :priority
+ attr_accessor :hours, :step_priority
+
- after_initialize do
- hours = minutes / 80
- end
-
+ after_initialize :setup_deep_values
+
+ private
+ def setup_deep_values
+ @hours = self.minutes / 80
+ @step_priority = priority * (rand(Cell::DEEP)+1)
+ end
end
View
1 db/migrate/20130112134917_create_group_reader_subjects.rb
@@ -5,6 +5,7 @@ def change
t.references :reader
t.references :subject
t.integer :minutes
+ t.integer :priority
t.timestamps
end
add_index :group_reader_subjects, :group_id
View
1 db/schema.rb
@@ -37,6 +37,7 @@
t.integer "reader_id"
t.integer "subject_id"
t.integer "minutes"
+ t.integer "priority"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
View
6 db/seeds.rb
@@ -4,7 +4,7 @@
# Examples:
#
# cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }])
-# Mayor.create(name: 'Emanuel', city: cities.first)
+# Mayor.create(name: 'Emanuel', city: cities.first)
(1..10).each do |i|
Reader.create(name: Faker::Name.name, ravity: rand(10))
@@ -22,12 +22,12 @@
{week_num: week_num, start_time: "16:00", end_time: "17:20"}])
end
-minutes = (1..24).map{|i| i*80*(rand(3)+1)}
+minutes = (1..24).map{|i| i*80*(rand(3)+1)} #max 3 times per week durring 24 weeks
(1..10).each do |i|
reader = Reader.find(i)
subject = Subject.find(i)
group = Group.find(i)
- GroupReaderSubject.create(reader: reader, group: group, subject: subject, minutes: minutes[rand(23)+1])
+ GroupReaderSubject.create(reader: reader, group: group, subject: subject, minutes: minutes[rand(23)+1], priority: Cell::PRIORITY[rand(3)])
end

0 comments on commit dabfc7e

Please sign in to comment.
Something went wrong with that request. Please try again.