Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #49 from portabilis/portabilis-patch-2019-07-26
Portabilis Patch 26/07/2019
- Loading branch information
Showing
12 changed files
with
168 additions
and
20 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
class ParallelExamsCalculationTypes < EnumerateIt::Base | ||
associate_values substitution: 1, | ||
average: 2, | ||
sum: 3 | ||
|
||
sort_by :none | ||
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,46 @@ | ||
class ConceptualExamValueCreator | ||
def self.create_empty_by(classroom_id, teacher_id) | ||
new(classroom_id, teacher_id).create_empty | ||
end | ||
|
||
def initialize(classroom_id, teacher_id) | ||
raise ArgumentError if classroom_id.blank? || teacher_id.blank? | ||
|
||
@classroom = Classroom.find(classroom_id) | ||
@teacher_id = teacher_id | ||
end | ||
|
||
def create_empty | ||
TeacherDisciplineClassroom.joins(join_conceptual_exam_value) | ||
.joins(join_conceptual_exam) | ||
.select( | ||
'conceptual_exams.id AS conceptual_exam_id, | ||
teacher_discipline_classrooms.discipline_id AS discipline_id' | ||
) | ||
.by_teacher_id(@teacher_id) | ||
.by_classroom(@classroom) | ||
.where('conceptual_exams.discarded_at IS NULL') | ||
.where('conceptual_exam_values.id IS NULL').each do |record| | ||
ConceptualExamValue.create!( | ||
conceptual_exam_id: record.conceptual_exam_id, | ||
discipline_id: record.discipline_id, | ||
value: nil, | ||
exempted_discipline: false | ||
) | ||
end | ||
end | ||
|
||
def join_conceptual_exam | ||
<<-SQL | ||
JOIN conceptual_exams | ||
ON conceptual_exams.classroom_id = teacher_discipline_classrooms.classroom_id | ||
SQL | ||
end | ||
|
||
def join_conceptual_exam_value | ||
<<-SQL | ||
LEFT JOIN conceptual_exam_values | ||
ON conceptual_exam_values.discipline_id = teacher_discipline_classrooms.discipline_id | ||
SQL | ||
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,11 @@ | ||
class CreateEmptyConceptualExamValueWorker | ||
include Sidekiq::Worker | ||
|
||
sidekiq_options unique: :until_and_while_executing, queue: :low | ||
|
||
def perform(entity_id, classroom_id, teacher_id) | ||
Entity.find(entity_id).using_connection do | ||
ConceptualExamValueCreator.create_empty_by(classroom_id, teacher_id) | ||
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 |
---|---|---|
@@ -1 +1,5 @@ | ||
$REDIS_DB = Redis.new | ||
$REDIS_DB = if Rails.application.secrets[:redis_url] | ||
Redis.new(url: Rails.application.secrets[:redis_url]) | ||
else | ||
Redis.new | ||
end |
29 changes: 29 additions & 0 deletions
29
...20190717211725_migrate_calculate_avg_parallel_exams_to_parallel_exams_calculation_type.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,29 @@ | ||
class MigrateCalculateAvgParallelExamsToParallelExamsCalculationType < ActiveRecord::Migration | ||
def up | ||
add_column :exam_rules, :parallel_exams_calculation_type, :integer, null: false, default: 1 | ||
|
||
execute <<-SQL | ||
UPDATE exam_rules | ||
SET parallel_exams_calculation_type = CASE | ||
WHEN calculate_avg_parallel_exams THEN 2 | ||
ELSE 1 | ||
END | ||
SQL | ||
|
||
remove_column :exam_rules, :calculate_avg_parallel_exams | ||
end | ||
|
||
def down | ||
add_column :exam_rules, :calculate_avg_parallel_exams, :boolean, null: false, default: false | ||
|
||
execute <<-SQL | ||
UPDATE exam_rules | ||
SET calculate_avg_parallel_exams = CASE | ||
WHEN parallel_exams_calculation_type = 2 THEN true | ||
ELSE false | ||
END | ||
SQL | ||
|
||
remove_column :exam_rules, :parallel_exams_calculation_type | ||
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