Created
July 6, 2022 16:48
-
-
Save criess/0357a62e17c5115fa13a6f5b913fa001 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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