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
58046383
Commit
58046383
authored
Sep 18, 2014
by
Clinton Blackburn
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Including Creation Datetime with All Data
parent
dc785961
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
26 additions
and
12 deletions
+26
-12
analytics_data_api/v0/models.py
+1
-0
analytics_data_api/v0/serializers.py
+9
-6
analytics_data_api/v0/tests/test_views.py
+10
-5
analytics_data_api/v0/views/courses.py
+6
-1
No files found.
analytics_data_api/v0/models.py
View file @
58046383
...
...
@@ -18,6 +18,7 @@ class CourseActivityWeekly(models.Model):
interval_end
=
models
.
DateTimeField
(
db_index
=
True
)
activity_type
=
models
.
CharField
(
db_index
=
True
,
max_length
=
255
,
db_column
=
'label'
)
count
=
models
.
IntegerField
()
created
=
models
.
DateTimeField
(
auto_now_add
=
True
)
@classmethod
def
get_most_recent
(
cls
,
course_id
,
activity_type
):
...
...
analytics_data_api/v0/serializers.py
View file @
58046383
...
...
@@ -56,6 +56,7 @@ class ProblemResponseAnswerDistributionSerializer(serializers.ModelSerializer):
class
BaseCourseEnrollmentModelSerializer
(
serializers
.
ModelSerializer
):
date
=
serializers
.
DateField
(
format
=
settings
.
DATE_FORMAT
)
created
=
serializers
.
DateTimeField
(
format
=
settings
.
DATETIME_FORMAT
)
class
CourseEnrollmentDailySerializer
(
BaseCourseEnrollmentModelSerializer
):
...
...
@@ -63,7 +64,7 @@ class CourseEnrollmentDailySerializer(BaseCourseEnrollmentModelSerializer):
class
Meta
(
object
):
model
=
models
.
CourseEnrollmentDaily
fields
=
(
'course_id'
,
'date'
,
'count'
)
fields
=
(
'course_id'
,
'date'
,
'count'
,
'created'
)
class
CountrySerializer
(
serializers
.
Serializer
):
...
...
@@ -92,13 +93,13 @@ class CourseEnrollmentByCountrySerializer(BaseCourseEnrollmentModelSerializer):
class
Meta
(
object
):
model
=
models
.
CourseEnrollmentByCountry
fields
=
(
'date'
,
'course_id'
,
'country'
,
'count'
)
fields
=
(
'date'
,
'course_id'
,
'country'
,
'count'
,
'created'
)
class
CourseEnrollmentByGenderSerializer
(
BaseCourseEnrollmentModelSerializer
):
class
Meta
(
object
):
model
=
models
.
CourseEnrollmentByGender
fields
=
(
'course_id'
,
'date'
,
'gender'
,
'count'
)
fields
=
(
'course_id'
,
'date'
,
'gender'
,
'count'
,
'created'
)
class
CourseEnrollmentByEducationSerializer
(
BaseCourseEnrollmentModelSerializer
):
...
...
@@ -106,13 +107,13 @@ class CourseEnrollmentByEducationSerializer(BaseCourseEnrollmentModelSerializer)
class
Meta
(
object
):
model
=
models
.
CourseEnrollmentByEducation
fields
=
(
'course_id'
,
'date'
,
'education_level'
,
'count'
)
fields
=
(
'course_id'
,
'date'
,
'education_level'
,
'count'
,
'created'
)
class
CourseEnrollmentByBirthYearSerializer
(
BaseCourseEnrollmentModelSerializer
):
class
Meta
(
object
):
model
=
models
.
CourseEnrollmentByBirthYear
fields
=
(
'course_id'
,
'date'
,
'birth_year'
,
'count'
)
fields
=
(
'course_id'
,
'date'
,
'birth_year'
,
'count'
,
'created'
)
class
CourseActivityWeeklySerializer
(
serializers
.
ModelSerializer
):
...
...
@@ -122,8 +123,10 @@ class CourseActivityWeeklySerializer(serializers.ModelSerializer):
attempted_problem
=
serializers
.
IntegerField
(
required
=
False
)
played_video
=
serializers
.
IntegerField
(
required
=
False
)
posted_forum
=
serializers
.
IntegerField
(
required
=
False
)
created
=
serializers
.
DateTimeField
(
format
=
settings
.
DATETIME_FORMAT
)
class
Meta
(
object
):
model
=
CourseActivityWeekly
fields
=
(
'interval_start'
,
'interval_end'
,
'course_id'
,
'any'
,
'attempted_problem'
,
'played_video'
,
'posted_forum'
)
'interval_start'
,
'interval_end'
,
'course_id'
,
'any'
,
'attempted_problem'
,
'played_video'
,
'posted_forum'
,
'created'
)
analytics_data_api/v0/tests/test_views.py
View file @
58046383
...
...
@@ -225,7 +225,7 @@ class CourseEnrollmentByBirthYearViewTests(CourseEnrollmentViewTestCaseMixin, Te
def
format_as_response
(
self
,
*
args
):
return
[
{
'course_id'
:
str
(
ce
.
course_id
),
'count'
:
ce
.
count
,
'date'
:
ce
.
date
.
strftime
(
settings
.
DATE_FORMAT
),
'birth_year'
:
ce
.
birth_year
}
for
ce
in
args
]
'birth_year'
:
ce
.
birth_year
,
'created'
:
ce
.
created
.
strftime
(
settings
.
DATETIME_FORMAT
)
}
for
ce
in
args
]
def
test_get
(
self
):
response
=
self
.
authenticated_get
(
'/api/v0/courses/
%
s
%
s'
%
(
self
.
course_id
,
self
.
path
,))
...
...
@@ -252,7 +252,8 @@ class CourseEnrollmentByEducationViewTests(CourseEnrollmentViewTestCaseMixin, Te
def
format_as_response
(
self
,
*
args
):
return
[
{
'course_id'
:
str
(
ce
.
course_id
),
'count'
:
ce
.
count
,
'date'
:
ce
.
date
.
strftime
(
settings
.
DATE_FORMAT
),
'education_level'
:
{
'name'
:
ce
.
education_level
.
name
,
'short_name'
:
ce
.
education_level
.
short_name
}}
for
'education_level'
:
{
'name'
:
ce
.
education_level
.
name
,
'short_name'
:
ce
.
education_level
.
short_name
},
'created'
:
ce
.
created
.
strftime
(
settings
.
DATETIME_FORMAT
)}
for
ce
in
args
]
...
...
@@ -270,7 +271,7 @@ class CourseEnrollmentByGenderViewTests(CourseEnrollmentViewTestCaseMixin, TestC
def
format_as_response
(
self
,
*
args
):
return
[
{
'course_id'
:
str
(
ce
.
course_id
),
'count'
:
ce
.
count
,
'date'
:
ce
.
date
.
strftime
(
settings
.
DATE_FORMAT
),
'gender'
:
ce
.
gender
}
for
ce
in
args
]
'gender'
:
ce
.
gender
,
'created'
:
ce
.
created
.
strftime
(
settings
.
DATETIME_FORMAT
)
}
for
ce
in
args
]
# pylint: disable=no-member,no-value-for-parameter
...
...
@@ -315,7 +316,8 @@ class CourseEnrollmentViewTests(CourseEnrollmentViewTestCaseMixin, TestCaseWithA
def
format_as_response
(
self
,
*
args
):
return
[
{
'course_id'
:
str
(
ce
.
course_id
),
'count'
:
ce
.
count
,
'date'
:
ce
.
date
.
strftime
(
settings
.
DATE_FORMAT
)}
{
'course_id'
:
str
(
ce
.
course_id
),
'count'
:
ce
.
count
,
'date'
:
ce
.
date
.
strftime
(
settings
.
DATE_FORMAT
),
'created'
:
ce
.
created
.
strftime
(
settings
.
DATETIME_FORMAT
)}
for
ce
in
args
]
...
...
@@ -332,6 +334,7 @@ class CourseEnrollmentByLocationViewTests(CourseEnrollmentViewTestCaseMixin, Tes
unknown
[
'course_id'
]
=
arg
.
course_id
unknown
[
'date'
]
=
arg
.
date
.
strftime
(
settings
.
DATE_FORMAT
)
unknown
[
'count'
]
+=
arg
.
count
unknown
[
'created'
]
=
arg
.
created
.
strftime
(
settings
.
DATETIME_FORMAT
)
args
=
[
arg
for
arg
in
args
if
arg
.
country
!=
UNKNOWN_COUNTRY
]
args
=
sorted
(
args
,
key
=
lambda
item
:
(
item
.
date
,
item
.
course_id
,
item
.
country
.
alpha3
))
...
...
@@ -339,7 +342,8 @@ class CourseEnrollmentByLocationViewTests(CourseEnrollmentViewTestCaseMixin, Tes
response
=
[
unknown
]
response
+=
[
{
'course_id'
:
str
(
ce
.
course_id
),
'count'
:
ce
.
count
,
'date'
:
ce
.
date
.
strftime
(
settings
.
DATE_FORMAT
),
'country'
:
{
'alpha2'
:
ce
.
country
.
alpha2
,
'alpha3'
:
ce
.
country
.
alpha3
,
'name'
:
ce
.
country
.
name
}}
for
ce
in
'country'
:
{
'alpha2'
:
ce
.
country
.
alpha2
,
'alpha3'
:
ce
.
country
.
alpha3
,
'name'
:
ce
.
country
.
name
},
'created'
:
ce
.
created
.
strftime
(
settings
.
DATETIME_FORMAT
)}
for
ce
in
args
]
return
response
...
...
@@ -399,6 +403,7 @@ class CourseActivityWeeklyViewTests(CourseViewTestCaseMixin, TestCaseWithAuthent
u'course_id'
:
activity
.
course_id
,
u'interval_start'
:
activity
.
interval_start
.
strftime
(
settings
.
DATETIME_FORMAT
),
u'interval_end'
:
activity
.
interval_end
.
strftime
(
settings
.
DATETIME_FORMAT
),
u'created'
:
activity
.
created
.
strftime
(
settings
.
DATETIME_FORMAT
),
activity_type
:
activity
.
count
})
...
...
analytics_data_api/v0/views/courses.py
View file @
58046383
...
...
@@ -128,11 +128,13 @@ class CourseActivityWeeklyView(BaseCourseView):
u'course_id'
:
key
[
0
],
u'interval_start'
:
key
[
1
],
u'interval_end'
:
key
[
2
],
u'created'
:
None
}
for
activity
in
group
:
activity_type
=
self
.
_format_activity_type
(
activity
.
activity_type
)
item
[
activity_type
]
=
activity
.
count
item
[
u'created'
]
=
max
(
activity
.
created
,
item
[
u'created'
])
if
item
[
u'created'
]
else
activity
.
created
formatted_data
.
append
(
item
)
...
...
@@ -348,8 +350,10 @@ class CourseEnrollmentByLocationView(BaseCourseEnrollmentView):
date
=
key
[
0
]
country_code
=
key
[
1
]
course_id
=
key
[
2
]
created
=
None
for
item
in
group
:
created
=
max
(
created
,
item
.
created
)
if
created
else
item
.
created
count
+=
item
.
count
# pylint: disable=no-value-for-parameter,unexpected-keyword-arg
...
...
@@ -357,7 +361,8 @@ class CourseEnrollmentByLocationView(BaseCourseEnrollmentView):
course_id
=
course_id
,
date
=
date
,
country_code
=
country_code
,
count
=
count
count
=
count
,
created
=
created
))
# Note: We are returning a list, instead of a queryset. This is
...
...
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