Skip to content

Instantly share code, notes, and snippets.

@ijunaid8989
Last active May 30, 2016 11:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ijunaid8989/ec180dd96f46604ba07c46fcc175758c to your computer and use it in GitHub Desktop.
Save ijunaid8989/ec180dd96f46604ba07c46fcc175758c to your computer and use it in GitHub Desktop.
params[:id].downcase!
camera = get_cam(params[:id])
if params[:from].present? and params[:to].present? and params[:from].to_i > params[:to].to_i
raise(BadRequestError, "From can't be higher than to")
end
from = Time.at(params[:from].to_i).to_s || 0
to = Time.at(params[:to].to_i).to_s
to = Time.now.to_s if params[:to].blank?
limit = params[:limit] || DEFAULT_LIMIT
page = params[:page] || 0
page = 0 if page < 0
limit = DEFAULT_LIMIT if limit < 1
types = params[:types].split(',').map(&:strip)
results = CameraActivity.where(camera_id: camera.id).filter(:done_at => (from..to)).reverse_order(:done_at)
results = results.where(:action => types) unless types.blank?
total_pages = results.count / limit
results = results.limit(limit, page * limit).all
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment