Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-analytics-data-api-client
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
OpenEdx
edx-analytics-data-api-client
Commits
c7326041
Commit
c7326041
authored
Sep 02, 2014
by
Clinton Blackburn
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added support for course activity resource
parent
c2264bdd
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
63 additions
and
2 deletions
+63
-2
analyticsclient/course.py
+32
-1
analyticsclient/tests/test_course.py
+30
-0
setup.py
+1
-1
No files found.
analyticsclient/course.py
View file @
c7326041
import
urllib
import
warnings
import
analyticsclient.activity_type
as
AT
import
analyticsclient.data_format
as
DF
from
analyticsclient.exceptions
import
InvalidRequestError
class
Course
(
object
):
...
...
@@ -33,7 +35,7 @@ class Course(object):
Arguments:
demographic (str): Demographic by which enrollment data should be grouped.
start_date (str): Minimum date for returned enrollment data
end_date (str): Max
m
imum date for returned enrollment data
end_date (str): Maximum date for returned enrollment data
data_format (str): Format in which data should be returned
"""
path
=
'courses/{0}/enrollment/'
.
format
(
self
.
course_id
)
...
...
@@ -53,6 +55,33 @@ class Course(object):
return
self
.
client
.
get
(
path
,
data_format
=
data_format
)
def
activity
(
self
,
activity_type
=
AT
.
ANY
,
start_date
=
None
,
end_date
=
None
,
data_format
=
DF
.
JSON
):
"""
Get the course student activity.
Arguments:
activity_type (str): The type of recent activity to return. Defaults to ANY.
data_format (str): Format in which data should be returned
"""
if
not
activity_type
:
raise
InvalidRequestError
(
'activity_type cannot be None.'
)
params
=
{
'activity_type'
:
activity_type
}
if
start_date
:
params
[
'start_date'
]
=
start_date
if
end_date
:
params
[
'end_date'
]
=
end_date
path
=
'courses/{0}/activity/'
.
format
(
self
.
course_id
)
querystring
=
urllib
.
urlencode
(
params
)
path
+=
'?{0}'
.
format
(
querystring
)
return
self
.
client
.
get
(
path
,
data_format
=
data_format
)
def
recent_activity
(
self
,
activity_type
=
AT
.
ANY
,
data_format
=
DF
.
JSON
):
"""
Get the recent course activity.
...
...
@@ -61,5 +90,7 @@ class Course(object):
activity_type (str): The type of recent activity to return. Defaults to ANY.
data_format (str): Format in which data should be returned
"""
warnings
.
warn
(
'recent_activity has been deprecated! Use activity instead.'
,
DeprecationWarning
)
path
=
'courses/{0}/recent_activity/?activity_type={1}'
.
format
(
self
.
course_id
,
activity_type
)
return
self
.
client
.
get
(
path
,
data_format
=
data_format
)
analyticsclient/tests/test_course.py
View file @
c7326041
...
...
@@ -44,6 +44,29 @@ class CoursesTests(ClientTestCase):
httpretty
.
register_uri
(
httpretty
.
GET
,
'{0}?start_date={1}&end_date={1}'
.
format
(
uri
,
date
),
body
=
'{}'
)
course
.
enrollment
(
demographic
,
start_date
=
date
,
end_date
=
date
)
def
assertCorrectActivityUrl
(
self
,
course
,
activity_type
=
None
):
""" Verifies that the activity URL is correct. """
uri
=
self
.
get_api_url
(
'courses/{0}/activity/'
.
format
(
course
.
course_id
))
if
activity_type
:
uri
+=
'?activity_type=
%
s'
%
activity_type
httpretty
.
register_uri
(
httpretty
.
GET
,
uri
,
body
=
'{}'
)
course
.
activity
(
activity_type
)
date
=
'2014-01-01'
httpretty
.
reset
()
httpretty
.
register_uri
(
httpretty
.
GET
,
'{0}&start_date={1}'
.
format
(
uri
,
date
),
body
=
'{}'
)
course
.
activity
(
activity_type
,
start_date
=
date
)
httpretty
.
reset
()
httpretty
.
register_uri
(
httpretty
.
GET
,
'{0}&end_date={1}'
.
format
(
uri
,
date
),
body
=
'{}'
)
course
.
activity
(
activity_type
,
end_date
=
date
)
httpretty
.
reset
()
httpretty
.
register_uri
(
httpretty
.
GET
,
'{0}&start_date={1}&end_date={1}'
.
format
(
uri
,
date
),
body
=
'{}'
)
course
.
activity
(
activity_type
,
start_date
=
date
,
end_date
=
date
)
@httpretty.activate
def
assertRecentActivityResponseData
(
self
,
course
,
activity_type
):
body
=
{
...
...
@@ -93,6 +116,13 @@ class CoursesTests(ClientTestCase):
self
.
assertCorrectEnrollmentUrl
(
self
.
course
,
demo
.
GENDER
)
self
.
assertCorrectEnrollmentUrl
(
self
.
course
,
demo
.
LOCATION
)
def
test_activity
(
self
):
self
.
assertRaises
(
InvalidRequestError
,
self
.
assertCorrectActivityUrl
,
self
.
course
,
None
)
self
.
assertCorrectActivityUrl
(
self
.
course
,
at
.
ANY
)
self
.
assertCorrectActivityUrl
(
self
.
course
,
at
.
ATTEMPTED_PROBLEM
)
self
.
assertCorrectActivityUrl
(
self
.
course
,
at
.
PLAYED_VIDEO
)
self
.
assertCorrectActivityUrl
(
self
.
course
,
at
.
POSTED_FORUM
)
def
test_enrollment_data_format
(
self
):
uri
=
self
.
get_api_url
(
'courses/{0}/enrollment/'
.
format
(
self
.
course
.
course_id
))
...
...
setup.py
View file @
c7326041
...
...
@@ -2,7 +2,7 @@ from distutils.core import setup
setup
(
name
=
'edx-analytics-data-api-client'
,
version
=
'0.
1
.0'
,
version
=
'0.
2
.0'
,
packages
=
[
'analyticsclient'
],
url
=
'https://github.com/edx/edx-analytics-data-api-client'
,
description
=
'Client used to access edX analytics data warehouse'
,
...
...
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