From 134139c39d60e85daa4f69cbe369aa94b278e492 Mon Sep 17 00:00:00 2001 From: Mahdi Date: Sun, 11 May 2014 18:38:29 +0200 Subject: [PATCH] Issue #476 Modified the statistics method --- tutor/Gemfile.lock | 4 ++++ tutor/app/controllers/application_controller.rb | 2 +- tutor/app/controllers/students_controller.rb | 15 +++++++++------ .../app/views/students/get_performance.html.erb | 17 +++++++---------- tutor/app/views/students/list_courses.html.erb | 6 ++++++ tutor/config/routes.rb | 4 ++++ 6 files changed, 31 insertions(+), 17 deletions(-) create mode 100644 tutor/app/views/students/list_courses.html.erb diff --git a/tutor/Gemfile.lock b/tutor/Gemfile.lock index ee92c0fb..04b64b45 100644 --- a/tutor/Gemfile.lock +++ b/tutor/Gemfile.lock @@ -36,6 +36,7 @@ GEM activesupport (>= 3.2.0) json (>= 1.7) mime-types (>= 1.16) + chartkick (1.2.4) chronic (0.10.2) coffee-rails (4.0.1) coffee-script (>= 2.2.0) @@ -58,6 +59,7 @@ GEM foreman (0.63.0) dotenv (>= 0.7) thor (>= 0.13.6) + googlecharts (1.6.8) hashr (0.0.22) hike (1.2.3) i18n (0.6.9) @@ -155,10 +157,12 @@ PLATFORMS DEPENDENCIES acts_as_list carrierwave + chartkick coffee-rails (~> 4.0.0) composite_primary_keys (~> 6.0.1) devise foreman + googlecharts jbuilder (~> 1.2) jquery-rails (~> 3.1.0) json_builder (= 3.1.0) diff --git a/tutor/app/controllers/application_controller.rb b/tutor/app/controllers/application_controller.rb index 897c93b6..b8dca643 100644 --- a/tutor/app/controllers/application_controller.rb +++ b/tutor/app/controllers/application_controller.rb @@ -7,7 +7,7 @@ class ApplicationController < ActionController::Base before_action :update_sanitized_params, if: :devise_controller? before_action :check_resource, if: :devise_controller? - rescue_from Exception, :with => :render_not_found + #rescue_from Exception, :with => :render_not_found private diff --git a/tutor/app/controllers/students_controller.rb b/tutor/app/controllers/students_controller.rb index f2214bde..3c6a3be3 100644 --- a/tutor/app/controllers/students_controller.rb +++ b/tutor/app/controllers/students_controller.rb @@ -11,11 +11,14 @@ class StudentsController < ApplicationController # @incomplete: [int] The number of incomplete problems # Author: Mahdi def get_performance - @solved = Attempt.where(student_id:params[:id], success:true).select("DISTINCT problem_id").count - @failed = Attempt.where(student_id:params[:id], failure:true).select("DISTINCT problem_id").count - @incomplete = Attempt.where(student_id:params[:id], incomplete:true).select("DISTINCT problem_id").count + @solved = Attempt.where(student_id:params[:student_id], success:true).joins(problem: {track: :topic}).where('topics.course_id' => params[:course_id]).select("DISTINCT problem_id").count + @failed = Attempt.where(student_id:params[:student_id], failure:true).joins(problem: {track: :topic}).where('topics.course_id' => params[:course_id]).select("DISTINCT problem_id").count + @incomplete = Attempt.where(student_id:params[:student_id], incomplete:true).joins(problem: {track: :topic}).where('topics.course_id' => params[:course_id]).select("DISTINCT problem_id").count end + def list_courses + @courses_list = CourseStudent.where(student_id: current_student.id) + end # [Performance of a student - Story 5.3] # This method retrieve variables from tables in the database # Parameters: @@ -24,7 +27,7 @@ def get_performance # An array of solved problems # Author: Mahdi def solved_problems - @solved_list = Attempt.where(student_id:params[:id], success:true).select("DISTINCT problem_id") + @solved_list = Attempt.where(student_id:params[:student_id], success:true).joins(problem: {track: :topic}).where('topics.course_id' => params[:course_id]).select("DISTINCT problem_id") end # [Performance of a student - Story 5.3] @@ -35,7 +38,7 @@ def solved_problems # An array of failed problems # Author: Mahdi def failed_problems - @failure_list = Attempt.where(student_id:params[:id], failure:true).select("DISTINCT problem_id") + @failure_list = Attempt.where(student_id:params[:id], failure:true).where('topics.course_id' => params[:course_id]).select("DISTINCT problem_id") end # [Performance of a student - Story 5.3] @@ -46,7 +49,7 @@ def failed_problems # An array of incomplete problems # Author: Mahdi def incomplete_problems - @incomplete_list = Attempt.where(student_id:params[:id], incomplete:true).select("DISTINCT problem_id") + @incomplete_list = Attempt.where(student_id:params[:id], incomplete:true).where('topics.course_id' => params[:course_id]).select("DISTINCT problem_id") end diff --git a/tutor/app/views/students/get_performance.html.erb b/tutor/app/views/students/get_performance.html.erb index cf8ed5f6..fe2102e3 100644 --- a/tutor/app/views/students/get_performance.html.erb +++ b/tutor/app/views/students/get_performance.html.erb @@ -1,16 +1,13 @@ <%= javascript_include_tag "//www.google.com/jsapi", "chartkick" %> -<%= column_chart -[ - [ "Solved ones", @solved ], - [ "Wrong attempts", @failed ], - [ "Uncompleted ones", @incomplete] -], - library: {bar: {groupWidth: "10%"}}, - colors: ["lightblue"] -%> +<%= column_chart [["Solved ones", @solved], + ["Wrong attempts", @failed], + ["Incomplete attempts", @incomplete]], + library: {bar: {groupWidth: "10%"}}, + colors: ["lightblue"]%> +
-
+
\ No newline at end of file diff --git a/tutor/app/views/students/list_courses.html.erb b/tutor/app/views/students/list_courses.html.erb new file mode 100644 index 00000000..59c91dd5 --- /dev/null +++ b/tutor/app/views/students/list_courses.html.erb @@ -0,0 +1,6 @@ +

Choose a course :-


+<% @courses_list.each do |crs| %> +
  • <%= link_to (Course.find_by_id(crs.course_id).name), students_get_performance_path(:student_id => crs.student_id, :course_id => crs.course_id) %>

  • +<% end %> + +<%= debug(@courses_list) %> \ No newline at end of file diff --git a/tutor/config/routes.rb b/tutor/config/routes.rb index 1b36444b..25c6c281 100644 --- a/tutor/config/routes.rb +++ b/tutor/config/routes.rb @@ -24,6 +24,10 @@ post '/posts/:id' => 'posts#update' post 'tracks/insert_recommendation' => 'tracks#insert_recommendation' post 'debuggers/:id' => 'debuggers#start' + get 'students/get_performance' => 'students#get_performance' + get 'students/list_courses' => 'students#list_courses' + get 'students/solved_problems' => 'students#solved_problems' + get 'students/failed_problems' => 'students#failed_problems' get 'problems/edit'