Module: Auth::Concerns::Shopping::ProductConcern::ClassMethods

Defined in:
app/models/auth/concerns/shopping/product_concern.rb

Instance Method Summary collapse

Instance Method Details

#add_to_previous_rolling_n_minutes(minutes, origin_epoch, cycle_to_add) ⇒ Object

so we have completed the rolling n minutes.



121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# File 'app/models/auth/concerns/shopping/product_concern.rb', line 121

def add_to_previous_rolling_n_minutes(minutes,origin_epoch,cycle_to_add)

  ## get all the minutes less than that.
  rolling_n_minutes_less_than_that = minutes.keys.select{|c| c < origin_epoch}     

  end_min = rolling_n_minutes_less_than_that.size < Auth.configuration.rolling_minutes ? rolling_n_minutes_less_than_that.size : Auth.configuration.rolling_minutes

  end_min = end_min - 1

  end_min = end_min > 0 ? end_min : 0
  rolling_n_minutes_less_than_that[0..end_min].each do |epoch|
    minutes[epoch].cycles << cycle_to_add
  end

end

#schedule_cycles(minutes, location_id, conditions = {}) ⇒ Object

minutes : => minute object



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/concerns/shopping/product_concern.rb', line 138

def schedule_cycles(minutes,location_id,conditions = {})

  products = Auth.configuration.product_class.constantize.all if conditions.blank?

  products = Auth.configuration.product_class.constantize.where(conditions) if !conditions.blank?

  minutes.keys.each do |epoch|
    
    products.each do |product|
    
      all_cycles_valid = true
      product.cycles.each do |cycle|
    
        all_cycles_valid = cycle.requirements_satisfied(epoch + cycle.time_since_prev_cycle.minutes*60,location_id)
            
      end

      ## just because the cycles are valid, it means we have workers, but how many?
      ## that also has to be returned by the cycle validity statements

      if all_cycles_valid == true
        cycle_chain = []
        product.cycles.each do |cycle|
          epoch_at_which_to_add = epoch + cycle.time_since_prev_cycle.minutes*60
          cycle_to_add = cycle.dup
          cycle_to_add.origin_epoch = epoch_at_which_to_add
          cycle_to_add.cycle_chain = cycle_chain
          if minutes[epoch_at_which_to_add]
            
            add_to_previous_rolling_n_minutes(minutes,epoch_at_which_to_add,cycle_to_add)

            minutes[epoch_at_which_to_add].cycles << cycle_to_add

            cycle_chain << cycle_to_add.id.to_s
          else
            #raise "necessary minute not in range."
          end
        end
      end
    end
  end
  minutes
end