{"action":"created","comment":{"url":"https://api.github.com/repos/oppia/oppia/pulls/comments/79826055","id":79826055,"diff_hunk":"@@ -0,0 +1,143 @@\n+# coding: utf-8\n+#\n+# Copyright 2016 The Oppia Authors. All Rights Reserved.\n+#\n+# Licensed under the Apache License, Version 2.0 (the \"License\");\n+# you may not use this file except in compliance with the License.\n+# You may obtain a copy of the License at\n+#\n+#      http://www.apache.org/licenses/LICENSE-2.0\n+#\n+# Unless required by applicable law or agreed to in writing, software\n+# distributed under the License is distributed on an \"AS-IS\" BASIS,\n+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n+# See the License for the specific language governing permissions and\n+# limitations under the License.\n+\n+\"\"\"Jobs to execute and get result of a query.\"\"\"\n+import ast\n+import datetime\n+\n+from core import jobs\n+from core.domain import exp_services\n+from core.domain import query_domain\n+from core.platform import models\n+\n+(user_models, job_models, exp_models) = (\n+    models.Registry.import_models(\n+        [models.NAMES.user, models.NAMES.job, models.NAMES.exploration]))\n+\n+\n+class QueryOneOffJob(jobs.BaseMapReduceJobManager):\n+    \"\"\"One-off job for excuting query with given query parameters.\n+    For each user we check if he/she satisfies query criteria. If user satisfies\n+    query criteria then yeilds a tuple of (query_id, user_id). Reducer function\n+    stores all such satisfying user_ids in query result model.\"\"\"\n+\n+    @classmethod\n+    def entity_classes_to_map_over(cls):\n+        return [user_models.UserSettingsModel]\n+\n+    @staticmethod\n+    def map(user_settings_model):\n+        query_id = jobs.BaseMapReduceJobManager.get_mapper_param('query_id')\n+        query = job_models.QueryModel.get(query_id)\n+        query_parameters = query_domain.get_parameters_from_query(query)\n+        user_id = user_settings_model.id\n+        user_qualified = True\n+\n+        if user_id == query.submitter_id:\n+            user_qualified = False\n+\n+        if user_settings_model.username == 'tmpsuperadm1n':\n+            user_qualified = False\n+\n+        if (query_parameters.created_or_edited_exploration_in_n_days is not None\n+                and user_qualified):\n+            days = query_parameters.created_or_edited_exploration_in_n_days\n+            created_exploration_in_n_days = False\n+            edited_exploration_in_n_days = False\n+\n+            user_contributions = user_models.UserContributionsModel.get(user_id)\n+            created_explorations = exp_services.get_multiple_explorations_by_id(\n+                user_contributions.created_exploration_ids)\n+\n+            edited_explorations = (\n+                exp_models.ExplorationCommitLogEntryModel.query(\n+                    exp_models.ExplorationCommitLogEntryModel.user_id ==\n+                    user_id).fetch())\n+\n+            for exp in created_explorations.values():\n+                days_since_created = (\n+                    datetime.datetime.utcnow() - exp.created_on).days\n+                days_since_updated = (\n+                    datetime.datetime.utcnow() - exp.last_updated).days\n+                if days_since_created <= days or days_since_updated <= days:\n+                    created_exploration_in_n_days = True\n+                    break\n+\n+            for exp in edited_explorations:\n+                days_since_updated = (\n+                    datetime.datetime.utcnow() - exp.last_updated).days\n+                if days_since_updated <= days:\n+                    edited_exploration_in_n_days = True\n+                    break\n+\n+            user_qualified = (\n+                (created_exploration_in_n_days or edited_exploration_in_n_days)\n+                and user_qualified)\n+\n+        if (query_parameters.created_more_than_n_exploration is not None and\n+                user_qualified):\n+            exploration_count = query_parameters.created_more_than_n_exploration\n+            user_contributions = user_models.UserContributionsModel.get(user_id)\n+            created_explorations = exp_services.get_multiple_explorations_by_id(\n+                user_contributions.created_exploration_ids)\n+\n+            user_qualified = (\n+                (len(created_explorations) >= exploration_count) and\n+                user_qualified)\n+\n+        if (query_parameters.created_less_than_n_exploration is not None and\n+                user_qualified):\n+            exploration_count = query_parameters.created_less_than_n_exploration\n+            user_contributions = user_models.UserContributionsModel.get(user_id)\n+            created_explorations = exp_services.get_multiple_explorations_by_id(\n+                user_contributions.created_exploration_ids)\n+\n+            user_qualified = (\n+                (len(created_explorations) <= exploration_count) and\n+                user_qualified)\n+\n+        if (query_parameters.edited_more_than_n_exploration is not None and\n+                user_qualified):\n+            exploration_count = query_parameters.edited_more_than_n_exploration\n+            user_contributions = user_models.UserContributionsModel.get(user_id)\n+            edited_explorations = exp_services.get_multiple_explorations_by_id(\n+                user_contributions.edited_exploration_ids)\n+\n+            user_qualified = (\n+                (len(edited_explorations) >= exploration_count) and\n+                user_qualified)\n+\n+        if (query_parameters.edited_less_than_n_exploration is not None and\n+                user_qualified):\n+            exploration_count = query_parameters.edited_less_than_n_exploration\n+            user_contributions = user_models.UserContributionsModel.get(user_id)\n+            edited_explorations = exp_services.get_multiple_explorations_by_id(\n+                user_contributions.edited_exploration_ids)\n+\n+            user_qualified = (\n+                (len(edited_explorations) <= exploration_count) and\n+                user_qualified)\n+\n+        if user_qualified:\n+            yield (query_id, user_id)\n+\n+    @staticmethod\n+    def reduce(query_model_id, stringified_user_ids):\n+        query = job_models.QueryModel.get(query_model_id)\n+        user_ids = [ast.literal_eval(v) for v in stringified_user_ids]\n+        new_user_ids = set(query.user_ids + user_ids)","path":"core/domain/query_jobs_one_off.py","position":141,"original_position":141,"commit_id":"8b65498df723f9eac741de97e5607404812eb34c","original_commit_id":"8b65498df723f9eac741de97e5607404812eb34c","user":{"login":"prasanna08","id":8678373,"avatar_url":"https://avatars.githubusercontent.com/u/8678373?v=3","gravatar_id":"","url":"https://api.github.com/users/prasanna08","html_url":"https://github.com/prasanna08","followers_url":"https://api.github.com/users/prasanna08/followers","following_url":"https://api.github.com/users/prasanna08/following{/other_user}","gists_url":"https://api.github.com/users/prasanna08/gists{/gist_id}","starred_url":"https://api.github.com/users/prasanna08/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/prasanna08/subscriptions","organizations_url":"https://api.github.com/users/prasanna08/orgs","repos_url":"https://api.github.com/users/prasanna08/repos","events_url":"https://api.github.com/users/prasanna08/events{/privacy}","received_events_url":"https://api.github.com/users/prasanna08/received_events","type":"User","site_admin":false},"body":"Yeah. Generally speaking there won't be any ids in model. I did it because I wasn't sure about how shuffled stage of MR job works. From what I read, all values for same key are gathered in single list and then passed over to reducer. But I was not sure about it. \r\n\r\nIf you are sure the I will remove it. Thanks","created_at":"2016-09-21T12:56:24Z","updated_at":"2016-09-21T12:56:24Z","html_url":"https://github.com/oppia/oppia/pull/2491#discussion_r79826055","pull_request_url":"https://api.github.com/repos/oppia/oppia/pulls/2491","_links":{"self":{"href":"https://api.github.com/repos/oppia/oppia/pulls/comments/79826055"},"html":{"href":"https://github.com/oppia/oppia/pull/2491#discussion_r79826055"},"pull_request":{"href":"https://api.github.com/repos/oppia/oppia/pulls/2491"}}},"pull_request":{"url":"https://api.github.com/repos/oppia/oppia/pulls/2491","id":85968637,"html_url":"https://github.com/oppia/oppia/pull/2491","diff_url":"https://github.com/oppia/oppia/pull/2491.diff","patch_url":"https://github.com/oppia/oppia/pull/2491.patch","issue_url":"https://api.github.com/repos/oppia/oppia/issues/2491","number":2491,"state":"open","locked":false,"title":"Fix part of #2269: Implement MR job for executing queries.","user":{"login":"prasanna08","id":8678373,"avatar_url":"https://avatars.githubusercontent.com/u/8678373?v=3","gravatar_id":"","url":"https://api.github.com/users/prasanna08","html_url":"https://github.com/prasanna08","followers_url":"https://api.github.com/users/prasanna08/followers","following_url":"https://api.github.com/users/prasanna08/following{/other_user}","gists_url":"https://api.github.com/users/prasanna08/gists{/gist_id}","starred_url":"https://api.github.com/users/prasanna08/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/prasanna08/subscriptions","organizations_url":"https://api.github.com/users/prasanna08/orgs","repos_url":"https://api.github.com/users/prasanna08/repos","events_url":"https://api.github.com/users/prasanna08/events{/privacy}","received_events_url":"https://api.github.com/users/prasanna08/received_events","type":"User","site_admin":false},"body":"This commit implements MR job for executing query.\r\n\r\n","created_at":"2016-09-20T12:52:10Z","updated_at":"2016-09-21T12:56:24Z","closed_at":null,"merged_at":null,"merge_commit_sha":"e2163da2a3cb7f1693cf42bb6fb991b9807e64c6","assignee":{"login":"seanlip","id":10575562,"avatar_url":"https://avatars.githubusercontent.com/u/10575562?v=3","gravatar_id":"","url":"https://api.github.com/users/seanlip","html_url":"https://github.com/seanlip","followers_url":"https://api.github.com/users/seanlip/followers","following_url":"https://api.github.com/users/seanlip/following{/other_user}","gists_url":"https://api.github.com/users/seanlip/gists{/gist_id}","starred_url":"https://api.github.com/users/seanlip/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/seanlip/subscriptions","organizations_url":"https://api.github.com/users/seanlip/orgs","repos_url":"https://api.github.com/users/seanlip/repos","events_url":"https://api.github.com/users/seanlip/events{/privacy}","received_events_url":"https://api.github.com/users/seanlip/received_events","type":"User","site_admin":false},"assignees":[{"login":"seanlip","id":10575562,"avatar_url":"https://avatars.githubusercontent.com/u/10575562?v=3","gravatar_id":"","url":"https://api.github.com/users/seanlip","html_url":"https://github.com/seanlip","followers_url":"https://api.github.com/users/seanlip/followers","following_url":"https://api.github.com/users/seanlip/following{/other_user}","gists_url":"https://api.github.com/users/seanlip/gists{/gist_id}","starred_url":"https://api.github.com/users/seanlip/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/seanlip/subscriptions","organizations_url":"https://api.github.com/users/seanlip/orgs","repos_url":"https://api.github.com/users/seanlip/repos","events_url":"https://api.github.com/users/seanlip/events{/privacy}","received_events_url":"https://api.github.com/users/seanlip/received_events","type":"User","site_admin":false}],"milestone":null,"commits_url":"https://api.github.com/repos/oppia/oppia/pulls/2491/commits","review_comments_url":"https://api.github.com/repos/oppia/oppia/pulls/2491/comments","review_comment_url":"https://api.github.com/repos/oppia/oppia/pulls/comments{/number}","comments_url":"https://api.github.com/repos/oppia/oppia/issues/2491/comments","statuses_url":"https://api.github.com/repos/oppia/oppia/statuses/8b65498df723f9eac741de97e5607404812eb34c","head":{"label":"prasanna08:query-mapreduce-job","ref":"query-mapreduce-job","sha":"8b65498df723f9eac741de97e5607404812eb34c","user":{"login":"prasanna08","id":8678373,"avatar_url":"https://avatars.githubusercontent.com/u/8678373?v=3","gravatar_id":"","url":"https://api.github.com/users/prasanna08","html_url":"https://github.com/prasanna08","followers_url":"https://api.github.com/users/prasanna08/followers","following_url":"https://api.github.com/users/prasanna08/following{/other_user}","gists_url":"https://api.github.com/users/prasanna08/gists{/gist_id}","starred_url":"https://api.github.com/users/prasanna08/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/prasanna08/subscriptions","organizations_url":"https://api.github.com/users/prasanna08/orgs","repos_url":"https://api.github.com/users/prasanna08/repos","events_url":"https://api.github.com/users/prasanna08/events{/privacy}","received_events_url":"https://api.github.com/users/prasanna08/received_events","type":"User","site_admin":false},"repo":{"id":49757386,"name":"oppia","full_name":"prasanna08/oppia","owner":{"login":"prasanna08","id":8678373,"avatar_url":"https://avatars.githubusercontent.com/u/8678373?v=3","gravatar_id":"","url":"https://api.github.com/users/prasanna08","html_url":"https://github.com/prasanna08","followers_url":"https://api.github.com/users/prasanna08/followers","following_url":"https://api.github.com/users/prasanna08/following{/other_user}","gists_url":"https://api.github.com/users/prasanna08/gists{/gist_id}","starred_url":"https://api.github.com/users/prasanna08/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/prasanna08/subscriptions","organizations_url":"https://api.github.com/users/prasanna08/orgs","repos_url":"https://api.github.com/users/prasanna08/repos","events_url":"https://api.github.com/users/prasanna08/events{/privacy}","received_events_url":"https://api.github.com/users/prasanna08/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/prasanna08/oppia","description":"Tool for collaboratively building intelligent tutors.","fork":true,"url":"https://api.github.com/repos/prasanna08/oppia","forks_url":"https://api.github.com/repos/prasanna08/oppia/forks","keys_url":"https://api.github.com/repos/prasanna08/oppia/keys{/key_id}","collaborators_url":"https://api.github.com/repos/prasanna08/oppia/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/prasanna08/oppia/teams","hooks_url":"https://api.github.com/repos/prasanna08/oppia/hooks","issue_events_url":"https://api.github.com/repos/prasanna08/oppia/issues/events{/number}","events_url":"https://api.github.com/repos/prasanna08/oppia/events","assignees_url":"https://api.github.com/repos/prasanna08/oppia/assignees{/user}","branches_url":"https://api.github.com/repos/prasanna08/oppia/branches{/branch}","tags_url":"https://api.github.com/repos/prasanna08/oppia/tags","blobs_url":"https://api.github.com/repos/prasanna08/oppia/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/prasanna08/oppia/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/prasanna08/oppia/git/refs{/sha}","trees_url":"https://api.github.com/repos/prasanna08/oppia/git/trees{/sha}","statuses_url":"https://api.github.com/repos/prasanna08/oppia/statuses/{sha}","languages_url":"https://api.github.com/repos/prasanna08/oppia/languages","stargazers_url":"https://api.github.com/repos/prasanna08/oppia/stargazers","contributors_url":"https://api.github.com/repos/prasanna08/oppia/contributors","subscribers_url":"https://api.github.com/repos/prasanna08/oppia/subscribers","subscription_url":"https://api.github.com/repos/prasanna08/oppia/subscription","commits_url":"https://api.github.com/repos/prasanna08/oppia/commits{/sha}","git_commits_url":"https://api.github.com/repos/prasanna08/oppia/git/commits{/sha}","comments_url":"https://api.github.com/repos/prasanna08/oppia/comments{/number}","issue_comment_url":"https://api.github.com/repos/prasanna08/oppia/issues/comments{/number}","contents_url":"https://api.github.com/repos/prasanna08/oppia/contents/{+path}","compare_url":"https://api.github.com/repos/prasanna08/oppia/compare/{base}...{head}","merges_url":"https://api.github.com/repos/prasanna08/oppia/merges","archive_url":"https://api.github.com/repos/prasanna08/oppia/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/prasanna08/oppia/downloads","issues_url":"https://api.github.com/repos/prasanna08/oppia/issues{/number}","pulls_url":"https://api.github.com/repos/prasanna08/oppia/pulls{/number}","milestones_url":"https://api.github.com/repos/prasanna08/oppia/milestones{/number}","notifications_url":"https://api.github.com/repos/prasanna08/oppia/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/prasanna08/oppia/labels{/name}","releases_url":"https://api.github.com/repos/prasanna08/oppia/releases{/id}","deployments_url":"https://api.github.com/repos/prasanna08/oppia/deployments","created_at":"2016-01-16T03:21:22Z","updated_at":"2016-01-16T03:21:24Z","pushed_at":"2016-09-20T12:50:33Z","git_url":"git://github.com/prasanna08/oppia.git","ssh_url":"git@github.com:prasanna08/oppia.git","clone_url":"https://github.com/prasanna08/oppia.git","svn_url":"https://github.com/prasanna08/oppia","homepage":"https://www.oppia.org","size":47078,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_downloads":false,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"develop"}},"base":{"label":"oppia:develop","ref":"develop","sha":"176baa1e1439a1238c2b69cc6e88aeea0fe8e4a6","user":{"login":"oppia","id":11620230,"avatar_url":"https://avatars.githubusercontent.com/u/11620230?v=3","gravatar_id":"","url":"https://api.github.com/users/oppia","html_url":"https://github.com/oppia","followers_url":"https://api.github.com/users/oppia/followers","following_url":"https://api.github.com/users/oppia/following{/other_user}","gists_url":"https://api.github.com/users/oppia/gists{/gist_id}","starred_url":"https://api.github.com/users/oppia/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/oppia/subscriptions","organizations_url":"https://api.github.com/users/oppia/orgs","repos_url":"https://api.github.com/users/oppia/repos","events_url":"https://api.github.com/users/oppia/events{/privacy}","received_events_url":"https://api.github.com/users/oppia/received_events","type":"Organization","site_admin":false},"repo":{"id":40687563,"name":"oppia","full_name":"oppia/oppia","owner":{"login":"oppia","id":11620230,"avatar_url":"https://avatars.githubusercontent.com/u/11620230?v=3","gravatar_id":"","url":"https://api.github.com/users/oppia","html_url":"https://github.com/oppia","followers_url":"https://api.github.com/users/oppia/followers","following_url":"https://api.github.com/users/oppia/following{/other_user}","gists_url":"https://api.github.com/users/oppia/gists{/gist_id}","starred_url":"https://api.github.com/users/oppia/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/oppia/subscriptions","organizations_url":"https://api.github.com/users/oppia/orgs","repos_url":"https://api.github.com/users/oppia/repos","events_url":"https://api.github.com/users/oppia/events{/privacy}","received_events_url":"https://api.github.com/users/oppia/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/oppia/oppia","description":"Tool for collaboratively building interactive lessons.","fork":false,"url":"https://api.github.com/repos/oppia/oppia","forks_url":"https://api.github.com/repos/oppia/oppia/forks","keys_url":"https://api.github.com/repos/oppia/oppia/keys{/key_id}","collaborators_url":"https://api.github.com/repos/oppia/oppia/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/oppia/oppia/teams","hooks_url":"https://api.github.com/repos/oppia/oppia/hooks","issue_events_url":"https://api.github.com/repos/oppia/oppia/issues/events{/number}","events_url":"https://api.github.com/repos/oppia/oppia/events","assignees_url":"https://api.github.com/repos/oppia/oppia/assignees{/user}","branches_url":"https://api.github.com/repos/oppia/oppia/branches{/branch}","tags_url":"https://api.github.com/repos/oppia/oppia/tags","blobs_url":"https://api.github.com/repos/oppia/oppia/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/oppia/oppia/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/oppia/oppia/git/refs{/sha}","trees_url":"https://api.github.com/repos/oppia/oppia/git/trees{/sha}","statuses_url":"https://api.github.com/repos/oppia/oppia/statuses/{sha}","languages_url":"https://api.github.com/repos/oppia/oppia/languages","stargazers_url":"https://api.github.com/repos/oppia/oppia/stargazers","contributors_url":"https://api.github.com/repos/oppia/oppia/contributors","subscribers_url":"https://api.github.com/repos/oppia/oppia/subscribers","subscription_url":"https://api.github.com/repos/oppia/oppia/subscription","commits_url":"https://api.github.com/repos/oppia/oppia/commits{/sha}","git_commits_url":"https://api.github.com/repos/oppia/oppia/git/commits{/sha}","comments_url":"https://api.github.com/repos/oppia/oppia/comments{/number}","issue_comment_url":"https://api.github.com/repos/oppia/oppia/issues/comments{/number}","contents_url":"https://api.github.com/repos/oppia/oppia/contents/{+path}","compare_url":"https://api.github.com/repos/oppia/oppia/compare/{base}...{head}","merges_url":"https://api.github.com/repos/oppia/oppia/merges","archive_url":"https://api.github.com/repos/oppia/oppia/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/oppia/oppia/downloads","issues_url":"https://api.github.com/repos/oppia/oppia/issues{/number}","pulls_url":"https://api.github.com/repos/oppia/oppia/pulls{/number}","milestones_url":"https://api.github.com/repos/oppia/oppia/milestones{/number}","notifications_url":"https://api.github.com/repos/oppia/oppia/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/oppia/oppia/labels{/name}","releases_url":"https://api.github.com/repos/oppia/oppia/releases{/id}","deployments_url":"https://api.github.com/repos/oppia/oppia/deployments","created_at":"2015-08-14T00:16:14Z","updated_at":"2016-09-13T07:22:21Z","pushed_at":"2016-09-21T12:44:00Z","git_url":"git://github.com/oppia/oppia.git","ssh_url":"git@github.com:oppia/oppia.git","clone_url":"https://github.com/oppia/oppia.git","svn_url":"https://github.com/oppia/oppia","homepage":"https://www.oppia.org","size":89327,"stargazers_count":161,"watchers_count":161,"language":"Python","has_issues":true,"has_downloads":false,"has_wiki":true,"has_pages":false,"forks_count":251,"mirror_url":null,"open_issues_count":338,"forks":251,"open_issues":338,"watchers":161,"default_branch":"develop"}},"_links":{"self":{"href":"https://api.github.com/repos/oppia/oppia/pulls/2491"},"html":{"href":"https://github.com/oppia/oppia/pull/2491"},"issue":{"href":"https://api.github.com/repos/oppia/oppia/issues/2491"},"comments":{"href":"https://api.github.com/repos/oppia/oppia/issues/2491/comments"},"review_comments":{"href":"https://api.github.com/repos/oppia/oppia/pulls/2491/comments"},"review_comment":{"href":"https://api.github.com/repos/oppia/oppia/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/oppia/oppia/pulls/2491/commits"},"statuses":{"href":"https://api.github.com/repos/oppia/oppia/statuses/8b65498df723f9eac741de97e5607404812eb34c"}}}}
{"actor":{"display_login":"prasanna08"}}