Skip to content

Instantly share code, notes, and snippets.

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 criess/0357a62e17c5115fa13a6f5b913fa001 to your computer and use it in GitHub Desktop.
Save criess/0357a62e17c5115fa13a6f5b913fa001 to your computer and use it in GitHub Desktop.
puts(
((0..9).to_a + %w[a b c d e f]).in_groups_of(4).map do |g|
AnalyticsEvent.where(context_scope: :SellingProfile).where('context_id::varchar LIKE ? OR context_id::varchar LIKE ? OR context_id::varchar LIKE ? OR context_id::varchar LIKE ?', "#{g[0]}%", "#{g[1]}%", "#{g[2]}%", "#{g[3]}%").group(:context_id).pluck(:context_id, Arel.sql('ARRAY_AGG(ARRAY[session_id::varchar,user_id::varchar])')).map do |k|
calced = Time.now
uniq_sessions = k[1].map(&:first).uniq.size
uniq_users = k[1].map(&:last).uniq.size
[uniq_sessions, "::OUT:: selling profile #{k[0]} with uniq sessions #{uniq_sessions} and uniq users #{uniq_users} (in #{'%.4f' % ((Time.now - calced) * 1000)} ms)"]
end
end.inject([], &:+).sort_by(&:first).map(&:last)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment