diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css index ef8af6a..ae6c6e3 100644 --- a/app/assets/stylesheets/application.css +++ b/app/assets/stylesheets/application.css @@ -3589,7 +3589,7 @@ hr { .report-bar-row { display: grid; - grid-template-columns: minmax(8rem, 1fr) 2fr auto; + grid-template-columns: 11rem 1fr 5.5rem; gap: 1rem; align-items: center; } @@ -3624,6 +3624,7 @@ hr { color: #0C2866; font-size: 0.9375rem; white-space: nowrap; + text-align: right; } .report-bar-row__count { diff --git a/app/models/embassy_application.rb b/app/models/embassy_application.rb index 951c40b..ddc3869 100644 --- a/app/models/embassy_application.rb +++ b/app/models/embassy_application.rb @@ -11,6 +11,7 @@ class EmbassyApplication < ApplicationRecord validate :required_questions_answered, on: :submit before_validation :assign_serial, on: :create + after_update_commit :bust_annual_report_cache, if: :saved_change_to_state? def to_param = serial @@ -38,6 +39,10 @@ def assign_serial self.serial ||= EmbassyApplicationSerialGenerator.next end + def bust_annual_report_cache + Rails.cache.delete("annual_report:v1") if submitted? + end + def required_questions_answered answers_by_qid = embassy_application_answers.includes(:question).index_by(&:question_id) diff --git a/app/services/annual_report.rb b/app/services/annual_report.rb index 4fe5ccf..e2a108b 100644 --- a/app/services/annual_report.rb +++ b/app/services/annual_report.rb @@ -101,9 +101,10 @@ def self.other_language_stat(question) def self.sentimental_version_stat(question) raw = submitted_answers_for(question).pluck(:value_text).compact.reject(&:blank?) cleaned = raw.reject { |v| REFUSAL_PHRASES.any? { |p| v.downcase.include?(p) } } - versions = cleaned.filter_map { |v| v[/\d+(?:\.\d+){0,2}/] } - counts = versions.tally.sort_by { |_, c| -c }.first(5).to_h - parseable = versions.filter_map { |v| Gem::Version.new(v) rescue nil }.sort + raw_versions = cleaned.filter_map { |v| v[/\d+(?:\.\d+){0,2}/] } + normalized = raw_versions.map { |v| v.split(".").first(2).join(".") } + counts = normalized.tally.sort_by { |_, c| -c }.first(5).to_h + parseable = raw_versions.filter_map { |v| Gem::Version.new(v) rescue nil }.sort Stat.new( question: question, total_respondents: raw.count, diff --git a/app/views/report/index.html.erb b/app/views/report/index.html.erb index 1dfc63f..cdb9b5a 100644 --- a/app/views/report/index.html.erb +++ b/app/views/report/index.html.erb @@ -168,7 +168,7 @@

<%= s.total_respondents %> diplomats declared one or more sentiments. Percentages reflect share of diplomats who selected each.

- <% s.breakdown.each do |label, count| %> + <% s.breakdown.sort_by { |_, c| -c }.each do |label, count| %>
<%= percent.call(count) %>%
<%= label %>
@@ -186,7 +186,7 @@

<%= s.total_respondents %> diplomats claimed one or more identities.

- <% s.breakdown.each do |label, count| %> + <% s.breakdown.sort_by { |_, c| -c }.each do |label, count| %>
<%= percent.call(count) %>%
<%= label %>
diff --git a/app/views/shared/_navbar.html.erb b/app/views/shared/_navbar.html.erb index 577da8f..2a10028 100644 --- a/app/views/shared/_navbar.html.erb +++ b/app/views/shared/_navbar.html.erb @@ -14,6 +14,7 @@ <%= link_to "Schedule", schedule_path, class: "text-blue px-3 py-1 text-lg font-medium" %> <%= link_to "My Plan", plan_path, class: "text-blue px-3 py-1 text-lg font-medium" %> Guide + <%= link_to "Annual Report", report_path, class: "text-blue px-3 py-1 text-lg font-medium" %> <% if admin? %> <%= link_to "Admin", admin_root_path, class: "text-blue px-3 py-1 text-lg font-medium" %> <% end %> @@ -21,6 +22,7 @@ <% else %> Schedule Speakers + <%= link_to "Annual Report", report_path, class: "text-blue px-3 py-1 text-lg font-medium" %> <%= link_to "Log In", new_session_path, class: "text-blue px-3 py-1 text-lg font-medium" %> Register <% end %> @@ -44,6 +46,7 @@ <%= link_to "Schedule", schedule_path, class: "text-blue block py-2 font-medium" %> <%= link_to "My Plan", plan_path, class: "text-blue block py-2 font-medium" %> Guide + <%= link_to "Annual Report", report_path, class: "text-blue block py-2 font-medium" %> <% if admin? %> <%= link_to "Admin", admin_root_path, class: "text-blue block py-2 font-medium" %> <% end %> @@ -51,6 +54,7 @@ <% else %> Schedule Speakers + <%= link_to "Annual Report", report_path, class: "text-blue block py-2 font-medium" %> <%= link_to "Log In", new_session_path, class: "text-blue block py-2 font-medium" %>