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
Returns the value of attribute cycle_index.
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.
-
#end_time ⇒ Object
unix epoch.
-
#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
-
#start_time ⇒ Object
unix epoch.
-
#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
Returns the value of attribute cycle_index.
5 6 7 |
# File 'app/models/auth/work/cycle.rb', line 5 def cycle_index @cycle_index end |
Instance Method Details
#after_book ⇒ Object
199 200 201 202 203 204 205 206 |
# File 'app/models/auth/work/cycle.rb', line 199 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
208 209 210 |
# File 'app/models/auth/work/cycle.rb', line 208 def book after_book end |
#capacity ⇒ Object
each cycle will have a limit
22 |
# File 'app/models/auth/work/cycle.rb', line 22 field :capacity, type: Integer, default: 0 |
#cycle_chain ⇒ Object
the ids of the related cycles.
66 |
# File 'app/models/auth/work/cycle.rb', line 66 field :cycle_chain, type: Array, default: [] |
#duration ⇒ Object
it has a fixed duration. defined in seconds.
45 |
# File 'app/models/auth/work/cycle.rb', line 45 field :duration, type: Integer |
#end_time ⇒ Object
unix epoch.
11 |
# File 'app/models/auth/work/cycle.rb', line 11 field :end_time, type: Integer |
#entities_assigned ⇒ Object
the entities assigned, finally.
37 |
# File 'app/models/auth/work/cycle.rb', line 37 field :entities_assigned, type: Array |
#entities_available ⇒ Object
the available entities, these are set at the time of creating the minutes.
33 |
# File 'app/models/auth/work/cycle.rb', line 33 field :entities_available, type: Array |
#generate_output(prev_step_output, cart_item_ids = nil) ⇒ Object
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'app/models/auth/work/cycle.rb', line 77 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?
55 |
# File 'app/models/auth/work/cycle.rb', line 55 field :output, type: Array, default: [] |
#priority ⇒ Object
it has to have a priority score
41 |
# File 'app/models/auth/work/cycle.rb', line 41 field :priority, type: Float |
#requirements_satisfied(epoch, location_id) ⇒ Object
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 181 182 183 184 185 186 |
# File 'app/models/auth/work/cycle.rb', line 99 def requirements_satisfied(epoch,location_id) 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) ## the object should also carry its own type as well. 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 |
#start_time ⇒ Object
unix epoch.
8 |
# File 'app/models/auth/work/cycle.rb', line 8 field :start_time, type: Integer |
#time_since_prev_cycle ⇒ Object
time to next cycle
48 |
# File 'app/models/auth/work/cycle.rb', line 48 field :time_since_prev_cycle, type: Integer, default: 0 |
#workers_assigned ⇒ Object
it will have a list of workers to whom it is assigned
29 |
# File 'app/models/auth/work/cycle.rb', line 29 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.
25 |
# File 'app/models/auth/work/cycle.rb', line 25 field :workers_available, type: Array |