Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-analytics-data-api
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-analytics-data-api
Commits
9d4dd1fe
Commit
9d4dd1fe
authored
Aug 01, 2014
by
Clinton Blackburn
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Restore support for old data schema
- Changed activity_type column to label - Using uppercase activity_type
parent
82204925
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
43 additions
and
9 deletions
+43
-9
analytics_data_api/v0/models.py
+3
-2
analytics_data_api/v0/tests/test_views.py
+13
-5
analytics_data_api/v0/views/courses.py
+27
-2
No files found.
analytics_data_api/v0/models.py
View file @
9d4dd1fe
...
@@ -8,11 +8,12 @@ class CourseActivityByWeek(models.Model):
...
@@ -8,11 +8,12 @@ class CourseActivityByWeek(models.Model):
class
Meta
(
object
):
class
Meta
(
object
):
db_table
=
'course_activity'
db_table
=
'course_activity'
index_together
=
[[
'course_id'
,
'activity_type'
]]
course_id
=
models
.
CharField
(
max_length
=
255
)
course_id
=
models
.
CharField
(
db_index
=
True
,
max_length
=
255
)
interval_start
=
models
.
DateTimeField
()
interval_start
=
models
.
DateTimeField
()
interval_end
=
models
.
DateTimeField
()
interval_end
=
models
.
DateTimeField
()
activity_type
=
models
.
CharField
(
db_index
=
True
,
max_length
=
255
)
activity_type
=
models
.
CharField
(
db_index
=
True
,
max_length
=
255
,
db_column
=
'label'
)
count
=
models
.
IntegerField
()
count
=
models
.
IntegerField
()
@classmethod
@classmethod
...
...
analytics_data_api/v0/tests/test_views.py
View file @
9d4dd1fe
...
@@ -24,13 +24,13 @@ class CourseActivityLastWeekTest(TestCaseWithAuthentication):
...
@@ -24,13 +24,13 @@ class CourseActivityLastWeekTest(TestCaseWithAuthentication):
interval_start
=
'2014-05-24T00:00:00Z'
interval_start
=
'2014-05-24T00:00:00Z'
interval_end
=
'2014-06-01T00:00:00Z'
interval_end
=
'2014-06-01T00:00:00Z'
G
(
models
.
CourseActivityByWeek
,
course_id
=
self
.
course_id
,
interval_start
=
interval_start
,
interval_end
=
interval_end
,
G
(
models
.
CourseActivityByWeek
,
course_id
=
self
.
course_id
,
interval_start
=
interval_start
,
interval_end
=
interval_end
,
activity_type
=
'
posted_forum
'
,
count
=
100
)
activity_type
=
'
POSTED_FORUM
'
,
count
=
100
)
G
(
models
.
CourseActivityByWeek
,
course_id
=
self
.
course_id
,
interval_start
=
interval_start
,
interval_end
=
interval_end
,
G
(
models
.
CourseActivityByWeek
,
course_id
=
self
.
course_id
,
interval_start
=
interval_start
,
interval_end
=
interval_end
,
activity_type
=
'
attempted_problem
'
,
count
=
200
)
activity_type
=
'
ATTEMPTED_PROBLEM
'
,
count
=
200
)
G
(
models
.
CourseActivityByWeek
,
course_id
=
self
.
course_id
,
interval_start
=
interval_start
,
interval_end
=
interval_end
,
G
(
models
.
CourseActivityByWeek
,
course_id
=
self
.
course_id
,
interval_start
=
interval_start
,
interval_end
=
interval_end
,
activity_type
=
'
any
'
,
count
=
300
)
activity_type
=
'
ACTIVE
'
,
count
=
300
)
G
(
models
.
CourseActivityByWeek
,
course_id
=
self
.
course_id
,
interval_start
=
interval_start
,
interval_end
=
interval_end
,
G
(
models
.
CourseActivityByWeek
,
course_id
=
self
.
course_id
,
interval_start
=
interval_start
,
interval_end
=
interval_end
,
activity_type
=
'
played_video
'
,
count
=
400
)
activity_type
=
'
PLAYED_VIDEO
'
,
count
=
400
)
def
test_activity
(
self
):
def
test_activity
(
self
):
response
=
self
.
authenticated_get
(
'/api/v0/courses/{0}/recent_activity'
.
format
(
self
.
course_id
))
response
=
self
.
authenticated_get
(
'/api/v0/courses/{0}/recent_activity'
.
format
(
self
.
course_id
))
...
@@ -43,10 +43,11 @@ class CourseActivityLastWeekTest(TestCaseWithAuthentication):
...
@@ -43,10 +43,11 @@ class CourseActivityLastWeekTest(TestCaseWithAuthentication):
'course_id'
:
'edX/DemoX/Demo_Course'
,
'course_id'
:
'edX/DemoX/Demo_Course'
,
'interval_start'
:
datetime
.
datetime
(
2014
,
5
,
24
,
0
,
0
,
tzinfo
=
pytz
.
utc
),
'interval_start'
:
datetime
.
datetime
(
2014
,
5
,
24
,
0
,
0
,
tzinfo
=
pytz
.
utc
),
'interval_end'
:
datetime
.
datetime
(
2014
,
6
,
1
,
0
,
0
,
tzinfo
=
pytz
.
utc
),
'interval_end'
:
datetime
.
datetime
(
2014
,
6
,
1
,
0
,
0
,
tzinfo
=
pytz
.
utc
),
'activity_type'
:
'
any
'
,
'activity_type'
:
'
ACTIVE
'
,
'count'
:
300
,
'count'
:
300
,
}
}
default
.
update
(
kwargs
)
default
.
update
(
kwargs
)
default
[
'activity_type'
]
=
default
[
'activity_type'
]
.
upper
()
return
default
return
default
def
test_activity_auth
(
self
):
def
test_activity_auth
(
self
):
...
@@ -79,6 +80,13 @@ class CourseActivityLastWeekTest(TestCaseWithAuthentication):
...
@@ -79,6 +80,13 @@ class CourseActivityLastWeekTest(TestCaseWithAuthentication):
response
=
self
.
authenticated_get
(
'/api/v0/courses/recent_activity'
)
response
=
self
.
authenticated_get
(
'/api/v0/courses/recent_activity'
)
self
.
assertEquals
(
response
.
status_code
,
404
)
self
.
assertEquals
(
response
.
status_code
,
404
)
def
test_label_parameter
(
self
):
activity_type
=
'played_video'
response
=
self
.
authenticated_get
(
'/api/v0/courses/{0}/recent_activity?label={1}'
.
format
(
self
.
course_id
,
activity_type
))
self
.
assertEquals
(
response
.
status_code
,
200
)
self
.
assertEquals
(
response
.
data
,
self
.
get_activity_record
(
activity_type
=
activity_type
,
count
=
400
))
# pylint: disable=no-member
# pylint: disable=no-member
class
CourseEnrollmentViewTestCase
(
object
):
class
CourseEnrollmentViewTestCase
(
object
):
...
...
analytics_data_api/v0/views/courses.py
View file @
9d4dd1fe
...
@@ -38,12 +38,37 @@ class CourseActivityMostRecentWeekView(generics.RetrieveAPIView):
...
@@ -38,12 +38,37 @@ class CourseActivityMostRecentWeekView(generics.RetrieveAPIView):
"""
"""
serializer_class
=
serializers
.
CourseActivityByWeekSerializer
serializer_class
=
serializers
.
CourseActivityByWeekSerializer
DEFAULT_ACTIVITY_TYPE
=
'ACTIVE'
def
_format_activity_type
(
self
,
activity_type
):
"""
Modify the activity type parameter for use with our data.
Arguments:
activity_type (str): String to be formatted
"""
activity_type
=
activity_type
.
upper
()
if
activity_type
==
'ANY'
:
activity_type
=
self
.
DEFAULT_ACTIVITY_TYPE
return
activity_type
def
_get_activity_type
(
self
):
""" Retrieve the activity type from the query string. """
# Support the old label param
activity_type
=
self
.
request
.
QUERY_PARAMS
.
get
(
'label'
,
None
)
activity_type
=
activity_type
or
self
.
request
.
QUERY_PARAMS
.
get
(
'activity_type'
,
self
.
DEFAULT_ACTIVITY_TYPE
)
activity_type
=
self
.
_format_activity_type
(
activity_type
)
return
activity_type
def
get_object
(
self
,
queryset
=
None
):
def
get_object
(
self
,
queryset
=
None
):
"""Select the activity report for the given course and activity type."""
"""Select the activity report for the given course and activity type."""
course_id
=
self
.
kwargs
.
get
(
'course_id'
)
course_id
=
self
.
kwargs
.
get
(
'course_id'
)
activity_type
=
self
.
request
.
QUERY_PARAMS
.
get
(
'activity_type'
,
'any'
)
activity_type
=
self
.
_get_activity_type
()
activity_type
=
activity_type
.
lower
()
try
:
try
:
return
models
.
CourseActivityByWeek
.
get_most_recent
(
course_id
,
activity_type
)
return
models
.
CourseActivityByWeek
.
get_most_recent
(
course_id
,
activity_type
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment