{"action":"created","comment":{"url":"https://api.github.com/repos/Yinaura/jagi/pulls/comments/37720858","id":37720858,"diff_hunk":"@@ -1,12 +1,50 @@\n class UserProfile < ActiveRecord::Base\n   belongs_to :user\n   has_many :profile_images\n+  belongs_to :project\n+  belongs_to :group\n+\n   delegate :name, to: :user\n+\n   validates :user_id, presence: true, numericality: true, uniqueness: true\n-  validates :answer_name, length: { maximum: 30 }\n+  validates :answer_name, allow_nil: true, length: { maximum: 30 }\n+  validates :group_id, allow_nil: true, numericality: true\n+  validates :project_id, allow_nil: true, numericality: true\n+  validates :gender, allow_nil: true, inclusion: { in: ['', 'male', 'female'] }\n+  validates :joined_year, allow_nil: true, numericality: true\n+  validates :detail, allow_nil: true, length: { maximum: 10000 }\n \n-  def answer_user\n-    self.class.all.sample\n+  def self.for_filter_params\n+    [:joined_year, :group_id, :project_id]\n+  end\n+\n+  def answer_user(filter = {}, user_profile = {})\n+    conditions = {}\n+    not_where = {}\n+\n+    not_where[:answer_name] = nil\n+    not_where[:id] = user_profile.id if !Rails.env.development? && user_profile.present?\n+\n+    conditions[:project_id] = filter['project_id'] if filter['project_id'].present?\n+    conditions[:group_id] = filter['group_id'] if filter['group_id'].present?\n+    conditions[:joined_year] = filter['joined_year'] if filter['joined_year'].present?\n+\n+    conditions[:id] = self.review_mode_user_profile_ids(user_profile) if filter['review_mode'].present? && user_profile.present?\n+\n+    UserProfile.where(conditions).where.not(not_where).sample\n+  end\n+\n+  def review_mode_user_profile_ids(user_profile)\n+    # ActiveRecordでの書き方がわからない\n+    sql_query = 'SELECT `answers`.*, SUM(correct=1) AS count_correct, SUM(correct=0) AS count_incorrect FROM answers WHERE user_profile_id = ? GROUP BY to_user_profile_id HAVING count_incorrect >= count_correct AND count_incorrect >= 1'\n+\n+    distincted_answers = Answer.find_by_sql([sql_query, user_profile.id])\n+\n+    user_profile_ids = []\n+    distincted_answers.each do |answer|\n+      user_profile_ids.push answer.to_user_profile_id\n+    end\n+    user_profile_ids","path":"app/models/user_profile.rb","position":50,"original_position":50,"commit_id":"49210509dbd387901970b0c9b84f099adc3f054a","original_commit_id":"49210509dbd387901970b0c9b84f099adc3f054a","user":{"login":"Yinaura","id":13635059,"avatar_url":"https://avatars.githubusercontent.com/u/13635059?v=3","gravatar_id":"","url":"https://api.github.com/users/Yinaura","html_url":"https://github.com/Yinaura","followers_url":"https://api.github.com/users/Yinaura/followers","following_url":"https://api.github.com/users/Yinaura/following{/other_user}","gists_url":"https://api.github.com/users/Yinaura/gists{/gist_id}","starred_url":"https://api.github.com/users/Yinaura/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Yinaura/subscriptions","organizations_url":"https://api.github.com/users/Yinaura/orgs","repos_url":"https://api.github.com/users/Yinaura/repos","events_url":"https://api.github.com/users/Yinaura/events{/privacy}","received_events_url":"https://api.github.com/users/Yinaura/received_events","type":"User","site_admin":false},"body":"ここまで省略できるんですね :)","created_at":"2015-08-24T05:48:12Z","updated_at":"2015-08-24T05:48:12Z","html_url":"https://github.com/Yinaura/jagi/pull/18#discussion_r37720858","pull_request_url":"https://api.github.com/repos/Yinaura/jagi/pulls/18","_links":{"self":{"href":"https://api.github.com/repos/Yinaura/jagi/pulls/comments/37720858"},"html":{"href":"https://github.com/Yinaura/jagi/pull/18#discussion_r37720858"},"pull_request":{"href":"https://api.github.com/repos/Yinaura/jagi/pulls/18"}}},"pull_request":{"url":"https://api.github.com/repos/Yinaura/jagi/pulls/18","id":43022474,"html_url":"https://github.com/Yinaura/jagi/pull/18","diff_url":"https://github.com/Yinaura/jagi/pull/18.diff","patch_url":"https://github.com/Yinaura/jagi/pull/18.patch","issue_url":"https://api.github.com/repos/Yinaura/jagi/issues/18","number":18,"state":"open","locked":false,"title":"出題のフィルタリングが出来るようにする","user":{"login":"Yinaura","id":13635059,"avatar_url":"https://avatars.githubusercontent.com/u/13635059?v=3","gravatar_id":"","url":"https://api.github.com/users/Yinaura","html_url":"https://github.com/Yinaura","followers_url":"https://api.github.com/users/Yinaura/followers","following_url":"https://api.github.com/users/Yinaura/following{/other_user}","gists_url":"https://api.github.com/users/Yinaura/gists{/gist_id}","starred_url":"https://api.github.com/users/Yinaura/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Yinaura/subscriptions","organizations_url":"https://api.github.com/users/Yinaura/orgs","repos_url":"https://api.github.com/users/Yinaura/repos","events_url":"https://api.github.com/users/Yinaura/events{/privacy}","received_events_url":"https://api.github.com/users/Yinaura/received_events","type":"User","site_admin":false},"body":"# 前提\r\n- add-register-profile に依存しています。\r\n\r\n- フィルタ項目\r\n - 所属プロジェクト\r\n - 所属グループ \r\n - 入社年度\r\n - 過去に不正解だった問題 (正解数より不正解数が多いもの)\r\n\r\n# 指摘への対応\r\n\r\n- alel_table で書いていた部分を、普通にwhereで書くようにした\r\n- ViewHelper で入社年度の選択肢を扱うようにした\r\n- モックの書き方を変えた（「書き換えるメソッドの範囲」を限定した）\r\n\r\n# その他\r\n\r\n- コミットがほとんど分割されてません、すいません。","created_at":"2015-08-21T10:06:45Z","updated_at":"2015-08-24T05:48:12Z","closed_at":null,"merged_at":null,"merge_commit_sha":"7ebe4aca6c457529513d6d96a983b9b090461952","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/Yinaura/jagi/pulls/18/commits","review_comments_url":"https://api.github.com/repos/Yinaura/jagi/pulls/18/comments","review_comment_url":"https://api.github.com/repos/Yinaura/jagi/pulls/comments{/number}","comments_url":"https://api.github.com/repos/Yinaura/jagi/issues/18/comments","statuses_url":"https://api.github.com/repos/Yinaura/jagi/statuses/49210509dbd387901970b0c9b84f099adc3f054a","head":{"label":"Yinaura:filter","ref":"filter","sha":"49210509dbd387901970b0c9b84f099adc3f054a","user":{"login":"Yinaura","id":13635059,"avatar_url":"https://avatars.githubusercontent.com/u/13635059?v=3","gravatar_id":"","url":"https://api.github.com/users/Yinaura","html_url":"https://github.com/Yinaura","followers_url":"https://api.github.com/users/Yinaura/followers","following_url":"https://api.github.com/users/Yinaura/following{/other_user}","gists_url":"https://api.github.com/users/Yinaura/gists{/gist_id}","starred_url":"https://api.github.com/users/Yinaura/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Yinaura/subscriptions","organizations_url":"https://api.github.com/users/Yinaura/orgs","repos_url":"https://api.github.com/users/Yinaura/repos","events_url":"https://api.github.com/users/Yinaura/events{/privacy}","received_events_url":"https://api.github.com/users/Yinaura/received_events","type":"User","site_admin":false},"repo":{"id":40160096,"name":"jagi","full_name":"Yinaura/jagi","owner":{"login":"Yinaura","id":13635059,"avatar_url":"https://avatars.githubusercontent.com/u/13635059?v=3","gravatar_id":"","url":"https://api.github.com/users/Yinaura","html_url":"https://github.com/Yinaura","followers_url":"https://api.github.com/users/Yinaura/followers","following_url":"https://api.github.com/users/Yinaura/following{/other_user}","gists_url":"https://api.github.com/users/Yinaura/gists{/gist_id}","starred_url":"https://api.github.com/users/Yinaura/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Yinaura/subscriptions","organizations_url":"https://api.github.com/users/Yinaura/orgs","repos_url":"https://api.github.com/users/Yinaura/repos","events_url":"https://api.github.com/users/Yinaura/events{/privacy}","received_events_url":"https://api.github.com/users/Yinaura/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/Yinaura/jagi","description":"","fork":false,"url":"https://api.github.com/repos/Yinaura/jagi","forks_url":"https://api.github.com/repos/Yinaura/jagi/forks","keys_url":"https://api.github.com/repos/Yinaura/jagi/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Yinaura/jagi/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Yinaura/jagi/teams","hooks_url":"https://api.github.com/repos/Yinaura/jagi/hooks","issue_events_url":"https://api.github.com/repos/Yinaura/jagi/issues/events{/number}","events_url":"https://api.github.com/repos/Yinaura/jagi/events","assignees_url":"https://api.github.com/repos/Yinaura/jagi/assignees{/user}","branches_url":"https://api.github.com/repos/Yinaura/jagi/branches{/branch}","tags_url":"https://api.github.com/repos/Yinaura/jagi/tags","blobs_url":"https://api.github.com/repos/Yinaura/jagi/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Yinaura/jagi/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Yinaura/jagi/git/refs{/sha}","trees_url":"https://api.github.com/repos/Yinaura/jagi/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Yinaura/jagi/statuses/{sha}","languages_url":"https://api.github.com/repos/Yinaura/jagi/languages","stargazers_url":"https://api.github.com/repos/Yinaura/jagi/stargazers","contributors_url":"https://api.github.com/repos/Yinaura/jagi/contributors","subscribers_url":"https://api.github.com/repos/Yinaura/jagi/subscribers","subscription_url":"https://api.github.com/repos/Yinaura/jagi/subscription","commits_url":"https://api.github.com/repos/Yinaura/jagi/commits{/sha}","git_commits_url":"https://api.github.com/repos/Yinaura/jagi/git/commits{/sha}","comments_url":"https://api.github.com/repos/Yinaura/jagi/comments{/number}","issue_comment_url":"https://api.github.com/repos/Yinaura/jagi/issues/comments{/number}","contents_url":"https://api.github.com/repos/Yinaura/jagi/contents/{+path}","compare_url":"https://api.github.com/repos/Yinaura/jagi/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Yinaura/jagi/merges","archive_url":"https://api.github.com/repos/Yinaura/jagi/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Yinaura/jagi/downloads","issues_url":"https://api.github.com/repos/Yinaura/jagi/issues{/number}","pulls_url":"https://api.github.com/repos/Yinaura/jagi/pulls{/number}","milestones_url":"https://api.github.com/repos/Yinaura/jagi/milestones{/number}","notifications_url":"https://api.github.com/repos/Yinaura/jagi/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Yinaura/jagi/labels{/name}","releases_url":"https://api.github.com/repos/Yinaura/jagi/releases{/id}","created_at":"2015-08-04T02:57:51Z","updated_at":"2015-08-04T03:10:49Z","pushed_at":"2015-08-24T05:38:24Z","git_url":"git://github.com/Yinaura/jagi.git","ssh_url":"git@github.com:Yinaura/jagi.git","clone_url":"https://github.com/Yinaura/jagi.git","svn_url":"https://github.com/Yinaura/jagi","homepage":null,"size":1444,"stargazers_count":0,"watchers_count":0,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":7,"forks":1,"open_issues":7,"watchers":0,"default_branch":"master"}},"base":{"label":"Yinaura:master","ref":"master","sha":"21e76342677b94556d39ddded771a73013addce9","user":{"login":"Yinaura","id":13635059,"avatar_url":"https://avatars.githubusercontent.com/u/13635059?v=3","gravatar_id":"","url":"https://api.github.com/users/Yinaura","html_url":"https://github.com/Yinaura","followers_url":"https://api.github.com/users/Yinaura/followers","following_url":"https://api.github.com/users/Yinaura/following{/other_user}","gists_url":"https://api.github.com/users/Yinaura/gists{/gist_id}","starred_url":"https://api.github.com/users/Yinaura/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Yinaura/subscriptions","organizations_url":"https://api.github.com/users/Yinaura/orgs","repos_url":"https://api.github.com/users/Yinaura/repos","events_url":"https://api.github.com/users/Yinaura/events{/privacy}","received_events_url":"https://api.github.com/users/Yinaura/received_events","type":"User","site_admin":false},"repo":{"id":40160096,"name":"jagi","full_name":"Yinaura/jagi","owner":{"login":"Yinaura","id":13635059,"avatar_url":"https://avatars.githubusercontent.com/u/13635059?v=3","gravatar_id":"","url":"https://api.github.com/users/Yinaura","html_url":"https://github.com/Yinaura","followers_url":"https://api.github.com/users/Yinaura/followers","following_url":"https://api.github.com/users/Yinaura/following{/other_user}","gists_url":"https://api.github.com/users/Yinaura/gists{/gist_id}","starred_url":"https://api.github.com/users/Yinaura/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Yinaura/subscriptions","organizations_url":"https://api.github.com/users/Yinaura/orgs","repos_url":"https://api.github.com/users/Yinaura/repos","events_url":"https://api.github.com/users/Yinaura/events{/privacy}","received_events_url":"https://api.github.com/users/Yinaura/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/Yinaura/jagi","description":"","fork":false,"url":"https://api.github.com/repos/Yinaura/jagi","forks_url":"https://api.github.com/repos/Yinaura/jagi/forks","keys_url":"https://api.github.com/repos/Yinaura/jagi/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Yinaura/jagi/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Yinaura/jagi/teams","hooks_url":"https://api.github.com/repos/Yinaura/jagi/hooks","issue_events_url":"https://api.github.com/repos/Yinaura/jagi/issues/events{/number}","events_url":"https://api.github.com/repos/Yinaura/jagi/events","assignees_url":"https://api.github.com/repos/Yinaura/jagi/assignees{/user}","branches_url":"https://api.github.com/repos/Yinaura/jagi/branches{/branch}","tags_url":"https://api.github.com/repos/Yinaura/jagi/tags","blobs_url":"https://api.github.com/repos/Yinaura/jagi/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Yinaura/jagi/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Yinaura/jagi/git/refs{/sha}","trees_url":"https://api.github.com/repos/Yinaura/jagi/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Yinaura/jagi/statuses/{sha}","languages_url":"https://api.github.com/repos/Yinaura/jagi/languages","stargazers_url":"https://api.github.com/repos/Yinaura/jagi/stargazers","contributors_url":"https://api.github.com/repos/Yinaura/jagi/contributors","subscribers_url":"https://api.github.com/repos/Yinaura/jagi/subscribers","subscription_url":"https://api.github.com/repos/Yinaura/jagi/subscription","commits_url":"https://api.github.com/repos/Yinaura/jagi/commits{/sha}","git_commits_url":"https://api.github.com/repos/Yinaura/jagi/git/commits{/sha}","comments_url":"https://api.github.com/repos/Yinaura/jagi/comments{/number}","issue_comment_url":"https://api.github.com/repos/Yinaura/jagi/issues/comments{/number}","contents_url":"https://api.github.com/repos/Yinaura/jagi/contents/{+path}","compare_url":"https://api.github.com/repos/Yinaura/jagi/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Yinaura/jagi/merges","archive_url":"https://api.github.com/repos/Yinaura/jagi/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Yinaura/jagi/downloads","issues_url":"https://api.github.com/repos/Yinaura/jagi/issues{/number}","pulls_url":"https://api.github.com/repos/Yinaura/jagi/pulls{/number}","milestones_url":"https://api.github.com/repos/Yinaura/jagi/milestones{/number}","notifications_url":"https://api.github.com/repos/Yinaura/jagi/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Yinaura/jagi/labels{/name}","releases_url":"https://api.github.com/repos/Yinaura/jagi/releases{/id}","created_at":"2015-08-04T02:57:51Z","updated_at":"2015-08-04T03:10:49Z","pushed_at":"2015-08-24T05:38:24Z","git_url":"git://github.com/Yinaura/jagi.git","ssh_url":"git@github.com:Yinaura/jagi.git","clone_url":"https://github.com/Yinaura/jagi.git","svn_url":"https://github.com/Yinaura/jagi","homepage":null,"size":1444,"stargazers_count":0,"watchers_count":0,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":7,"forks":1,"open_issues":7,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/Yinaura/jagi/pulls/18"},"html":{"href":"https://github.com/Yinaura/jagi/pull/18"},"issue":{"href":"https://api.github.com/repos/Yinaura/jagi/issues/18"},"comments":{"href":"https://api.github.com/repos/Yinaura/jagi/issues/18/comments"},"review_comments":{"href":"https://api.github.com/repos/Yinaura/jagi/pulls/18/comments"},"review_comment":{"href":"https://api.github.com/repos/Yinaura/jagi/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/Yinaura/jagi/pulls/18/commits"},"statuses":{"href":"https://api.github.com/repos/Yinaura/jagi/statuses/49210509dbd387901970b0c9b84f099adc3f054a"}}}}