{"action":"created","comment":{"url":"https://api.github.com/repos/krazemon/repcoin/pulls/comments/27246181","id":27246181,"diff_hunk":"@@ -254,114 +254,103 @@ UserSchema.statics.getLeadersByTimeStamp = function(high) {\n     .exec();\n };\n \n-// Find the top 10 leaders by investor reps\n-UserSchema.statics.getLeadersByExpertReps = function(high) {\n-  return this.find({}, privateFields)\n-    .sort({ \"categories.reps\": high })\n-    .limit(10)\n-    .exec();\n-};\n-\n-// Get top ranked user ids for a given investor category, descending\n-// Ranking done by total reps\n-// Only returns the username, picture, rank, and reps for the category\n-UserSchema.statics.findTopRankedInvestors = function(category) {\n-  return this.aggregate([\n-    { $match: { \"portfolio.category\": category }},\n-    { $unwind: \"$portfolio\" },\n-    { $match: { \"portfolio.category\": category }},\n-    { $sort: { \"portfolio.rank\": 1 }},\n-    { $project: { _id: 1, picture: 1, \"portfolio.rank\": 1, username: 1 }},\n-    { $limit: 10 },\n-  ]).exec();\n-};\n+// Find the top 10 experts by metric for a given category\n+// Metrics available are timeStamp and reps given\n+// Returns truncated data for efficiency\n+UserSchema.statics.getExpertsByMetricForCategory = function(high, category, metric) {\n+  var sorter = {};\n+  switch(metric) {\n+    case 'timeStamp':\n+      sorter[metric] = high;\n+      break;\n+\n+    case 'reps':\n+      sorter['categories.reps'] = high;\n+      break;\n+\n+    default:\n+      sorter['categories.reps'] = high;\n+      break;\n+  }\n \n-// Get top ranked user ids for a given expert category, descending\n-// Ranking done by total reps\n-// Only returns the username, picture, rank, and reps for the category\n-UserSchema.statics.findTopRankedExperts = function(category) {\n   return this.aggregate([\n     { $match: { \"categories.name\": category }},\n     { $unwind: \"$categories\" },\n     { $match: { \"categories.name\": category }},\n-    { $sort: { \"categories.rank\": 1 }},\n-    { $project: { _id: 1, picture: 1, \"categories.rank\": 1, \"categories.reps\": 1, username: 1 }},\n+    { $sort: sorter},\n+    { $project: { _id: 1, picture: 1, rank: \"$categories.rank\", reps: \"$categories.reps\", username: 1, about: 1 }},\n     { $limit: 10 },\n   ]).exec();\n };\n \n-// Get ranked user ids for a given expert category, descending\n-// Ranking done by total reps\n-// Only returns the IDs of the users in ranked order\n-UserSchema.statics.findRankedExperts = function(category) {\n-  return this.aggregate([\n-    { $match: { \"categories.name\": category }},\n-    { $unwind: \"$categories\" },\n-    { $match: { \"categories.name\": category }},\n-    { $sort: { \"categories.reps\": -1 }},\n-    { $project: { _id: 1 }},\n-  ]).exec();\n-};\n-\n-// Get ranked user ids for a given expert category, decreasing\n-// Ranking done by total dividends\n-UserSchema.statics.findRankedInvestors = function(category) {\n+// Find the top 10 investors by metric for a given category\n+// Metrics available are timeStamp, average return, total dividends, and rank\n+// Currently used for the Investor Dashboard on the Category Page\n+// Returns truncated data for efficiency\n+UserSchema.statics.getInvestorsByMetricForCategory = function(high, category, metric) {\n+  var sorter = {};\n+  sorter[metric] = high;\n   return this.aggregate([\n     { $match: { \"portfolio.category\": category }},\n     { $unwind: \"$portfolio\" },\n     { $unwind: \"$portfolio.investments\" },\n-    { $match: { \"portfolio.category\": category } },\n-    { $group: { _id: \"$_id\", dividends: { $sum: \"$portfolio.investments.dividend\" } }},\n-    { $sort: { \"dividends\": -1 }},\n-    { $project: { \"_id\": 1 } },\n+    { $match: { \"portfolio.category\": category }},\n+    { $group:","path":"api/models/User.js","position":92,"original_position":92,"commit_id":"11f4d150938b401f6eafe6e74cb3390e583ffb8e","original_commit_id":"11f4d150938b401f6eafe6e74cb3390e583ffb8e","user":{"login":"ritmatter","id":3967620,"avatar_url":"https://avatars.githubusercontent.com/u/3967620?v=3","gravatar_id":"","url":"https://api.github.com/users/ritmatter","html_url":"https://github.com/ritmatter","followers_url":"https://api.github.com/users/ritmatter/followers","following_url":"https://api.github.com/users/ritmatter/following{/other_user}","gists_url":"https://api.github.com/users/ritmatter/gists{/gist_id}","starred_url":"https://api.github.com/users/ritmatter/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ritmatter/subscriptions","organizations_url":"https://api.github.com/users/ritmatter/orgs","repos_url":"https://api.github.com/users/ritmatter/repos","events_url":"https://api.github.com/users/ritmatter/events{/privacy}","received_events_url":"https://api.github.com/users/ritmatter/received_events","type":"User","site_admin":false},"body":"Grouping requires fields to be inside an object. we put all the old stuff we want to keep inside the _id json block and then unpack it in the $project.","created_at":"2015-03-26T19:14:24Z","updated_at":"2015-03-26T19:14:24Z","html_url":"https://github.com/krazemon/repcoin/pull/737#discussion_r27246181","pull_request_url":"https://api.github.com/repos/krazemon/repcoin/pulls/737","_links":{"self":{"href":"https://api.github.com/repos/krazemon/repcoin/pulls/comments/27246181"},"html":{"href":"https://github.com/krazemon/repcoin/pull/737#discussion_r27246181"},"pull_request":{"href":"https://api.github.com/repos/krazemon/repcoin/pulls/737"}}},"pull_request":{"url":"https://api.github.com/repos/krazemon/repcoin/pulls/737","id":32050605,"html_url":"https://github.com/krazemon/repcoin/pull/737","diff_url":"https://github.com/krazemon/repcoin/pull/737.diff","patch_url":"https://github.com/krazemon/repcoin/pull/737.patch","issue_url":"https://api.github.com/repos/krazemon/repcoin/issues/737","number":737,"state":"open","locked":false,"title":"Add category page dashboard first iteration","user":{"login":"ritmatter","id":3967620,"avatar_url":"https://avatars.githubusercontent.com/u/3967620?v=3","gravatar_id":"","url":"https://api.github.com/users/ritmatter","html_url":"https://github.com/ritmatter","followers_url":"https://api.github.com/users/ritmatter/followers","following_url":"https://api.github.com/users/ritmatter/following{/other_user}","gists_url":"https://api.github.com/users/ritmatter/gists{/gist_id}","starred_url":"https://api.github.com/users/ritmatter/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ritmatter/subscriptions","organizations_url":"https://api.github.com/users/ritmatter/orgs","repos_url":"https://api.github.com/users/ritmatter/repos","events_url":"https://api.github.com/users/ritmatter/events{/privacy}","received_events_url":"https://api.github.com/users/ritmatter/received_events","type":"User","site_admin":false},"body":"","created_at":"2015-03-26T19:12:22Z","updated_at":"2015-03-26T19:14:24Z","closed_at":null,"merged_at":null,"merge_commit_sha":"6bc314addb72ce4f72625cfb1a1e7becc375a5d3","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/krazemon/repcoin/pulls/737/commits","review_comments_url":"https://api.github.com/repos/krazemon/repcoin/pulls/737/comments","review_comment_url":"https://api.github.com/repos/krazemon/repcoin/pulls/comments{/number}","comments_url":"https://api.github.com/repos/krazemon/repcoin/issues/737/comments","statuses_url":"https://api.github.com/repos/krazemon/repcoin/statuses/11f4d150938b401f6eafe6e74cb3390e583ffb8e","head":{"label":"krazemon:category-dashboard","ref":"category-dashboard","sha":"11f4d150938b401f6eafe6e74cb3390e583ffb8e","user":{"login":"krazemon","id":1093790,"avatar_url":"https://avatars.githubusercontent.com/u/1093790?v=3","gravatar_id":"","url":"https://api.github.com/users/krazemon","html_url":"https://github.com/krazemon","followers_url":"https://api.github.com/users/krazemon/followers","following_url":"https://api.github.com/users/krazemon/following{/other_user}","gists_url":"https://api.github.com/users/krazemon/gists{/gist_id}","starred_url":"https://api.github.com/users/krazemon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/krazemon/subscriptions","organizations_url":"https://api.github.com/users/krazemon/orgs","repos_url":"https://api.github.com/users/krazemon/repos","events_url":"https://api.github.com/users/krazemon/events{/privacy}","received_events_url":"https://api.github.com/users/krazemon/received_events","type":"User","site_admin":false},"repo":{"id":24356890,"name":"repcoin","full_name":"krazemon/repcoin","owner":{"login":"krazemon","id":1093790,"avatar_url":"https://avatars.githubusercontent.com/u/1093790?v=3","gravatar_id":"","url":"https://api.github.com/users/krazemon","html_url":"https://github.com/krazemon","followers_url":"https://api.github.com/users/krazemon/followers","following_url":"https://api.github.com/users/krazemon/following{/other_user}","gists_url":"https://api.github.com/users/krazemon/gists{/gist_id}","starred_url":"https://api.github.com/users/krazemon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/krazemon/subscriptions","organizations_url":"https://api.github.com/users/krazemon/orgs","repos_url":"https://api.github.com/users/krazemon/repos","events_url":"https://api.github.com/users/krazemon/events{/privacy}","received_events_url":"https://api.github.com/users/krazemon/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/krazemon/repcoin","description":"The only market-based approach to reputation.","fork":false,"url":"https://api.github.com/repos/krazemon/repcoin","forks_url":"https://api.github.com/repos/krazemon/repcoin/forks","keys_url":"https://api.github.com/repos/krazemon/repcoin/keys{/key_id}","collaborators_url":"https://api.github.com/repos/krazemon/repcoin/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/krazemon/repcoin/teams","hooks_url":"https://api.github.com/repos/krazemon/repcoin/hooks","issue_events_url":"https://api.github.com/repos/krazemon/repcoin/issues/events{/number}","events_url":"https://api.github.com/repos/krazemon/repcoin/events","assignees_url":"https://api.github.com/repos/krazemon/repcoin/assignees{/user}","branches_url":"https://api.github.com/repos/krazemon/repcoin/branches{/branch}","tags_url":"https://api.github.com/repos/krazemon/repcoin/tags","blobs_url":"https://api.github.com/repos/krazemon/repcoin/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/krazemon/repcoin/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/krazemon/repcoin/git/refs{/sha}","trees_url":"https://api.github.com/repos/krazemon/repcoin/git/trees{/sha}","statuses_url":"https://api.github.com/repos/krazemon/repcoin/statuses/{sha}","languages_url":"https://api.github.com/repos/krazemon/repcoin/languages","stargazers_url":"https://api.github.com/repos/krazemon/repcoin/stargazers","contributors_url":"https://api.github.com/repos/krazemon/repcoin/contributors","subscribers_url":"https://api.github.com/repos/krazemon/repcoin/subscribers","subscription_url":"https://api.github.com/repos/krazemon/repcoin/subscription","commits_url":"https://api.github.com/repos/krazemon/repcoin/commits{/sha}","git_commits_url":"https://api.github.com/repos/krazemon/repcoin/git/commits{/sha}","comments_url":"https://api.github.com/repos/krazemon/repcoin/comments{/number}","issue_comment_url":"https://api.github.com/repos/krazemon/repcoin/issues/comments{/number}","contents_url":"https://api.github.com/repos/krazemon/repcoin/contents/{+path}","compare_url":"https://api.github.com/repos/krazemon/repcoin/compare/{base}...{head}","merges_url":"https://api.github.com/repos/krazemon/repcoin/merges","archive_url":"https://api.github.com/repos/krazemon/repcoin/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/krazemon/repcoin/downloads","issues_url":"https://api.github.com/repos/krazemon/repcoin/issues{/number}","pulls_url":"https://api.github.com/repos/krazemon/repcoin/pulls{/number}","milestones_url":"https://api.github.com/repos/krazemon/repcoin/milestones{/number}","notifications_url":"https://api.github.com/repos/krazemon/repcoin/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/krazemon/repcoin/labels{/name}","releases_url":"https://api.github.com/repos/krazemon/repcoin/releases{/id}","created_at":"2014-09-23T04:35:30Z","updated_at":"2015-03-17T00:01:47Z","pushed_at":"2015-03-26T19:12:22Z","git_url":"git://github.com/krazemon/repcoin.git","ssh_url":"git@github.com:krazemon/repcoin.git","clone_url":"https://github.com/krazemon/repcoin.git","svn_url":"https://github.com/krazemon/repcoin","homepage":"","size":7420,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":53,"forks":0,"open_issues":53,"watchers":0,"default_branch":"master"}},"base":{"label":"krazemon:master","ref":"master","sha":"2644225f769a769a8f6b1b9510aee684076fe67b","user":{"login":"krazemon","id":1093790,"avatar_url":"https://avatars.githubusercontent.com/u/1093790?v=3","gravatar_id":"","url":"https://api.github.com/users/krazemon","html_url":"https://github.com/krazemon","followers_url":"https://api.github.com/users/krazemon/followers","following_url":"https://api.github.com/users/krazemon/following{/other_user}","gists_url":"https://api.github.com/users/krazemon/gists{/gist_id}","starred_url":"https://api.github.com/users/krazemon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/krazemon/subscriptions","organizations_url":"https://api.github.com/users/krazemon/orgs","repos_url":"https://api.github.com/users/krazemon/repos","events_url":"https://api.github.com/users/krazemon/events{/privacy}","received_events_url":"https://api.github.com/users/krazemon/received_events","type":"User","site_admin":false},"repo":{"id":24356890,"name":"repcoin","full_name":"krazemon/repcoin","owner":{"login":"krazemon","id":1093790,"avatar_url":"https://avatars.githubusercontent.com/u/1093790?v=3","gravatar_id":"","url":"https://api.github.com/users/krazemon","html_url":"https://github.com/krazemon","followers_url":"https://api.github.com/users/krazemon/followers","following_url":"https://api.github.com/users/krazemon/following{/other_user}","gists_url":"https://api.github.com/users/krazemon/gists{/gist_id}","starred_url":"https://api.github.com/users/krazemon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/krazemon/subscriptions","organizations_url":"https://api.github.com/users/krazemon/orgs","repos_url":"https://api.github.com/users/krazemon/repos","events_url":"https://api.github.com/users/krazemon/events{/privacy}","received_events_url":"https://api.github.com/users/krazemon/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/krazemon/repcoin","description":"The only market-based approach to reputation.","fork":false,"url":"https://api.github.com/repos/krazemon/repcoin","forks_url":"https://api.github.com/repos/krazemon/repcoin/forks","keys_url":"https://api.github.com/repos/krazemon/repcoin/keys{/key_id}","collaborators_url":"https://api.github.com/repos/krazemon/repcoin/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/krazemon/repcoin/teams","hooks_url":"https://api.github.com/repos/krazemon/repcoin/hooks","issue_events_url":"https://api.github.com/repos/krazemon/repcoin/issues/events{/number}","events_url":"https://api.github.com/repos/krazemon/repcoin/events","assignees_url":"https://api.github.com/repos/krazemon/repcoin/assignees{/user}","branches_url":"https://api.github.com/repos/krazemon/repcoin/branches{/branch}","tags_url":"https://api.github.com/repos/krazemon/repcoin/tags","blobs_url":"https://api.github.com/repos/krazemon/repcoin/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/krazemon/repcoin/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/krazemon/repcoin/git/refs{/sha}","trees_url":"https://api.github.com/repos/krazemon/repcoin/git/trees{/sha}","statuses_url":"https://api.github.com/repos/krazemon/repcoin/statuses/{sha}","languages_url":"https://api.github.com/repos/krazemon/repcoin/languages","stargazers_url":"https://api.github.com/repos/krazemon/repcoin/stargazers","contributors_url":"https://api.github.com/repos/krazemon/repcoin/contributors","subscribers_url":"https://api.github.com/repos/krazemon/repcoin/subscribers","subscription_url":"https://api.github.com/repos/krazemon/repcoin/subscription","commits_url":"https://api.github.com/repos/krazemon/repcoin/commits{/sha}","git_commits_url":"https://api.github.com/repos/krazemon/repcoin/git/commits{/sha}","comments_url":"https://api.github.com/repos/krazemon/repcoin/comments{/number}","issue_comment_url":"https://api.github.com/repos/krazemon/repcoin/issues/comments{/number}","contents_url":"https://api.github.com/repos/krazemon/repcoin/contents/{+path}","compare_url":"https://api.github.com/repos/krazemon/repcoin/compare/{base}...{head}","merges_url":"https://api.github.com/repos/krazemon/repcoin/merges","archive_url":"https://api.github.com/repos/krazemon/repcoin/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/krazemon/repcoin/downloads","issues_url":"https://api.github.com/repos/krazemon/repcoin/issues{/number}","pulls_url":"https://api.github.com/repos/krazemon/repcoin/pulls{/number}","milestones_url":"https://api.github.com/repos/krazemon/repcoin/milestones{/number}","notifications_url":"https://api.github.com/repos/krazemon/repcoin/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/krazemon/repcoin/labels{/name}","releases_url":"https://api.github.com/repos/krazemon/repcoin/releases{/id}","created_at":"2014-09-23T04:35:30Z","updated_at":"2015-03-17T00:01:47Z","pushed_at":"2015-03-26T19:12:22Z","git_url":"git://github.com/krazemon/repcoin.git","ssh_url":"git@github.com:krazemon/repcoin.git","clone_url":"https://github.com/krazemon/repcoin.git","svn_url":"https://github.com/krazemon/repcoin","homepage":"","size":7420,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":53,"forks":0,"open_issues":53,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/krazemon/repcoin/pulls/737"},"html":{"href":"https://github.com/krazemon/repcoin/pull/737"},"issue":{"href":"https://api.github.com/repos/krazemon/repcoin/issues/737"},"comments":{"href":"https://api.github.com/repos/krazemon/repcoin/issues/737/comments"},"review_comments":{"href":"https://api.github.com/repos/krazemon/repcoin/pulls/737/comments"},"review_comment":{"href":"https://api.github.com/repos/krazemon/repcoin/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/krazemon/repcoin/pulls/737/commits"},"statuses":{"href":"https://api.github.com/repos/krazemon/repcoin/statuses/11f4d150938b401f6eafe6e74cb3390e583ffb8e"}}}}