-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
44 changed files
with
443 additions
and
388 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
class QuestionsController < ApplicationController | ||
|
||
def show | ||
@question = Question.from(params[:id]) | ||
@responses = SurveyResponse.where("#{@question.key} IS NOT NULL").order(:created_at) | ||
@question = Question.find(params[:id]) | ||
@responses = @question.responses.order(:survey_response_id) | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
class ResponsesController < ApplicationController | ||
|
||
def update | ||
@response = Response.find(params[:id]) | ||
success = @response.update(raw_codes: response_params[:raw_codes].join(",").split(",").reject(&:empty?).compact.map(&:strip).map(&:downcase)) | ||
|
||
respond_to do |format| | ||
format.turbo_stream do | ||
render turbo_stream: turbo_stream.replace("frame-response-#{@response.id}", partial: "/responses/form", locals: { response: @response, success: success, filters: false }) | ||
end | ||
end | ||
end | ||
|
||
private | ||
|
||
def response_params | ||
params.require(:response).permit(raw_codes: []) | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# This background job performs the Keyword extraction process. | ||
class PopulateSurveyResponseJob | ||
|
||
include Sidekiq::Job | ||
|
||
queue_as :default | ||
|
||
def perform(context, record) | ||
Rails.logger.info("PopulateSurveyResponseJob running with context #{context}") | ||
survey_response = SurveyResponse.from(context, record) | ||
survey_response.generate_wordcloud | ||
survey_response.classify_sentiment | ||
Keyword.from(self.id) | ||
end | ||
|
||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# A Context reflects a demographic category. | ||
class Context < ApplicationRecord | ||
|
||
validates_presence_of :name | ||
validates_presence_of :display_name | ||
validates_uniqueness_of :name | ||
|
||
has_many :questions | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,72 +1,21 @@ | ||
# A Question is a representation of a survey question. | ||
# This class provides convenience methods for navigating question keys and labels, as well as selecting topical subsets of questions. | ||
# For now, Questions are hardcoded and not persisted. | ||
class Question | ||
class Question < ApplicationRecord | ||
|
||
attr_accessor :key, :label | ||
|
||
QUESTIONS = { | ||
age_given: "Age", | ||
age_exp: "Experience with Age", | ||
klass_given: "Class", | ||
klass_exp: "Experience with Class", | ||
race_ethnicity_given: "Race/Ethnicity", | ||
race_ethnicity_exp: "Experience with Race/Ethnicity", | ||
religion_given: "Religion", | ||
religion_exp: "Experience with Religion", | ||
disability_given: "Disability", | ||
disability_exp: "Experience with Disability", | ||
neurodiversity_given: "Neurodiversity", | ||
neurodiversity_exp: "Experience with Neurodiversity", | ||
gender_given: "Gender", | ||
gender_exp: "Experience with Gender", | ||
lgbtqia_given: "LGBTQIA+ Status", | ||
lgbtqia_exp: "Experience with LGBTQIA+", | ||
pronouns_given: "Pronouns Given", | ||
pronouns_exp: "Experience with Pronouns", | ||
pronouns_feel: "Pronoun Feelings", | ||
affinity: "Identity Affinities", | ||
notes: "Identity Reflection" | ||
} | ||
|
||
def self.from(key) | ||
new(key: key, label: QUESTIONS[key.to_sym]) | ||
end | ||
has_many :responses | ||
belongs_to :context | ||
|
||
def self.experience_questions | ||
QUESTIONS.keys.select{|k| k.to_s.include?("_exp")} | ||
Question.where(is_experience: true) | ||
end | ||
|
||
def self.identity_questions | ||
QUESTIONS.keys.select{|k| k.to_s.include?("_given")} | ||
end | ||
|
||
def self.freeform_questions | ||
[:pronouns_feel, :affinity, :notes] | ||
end | ||
|
||
def initialize(attrs={}) | ||
self.key = attrs[:key] | ||
self.label = attrs[:label] | ||
end | ||
|
||
def context | ||
"#{self.key}".gsub("_given","").gsub("klass","class").gsub("_exp", "").gsub("_","-") | ||
end | ||
|
||
def codes_field | ||
"#{self.key}_codes".gsub("given","id") | ||
end | ||
|
||
def identity_field? | ||
self.key.include? "_given" | ||
Question.where(is_identity: true) | ||
end | ||
|
||
def experience_field? | ||
return true if self.key.include? "_exp" | ||
return true if self.key.include? "_feel" | ||
return true if self.key == "affinity" | ||
return true if self.key == "notes" | ||
def self.reflection_questions | ||
Question.where(is_reflection: true) | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
class Response < ApplicationRecord | ||
|
||
after_update :enqueue_export_to_graph | ||
|
||
belongs_to :survey_response | ||
belongs_to :question | ||
|
||
def codes | ||
Code.where(name: self.raw_codes) | ||
end | ||
|
||
private | ||
|
||
# Invokes a service to update the graph databases from the associated SurveyResponse object. | ||
def enqueue_export_to_graph | ||
SurveyResponse.find(self.survey_response_id).save | ||
end | ||
|
||
end |
Oops, something went wrong.