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
035003d5
Commit
035003d5
authored
Aug 08, 2014
by
Clinton Blackburn
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Returning both alpha2 and alpha3 country codes
This replaces the code field with two fields, alpha2 and alpha3.
parent
95547969
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
30 additions
and
25 deletions
+30
-25
analytics_data_api/v0/models.py
+4
-6
analytics_data_api/v0/serializers.py
+9
-1
analytics_data_api/v0/tests/test_models.py
+4
-11
analytics_data_api/v0/tests/test_views.py
+13
-7
No files found.
analytics_data_api/v0/models.py
View file @
035003d5
from
collections
import
namedtuple
from
django.db
import
models
from
iso3166
import
countries
...
...
@@ -97,16 +96,15 @@ class ProblemResponseAnswerDistribution(models.Model):
created
=
models
.
DateTimeField
(
auto_now_add
=
True
,
db_column
=
'created'
)
Country
=
namedtuple
(
'Country'
,
'name code'
)
class
CourseEnrollmentByCountry
(
BaseCourseEnrollment
):
country_code
=
models
.
CharField
(
max_length
=
255
,
null
=
False
,
db_column
=
'country_code'
)
@property
def
country
(
self
):
country
=
countries
.
get
(
self
.
country_code
)
return
Country
(
country
.
name
,
country
.
alpha2
)
"""
Returns a Country object representing the country in this model's country_code.
"""
return
countries
.
get
(
self
.
country_code
)
class
Meta
(
BaseCourseEnrollment
.
Meta
):
db_table
=
'course_enrollment_location_current'
...
...
analytics_data_api/v0/serializers.py
View file @
035003d5
...
...
@@ -66,7 +66,15 @@ class CourseEnrollmentDailySerializer(BaseCourseEnrollmentModelSerializer):
class
CountrySerializer
(
serializers
.
Serializer
):
code
=
serializers
.
CharField
()
"""
Serialize country to an object with fields for the complete country name
and the ISO-3166 two- and three-digit codes.
Some downstream consumers need two-digit codes, others need three. Both are provided to avoid the need
for conversion.
"""
alpha2
=
serializers
.
CharField
()
alpha3
=
serializers
.
CharField
()
name
=
serializers
.
CharField
()
...
...
analytics_data_api/v0/tests/test_models.py
View file @
035003d5
from
django.test
import
TestCase
from
django_dynamic_fixture
import
G
from
iso3166
import
countries
from
analytics_data_api.v0
import
models
...
...
@@ -16,17 +17,9 @@ class EducationLevelTests(TestCase):
"{0} - {1}"
.
format
(
short_name
,
name
))
class
CountryTests
(
TestCase
):
# pylint: disable=no-member
def
test_attributes
(
self
):
country
=
models
.
Country
(
'Canada'
,
'CA'
)
self
.
assertEqual
(
country
.
code
,
'CA'
)
self
.
assertEqual
(
country
.
name
,
'Canada'
)
class
CourseEnrollmentByCountryTests
(
TestCase
):
def
test_country
(
self
):
country
=
models
.
Country
(
'United States'
,
'US'
)
instance
=
G
(
models
.
CourseEnrollmentByCountry
,
country_code
=
country
.
code
)
country
=
countries
.
get
(
'US'
)
self
.
assertEqual
(
country
.
alpha2
,
'US'
)
instance
=
G
(
models
.
CourseEnrollmentByCountry
,
country_code
=
country
.
alpha2
)
self
.
assertEqual
(
instance
.
country
,
country
)
analytics_data_api/v0/tests/test_views.py
View file @
035003d5
...
...
@@ -23,13 +23,17 @@ class CourseActivityLastWeekTest(TestCaseWithAuthentication):
self
.
course_id
=
'edX/DemoX/Demo_Course'
interval_start
=
'2014-05-24T00: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
)
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
)
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
=
'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
)
def
test_activity
(
self
):
...
...
@@ -109,7 +113,8 @@ class CourseEnrollmentViewTestCase(object):
self
.
assertEquals
(
response
.
status_code
,
200
)
# Validate the data is correct and sorted chronologically
expected
=
self
.
get_expected_response
(
*
self
.
model
.
objects
.
filter
(
date
=
self
.
date
)
.
order_by
(
'date'
,
*
self
.
order_by
))
# pylint: disable=line-too-long
expected
=
self
.
get_expected_response
(
*
self
.
model
.
objects
.
filter
(
date
=
self
.
date
)
.
order_by
(
'date'
,
*
self
.
order_by
))
# pylint: disable=line-too-long
self
.
assertEquals
(
response
.
data
,
expected
)
def
test_get_csv
(
self
):
...
...
@@ -288,10 +293,11 @@ class CourseEnrollmentByLocationViewTests(TestCaseWithAuthentication, CourseEnro
model
=
models
.
CourseEnrollmentByCountry
def
get_expected_response
(
self
,
*
args
):
args
=
sorted
(
args
,
key
=
lambda
item
:
(
item
.
date
,
item
.
course_id
,
item
.
country
.
code
))
args
=
sorted
(
args
,
key
=
lambda
item
:
(
item
.
date
,
item
.
course_id
,
item
.
country
.
alpha3
))
return
[
{
'course_id'
:
str
(
ce
.
course_id
),
'count'
:
ce
.
count
,
'date'
:
ce
.
date
.
strftime
(
settings
.
DATE_FORMAT
),
'country'
:
{
'code'
:
ce
.
country
.
code
,
'name'
:
ce
.
country
.
name
}}
for
ce
in
args
]
'country'
:
{
'alpha2'
:
ce
.
country
.
alpha2
,
'alpha3'
:
ce
.
country
.
alpha3
,
'name'
:
ce
.
country
.
name
}}
for
ce
in
args
]
@classmethod
def
setUpClass
(
cls
):
...
...
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