Class: Auth::Work::Cycle
- Inherits:
-
Object
- Object
- Auth::Work::Cycle
- Includes:
- Mongoid::Document
- Defined in:
- app/models/auth/work/cycle.rb
Instance Attribute Summary collapse
-
#cycle_index ⇒ Object
for aggs.
Instance Method Summary collapse
- #after_book ⇒ Object
- #book ⇒ Object
-
#capacity ⇒ Object
each cycle will have a limit.
-
#cycle_chain ⇒ Object
the ids of the related cycles.
-
#duration ⇒ Object
it has a fixed duration.
-
#entities_assigned ⇒ Object
the entities assigned, finally.
-
#entities_available ⇒ Object
the available entities, these are set at the time of creating the minutes.
- #generate_output(prev_step_output, cart_item_ids = nil) ⇒ Object
-
#output ⇒ Object
to process one product.
-
#priority ⇒ Object
it has to have a priority score.
- #requirements_satisfied(epoch, location_id) ⇒ Object
-
#time_since_prev_cycle ⇒ Object
time to next cycle.
-
#workers_assigned ⇒ Object
it will have a list of workers to whom it is assigned.
-
#workers_available ⇒ Object
there will have to be another field, saying workers who can do it, and entities who can do it.
Instance Attribute Details
#cycle_index ⇒ Object
for aggs.
6 7 8 |
# File 'app/models/auth/work/cycle.rb', line 6 def cycle_index @cycle_index end |
Instance Method Details
#after_book ⇒ Object
193 194 195 196 197 198 199 200 |
# File 'app/models/auth/work/cycle.rb', line 193 def after_book Auth::Work::Minute.get_affected_minutes(self.start_time,self.end_time,self.workers_assigned,self.entities_assigned).each do |minute| ## each cycle has its index as cycle_index ## this is used to update the cycles. end end |
#book ⇒ Object
202 203 204 |
# File 'app/models/auth/work/cycle.rb', line 202 def book after_book end |
#capacity ⇒ Object
each cycle will have a limit
17 |
# File 'app/models/auth/work/cycle.rb', line 17 field :capacity, type: Integer, default: 0 |
#cycle_chain ⇒ Object
the ids of the related cycles.
60 |
# File 'app/models/auth/work/cycle.rb', line 60 field :cycle_chain, type: Array |
#duration ⇒ Object
it has a fixed duration.
39 |
# File 'app/models/auth/work/cycle.rb', line 39 field :duration, type: Integer |
#entities_assigned ⇒ Object
the entities assigned, finally.
32 |
# File 'app/models/auth/work/cycle.rb', line 32 field :entities_assigned, type: Array |
#entities_available ⇒ Object
the available entities, these are set at the time of creating the minutes.
28 |
# File 'app/models/auth/work/cycle.rb', line 28 field :entities_available, type: Array |
#generate_output(prev_step_output, cart_item_ids = nil) ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'app/models/auth/work/cycle.rb', line 70 def generate_output(prev_step_output,cart_item_ids=nil) if cart_item_ids.nil? prev_step_output.each do |cart_item_output| end else cart_item_ids.each do |cid| output_hash = {} ## each template is for one product id. ## and inside summate it can crosses the individual products to do the summation. self.templates.each_with_index {|template,key| if template.summate template.summate_items(key,output_hash) else template.add_item_to_output_hash(key,output_hash) end } self.output << output_hash end end end |
#output ⇒ Object
to process one product. how does the multiple work? how many to pass into the product crawl calculation, is it directly linear, or do we have a specific function?
49 |
# File 'app/models/auth/work/cycle.rb', line 49 field :output, type: Array, default: [] |
#priority ⇒ Object
it has to have a priority score
36 |
# File 'app/models/auth/work/cycle.rb', line 36 field :priority, type: Float |
#requirements_satisfied(epoch, location_id) ⇒ Object
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 |
# File 'app/models/auth/work/cycle.rb', line 92 def requirements_satisfied(epoch,location_id) #puts "came to requirements satisfied" Auth.configuration.location_class.constantize.all.each do |l| puts l.attributes.to_s end location = Auth.configuration.location_class.constantize.find(location_id) #puts "location found :#{location}" #puts "epoch : #{epoch}, and location id: #{location_id}" time_for_query = Time.at(epoch) applicable_schedules = Auth::Work::Schedule.collection.find({ "$and" => [ { "location_id" => location_id }, { "start_time" => { "$lte" => time_for_query } }, { "end_time" => { "$gte" => time_for_query } } ] }) #puts "applicable schedules:" #puts applicable_schedules.to_s applicable_schedules = applicable_schedules.to_a return false if (applicable_schedules.blank? || applicable_schedules.size == 0) #puts "there are applicable schedules" req = self.requirements.deep_dup #puts "req are:" #puts req.to_s applicable_schedules.map!{|c| c = Mongoid::Factory.from_db(Auth::Work::Schedule,c)} ## here basically suppose you have n applicable schedules. ## you need to combine them into cycle categories and see how many combinations you get out of it. available_resources = {} applicable_schedules.each do |schedule| schedule_for_object = schedule.for_object_class.constantize.find(schedule.for_object_id) schedule_for_object.cycle_types.keys.each do |type| #req[type] = req[type] - 1 if req[type] available_resources[type] = 0 unless available_resources[type] available_resources[type]+=1 end end ## now we have certain type counts necessary for this cycle. ## now how to return the available capacity. #k = req.values.uniq #return true if ((k[0] == 0) && (k.size == 1)) #return false ## so how to split into multiples ? ## just do it sequentially. failed = false while failed == false self.requirements.keys.each do |req| failed = true unless available_resources[req] break unless available_resources[req] failed = true if available_resources[req] < self.requirements[req] break if available_resources[req] < self.requirements[req] available_resources[req] -= self.requirements[req] end self.capacity+=1 if failed == false end ## now this becomes the cycle capacity. ## but only for the origin minute. return self.capacity > 0 end |
#time_since_prev_cycle ⇒ Object
time to next cycle
42 |
# File 'app/models/auth/work/cycle.rb', line 42 field :time_since_prev_cycle, type: Integer, default: 0 |
#workers_assigned ⇒ Object
it will have a list of workers to whom it is assigned
24 |
# File 'app/models/auth/work/cycle.rb', line 24 field :workers_assigned, type: Array |
#workers_available ⇒ Object
there will have to be another field, saying workers who can do it, and entities who can do it.
20 |
# File 'app/models/auth/work/cycle.rb', line 20 field :workers_available, type: Array |