Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions app/controllers/peer_progress_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
class PeerProgressController < ApplicationController
def show
student_id = params[:student_id].to_i
unit_id = params[:unit_id].to_i

project = Project.find_by(user_id: student_id, unit_id: unit_id)

return render json: { error: "Project not found" }, status: :not_found unless project

target_grade = project.target_grade

required_tasks = project.unit.tasks.where(project_id: project.id).select do |task|
task.task_definition.present? &&
task.task_definition.target_grade.present? &&
task.task_definition.target_grade <= target_grade
end

tasks_required = required_tasks.count
tasks_completed = required_tasks.select(&:complete?).count

progress_percentage =
tasks_required.positive? ? ((tasks_completed.to_f / tasks_required) * 100).round : 0

render json: {
student_id: student_id,
unit_id: unit_id,
target_grade: project.target_grade_desc,
tasks_completed: tasks_completed,
tasks_required: tasks_required,
progress_percentage: progress_percentage
}
end
end
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
get 'api/submission/unit/:id/task_definitions/:task_def_id/download_submissions', to: 'task_downloads#index'
get 'api/submission/unit/:id/task_definitions/:task_def_id/student_pdfs', to: 'task_submission_pdfs#index'
get 'api/units/:id/all_resources', to: 'lecture_resource_downloads#index'
get 'api/peer_progress/:unit_id/:student_id', to: 'peer_progress#show'

mount ApiRoot => '/'
mount GrapeSwaggerRails::Engine => '/api/docs'
Expand Down