Fix rubocop offenses

This commit is contained in:
Sebastian Serth
2021-10-05 12:09:56 +02:00
parent 2c0a9fda8d
commit 74e285e9fd
11 changed files with 16 additions and 14 deletions

View File

@@ -6,7 +6,7 @@ module FileParameters
params.reject do |_, file_attributes|
file = CodeOcean::File.find_by(id: file_attributes[:file_id])
# avoid that public files from other contexts can be created
file.nil? || file.hidden || file.read_only || file.context_type == 'Exercise' && file.context_id != exercise.id
file.nil? || file.hidden || file.read_only || (file.context_type == 'Exercise' && file.context_id != exercise.id)
end
else
[]

View File

@@ -5,7 +5,7 @@ module TimeHelper
def time_to_f(timestamp)
unless timestamp.nil?
timestamp = timestamp.split(':')
return timestamp[0].to_i * 60 * 60 + timestamp[1].to_i * 60 + timestamp[2].to_f
return (timestamp[0].to_i * 60 * 60) + (timestamp[1].to_i * 60) + timestamp[2].to_f
end
nil
end

View File

@@ -68,7 +68,9 @@ class Exercise < ApplicationRecord
if submissions.exists?(cause: 'submit')
maximum_scores_query = submissions.select('MAX(score) AS maximum_score').group(:user_id).to_sql.sub('$1', id.to_s)
self.class.connection.execute("SELECT AVG(maximum_score) AS average_score FROM (#{maximum_scores_query}) AS maximum_scores").first['average_score'].to_f
else 0 end
else
0
end
end
def average_number_of_submissions

View File

@@ -240,7 +240,7 @@ class ProxyExercise < ApplicationRecord
def tag_diminishing_return_function(count_tag, total_count_tag)
total_count_tag += 1 # bonus exercise comes on top
1 / (1 + (Math::E**(-3 / (0.5 * total_count_tag) * (count_tag - 0.5 * total_count_tag))))
1 / (1 + (Math::E**(-3 / (0.5 * total_count_tag) * (count_tag - (0.5 * total_count_tag)))))
end
def select_easiest_exercise(exercises)

View File

@@ -6,7 +6,7 @@ class ExercisePolicy < AdminOrAuthorPolicy
end
%i[show? feedback? statistics? rfcs_for_exercise?].each do |action|
define_method(action) { admin? || teacher_in_study_group? || teacher? && @record.public? || author? }
define_method(action) { admin? || teacher_in_study_group? || (teacher? && @record.public?) || author? }
end
def study_group_dashboard?

View File

@@ -6,7 +6,7 @@ class ProxyExercisePolicy < AdminOrAuthorPolicy
end
def show?
admin? || teacher_in_study_group? || teacher? && @record.public? || author?
admin? || teacher_in_study_group? || (teacher? && @record.public?) || author?
end
%i[clone? destroy? edit? update?].each do |action|

View File

@@ -6,7 +6,7 @@ class StudyGroupPolicy < AdminOnlyPolicy
end
%i[show? destroy? edit? update? stream_la?].each do |action|
define_method(action) { admin? || @user.teacher? && @record.present? && @user.study_groups.exists?(@record.id) }
define_method(action) { admin? || (@user.teacher? && @record.present? && @user.study_groups.exists?(@record.id)) }
end
class Scope < Scope