-
Notifications
You must be signed in to change notification settings - Fork 0
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
96 changed files
with
2,531 additions
and
365 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
25 changes: 25 additions & 0 deletions
25
app/controllers/registration/early_years_emails_controller.rb
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,25 @@ | ||
class Registration::EarlyYearsEmailsController < Registration::BaseController | ||
def edit | ||
@user_form = Users::EarlyYearsEmailsForm.new(user: current_user, early_years_emails: current_user.early_years_emails) | ||
end | ||
|
||
def update | ||
@user_form = Users::EarlyYearsEmailsForm.new(user_params.merge(user: current_user)) | ||
|
||
if @user_form.save | ||
if current_user.registration_complete? | ||
redirect_to my_modules_path, notice: t('.complete_update') | ||
else | ||
complete_registration | ||
end | ||
else | ||
render :edit, status: :unprocessable_entity | ||
end | ||
end | ||
|
||
private | ||
|
||
def user_params | ||
params.require(:user).permit(:early_years_emails) | ||
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
25 changes: 25 additions & 0 deletions
25
app/controllers/registration/training_emails_controller.rb
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,25 @@ | ||
class Registration::TrainingEmailsController < Registration::BaseController | ||
def edit | ||
@user_form = Users::TrainingEmailsForm.new(user: current_user, training_emails: current_user.training_emails) | ||
end | ||
|
||
def update | ||
@user_form = Users::TrainingEmailsForm.new(user_params.merge(user: current_user)) | ||
|
||
if @user_form.save | ||
if current_user.registration_complete? | ||
redirect_to my_modules_path, notice: t('.complete_update') | ||
else | ||
complete_registration | ||
end | ||
else | ||
render :edit, status: :unprocessable_entity | ||
end | ||
end | ||
|
||
private | ||
|
||
def user_params | ||
params.require(:user).permit(:training_emails) | ||
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,37 @@ | ||
class CoercionDecorator | ||
extend Dry::Initializer | ||
|
||
param :input, type: Types::Strict::Array.of(Types::Strict::Hash) | ||
|
||
# @return [Array<Hash>] | ||
def call | ||
input.each { |row| row.map { |key, value| row[key] = format_value(key, value) } } | ||
end | ||
|
||
private | ||
|
||
# @param key [Symbol] | ||
# @param value [Mixed] | ||
# @return [Mixed] | ||
def format_value(key, value) | ||
if value.is_a?(Time) || value.is_a?(DateTime) | ||
format_datetime(value) | ||
elsif key.to_s.include?('percentage') | ||
format_percentage(value) | ||
else | ||
value | ||
end | ||
end | ||
|
||
# @param value [Numeric] | ||
# @return [String] | ||
def format_percentage(value) | ||
"#{(value * 100).round(2)}%" | ||
end | ||
|
||
# @param value [Time, DateTime] | ||
# @return [String] | ||
def format_datetime(value) | ||
value.strftime('%Y-%m-%d %H:%M:%S') | ||
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 @@ | ||
module Users | ||
class EarlyYearsEmailsForm < BaseForm | ||
attr_accessor :early_years_emails | ||
|
||
validates :early_years_emails, presence: true | ||
|
||
def name | ||
'early_years_emails' | ||
end | ||
|
||
def save | ||
if valid? | ||
user.update!( | ||
early_years_emails: early_years_emails, | ||
) | ||
end | ||
end | ||
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 @@ | ||
module Users | ||
class TrainingEmailsForm < BaseForm | ||
attr_accessor :training_emails | ||
|
||
validates :training_emails, presence: true | ||
|
||
def name | ||
'training_emails' | ||
end | ||
|
||
def save | ||
if valid? | ||
user.update!( | ||
training_emails: training_emails, | ||
) | ||
end | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
module Data | ||
class AveragePassScores | ||
include ToCsv | ||
|
||
class << self | ||
# @return [Array<String>] | ||
def column_names | ||
['Module', 'Average Pass Score'] | ||
end | ||
|
||
# TODO: Upcoming changes to UserAssessment will make this type coercion unnecessary | ||
# @return [Array<Hash{Symbol => Mixed}>] | ||
def dashboard | ||
UserAssessment.summative.passes.group(:module).average('CAST(score AS float)').map do |module_name, score| | ||
{ | ||
module_name: module_name, | ||
pass_score: score, | ||
} | ||
end | ||
end | ||
end | ||
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,58 @@ | ||
module Data | ||
class HighFailQuestions | ||
include ToCsv | ||
|
||
class << self | ||
# @return [Array<String>] | ||
def column_names | ||
['Module', 'Question', 'Failure Rate Percentage'] | ||
end | ||
|
||
# @return [Array<Hash{Symbol => Mixed}>] | ||
def dashboard | ||
high_fail_questions.map do |(module_name, question_name), fail_rate| | ||
{ | ||
module_name: module_name, | ||
question_name: question_name, | ||
fail_rate_percentage: fail_rate, | ||
} | ||
end | ||
end | ||
|
||
private | ||
|
||
# @return [Hash{Array<String, String> => Integer}] | ||
def question_attempts | ||
UserAnswer.summative.group(:module, :name).count | ||
end | ||
|
||
# @return [Hash{Array<String, String> => Integer}] | ||
def question_failures | ||
UserAnswer.summative.where(correct: false).group(:module, :name).count | ||
end | ||
|
||
# @return [Integer] | ||
def total_attempts | ||
question_attempts.values.sum | ||
end | ||
|
||
# @return [Hash{Symbol => Mixed}] | ||
def high_fail_questions | ||
average_fail_rate = question_failures.values.sum / total_attempts.to_f | ||
|
||
high_fail_questions = {} | ||
|
||
question_failures.each do |(module_name, question_name), fail_count| | ||
total_count = question_attempts[[module_name, question_name]] | ||
fail_rate = fail_count / total_count | ||
|
||
if fail_rate > average_fail_rate | ||
high_fail_questions[[module_name, question_name]] = fail_rate.to_f | ||
end | ||
end | ||
|
||
{ average: average_fail_rate }.merge(high_fail_questions) | ||
end | ||
end | ||
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
Oops, something went wrong.