Skip to content

Commit

Permalink
Hourly bins for the user agent data
Browse files Browse the repository at this point in the history
  • Loading branch information
ujh committed Jan 7, 2025
1 parent 2396389 commit ccab06b
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions app/controllers/admins/graphs_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,14 @@ def user_agents
data:
base_relation
.where(name: name)
.group(:day)
.order(day: :asc)
.pluck(Arel.sql("day, count(*)"))
.map { |d| [d.first.to_datetime.to_i * 1000, d.last] }
.group("date_trunc('hour', created_at)")
.order("hour asc")
.pluck(
Arel.sql(
"date_trunc('hour', created_at) as hour, count(*) as hour_count"
)
)
.map { |d| [d.first.to_i * 1000, d.last] }
}
end
.reject { |data| data[:data].map(&:last).all? { |count| count < 10 } }
Expand Down

0 comments on commit ccab06b

Please sign in to comment.