Skip to content
Merged
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
3 changes: 2 additions & 1 deletion app/assets/stylesheets/application.css
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -3624,6 +3624,7 @@ hr {
color: #0C2866;
font-size: 0.9375rem;
white-space: nowrap;
text-align: right;
}

.report-bar-row__count {
Expand Down
5 changes: 5 additions & 0 deletions app/models/embassy_application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)

Expand Down
7 changes: 4 additions & 3 deletions app/services/annual_report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions app/views/report/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@
<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>

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

<div class="report-callouts">
<% s.breakdown.each do |label, count| %>
<% s.breakdown.sort_by { |_, c| -c }.each do |label, count| %>
<div class="report-callout report-callout--alt">
<div class="report-callout__value"><%= percent.call(count) %>%</div>
<div class="report-callout__label"><%= label %></div>
Expand Down
4 changes: 4 additions & 0 deletions app/views/shared/_navbar.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@
<%= 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" %>
<a href="https://blueridgeruby.com/guide" target="_blank" rel="noopener" class="text-blue px-3 py-1 text-lg font-medium">Guide</a>
<%= 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 %>
<%= button_to "Sign Out", session_path, method: :delete, class: "text-blue px-3 py-1 text-lg font-medium cursor-pointer" %>
<% else %>
<a href="https://blueridgeruby.com/schedule" class="text-blue px-3 py-1 text-lg font-medium">Schedule</a>
<a href="https://blueridgeruby.com/#speakers" class="text-blue px-3 py-1 text-lg font-medium">Speakers</a>
<%= 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" %>
<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>
<% end %>
Expand All @@ -44,13 +46,15 @@
<%= 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" %>
<a href="https://blueridgeruby.com/guide" target="_blank" rel="noopener" class="text-blue block py-2 font-medium">Guide</a>
<%= 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 %>
<%= button_to "Sign Out", session_path, method: :delete, class: "text-blue block py-2 font-medium text-left cursor-pointer" %>
<% else %>
<a href="https://blueridgeruby.com/schedule" class="text-blue block py-2 font-medium">Schedule</a>
<a href="https://blueridgeruby.com/#speakers" class="text-blue block py-2 font-medium">Speakers</a>
<%= 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" %>
<div class="py-2">
<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>
Expand Down
Loading