{"action":"created","comment":{"url":"https://api.github.com/repos/openstax/tutor-server/pulls/comments/28114091","id":28114091,"diff_hunk":"@@ -130,6 +130,25 @@ def practice_get\n       respond_with(task.task, represent_with: Api::V1::TaskRepresenter)\n   end\n \n+  api :GET, '/courses/:course_id/performance(/role/:role_id)', 'Returns performance book for the user'\n+  def performance\n+    course = Entity::Course.find(params[:id])\n+    if params[:role_id].present?\n+      roles = [Entity::Role.find(params[:role_id])]\n+    else\n+      roles = GetUserCourseRoles[course: course, user: current_human_user.entity_user]\n+    end\n+    pbook = Tasks::GetPerformanceBook[course: course, roles: roles]","path":"app/controllers/api/v1/courses_controller.rb","position":12,"original_position":12,"commit_id":"972d9aad3f87c9ad407127d07396cb0e40ce3fb5","original_commit_id":"972d9aad3f87c9ad407127d07396cb0e40ce3fb5","user":{"login":"jpslav","id":1001691,"avatar_url":"https://avatars.githubusercontent.com/u/1001691?v=3","gravatar_id":"","url":"https://api.github.com/users/jpslav","html_url":"https://github.com/jpslav","followers_url":"https://api.github.com/users/jpslav/followers","following_url":"https://api.github.com/users/jpslav/following{/other_user}","gists_url":"https://api.github.com/users/jpslav/gists{/gist_id}","starred_url":"https://api.github.com/users/jpslav/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jpslav/subscriptions","organizations_url":"https://api.github.com/users/jpslav/orgs","repos_url":"https://api.github.com/users/jpslav/repos","events_url":"https://api.github.com/users/jpslav/events{/privacy}","received_events_url":"https://api.github.com/users/jpslav/received_events","type":"User","site_admin":false},"body":"I guess I'm in part saying that there should be less logic in the controller, and that maybe there's a top-level routine (now just in `app/routines`) called `GetPerformanceBook` which calls `Tasks::GetPerformanceBook` and looks something like this:\r\n\r\n```ruby\r\nclass GetPerformanceBook\r\n  lev_routine\r\n\r\n  # maybe other routines called with uses_routine style...\r\n\r\n  uses_routine Tasks::GetPerformanceBook\r\n               as: :get_performance_book,\r\n               translations: { outputs: { type: :verbatim} }                             \r\n\r\n  def exec(course:, for_role:)\r\n    for_role_is_teacher = CourseMembership::IsCourseTeacher[course: course, roles: for_role]\r\n\r\n    student_roles = \r\n      for_role_is_teacher ?\r\n        CourseMembership::GetCourseRoles[course: course, type: :student] :\r\n        [for_role]\r\n\r\n    # The `GetPerformanceBook` in the `Tasks` subsystem doesn't need to know anything\r\n    # about courses, it just returns performance information for any specified set of roles.\r\n    # (the `Tasks` subsystem doesn't even know about students or teachers, it just knows \r\n    # of generic roles so this is a good thing).  It is the top-level `GetPerformanceBook` that \r\n    # can call various subsystems and figure out which roles we should get data for.\r\n    run(:get_performance_book, roles: student_roles)\r\n  end\r\nend\r\n```","created_at":"2015-04-10T00:05:28Z","updated_at":"2015-04-10T00:05:28Z","html_url":"https://github.com/openstax/tutor-server/pull/173#discussion_r28114091","pull_request_url":"https://api.github.com/repos/openstax/tutor-server/pulls/173","_links":{"self":{"href":"https://api.github.com/repos/openstax/tutor-server/pulls/comments/28114091"},"html":{"href":"https://github.com/openstax/tutor-server/pull/173#discussion_r28114091"},"pull_request":{"href":"https://api.github.com/repos/openstax/tutor-server/pulls/173"}}},"pull_request":{"url":"https://api.github.com/repos/openstax/tutor-server/pulls/173","id":32869764,"html_url":"https://github.com/openstax/tutor-server/pull/173","diff_url":"https://github.com/openstax/tutor-server/pull/173.diff","patch_url":"https://github.com/openstax/tutor-server/pull/173.patch","issue_url":"https://api.github.com/repos/openstax/tutor-server/issues/173","number":173,"state":"open","locked":false,"title":"WIP performance book API","user":{"login":"karenc","id":153353,"avatar_url":"https://avatars.githubusercontent.com/u/153353?v=3","gravatar_id":"","url":"https://api.github.com/users/karenc","html_url":"https://github.com/karenc","followers_url":"https://api.github.com/users/karenc/followers","following_url":"https://api.github.com/users/karenc/following{/other_user}","gists_url":"https://api.github.com/users/karenc/gists{/gist_id}","starred_url":"https://api.github.com/users/karenc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/karenc/subscriptions","organizations_url":"https://api.github.com/users/karenc/orgs","repos_url":"https://api.github.com/users/karenc/repos","events_url":"https://api.github.com/users/karenc/events{/privacy}","received_events_url":"https://api.github.com/users/karenc/received_events","type":"User","site_admin":false},"body":"TODO\r\n\r\n- Implement the API for teachers\r\n- Get default role to work\r\n- Class average for homework assignments\r\n- Real data for homework assignments for each student\r\n\r\nUsing `rake sprint:009sp`, logged in as `no_history`, going to `http://localhost:3001/api/courses/1/performance` returns:\r\n\r\n```\r\n{\r\n  \"data_headings\": [\r\n    {\r\n      \"title\": \"iReading 1: Force\",\r\n      \"class_average\": 81.2\r\n    },\r\n    {\r\n      \"title\": \"iReading 2: Newton's First Law of Motion: Inertia\",\r\n      \"class_average\": 81.2\r\n    },\r\n    {\r\n      \"title\": \"iReading 3: Newton's Second Law of Motion:\",\r\n      \"class_average\": 81.2\r\n    },\r\n    {\r\n      \"title\": \"iReading 4: Newton's Third Law of Motion\",\r\n      \"class_average\": 81.2\r\n    }\r\n  ],\r\n  \"students\": {\r\n    \"name\": \"238824d01158a4cba51f956d1d6c865c\",\r\n    \"role\": 3,\r\n    \"data\": [\r\n      {\r\n        \"status\": \"in_progress\",\r\n        \"type\": \"reading\",\r\n        \"id\": 3\r\n      },\r\n      {\r\n        \"status\": \"in_progress\",\r\n        \"type\": \"reading\",\r\n        \"id\": 6\r\n      },\r\n      {\r\n        \"status\": \"in_progress\",\r\n        \"type\": \"reading\",\r\n        \"id\": 9\r\n      },\r\n      {\r\n        \"status\": \"in_progress\",\r\n        \"type\": \"reading\",\r\n        \"id\": 12\r\n      }\r\n    ]\r\n  }\r\n}\r\n```","created_at":"2015-04-08T15:10:40Z","updated_at":"2015-04-10T00:05:28Z","closed_at":null,"merged_at":null,"merge_commit_sha":"9a1d0c3d0c67391ed37e2096ad8cfc672a87bded","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/openstax/tutor-server/pulls/173/commits","review_comments_url":"https://api.github.com/repos/openstax/tutor-server/pulls/173/comments","review_comment_url":"https://api.github.com/repos/openstax/tutor-server/pulls/comments{/number}","comments_url":"https://api.github.com/repos/openstax/tutor-server/issues/173/comments","statuses_url":"https://api.github.com/repos/openstax/tutor-server/statuses/972d9aad3f87c9ad407127d07396cb0e40ce3fb5","head":{"label":"openstax:performance-book","ref":"performance-book","sha":"972d9aad3f87c9ad407127d07396cb0e40ce3fb5","user":{"login":"openstax","id":3805549,"avatar_url":"https://avatars.githubusercontent.com/u/3805549?v=3","gravatar_id":"","url":"https://api.github.com/users/openstax","html_url":"https://github.com/openstax","followers_url":"https://api.github.com/users/openstax/followers","following_url":"https://api.github.com/users/openstax/following{/other_user}","gists_url":"https://api.github.com/users/openstax/gists{/gist_id}","starred_url":"https://api.github.com/users/openstax/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/openstax/subscriptions","organizations_url":"https://api.github.com/users/openstax/orgs","repos_url":"https://api.github.com/users/openstax/repos","events_url":"https://api.github.com/users/openstax/events{/privacy}","received_events_url":"https://api.github.com/users/openstax/received_events","type":"Organization","site_admin":false},"repo":{"id":24337612,"name":"tutor-server","full_name":"openstax/tutor-server","owner":{"login":"openstax","id":3805549,"avatar_url":"https://avatars.githubusercontent.com/u/3805549?v=3","gravatar_id":"","url":"https://api.github.com/users/openstax","html_url":"https://github.com/openstax","followers_url":"https://api.github.com/users/openstax/followers","following_url":"https://api.github.com/users/openstax/following{/other_user}","gists_url":"https://api.github.com/users/openstax/gists{/gist_id}","starred_url":"https://api.github.com/users/openstax/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/openstax/subscriptions","organizations_url":"https://api.github.com/users/openstax/orgs","repos_url":"https://api.github.com/users/openstax/repos","events_url":"https://api.github.com/users/openstax/events{/privacy}","received_events_url":"https://api.github.com/users/openstax/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/openstax/tutor-server","description":"OpenStax Tutor 3.0 Backend","fork":false,"url":"https://api.github.com/repos/openstax/tutor-server","forks_url":"https://api.github.com/repos/openstax/tutor-server/forks","keys_url":"https://api.github.com/repos/openstax/tutor-server/keys{/key_id}","collaborators_url":"https://api.github.com/repos/openstax/tutor-server/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/openstax/tutor-server/teams","hooks_url":"https://api.github.com/repos/openstax/tutor-server/hooks","issue_events_url":"https://api.github.com/repos/openstax/tutor-server/issues/events{/number}","events_url":"https://api.github.com/repos/openstax/tutor-server/events","assignees_url":"https://api.github.com/repos/openstax/tutor-server/assignees{/user}","branches_url":"https://api.github.com/repos/openstax/tutor-server/branches{/branch}","tags_url":"https://api.github.com/repos/openstax/tutor-server/tags","blobs_url":"https://api.github.com/repos/openstax/tutor-server/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/openstax/tutor-server/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/openstax/tutor-server/git/refs{/sha}","trees_url":"https://api.github.com/repos/openstax/tutor-server/git/trees{/sha}","statuses_url":"https://api.github.com/repos/openstax/tutor-server/statuses/{sha}","languages_url":"https://api.github.com/repos/openstax/tutor-server/languages","stargazers_url":"https://api.github.com/repos/openstax/tutor-server/stargazers","contributors_url":"https://api.github.com/repos/openstax/tutor-server/contributors","subscribers_url":"https://api.github.com/repos/openstax/tutor-server/subscribers","subscription_url":"https://api.github.com/repos/openstax/tutor-server/subscription","commits_url":"https://api.github.com/repos/openstax/tutor-server/commits{/sha}","git_commits_url":"https://api.github.com/repos/openstax/tutor-server/git/commits{/sha}","comments_url":"https://api.github.com/repos/openstax/tutor-server/comments{/number}","issue_comment_url":"https://api.github.com/repos/openstax/tutor-server/issues/comments{/number}","contents_url":"https://api.github.com/repos/openstax/tutor-server/contents/{+path}","compare_url":"https://api.github.com/repos/openstax/tutor-server/compare/{base}...{head}","merges_url":"https://api.github.com/repos/openstax/tutor-server/merges","archive_url":"https://api.github.com/repos/openstax/tutor-server/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/openstax/tutor-server/downloads","issues_url":"https://api.github.com/repos/openstax/tutor-server/issues{/number}","pulls_url":"https://api.github.com/repos/openstax/tutor-server/pulls{/number}","milestones_url":"https://api.github.com/repos/openstax/tutor-server/milestones{/number}","notifications_url":"https://api.github.com/repos/openstax/tutor-server/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/openstax/tutor-server/labels{/name}","releases_url":"https://api.github.com/repos/openstax/tutor-server/releases{/id}","created_at":"2014-09-22T17:10:29Z","updated_at":"2015-04-09T20:59:17Z","pushed_at":"2015-04-09T23:23:01Z","git_url":"git://github.com/openstax/tutor-server.git","ssh_url":"git@github.com:openstax/tutor-server.git","clone_url":"https://github.com/openstax/tutor-server.git","svn_url":"https://github.com/openstax/tutor-server","homepage":"","size":12279,"stargazers_count":1,"watchers_count":1,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":3,"mirror_url":null,"open_issues_count":10,"forks":3,"open_issues":10,"watchers":1,"default_branch":"master"}},"base":{"label":"openstax:master","ref":"master","sha":"34641ffb2204f3a5b653369ac0c24443f7747191","user":{"login":"openstax","id":3805549,"avatar_url":"https://avatars.githubusercontent.com/u/3805549?v=3","gravatar_id":"","url":"https://api.github.com/users/openstax","html_url":"https://github.com/openstax","followers_url":"https://api.github.com/users/openstax/followers","following_url":"https://api.github.com/users/openstax/following{/other_user}","gists_url":"https://api.github.com/users/openstax/gists{/gist_id}","starred_url":"https://api.github.com/users/openstax/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/openstax/subscriptions","organizations_url":"https://api.github.com/users/openstax/orgs","repos_url":"https://api.github.com/users/openstax/repos","events_url":"https://api.github.com/users/openstax/events{/privacy}","received_events_url":"https://api.github.com/users/openstax/received_events","type":"Organization","site_admin":false},"repo":{"id":24337612,"name":"tutor-server","full_name":"openstax/tutor-server","owner":{"login":"openstax","id":3805549,"avatar_url":"https://avatars.githubusercontent.com/u/3805549?v=3","gravatar_id":"","url":"https://api.github.com/users/openstax","html_url":"https://github.com/openstax","followers_url":"https://api.github.com/users/openstax/followers","following_url":"https://api.github.com/users/openstax/following{/other_user}","gists_url":"https://api.github.com/users/openstax/gists{/gist_id}","starred_url":"https://api.github.com/users/openstax/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/openstax/subscriptions","organizations_url":"https://api.github.com/users/openstax/orgs","repos_url":"https://api.github.com/users/openstax/repos","events_url":"https://api.github.com/users/openstax/events{/privacy}","received_events_url":"https://api.github.com/users/openstax/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/openstax/tutor-server","description":"OpenStax Tutor 3.0 Backend","fork":false,"url":"https://api.github.com/repos/openstax/tutor-server","forks_url":"https://api.github.com/repos/openstax/tutor-server/forks","keys_url":"https://api.github.com/repos/openstax/tutor-server/keys{/key_id}","collaborators_url":"https://api.github.com/repos/openstax/tutor-server/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/openstax/tutor-server/teams","hooks_url":"https://api.github.com/repos/openstax/tutor-server/hooks","issue_events_url":"https://api.github.com/repos/openstax/tutor-server/issues/events{/number}","events_url":"https://api.github.com/repos/openstax/tutor-server/events","assignees_url":"https://api.github.com/repos/openstax/tutor-server/assignees{/user}","branches_url":"https://api.github.com/repos/openstax/tutor-server/branches{/branch}","tags_url":"https://api.github.com/repos/openstax/tutor-server/tags","blobs_url":"https://api.github.com/repos/openstax/tutor-server/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/openstax/tutor-server/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/openstax/tutor-server/git/refs{/sha}","trees_url":"https://api.github.com/repos/openstax/tutor-server/git/trees{/sha}","statuses_url":"https://api.github.com/repos/openstax/tutor-server/statuses/{sha}","languages_url":"https://api.github.com/repos/openstax/tutor-server/languages","stargazers_url":"https://api.github.com/repos/openstax/tutor-server/stargazers","contributors_url":"https://api.github.com/repos/openstax/tutor-server/contributors","subscribers_url":"https://api.github.com/repos/openstax/tutor-server/subscribers","subscription_url":"https://api.github.com/repos/openstax/tutor-server/subscription","commits_url":"https://api.github.com/repos/openstax/tutor-server/commits{/sha}","git_commits_url":"https://api.github.com/repos/openstax/tutor-server/git/commits{/sha}","comments_url":"https://api.github.com/repos/openstax/tutor-server/comments{/number}","issue_comment_url":"https://api.github.com/repos/openstax/tutor-server/issues/comments{/number}","contents_url":"https://api.github.com/repos/openstax/tutor-server/contents/{+path}","compare_url":"https://api.github.com/repos/openstax/tutor-server/compare/{base}...{head}","merges_url":"https://api.github.com/repos/openstax/tutor-server/merges","archive_url":"https://api.github.com/repos/openstax/tutor-server/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/openstax/tutor-server/downloads","issues_url":"https://api.github.com/repos/openstax/tutor-server/issues{/number}","pulls_url":"https://api.github.com/repos/openstax/tutor-server/pulls{/number}","milestones_url":"https://api.github.com/repos/openstax/tutor-server/milestones{/number}","notifications_url":"https://api.github.com/repos/openstax/tutor-server/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/openstax/tutor-server/labels{/name}","releases_url":"https://api.github.com/repos/openstax/tutor-server/releases{/id}","created_at":"2014-09-22T17:10:29Z","updated_at":"2015-04-09T20:59:17Z","pushed_at":"2015-04-09T23:23:01Z","git_url":"git://github.com/openstax/tutor-server.git","ssh_url":"git@github.com:openstax/tutor-server.git","clone_url":"https://github.com/openstax/tutor-server.git","svn_url":"https://github.com/openstax/tutor-server","homepage":"","size":12279,"stargazers_count":1,"watchers_count":1,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":3,"mirror_url":null,"open_issues_count":10,"forks":3,"open_issues":10,"watchers":1,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/openstax/tutor-server/pulls/173"},"html":{"href":"https://github.com/openstax/tutor-server/pull/173"},"issue":{"href":"https://api.github.com/repos/openstax/tutor-server/issues/173"},"comments":{"href":"https://api.github.com/repos/openstax/tutor-server/issues/173/comments"},"review_comments":{"href":"https://api.github.com/repos/openstax/tutor-server/pulls/173/comments"},"review_comment":{"href":"https://api.github.com/repos/openstax/tutor-server/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/openstax/tutor-server/pulls/173/commits"},"statuses":{"href":"https://api.github.com/repos/openstax/tutor-server/statuses/972d9aad3f87c9ad407127d07396cb0e40ce3fb5"}}}}