{"action":"created","comment":{"url":"https://api.github.com/repos/edx/edx-analytics-pipeline/pulls/comments/41578825","id":41578825,"diff_hunk":"@@ -0,0 +1,75 @@\n+\"\"\"Group events by course and export them for research purposes\"\"\"\n+\n+import logging\n+import gzip\n+\n+import luigi\n+import luigi.date_interval\n+\n+from edx.analytics.tasks.mapreduce import MultiOutputMapReduceJobTask\n+from edx.analytics.tasks.pathutil import EventLogSelectionMixin\n+from edx.analytics.tasks.url import url_path_join\n+import edx.analytics.tasks.util.opaque_key_util as opaque_key_util\n+from edx.analytics.tasks.util import eventlog\n+\n+log = logging.getLogger(__name__)\n+\n+\n+class EventExportByCourseTask(EventLogSelectionMixin, MultiOutputMapReduceJobTask):\n+    \"\"\"\n+    Group events by course and export them for research purposes.\n+    \"\"\"\n+\n+    output_root = luigi.Parameter(\n+        config_path={'section': 'event-export-course', 'name': 'output_root'}\n+    )\n+\n+    course_id = luigi.Parameter(is_list=True, default=[])\n+\n+    def mapper(self, line):\n+        event, date_string = self.get_event_and_date_string(line) or (None, None)\n+        if event is None:\n+            return\n+\n+        course_id = eventlog.get_course_id(event, from_url=True)\n+\n+        if course_id is None:\n+            return\n+\n+        if self.course_id and course_id not in self.course_id:\n+            return\n+\n+        key = (date_string, course_id)\n+        yield tuple([value.encode('utf8') for value in key]), line.strip()\n+\n+    def get_event_time(self, event):\n+        # Some events may emitted and stored for quite some time before actually being entered into the tracking logs.\n+        # The primary cause of this is mobile devices that go offline for a significant period of time. They will store\n+        # events locally and then when connectivity is restored transmit them to the server. We log the time that they\n+        # were received by the server and use that to batch them into exports since it is much simpler than trying to\n+        # inject them into past exports.\n+        try:\n+            return event['context']['received_at']\n+        except KeyError:\n+            return super(EventExportByCourseTask, self).get_event_time(event)\n+\n+    def output_path_for_key(self, key):\n+        date, course_id = key\n+        filename_safe_course_id = opaque_key_util.get_filename_safe_course_id(course_id)\n+\n+        return url_path_join(\n+            self.output_root,\n+            '{course}_{date}.log.gz'.format(\n+                course=filename_safe_course_id.lower(),\n+                date=date,","path":"edx/analytics/tasks/event_exports_by_course.py","position":64,"original_position":64,"commit_id":"f71f0b22da31f65a498278caa6a0ded47708e80b","original_commit_id":"f71f0b22da31f65a498278caa6a0ded47708e80b","user":{"login":"brianhw","id":2534095,"avatar_url":"https://avatars.githubusercontent.com/u/2534095?v=3","gravatar_id":"","url":"https://api.github.com/users/brianhw","html_url":"https://github.com/brianhw","followers_url":"https://api.github.com/users/brianhw/followers","following_url":"https://api.github.com/users/brianhw/following{/other_user}","gists_url":"https://api.github.com/users/brianhw/gists{/gist_id}","starred_url":"https://api.github.com/users/brianhw/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/brianhw/subscriptions","organizations_url":"https://api.github.com/users/brianhw/orgs","repos_url":"https://api.github.com/users/brianhw/repos","events_url":"https://api.github.com/users/brianhw/events{/privacy}","received_events_url":"https://api.github.com/users/brianhw/received_events","type":"User","site_admin":false},"body":"I'm changing my mind on this, as I think about next steps.  I think it works better to have:\r\n\r\n<output_root>/<filename_safe_course_id>/events/<filename_safe_course_id>-events-<date>.log.gz\r\n\r\nThat way we can write events and database data for a given course into the same directory structure.","created_at":"2015-10-08T22:40:27Z","updated_at":"2015-10-08T22:40:27Z","html_url":"https://github.com/edx/edx-analytics-pipeline/pull/170#discussion_r41578825","pull_request_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/pulls/170","_links":{"self":{"href":"https://api.github.com/repos/edx/edx-analytics-pipeline/pulls/comments/41578825"},"html":{"href":"https://github.com/edx/edx-analytics-pipeline/pull/170#discussion_r41578825"},"pull_request":{"href":"https://api.github.com/repos/edx/edx-analytics-pipeline/pulls/170"}}},"pull_request":{"url":"https://api.github.com/repos/edx/edx-analytics-pipeline/pulls/170","id":47032726,"html_url":"https://github.com/edx/edx-analytics-pipeline/pull/170","diff_url":"https://github.com/edx/edx-analytics-pipeline/pull/170.diff","patch_url":"https://github.com/edx/edx-analytics-pipeline/pull/170.patch","issue_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/issues/170","number":170,"state":"open","locked":false,"title":"Event export on a per-course basis","user":{"login":"HassanJaveed84","id":5018044,"avatar_url":"https://avatars.githubusercontent.com/u/5018044?v=3","gravatar_id":"","url":"https://api.github.com/users/HassanJaveed84","html_url":"https://github.com/HassanJaveed84","followers_url":"https://api.github.com/users/HassanJaveed84/followers","following_url":"https://api.github.com/users/HassanJaveed84/following{/other_user}","gists_url":"https://api.github.com/users/HassanJaveed84/gists{/gist_id}","starred_url":"https://api.github.com/users/HassanJaveed84/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/HassanJaveed84/subscriptions","organizations_url":"https://api.github.com/users/HassanJaveed84/orgs","repos_url":"https://api.github.com/users/HassanJaveed84/repos","events_url":"https://api.github.com/users/HassanJaveed84/events{/privacy}","received_events_url":"https://api.github.com/users/HassanJaveed84/received_events","type":"User","site_admin":false},"body":"","created_at":"2015-10-07T14:16:41Z","updated_at":"2015-10-08T22:40:27Z","closed_at":null,"merged_at":null,"merge_commit_sha":"2884bb5d2a194cf12ae3beac7101110dbf8e42fd","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/pulls/170/commits","review_comments_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/pulls/170/comments","review_comment_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/pulls/comments{/number}","comments_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/issues/170/comments","statuses_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/statuses/f71f0b22da31f65a498278caa6a0ded47708e80b","head":{"label":"edx:hassan/event-export-by-course","ref":"hassan/event-export-by-course","sha":"f71f0b22da31f65a498278caa6a0ded47708e80b","user":{"login":"edx","id":3179841,"avatar_url":"https://avatars.githubusercontent.com/u/3179841?v=3","gravatar_id":"","url":"https://api.github.com/users/edx","html_url":"https://github.com/edx","followers_url":"https://api.github.com/users/edx/followers","following_url":"https://api.github.com/users/edx/following{/other_user}","gists_url":"https://api.github.com/users/edx/gists{/gist_id}","starred_url":"https://api.github.com/users/edx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/edx/subscriptions","organizations_url":"https://api.github.com/users/edx/orgs","repos_url":"https://api.github.com/users/edx/repos","events_url":"https://api.github.com/users/edx/events{/privacy}","received_events_url":"https://api.github.com/users/edx/received_events","type":"Organization","site_admin":false},"repo":{"id":22929261,"name":"edx-analytics-pipeline","full_name":"edx/edx-analytics-pipeline","owner":{"login":"edx","id":3179841,"avatar_url":"https://avatars.githubusercontent.com/u/3179841?v=3","gravatar_id":"","url":"https://api.github.com/users/edx","html_url":"https://github.com/edx","followers_url":"https://api.github.com/users/edx/followers","following_url":"https://api.github.com/users/edx/following{/other_user}","gists_url":"https://api.github.com/users/edx/gists{/gist_id}","starred_url":"https://api.github.com/users/edx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/edx/subscriptions","organizations_url":"https://api.github.com/users/edx/orgs","repos_url":"https://api.github.com/users/edx/repos","events_url":"https://api.github.com/users/edx/events{/privacy}","received_events_url":"https://api.github.com/users/edx/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/edx/edx-analytics-pipeline","description":"","fork":false,"url":"https://api.github.com/repos/edx/edx-analytics-pipeline","forks_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/forks","keys_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/keys{/key_id}","collaborators_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/teams","hooks_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/hooks","issue_events_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/issues/events{/number}","events_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/events","assignees_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/assignees{/user}","branches_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/branches{/branch}","tags_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/tags","blobs_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/git/refs{/sha}","trees_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/git/trees{/sha}","statuses_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/statuses/{sha}","languages_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/languages","stargazers_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/stargazers","contributors_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/contributors","subscribers_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/subscribers","subscription_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/subscription","commits_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/commits{/sha}","git_commits_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/git/commits{/sha}","comments_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/comments{/number}","issue_comment_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/issues/comments{/number}","contents_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/contents/{+path}","compare_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/compare/{base}...{head}","merges_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/merges","archive_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/downloads","issues_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/issues{/number}","pulls_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/pulls{/number}","milestones_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/milestones{/number}","notifications_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/labels{/name}","releases_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/releases{/id}","created_at":"2014-08-13T19:57:17Z","updated_at":"2015-09-24T20:45:04Z","pushed_at":"2015-10-08T11:34:44Z","git_url":"git://github.com/edx/edx-analytics-pipeline.git","ssh_url":"git@github.com:edx/edx-analytics-pipeline.git","clone_url":"https://github.com/edx/edx-analytics-pipeline.git","svn_url":"https://github.com/edx/edx-analytics-pipeline","homepage":null,"size":6634,"stargazers_count":12,"watchers_count":12,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":24,"mirror_url":null,"open_issues_count":10,"forks":24,"open_issues":10,"watchers":12,"default_branch":"master"}},"base":{"label":"edx:master","ref":"master","sha":"330f910b5d1ef88f93a9cd6789b5212c2c94b1dc","user":{"login":"edx","id":3179841,"avatar_url":"https://avatars.githubusercontent.com/u/3179841?v=3","gravatar_id":"","url":"https://api.github.com/users/edx","html_url":"https://github.com/edx","followers_url":"https://api.github.com/users/edx/followers","following_url":"https://api.github.com/users/edx/following{/other_user}","gists_url":"https://api.github.com/users/edx/gists{/gist_id}","starred_url":"https://api.github.com/users/edx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/edx/subscriptions","organizations_url":"https://api.github.com/users/edx/orgs","repos_url":"https://api.github.com/users/edx/repos","events_url":"https://api.github.com/users/edx/events{/privacy}","received_events_url":"https://api.github.com/users/edx/received_events","type":"Organization","site_admin":false},"repo":{"id":22929261,"name":"edx-analytics-pipeline","full_name":"edx/edx-analytics-pipeline","owner":{"login":"edx","id":3179841,"avatar_url":"https://avatars.githubusercontent.com/u/3179841?v=3","gravatar_id":"","url":"https://api.github.com/users/edx","html_url":"https://github.com/edx","followers_url":"https://api.github.com/users/edx/followers","following_url":"https://api.github.com/users/edx/following{/other_user}","gists_url":"https://api.github.com/users/edx/gists{/gist_id}","starred_url":"https://api.github.com/users/edx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/edx/subscriptions","organizations_url":"https://api.github.com/users/edx/orgs","repos_url":"https://api.github.com/users/edx/repos","events_url":"https://api.github.com/users/edx/events{/privacy}","received_events_url":"https://api.github.com/users/edx/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/edx/edx-analytics-pipeline","description":"","fork":false,"url":"https://api.github.com/repos/edx/edx-analytics-pipeline","forks_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/forks","keys_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/keys{/key_id}","collaborators_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/teams","hooks_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/hooks","issue_events_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/issues/events{/number}","events_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/events","assignees_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/assignees{/user}","branches_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/branches{/branch}","tags_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/tags","blobs_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/git/refs{/sha}","trees_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/git/trees{/sha}","statuses_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/statuses/{sha}","languages_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/languages","stargazers_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/stargazers","contributors_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/contributors","subscribers_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/subscribers","subscription_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/subscription","commits_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/commits{/sha}","git_commits_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/git/commits{/sha}","comments_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/comments{/number}","issue_comment_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/issues/comments{/number}","contents_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/contents/{+path}","compare_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/compare/{base}...{head}","merges_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/merges","archive_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/downloads","issues_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/issues{/number}","pulls_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/pulls{/number}","milestones_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/milestones{/number}","notifications_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/labels{/name}","releases_url":"https://api.github.com/repos/edx/edx-analytics-pipeline/releases{/id}","created_at":"2014-08-13T19:57:17Z","updated_at":"2015-09-24T20:45:04Z","pushed_at":"2015-10-08T11:34:44Z","git_url":"git://github.com/edx/edx-analytics-pipeline.git","ssh_url":"git@github.com:edx/edx-analytics-pipeline.git","clone_url":"https://github.com/edx/edx-analytics-pipeline.git","svn_url":"https://github.com/edx/edx-analytics-pipeline","homepage":null,"size":6634,"stargazers_count":12,"watchers_count":12,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":24,"mirror_url":null,"open_issues_count":10,"forks":24,"open_issues":10,"watchers":12,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/edx/edx-analytics-pipeline/pulls/170"},"html":{"href":"https://github.com/edx/edx-analytics-pipeline/pull/170"},"issue":{"href":"https://api.github.com/repos/edx/edx-analytics-pipeline/issues/170"},"comments":{"href":"https://api.github.com/repos/edx/edx-analytics-pipeline/issues/170/comments"},"review_comments":{"href":"https://api.github.com/repos/edx/edx-analytics-pipeline/pulls/170/comments"},"review_comment":{"href":"https://api.github.com/repos/edx/edx-analytics-pipeline/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/edx/edx-analytics-pipeline/pulls/170/commits"},"statuses":{"href":"https://api.github.com/repos/edx/edx-analytics-pipeline/statuses/f71f0b22da31f65a498278caa6a0ded47708e80b"}}}}