Skip to content

Commit

Permalink
Don't enqueue export to graph on response db migration
Browse files Browse the repository at this point in the history
  • Loading branch information
CoralineAda committed Oct 29, 2024
1 parent 2333381 commit 6ca81ae
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 34 deletions.
14 changes: 7 additions & 7 deletions app/controllers/codebooks_controller.rb
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
class CodebooksController < ApplicationController

def index
@contexts = Question::QUESTIONS
@questions = Question.all.order(:created_at)
end

def show
@question = Question.find_by(key: params[:id])
@question = Question.find(params[:id])
@context = @question.context
@context_key = @context.name
@enqueued_at = params[:enqueued_at].present? ? Time.at(params[:enqueued_at].to_i).strftime("%T %Z") : nil

# Support the previous/next navigation controls

sections = Question.all.pluck(:key)
previous_index = (sections.index(@question.key) - 1)
next_index = (sections.index(@question.key) + 1) % sections.length
sections = Question.all.pluck(:id)
previous_index = (sections.index(@question.id) - 1)
next_index = (sections.index(@question.id) + 1) % sections.length
@section_name = @question.label
@previous_section = sections[previous_index]
@next_section = sections[next_index]
Expand All @@ -24,7 +24,7 @@ def show
@frequencies = Identity.histogram(@context.name)
@frequencies_by_keys = @frequencies.sort{|a, b| a[0] <=> b[0]}
@frequencies_by_values = @frequencies.sort{|a, b| a[1] <=> b[1]}
elsif @question.is_experience?
else
# Experience fields have associated Code and Category objects.
@frequencies = Code.histogram(@context.name)
@frequencies_by_keys = @frequencies.sort{|a, b| a[0] <=> b[0]}
Expand All @@ -37,7 +37,7 @@ def show
end

def enqueue_categories
context = Question.find_by(params[:codebook_id]).context.name
context = Question.find(params[:codebook_id]).context.name
CategoryExtractorJob.perform_async(context)
redirect_to(action: :show, id: params[:codebook_id], params: {enqueued_at: Time.now.strftime("%s")})
end
Expand Down
1 change: 1 addition & 0 deletions app/models/response.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
class Response < ApplicationRecord

# TODO I need this to run under normal circumstances but NOT during the db migration that creates the records.
after_save_commit :enqueue_export_to_graph

belongs_to :survey_response
Expand Down
6 changes: 3 additions & 3 deletions app/views/codebooks/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

<h1>Browse the Codebook.</h1>

<h3>Contexts</h3>
<h3>Questions</h3>
<ul class="list">
<% @contexts.each do |context,label| %>
<% @questions.each do |question| %>
<li>
<%= link_to label, codebook_path(context) %>
<%= link_to question.label, codebook_path(question.id) %>
</li>
<% end %>
</ul>
4 changes: 2 additions & 2 deletions app/views/codebooks/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
<h1><%= pluralize(@frequencies.count, "Code") %> for "<%= @section_name %>".</h1>

<% if @previous_section %>
<%= link_to "<", codebook_path(@previous_section), class: "flip", id: "flip-left" %>
<%= link_to "<", codebook_path(id: @previous_section), class: "flip", id: "flip-left" %>
<% end %>
<% if @next_section %>
<%= link_to ">", codebook_path(@next_section), class: "flip", id: "flip-right" %>
<%= link_to ">", codebook_path(id: @next_section), class: "flip", id: "flip-right" %>
<% end %>

<% if @categories_histogram %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/questions/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

<h2>Reference:</h3>
<ul class="word-cloud">
<li><%= link_to "Codes for #{@question.label}", codebook_path(@question.key), class: "jump-link" %></li>
<li><%= link_to "Codes for #{@question.label}", codebook_path(@question.id), class: "jump-link" %></li>
</ul>

<table>
Expand Down
44 changes: 23 additions & 21 deletions db/migrate/20241029012413_populate_responses.rb
Original file line number Diff line number Diff line change
@@ -1,26 +1,28 @@
class PopulateResponses < ActiveRecord::Migration[7.2]
def up
SurveyResponse.all.each do |survey_response|
Response.create(question_id: Question.find_by(key: 'age_given').id, survey_response_id: survey_response.id, value: survey_response.age_given, raw_codes: survey_response.age_id_codes)
Response.create(question_id: Question.find_by(key: 'age_exp').id, survey_response_id: survey_response.id, value: survey_response.age_exp, raw_codes: survey_response.age_exp_codes)
Response.create(question_id: Question.find_by(key: 'klass_given').id, survey_response_id: survey_response.id, value: survey_response.klass_given, raw_codes: survey_response.klass_id_codes)
Response.create(question_id: Question.find_by(key: 'klass_exp').id, survey_response_id: survey_response.id, value: survey_response.klass_exp, raw_codes: survey_response.klass_exp_codes)
Response.create(question_id: Question.find_by(key: 'race_ethnicity_given').id, survey_response_id: survey_response.id, value: survey_response.race_ethnicity_given, raw_codes: survey_response.race_ethnicity_id_codes)
Response.create(question_id: Question.find_by(key: 'race_ethnicity_exp').id, survey_response_id: survey_response.id, value: survey_response.race_ethnicity_exp, raw_codes: survey_response.race_ethnicity_exp_codes)
Response.create(question_id: Question.find_by(key: 'religion_given').id, survey_response_id: survey_response.id, value: survey_response.religion_given, raw_codes: survey_response.religion_id_codes)
Response.create(question_id: Question.find_by(key: 'religion_exp').id, survey_response_id: survey_response.id, value: survey_response.religion_exp, raw_codes: survey_response.religion_exp_codes)
Response.create(question_id: Question.find_by(key: 'disability_given').id, survey_response_id: survey_response.id, value: survey_response.disability_given, raw_codes: survey_response.disability_id_codes)
Response.create(question_id: Question.find_by(key: 'disability_exp').id, survey_response_id: survey_response.id, value: survey_response.disability_exp, raw_codes: survey_response.disability_exp_codes)
Response.create(question_id: Question.find_by(key: 'neurodiversity_given').id, survey_response_id: survey_response.id, value: survey_response.neurodiversity_given, raw_codes: survey_response.neurodiversity_id_codes)
Response.create(question_id: Question.find_by(key: 'neurodiversity_exp').id, survey_response_id: survey_response.id, value: survey_response.neurodiversity_exp, raw_codes: survey_response.neurodiversity_exp_codes)
Response.create(question_id: Question.find_by(key: 'gender_given').id, survey_response_id: survey_response.id, value: survey_response.gender_given, raw_codes: survey_response.gender_id_codes)
Response.create(question_id: Question.find_by(key: 'gender_exp').id, survey_response_id: survey_response.id, value: survey_response.gender_exp, raw_codes: survey_response.gender_exp_codes)
Response.create(question_id: Question.find_by(key: 'lgbtqia_given').id, survey_response_id: survey_response.id, value: survey_response.lgbtqia_given, raw_codes: survey_response.lgbtqia_id_codes)
Response.create(question_id: Question.find_by(key: 'lgbtqia_exp').id, survey_response_id: survey_response.id, value: survey_response.lgbtqia_exp, raw_codes: survey_response.lgbtqia_exp_codes)
Response.create(question_id: Question.find_by(key: 'pronouns_given').id, survey_response_id: survey_response.id, value: survey_response.pronouns_given, raw_codes: survey_response.pronouns_id_codes)
Response.create(question_id: Question.find_by(key: 'pronouns_exp').id, survey_response_id: survey_response.id, value: survey_response.pronouns_exp, raw_codes: survey_response.pronouns_exp_codes)
Response.create(question_id: Question.find_by(key: 'pronouns_feel').id, survey_response_id: survey_response.id, value: survey_response.pronouns_feel, raw_codes: survey_response.pronouns_feel_codes)
Response.create(question_id: Question.find_by(key: 'affinity').id, survey_response_id: survey_response.id, value: survey_response.affinity, raw_codes: survey_response.affinity_codes)
Response.suppress do
SurveyResponse.all.each do |survey_response|
Response.create(question_id: Question.find_by(key: 'age_given').id, survey_response_id: survey_response.id, value: survey_response.age_given, raw_codes: survey_response.age_id_codes)
Response.create(question_id: Question.find_by(key: 'age_exp').id, survey_response_id: survey_response.id, value: survey_response.age_exp, raw_codes: survey_response.age_exp_codes)
Response.create(question_id: Question.find_by(key: 'klass_given').id, survey_response_id: survey_response.id, value: survey_response.klass_given, raw_codes: survey_response.klass_id_codes)
Response.create(question_id: Question.find_by(key: 'klass_exp').id, survey_response_id: survey_response.id, value: survey_response.klass_exp, raw_codes: survey_response.klass_exp_codes)
Response.create(question_id: Question.find_by(key: 'race_ethnicity_given').id, survey_response_id: survey_response.id, value: survey_response.race_ethnicity_given, raw_codes: survey_response.race_ethnicity_id_codes)
Response.create(question_id: Question.find_by(key: 'race_ethnicity_exp').id, survey_response_id: survey_response.id, value: survey_response.race_ethnicity_exp, raw_codes: survey_response.race_ethnicity_exp_codes)
Response.create(question_id: Question.find_by(key: 'religion_given').id, survey_response_id: survey_response.id, value: survey_response.religion_given, raw_codes: survey_response.religion_id_codes)
Response.create(question_id: Question.find_by(key: 'religion_exp').id, survey_response_id: survey_response.id, value: survey_response.religion_exp, raw_codes: survey_response.religion_exp_codes)
Response.create(question_id: Question.find_by(key: 'disability_given').id, survey_response_id: survey_response.id, value: survey_response.disability_given, raw_codes: survey_response.disability_id_codes)
Response.create(question_id: Question.find_by(key: 'disability_exp').id, survey_response_id: survey_response.id, value: survey_response.disability_exp, raw_codes: survey_response.disability_exp_codes)
Response.create(question_id: Question.find_by(key: 'neurodiversity_given').id, survey_response_id: survey_response.id, value: survey_response.neurodiversity_given, raw_codes: survey_response.neurodiversity_id_codes)
Response.create(question_id: Question.find_by(key: 'neurodiversity_exp').id, survey_response_id: survey_response.id, value: survey_response.neurodiversity_exp, raw_codes: survey_response.neurodiversity_exp_codes)
Response.create(question_id: Question.find_by(key: 'gender_given').id, survey_response_id: survey_response.id, value: survey_response.gender_given, raw_codes: survey_response.gender_id_codes)
Response.create(question_id: Question.find_by(key: 'gender_exp').id, survey_response_id: survey_response.id, value: survey_response.gender_exp, raw_codes: survey_response.gender_exp_codes)
Response.create(question_id: Question.find_by(key: 'lgbtqia_given').id, survey_response_id: survey_response.id, value: survey_response.lgbtqia_given, raw_codes: survey_response.lgbtqia_id_codes)
Response.create(question_id: Question.find_by(key: 'lgbtqia_exp').id, survey_response_id: survey_response.id, value: survey_response.lgbtqia_exp, raw_codes: survey_response.lgbtqia_exp_codes)
Response.create(question_id: Question.find_by(key: 'pronouns_given').id, survey_response_id: survey_response.id, value: survey_response.pronouns_given, raw_codes: survey_response.pronouns_id_codes)
Response.create(question_id: Question.find_by(key: 'pronouns_exp').id, survey_response_id: survey_response.id, value: survey_response.pronouns_exp, raw_codes: survey_response.pronouns_exp_codes)
Response.create(question_id: Question.find_by(key: 'pronouns_feel').id, survey_response_id: survey_response.id, value: survey_response.pronouns_feel, raw_codes: survey_response.pronouns_feel_codes)
Response.create(question_id: Question.find_by(key: 'affinity').id, survey_response_id: survey_response.id, value: survey_response.affinity, raw_codes: survey_response.affinity_codes)
end
end
end

Expand Down

0 comments on commit 6ca81ae

Please sign in to comment.