-
Notifications
You must be signed in to change notification settings - Fork 227
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enhance Export Functionality with PLD and GDU Metrics #2250
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -464,6 +464,33 @@ def date_to_s(date) | |||||||||||||||||||||||||||||||||
date.strftime("%a, %b %e at %l:%M%P") | ||||||||||||||||||||||||||||||||||
end | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
# Public method to access the PLD data | ||||||||||||||||||||||||||||||||||
def calculate_pld | ||||||||||||||||||||||||||||||||||
submissions.includes(:scores).map do |submission| | ||||||||||||||||||||||||||||||||||
late_days = [(submission.created_at.to_date - due_at.to_date).to_i, 0].max | ||||||||||||||||||||||||||||||||||
{ submission_id: submission.id, late_days: late_days } | ||||||||||||||||||||||||||||||||||
end | ||||||||||||||||||||||||||||||||||
end | ||||||||||||||||||||||||||||||||||
Comment on lines
+467
to
+473
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Consider handling edge cases and enriching the PLD data The implementation could be enhanced in the following ways:
def calculate_pld
- submissions.includes(:scores).map do |submission|
- late_days = [(submission.created_at.to_date - due_at.to_date).to_i, 0].max
- { submission_id: submission.id, late_days: late_days }
+ raise "Assessment due date not set" if due_at.nil?
+
+ submissions.includes(:scores, :course_user_datum).map do |submission|
+ extension = extensions.find_by(course_user_datum_id: submission.course_user_datum_id)
+ effective_due_at = extension ? extension.due_at : due_at
+ late_days = [(submission.created_at.to_date - effective_due_at.to_date).to_i, 0].max
+ {
+ submission_id: submission.id,
+ student_email: submission.course_user_datum.user.email,
+ submitted_at: submission.created_at,
+ late_days: late_days,
+ grace_days_used: submission.grace_days_used || 0,
+ extension_days: extension ? (extension.due_at.to_date - due_at.to_date).to_i : 0
+ }
end
end
|
||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
# Public method to access the GDU data | ||||||||||||||||||||||||||||||||||
def calculate_gdu | ||||||||||||||||||||||||||||||||||
# Define grade boundaries | ||||||||||||||||||||||||||||||||||
grade_boundaries = { 'A': 90, 'B': 80, 'C': 70, 'D': 60, 'F': 0 } | ||||||||||||||||||||||||||||||||||
# Initialize distribution | ||||||||||||||||||||||||||||||||||
distribution = Hash.new(0) | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
total_submissions = submissions.joins(:scores).count | ||||||||||||||||||||||||||||||||||
submissions.includes(:scores).each do |submission| | ||||||||||||||||||||||||||||||||||
# Assuming 'score' is a method that sums up scores for a submission | ||||||||||||||||||||||||||||||||||
score = submission.scores.sum(&:points) | ||||||||||||||||||||||||||||||||||
grade = grade_boundaries.keys.reverse.detect { |grade| score >= grade_boundaries[grade] } | ||||||||||||||||||||||||||||||||||
distribution[grade] += 1 | ||||||||||||||||||||||||||||||||||
end | ||||||||||||||||||||||||||||||||||
Comment on lines
+482
to
+488
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix variable shadowing and add error handling There are several issues to address:
- total_submissions = submissions.joins(:scores).count
- submissions.includes(:scores).each do |submission|
- # Assuming 'score' is a method that sums up scores for a submission
- score = submission.scores.sum(&:points)
- grade = grade_boundaries.keys.reverse.detect { |grade| score >= grade_boundaries[grade] }
- distribution[grade] += 1
+ submissions_with_scores = submissions.includes(:scores).select { |s| s.scores.any? }
+ total_submissions = submissions_with_scores.length
+
+ return {} if total_submissions.zero?
+
+ submissions_with_scores.each do |submission|
+ score = submission.scores.sum(&:points)
+ letter_grade = grade_boundaries.keys.reverse.detect { |g| score >= grade_boundaries[g] }
+ distribution[letter_grade] += 1 📝 Committable suggestion
Suggested change
🧰 Tools🪛 rubocop (1.68.0)[warning] 486-486: Shadowing outer local variable - (Lint/ShadowingOuterLocalVariable) |
||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
# Convert counts to percentages | ||||||||||||||||||||||||||||||||||
distribution.transform_values { |count| (count.to_f / total_submissions * 100).round(2) } | ||||||||||||||||||||||||||||||||||
end | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
def load_dir_to_tar(dir_path, asmt_dir, tar, filters = [], export_dir = "") | ||||||||||||||||||||||||||||||||||
Dir[File.join(dir_path, asmt_dir, "**")].each do |file| | ||||||||||||||||||||||||||||||||||
mode = File.stat(file).mode | ||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Add error handling for PLD and GDU calculations.
The calls to
calculate_pld
andcalculate_gdu
should be wrapped in error handling to gracefully handle potential calculation failures.📝 Committable suggestion