Skip to content

Commit 5533162

Browse files
authored
Annual Report: polish — chart alignment, sort, version grouping, freshness, nav link (#72)
- Bar charts (§3 Proficiency, §1 First Ruby) now share fixed column widths so they line up regardless of label or value text. - §2 Sentiment and §3 Persona render highest→lowest by percentage. - Sentimental Ruby versions normalize to MAJOR.MINOR before tallying so 3.4 / 3.4.0 / 3.4.6 / 3.4.9 group together. - Submitting an application busts the /report cache via after_update_commit, so totals reflect new submissions immediately instead of waiting up to an hour. - Adds "Annual Report" link back to the top navbar (logged-in and logged-out, desktop and mobile).
1 parent 9aa2173 commit 5533162

5 files changed

Lines changed: 17 additions & 6 deletions

File tree

app/assets/stylesheets/application.css

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3589,7 +3589,7 @@ hr {
35893589

35903590
.report-bar-row {
35913591
display: grid;
3592-
grid-template-columns: minmax(8rem, 1fr) 2fr auto;
3592+
grid-template-columns: 11rem 1fr 5.5rem;
35933593
gap: 1rem;
35943594
align-items: center;
35953595
}
@@ -3624,6 +3624,7 @@ hr {
36243624
color: #0C2866;
36253625
font-size: 0.9375rem;
36263626
white-space: nowrap;
3627+
text-align: right;
36273628
}
36283629

36293630
.report-bar-row__count {

app/models/embassy_application.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ class EmbassyApplication < ApplicationRecord
1111
validate :required_questions_answered, on: :submit
1212

1313
before_validation :assign_serial, on: :create
14+
after_update_commit :bust_annual_report_cache, if: :saved_change_to_state?
1415

1516
def to_param = serial
1617

@@ -38,6 +39,10 @@ def assign_serial
3839
self.serial ||= EmbassyApplicationSerialGenerator.next
3940
end
4041

42+
def bust_annual_report_cache
43+
Rails.cache.delete("annual_report:v1") if submitted?
44+
end
45+
4146
def required_questions_answered
4247
answers_by_qid = embassy_application_answers.includes(:question).index_by(&:question_id)
4348

app/services/annual_report.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,10 @@ def self.other_language_stat(question)
101101
def self.sentimental_version_stat(question)
102102
raw = submitted_answers_for(question).pluck(:value_text).compact.reject(&:blank?)
103103
cleaned = raw.reject { |v| REFUSAL_PHRASES.any? { |p| v.downcase.include?(p) } }
104-
versions = cleaned.filter_map { |v| v[/\d+(?:\.\d+){0,2}/] }
105-
counts = versions.tally.sort_by { |_, c| -c }.first(5).to_h
106-
parseable = versions.filter_map { |v| Gem::Version.new(v) rescue nil }.sort
104+
raw_versions = cleaned.filter_map { |v| v[/\d+(?:\.\d+){0,2}/] }
105+
normalized = raw_versions.map { |v| v.split(".").first(2).join(".") }
106+
counts = normalized.tally.sort_by { |_, c| -c }.first(5).to_h
107+
parseable = raw_versions.filter_map { |v| Gem::Version.new(v) rescue nil }.sort
107108
Stat.new(
108109
question: question,
109110
total_respondents: raw.count,

app/views/report/index.html.erb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@
168168
<p class="report-block__sub"><strong><%= s.total_respondents %></strong> diplomats declared one or more sentiments. Percentages reflect share of diplomats who selected each.</p>
169169

170170
<div class="report-callouts">
171-
<% s.breakdown.each do |label, count| %>
171+
<% s.breakdown.sort_by { |_, c| -c }.each do |label, count| %>
172172
<div class="report-callout">
173173
<div class="report-callout__value"><%= percent.call(count) %>%</div>
174174
<div class="report-callout__label"><%= label %></div>
@@ -186,7 +186,7 @@
186186
<p class="report-block__sub"><strong><%= s.total_respondents %></strong> diplomats claimed one or more identities.</p>
187187

188188
<div class="report-callouts">
189-
<% s.breakdown.each do |label, count| %>
189+
<% s.breakdown.sort_by { |_, c| -c }.each do |label, count| %>
190190
<div class="report-callout report-callout--alt">
191191
<div class="report-callout__value"><%= percent.call(count) %>%</div>
192192
<div class="report-callout__label"><%= label %></div>

app/views/shared/_navbar.html.erb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,15 @@
1414
<%= link_to "Schedule", schedule_path, class: "text-blue px-3 py-1 text-lg font-medium" %>
1515
<%= link_to "My Plan", plan_path, class: "text-blue px-3 py-1 text-lg font-medium" %>
1616
<a href="https://blueridgeruby.com/guide" target="_blank" rel="noopener" class="text-blue px-3 py-1 text-lg font-medium">Guide</a>
17+
<%= link_to "Annual Report", report_path, class: "text-blue px-3 py-1 text-lg font-medium" %>
1718
<% if admin? %>
1819
<%= link_to "Admin", admin_root_path, class: "text-blue px-3 py-1 text-lg font-medium" %>
1920
<% end %>
2021
<%= button_to "Sign Out", session_path, method: :delete, class: "text-blue px-3 py-1 text-lg font-medium cursor-pointer" %>
2122
<% else %>
2223
<a href="https://blueridgeruby.com/schedule" class="text-blue px-3 py-1 text-lg font-medium">Schedule</a>
2324
<a href="https://blueridgeruby.com/#speakers" class="text-blue px-3 py-1 text-lg font-medium">Speakers</a>
25+
<%= link_to "Annual Report", report_path, class: "text-blue px-3 py-1 text-lg font-medium" %>
2426
<%= link_to "Log In", new_session_path, class: "text-blue px-3 py-1 text-lg font-medium" %>
2527
<a href="https://blueridgeruby.com/#register" class="bg-red-gradient text-white font-medium py-2 px-4 shadow-sm rounded-sm cursor-pointer">Register</a>
2628
<% end %>
@@ -44,13 +46,15 @@
4446
<%= link_to "Schedule", schedule_path, class: "text-blue block py-2 font-medium" %>
4547
<%= link_to "My Plan", plan_path, class: "text-blue block py-2 font-medium" %>
4648
<a href="https://blueridgeruby.com/guide" target="_blank" rel="noopener" class="text-blue block py-2 font-medium">Guide</a>
49+
<%= link_to "Annual Report", report_path, class: "text-blue block py-2 font-medium" %>
4750
<% if admin? %>
4851
<%= link_to "Admin", admin_root_path, class: "text-blue block py-2 font-medium" %>
4952
<% end %>
5053
<%= button_to "Sign Out", session_path, method: :delete, class: "text-blue block py-2 font-medium text-left cursor-pointer" %>
5154
<% else %>
5255
<a href="https://blueridgeruby.com/schedule" class="text-blue block py-2 font-medium">Schedule</a>
5356
<a href="https://blueridgeruby.com/#speakers" class="text-blue block py-2 font-medium">Speakers</a>
57+
<%= link_to "Annual Report", report_path, class: "text-blue block py-2 font-medium" %>
5458
<%= link_to "Log In", new_session_path, class: "text-blue block py-2 font-medium" %>
5559
<div class="py-2">
5660
<a href="https://blueridgeruby.com/#register" class="bg-red-gradient text-white font-medium py-2 px-4 shadow-sm rounded-sm cursor-pointer">Register</a>

0 commit comments

Comments
 (0)