Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more speaker related charts in analytics #267

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions app/controllers/analytics/dashboards_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,47 @@ def yearly_talks
Talk.group_by_year(:date).count.map { |date, count| [date.year, count] }
end
end

def speaking_experience
@speaking_experience = Rails.cache.fetch(["speaking_experience", Talk.all]) do
Talk
.joins(:speakers)
.group("speakers.id")
.select("speakers.id, MIN(talks.date) AS first_talk_date")
.group_by { |talk| (Date.today - talk.first_talk_date.to_date).to_i / 365 }
.transform_keys { |years| "#{years} #{"year".pluralize(years)} of experience" }
.transform_values(&:count)
.sort_by { |years, _count| years.to_i }
end
end

def yearly_first_time_speakers
@yearly_first_time_speakers = Rails.cache.fetch(["yearly_first_time_speakers", Talk.all]) do
Talk
.joins(:speakers)
.group("speakers.id")
.select("MIN(talks.date) AS first_talk_date")
.group_by { |talk| Date.parse(talk.first_talk_date).year }
.transform_values(&:count)
end
end

def yearly_speakers
@yearly_speakers = Rails.cache.fetch(["yearly_speakers", Talk.all]) do
Talk
.joins(:speakers)
.group("strftime('%Y', talks.date)")
.count
end
end

def yearly_unique_speakers
@yearly_unique_speakers = Rails.cache.fetch(["yearly_unique_speakers", Talk.all]) do
Talk
.joins(:speakers)
.group("strftime('%Y', talks.date)")
.distinct
.count("speakers.id")
end
end
end
8 changes: 8 additions & 0 deletions app/views/analytics/dashboards/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,16 @@
<div class="grid grid-cols-1 lg:grid-cols-2 gap-8">
<%= turbo_frame_tag "daily_visits", src: daily_visits_analytics_dashboards_path, lazy: true %>
<%= turbo_frame_tag "daily_page_views", src: daily_page_views_analytics_dashboards_path, lazy: true %>

<%= turbo_frame_tag "monthly_visits", src: monthly_visits_analytics_dashboards_path, lazy: true %>
<%= turbo_frame_tag "monthly_page_views", src: monthly_page_views_analytics_dashboards_path, lazy: true %>

<%= turbo_frame_tag "yearly_talks", src: yearly_talks_analytics_dashboards_path, lazy: true %>
<%= turbo_frame_tag "yearly_speakers", src: yearly_speakers_analytics_dashboards_path, lazy: true %>

<%= turbo_frame_tag "yearly_first_time_speakers", src: yearly_first_time_speakers_analytics_dashboards_path, lazy: true %>
<%= turbo_frame_tag "yearly_unique_speakers", src: yearly_unique_speakers_analytics_dashboards_path, lazy: true %>

<%= turbo_frame_tag "speaking_experience", src: speaking_experience_analytics_dashboards_path, lazy: true %>
</div>
</div>
4 changes: 4 additions & 0 deletions app/views/analytics/dashboards/speaking_experience.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<%= turbo_frame_tag "speaking_experience" do %>
<h2 class="text-center mb-4">Years of speaking experience when giving the talk</h2>
<%= column_chart @speaking_experience, id: :speaking_experience_chart %>
<% end %>
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<%= turbo_frame_tag "yearly_first_time_speakers" do %>
<h2 class="text-center mb-4">Yearly first time speakers at Ruby Conferences</h2>
<%= column_chart @yearly_first_time_speakers, id: :yearly_first_time_speakers_chart %>
<% end %>
4 changes: 4 additions & 0 deletions app/views/analytics/dashboards/yearly_speakers.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<%= turbo_frame_tag "yearly_speakers" do %>
<h2 class="text-center mb-4">Yearly speakers at Ruby Conferences</h2>
<%= column_chart @yearly_speakers, id: :yearly_speakers_chart %>
<% end %>
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<%= turbo_frame_tag "yearly_unique_speakers" do %>
<h2 class="text-center mb-4">Yearly unique speakers at Ruby Conferences</h2>
<%= column_chart @yearly_unique_speakers, id: :yearly_unique_speakers_chart %>
<% end %>
4 changes: 4 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@
get :monthly_page_views
get :monthly_visits
get :yearly_talks
get :yearly_speakers
get :yearly_unique_speakers
get :yearly_first_time_speakers
get :speaking_experience
end
end
resources :talks, param: :slug, only: [:index, :show, :update, :edit] do
Expand Down