Unverified Commit 900d3f69 by Muhammad Ammar Committed by GitHub

Merge pull request #443 from edx/ammar/use-video-duration-in-event

use video duration from events
parents 973856c6 1c10f9a7
...@@ -212,6 +212,8 @@ class UserVideoViewingTask(EventLogSelectionMixin, MapReduceJobTask): ...@@ -212,6 +212,8 @@ class UserVideoViewingTask(EventLogSelectionMixin, MapReduceJobTask):
## self.incr_counter(self.counter_category_name, 'Discard Video Missing encoded_module_id', 1) ## self.incr_counter(self.counter_category_name, 'Discard Video Missing encoded_module_id', 1)
return return
video_duration = event_data.get('duration', VIDEO_UNKNOWN_DURATION)
# self.incr_counter(self.counter_category_name, 'Video Events Before Time Check', 1) # self.incr_counter(self.counter_category_name, 'Video Events Before Time Check', 1)
current_time = None current_time = None
...@@ -262,7 +264,7 @@ class UserVideoViewingTask(EventLogSelectionMixin, MapReduceJobTask): ...@@ -262,7 +264,7 @@ class UserVideoViewingTask(EventLogSelectionMixin, MapReduceJobTask):
# self.incr_counter(self.counter_category_name, 'Output Video Events from Mapper', 1) # self.incr_counter(self.counter_category_name, 'Output Video Events from Mapper', 1)
yield ( yield (
(username.encode('utf8'), course_id.encode('utf8'), encoded_module_id.encode('utf8')), (username.encode('utf8'), course_id.encode('utf8'), encoded_module_id.encode('utf8')),
(timestamp, event_type, current_time, old_time, youtube_id) (timestamp, event_type, current_time, old_time, youtube_id, video_duration)
) )
def _check_time_offset(self, time_value, line): def _check_time_offset(self, time_value, line):
...@@ -326,7 +328,7 @@ class UserVideoViewingTask(EventLogSelectionMixin, MapReduceJobTask): ...@@ -326,7 +328,7 @@ class UserVideoViewingTask(EventLogSelectionMixin, MapReduceJobTask):
for event in sorted_events: for event in sorted_events:
# self.incr_counter(self.counter_category_name, 'Input User_course_video events', 1) # self.incr_counter(self.counter_category_name, 'Input User_course_video events', 1)
timestamp, event_type, current_time, old_time, youtube_id = event timestamp, event_type, current_time, old_time, youtube_id, duration = event
parsed_timestamp = ciso8601.parse_datetime(timestamp) parsed_timestamp = ciso8601.parse_datetime(timestamp)
if current_time is not None: if current_time is not None:
current_time = float(current_time) current_time = float(current_time)
...@@ -336,8 +338,11 @@ class UserVideoViewingTask(EventLogSelectionMixin, MapReduceJobTask): ...@@ -336,8 +338,11 @@ class UserVideoViewingTask(EventLogSelectionMixin, MapReduceJobTask):
def start_viewing(): def start_viewing():
"""Returns a 'viewing' object representing the point where a video began to be played.""" """Returns a 'viewing' object representing the point where a video began to be played."""
# self.incr_counter(self.counter_category_name, 'Viewing Start', 1) # self.incr_counter(self.counter_category_name, 'Viewing Start', 1)
video_duration = VIDEO_UNKNOWN_DURATION
if youtube_id: video_duration = duration
# video_duration is set to VIDEO_UNKNOWN_DURATION only when duration is not present in
# a video event, In that case fetch duration using youtube API if video is from youtube.
if video_duration == VIDEO_UNKNOWN_DURATION and youtube_id:
# self.incr_counter(self.counter_category_name, 'Viewing Start with Video Id', 1) # self.incr_counter(self.counter_category_name, 'Viewing Start with Video Id', 1)
video_duration = self.video_durations.get(youtube_id) video_duration = self.video_durations.get(youtube_id)
if not video_duration: if not video_duration:
......
...@@ -23,3 +23,7 @@ ...@@ -23,3 +23,7 @@
# Different course. # Different course.
{"username": "dummy_username_1", "event_type": "play_video", "ip": "127.0.0.1", "agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1985.143 Safari/537.36", "host": "example.m.sandbox.edx.org", "session": "495604b91e7522ca25b9da1a15384aaa", "event": "{\"id\":\"0b9e39477cf34507a7a48f74be381fdd\",\"currentTime\":0,\"code\":\"b7xgknqkQk8\"}", "event_source": "browser", "context": {"user_id": 10001, "org_id": "edX", "course_id": "course-v1:edX+DemoX+Test_2014", "path": "/event"}, "time": "2014-05-02T17:47:25.605078+00:00", "page": "http://example.m.sandbox.edx.org/courses/course-v1:edX+DemoX+Test_2014/courseware/d8a6192ade314473a78242dfeedfbf5b/edx_introduction/"} {"username": "dummy_username_1", "event_type": "play_video", "ip": "127.0.0.1", "agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1985.143 Safari/537.36", "host": "example.m.sandbox.edx.org", "session": "495604b91e7522ca25b9da1a15384aaa", "event": "{\"id\":\"0b9e39477cf34507a7a48f74be381fdd\",\"currentTime\":0,\"code\":\"b7xgknqkQk8\"}", "event_source": "browser", "context": {"user_id": 10001, "org_id": "edX", "course_id": "course-v1:edX+DemoX+Test_2014", "path": "/event"}, "time": "2014-05-02T17:47:25.605078+00:00", "page": "http://example.m.sandbox.edx.org/courses/course-v1:edX+DemoX+Test_2014/courseware/d8a6192ade314473a78242dfeedfbf5b/edx_introduction/"}
{"username": "dummy_username_1", "event_type": "stop_video", "ip": "127.0.0.1", "agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1985.143 Safari/537.36", "host": "example.m.sandbox.edx.org", "session": "495604b91e7522ca25b9da1a15384aaa", "event": "{\"id\":\"0b9e39477cf34507a7a48f74be381fdd\",\"currentTime\":4,\"code\":\"b7xgknqkQk8\"}", "event_source": "browser", "context": {"user_id": 10001, "org_id": "edX", "course_id": "course-v1:edX+DemoX+Test_2014", "path": "/event"}, "time": "2014-05-02T17:47:35.605078+00:00", "page": "http://example.m.sandbox.edx.org/courses/course-v1:edX+DemoX+Test_2014/courseware/d8a6192ade314473a78242dfeedfbf5b/edx_introduction/"} {"username": "dummy_username_1", "event_type": "stop_video", "ip": "127.0.0.1", "agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1985.143 Safari/537.36", "host": "example.m.sandbox.edx.org", "session": "495604b91e7522ca25b9da1a15384aaa", "event": "{\"id\":\"0b9e39477cf34507a7a48f74be381fdd\",\"currentTime\":4,\"code\":\"b7xgknqkQk8\"}", "event_source": "browser", "context": {"user_id": 10001, "org_id": "edX", "course_id": "course-v1:edX+DemoX+Test_2014", "path": "/event"}, "time": "2014-05-02T17:47:35.605078+00:00", "page": "http://example.m.sandbox.edx.org/courses/course-v1:edX+DemoX+Test_2014/courseware/d8a6192ade314473a78242dfeedfbf5b/edx_introduction/"}
# events for video duration
{"username": "dummy_username_1", "event_type": "play_video", "ip": "127.0.0.1", "agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1985.143 Safari/537.36", "host": "example.m.sandbox.edx.org", "session": "495604b91e7522ca25b9da1a15384aaa1", "event": "{\"id\":\"0b9e39477cf34507a7a48f74be381fdd1\",\"currentTime\":0,\"code\":\"3_yD_cEKoCk\",\"duration\":444}", "event_source": "browser", "context": {"user_id": 10001, "org_id": "edX", "course_id": "course-v1:edX+DemoX+Test_2015", "path": "/event"}, "time": "2014-05-02T17:47:25.605078+00:00", "page": "http://example.m.sandbox.edx.org/courses/course-v1:edX+DemoX+Test_2015/courseware/d8a6192ade314473a78242dfeedfbf5b1/edx_introduction1/"}
{"username": "dummy_username_1", "event_type": "stop_video", "ip": "127.0.0.1", "agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1985.143 Safari/537.36", "host": "example.m.sandbox.edx.org", "session": "495604b91e7522ca25b9da1a15384aaa1", "event": "{\"id\":\"0b9e39477cf34507a7a48f74be381fdd1\",\"currentTime\":4,\"code\":\"3_yD_cEKoCk\",\"duration\":444}", "event_source": "browser", "context": {"user_id": 10001, "org_id": "edX", "course_id": "course-v1:edX+DemoX+Test_2015", "path": "/event"}, "time": "2014-05-02T17:47:35.605078+00:00", "page": "http://example.m.sandbox.edx.org/courses/course-v1:edX+DemoX+Test_2015/courseware/d8a6192ade314473a78242dfeedfbf5b1/edx_introduction1/"}
...@@ -69,6 +69,16 @@ class VideoAcceptanceTest(AcceptanceTestCase): ...@@ -69,6 +69,16 @@ class VideoAcceptanceTest(AcceptanceTestCase):
1, 1,
15, 15,
), ),
(
'course-v1:edX+DemoX+Test_2015|0b9e39477cf34507a7a48f74be381fdd1',
'course-v1:edX+DemoX+Test_2015',
'0b9e39477cf34507a7a48f74be381fdd1',
444,
5,
1,
0,
5
),
] ]
self.assertItemsEqual(expected, results) self.assertItemsEqual(expected, results)
...@@ -91,5 +101,6 @@ class VideoAcceptanceTest(AcceptanceTestCase): ...@@ -91,5 +101,6 @@ class VideoAcceptanceTest(AcceptanceTestCase):
('edX/DemoX/Demo_Course|i4x-edX-DemoX-video-8c0028eb2a724f48a074bc184cd8635f', 2, 1, 1), ('edX/DemoX/Demo_Course|i4x-edX-DemoX-video-8c0028eb2a724f48a074bc184cd8635f', 2, 1, 1),
('edX/DemoX/Demo_Course|i4x-edX-DemoX-video-8c0028eb2a724f48a074bc184cd8635f', 3, 1, 1), ('edX/DemoX/Demo_Course|i4x-edX-DemoX-video-8c0028eb2a724f48a074bc184cd8635f', 3, 1, 1),
('edX/DemoX/Demo_Course|i4x-edX-DemoX-video-8c0028eb2a724f48a074bc184cd8635f', 4, 1, 1), ('edX/DemoX/Demo_Course|i4x-edX-DemoX-video-8c0028eb2a724f48a074bc184cd8635f', 4, 1, 1),
('course-v1:edX+DemoX+Test_2015|0b9e39477cf34507a7a48f74be381fdd1', 0, 1, 1),
] ]
self.assertItemsEqual(expected, results) self.assertItemsEqual(expected, results)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment