Skip to content

Commit

Permalink
Add confidence check scores for manager or leader (#1385)
Browse files Browse the repository at this point in the history
  • Loading branch information
martikat authored Nov 18, 2024
1 parent b7e3065 commit 2d9f21e
Show file tree
Hide file tree
Showing 6 changed files with 209 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
module DataAnalysis
class ConfidenceCheckScoresForManagerOrLeaderAndOther
include ToCsv

class << self
# @return [Array<String>]
def column_names
%w[
Module
Question
Answers
Count
]
end

# @return [Array<Hash{Symbol => 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<String, String, String> => 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
module DataAnalysis
class ConfidenceCheckScoresForManagerOrLeaderOnly
include ToCsv

class << self
# @return [Array<String>]
def column_names
%w[
Module
Question
Answers
Count
]
end

# @return [Array<Hash{Symbol => 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<String, String, String> => 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
7 changes: 7 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
Expand Down
2 changes: 2 additions & 0 deletions app/services/dashboard.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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' },
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 2d9f21e

Please sign in to comment.