From 2d9f21edea2a2fc56bfd78f44ef66dec56d72c6b Mon Sep 17 00:00:00 2001 From: Katherine Martin <78093815+martikat@users.noreply.github.com> Date: Mon, 18 Nov 2024 11:45:46 +0000 Subject: [PATCH] Add confidence check scores for manager or leader (#1385) --- ..._scores_for_manager_or_leader_and_other.rb | 36 ++++++++++ ...check_scores_for_manager_or_leader_only.rb | 36 ++++++++++ app/models/user.rb | 7 ++ app/services/dashboard.rb | 2 + ...es_for_manager_or_leader_and_other_spec.rb | 67 +++++++++++++++++++ ..._scores_for_manager_or_leader_only_spec.rb | 61 +++++++++++++++++ 6 files changed, 209 insertions(+) create mode 100644 app/models/data_analysis/confidence_check_scores_for_manager_or_leader_and_other.rb create mode 100644 app/models/data_analysis/confidence_check_scores_for_manager_or_leader_only.rb create mode 100644 spec/models/data_analysis/confidence_check_scores_for_manager_or_leader_and_other_spec.rb create mode 100644 spec/models/data_analysis/confidence_check_scores_for_manager_or_leader_only_spec.rb diff --git a/app/models/data_analysis/confidence_check_scores_for_manager_or_leader_and_other.rb b/app/models/data_analysis/confidence_check_scores_for_manager_or_leader_and_other.rb new file mode 100644 index 000000000..03e8f5693 --- /dev/null +++ b/app/models/data_analysis/confidence_check_scores_for_manager_or_leader_and_other.rb @@ -0,0 +1,36 @@ +module DataAnalysis + class ConfidenceCheckScoresForManagerOrLeaderAndOther + include ToCsv + + class << self + # @return [Array] + def column_names + %w[ + Module + Question + Answers + Count + ] + end + + # @return [Array Mixed}>] + def dashboard + confidence_check_scores.map do |(module_name, question_name, answers), count| + { + module_name: module_name, + question_name: question_name, + answers: answers, + count: count, + } + end + end + + private + + # @return [Hash{Array => Integer}] + def confidence_check_scores + User.with_confidence_score.leader_or_manager_and_other.order(:question_name).group(:training_module, :question_name, :answers).count + end + end + end +end diff --git a/app/models/data_analysis/confidence_check_scores_for_manager_or_leader_only.rb b/app/models/data_analysis/confidence_check_scores_for_manager_or_leader_only.rb new file mode 100644 index 000000000..b243aa8ca --- /dev/null +++ b/app/models/data_analysis/confidence_check_scores_for_manager_or_leader_only.rb @@ -0,0 +1,36 @@ +module DataAnalysis + class ConfidenceCheckScoresForManagerOrLeaderOnly + include ToCsv + + class << self + # @return [Array] + def column_names + %w[ + Module + Question + Answers + Count + ] + end + + # @return [Array Mixed}>] + def dashboard + confidence_check_scores.map do |(module_name, question_name, answers), count| + { + module_name: module_name, + question_name: question_name, + answers: answers, + count: count, + } + end + end + + private + + # @return [Hash{Array => Integer}] + def confidence_check_scores + User.with_confidence_score.leader_or_manager_only.order(:question_name).group(:training_module, :question_name, :answers).count + end + end + end +end diff --git a/app/models/user.rb b/app/models/user.rb index cf2d5ee4a..c8ae1e6c5 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -94,6 +94,13 @@ def test_user? # feedback scope :with_feedback, -> { joins(:responses).merge(Response.feedback) } + # confidence + scope :role_type_leader, -> { where("lower(role_type_other) LIKE '%lead%'") } + scope :role_type_manager, -> { where("lower(role_type_other) LIKE '%manager%'") } + scope :leader_or_manager_only, -> { where(role_type: 'Manager or team leader') } + scope :leader_or_manager_and_other, -> { where(role_type: 'Manager or team leader').or(role_type_leader).or(role_type_manager) } + scope :with_confidence_score, -> { joins(:responses).merge(Response.confidence) } + # account status scope :public_beta_only_registration_complete, -> { registered_since_private_beta.registration_complete } scope :since_public_beta, -> { where(created_at: Rails.application.public_beta_launch_date..Time.zone.now) } diff --git a/app/services/dashboard.rb b/app/services/dashboard.rb index 1a7498a6d..4bfca2ca7 100644 --- a/app/services/dashboard.rb +++ b/app/services/dashboard.rb @@ -24,6 +24,8 @@ class Dashboard { model: 'Assessment', folder: 'training', file: 'assessments' }, { model: 'DataAnalysis::ConfidenceCheckScores', folder: 'training', file: 'confidence_check_scores' }, + { model: 'DataAnalysis::ConfidenceCheckScoresForManagerOrLeaderOnly', folder: 'training', file: 'confidence_check_scores_for_manager_or_leader_only' }, + { model: 'DataAnalysis::ConfidenceCheckScoresForManagerOrLeaderAndOther', folder: 'training', file: 'confidence_check_scores_for_manager_or_leader_and_other' }, # { model: 'DataAnalysis::AveragePassScores', folder: 'training', file: 'average_pass_scores' }, # { model: 'DataAnalysis::HighFailQuestions', folder: 'training', file: 'high_fail_questions' }, # { model: 'DataAnalysis::SettingPassRate', folder: 'training', file: 'setting_pass_rate' }, diff --git a/spec/models/data_analysis/confidence_check_scores_for_manager_or_leader_and_other_spec.rb b/spec/models/data_analysis/confidence_check_scores_for_manager_or_leader_and_other_spec.rb new file mode 100644 index 000000000..d71f129da --- /dev/null +++ b/spec/models/data_analysis/confidence_check_scores_for_manager_or_leader_and_other_spec.rb @@ -0,0 +1,67 @@ +require 'rails_helper' + +RSpec.describe DataAnalysis::ConfidenceCheckScoresForManagerOrLeaderAndOther do + let(:headers) do + %w[ + Module + Question + Answers + Count + ] + end + + let(:rows) do + [ + { + module_name: 'alpha', + question_name: '1-3-3-1', + answers: [1], + count: 1, + }, + { + module_name: 'alpha', + question_name: '1-3-3-2', + answers: [2], + count: 2, + }, + ] + end + + before do + user_one = create :user, role_type: 'Manager or team leader', role_type_other: '' + user_two = create :user, role_type: 'other', role_type_other: 'a leader' + user_three = create :user, role_type: 'other', role_type_other: 'a manager' + + create( + :response, + question_name: '1-3-3-1', + training_module: 'alpha', + answers: [1], + correct: true, + user: user_one, + question_type: 'confidence', + ) + + create( + :response, + question_name: '1-3-3-2', + training_module: 'alpha', + answers: [2], + correct: true, + user: user_two, + question_type: 'confidence', + ) + + create( + :response, + question_name: '1-3-3-2', + training_module: 'alpha', + answers: [2], + correct: true, + user: user_three, + question_type: 'confidence', + ) + end + + it_behaves_like 'a data export model' +end diff --git a/spec/models/data_analysis/confidence_check_scores_for_manager_or_leader_only_spec.rb b/spec/models/data_analysis/confidence_check_scores_for_manager_or_leader_only_spec.rb new file mode 100644 index 000000000..a84018756 --- /dev/null +++ b/spec/models/data_analysis/confidence_check_scores_for_manager_or_leader_only_spec.rb @@ -0,0 +1,61 @@ +require 'rails_helper' + +RSpec.describe DataAnalysis::ConfidenceCheckScoresForManagerOrLeaderOnly do + let(:headers) do + %w[ + Module + Question + Answers + Count + ] + end + + let(:rows) do + [ + { + module_name: 'alpha', + question_name: '1-3-3-1', + answers: [1], + count: 1, + }, + ] + end + + before do + user_one = create :user, role_type: 'Manager or team leader', role_type_other: '' + user_two = create :user, role_type: 'other', role_type_other: 'a leader' + user_three = create :user, role_type: 'other', role_type_other: 'a manager' + + create( + :response, + question_name: '1-3-3-1', + training_module: 'alpha', + answers: [1], + correct: true, + user: user_one, + question_type: 'confidence', + ) + + create( + :response, + question_name: '1-3-3-2', + training_module: 'alpha', + answers: [2], + correct: true, + user: user_two, + question_type: 'confidence', + ) + + create( + :response, + question_name: '1-3-3-2', + training_module: 'alpha', + answers: [2], + correct: true, + user: user_three, + question_type: 'confidence', + ) + end + + it_behaves_like 'a data export model' +end