Class: Auth::Work::Cycle

Inherits:
Object
  • Object
show all
Includes:
Mongoid::Document
Defined in:
app/models/auth/work/cycle.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#cycle_indexObject

Returns the value of attribute cycle_index.



6
7
8
# File 'app/models/auth/work/cycle.rb', line 6

def cycle_index
  @cycle_index
end

Instance Method Details

#after_bookObject



207
208
209
210
211
212
213
214
# File 'app/models/auth/work/cycle.rb', line 207

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

#bookObject



216
217
218
# File 'app/models/auth/work/cycle.rb', line 216

def book
	after_book
end

#capacityObject

each cycle will have a limit



25
# File 'app/models/auth/work/cycle.rb', line 25

field :capacity, type: Integer, default: 0

#cycle_chainObject

the ids of the related cycles.



74
# File 'app/models/auth/work/cycle.rb', line 74

field :cycle_chain, type: Array, default: []

#cycle_typeObject

every cycle should have a type. we search based on this type.



71
# File 'app/models/auth/work/cycle.rb', line 71

field :cycle_type, type: String

#durationObject

it has a fixed duration. defined in seconds.



49
# File 'app/models/auth/work/cycle.rb', line 49

field :duration, type: Integer

#end_timeObject

unix epoch.



12
# File 'app/models/auth/work/cycle.rb', line 12

field :end_time, type: Integer

#entities_assignedObject

the entities assigned, finally.



41
# File 'app/models/auth/work/cycle.rb', line 41

field :entities_assigned, type: Array

#entities_availableObject

the available entities, these are set at the time of creating the minutes.



37
# File 'app/models/auth/work/cycle.rb', line 37

field :entities_available, type: Array

#generate_output(prev_step_output, cart_item_ids = nil) ⇒ Object

@param prev_step_output: array of output hashes @param cart_item_ids: array of cart item ids to be processed. @return output : array of output hashes. Uses the templates to generate these hashes.



85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'app/models/auth/work/cycle.rb', line 85

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

#outputObject

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?



59
# File 'app/models/auth/work/cycle.rb', line 59

field :output, type: Array, default: []

#priorityObject

it has to have a priority score



45
# File 'app/models/auth/work/cycle.rb', line 45

field :priority, type: Float

#requirements_satisfied(epoch, location_id) ⇒ Object



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
187
188
189
190
191
192
193
194
# File 'app/models/auth/work/cycle.rb', line 107

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_timeObject

unix epoch.



9
# File 'app/models/auth/work/cycle.rb', line 9

field :start_time, type: Integer

#time_since_prev_cycleObject

time to next cycle



52
# File 'app/models/auth/work/cycle.rb', line 52

field :time_since_prev_cycle, type: Integer, default: 0

#workers_assignedObject

it will have a list of workers to whom it is assigned



33
# File 'app/models/auth/work/cycle.rb', line 33

field :workers_assigned, type: Array

#workers_availableObject

there will have to be another field, saying workers who can do it, and entities who can do it.



29
# File 'app/models/auth/work/cycle.rb', line 29

field :workers_available, type: Array