Skip to content

Commit

Permalink
Merge 53dc268 into 7fe4fa6
Browse files Browse the repository at this point in the history
  • Loading branch information
pomegranited committed Jul 29, 2016
2 parents 7fe4fa6 + 53dc268 commit 07fe6a7
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 1 deletion.
10 changes: 10 additions & 0 deletions analytics_data_api/v0/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,9 +249,19 @@ def get_last_updated(cls):
class RosterEntry(DocType):

course_id = String()
user_id = Integer()
username = String()
name = String()
email = String()
language = String()
location = String()
year_of_birth = Integer()
level_of_education = String()
gender = String()
mailing_address = String()
city = String()
country = String()
goals = String()
enrollment_mode = String()
cohort = String()
segments = String() # segments is an array/list of strings
Expand Down
10 changes: 10 additions & 0 deletions analytics_data_api/v0/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,11 +334,21 @@ class LastUpdatedSerializer(serializers.Serializer):


class LearnerSerializer(serializers.Serializer, DefaultIfNoneMixin):
user_id = serializers.IntegerField(source='user_id')
username = serializers.CharField(source='username')
enrollment_mode = serializers.CharField(source='enrollment_mode')
name = serializers.CharField(source='name')
account_url = serializers.SerializerMethodField('get_account_url')
email = serializers.CharField(source='email')
language = serializers.CharField(source='language')
location = serializers.CharField(source='location')
year_of_birth = serializers.IntegerField(source='year_of_birth')
level_of_education = serializers.CharField(source='level_of_education')
gender = serializers.CharField(source='gender')
mailing_address = serializers.CharField(source='mailing_address')
city = serializers.CharField(source='city')
country = serializers.CharField(source='country')
goals = serializers.CharField(source='goals')
segments = serializers.Field(source='segments')
engagements = serializers.SerializerMethodField('get_engagements')
enrollment_date = serializers.DateField(source='enrollment_date', format=settings.DATE_FORMAT)
Expand Down
49 changes: 48 additions & 1 deletion analytics_data_api/v0/tests/views/test_learners.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,16 @@ def _create_learner(
attempt_ratio_order=0,
videos_viewed=0,
enrollment_date='2015-01-28',
user_id=None,
language=None,
location=None,
year_of_birth=None,
level_of_education=None,
gender=None,
mailing_address=None,
city=None,
country=None,
goals=None,
):
"""Create a single learner roster entry in the elasticsearch index."""
body = {
Expand All @@ -61,6 +71,16 @@ def _create_learner(
'attempt_ratio_order': attempt_ratio_order,
'videos_viewed': videos_viewed,
'enrollment_date': enrollment_date,
"user_id": user_id,
"language": language,
"location": location,
"year_of_birth": year_of_birth,
"level_of_education": level_of_education,
"gender": gender,
"mailing_address": mailing_address,
"city": city,
"country": country,
"goals": goals,
}

# leave null fields from being stored in the index. Otherwise, they will have
Expand Down Expand Up @@ -112,13 +132,20 @@ class LearnerTests(VerifyCourseIdMixin, LearnerAPITestMixin, TestCaseWithAuthent
@ddt.data(
('ed_xavier', 'Edward Xavier', 'edX/DemoX/Demo_Course', 'honor', ['has_potential'], 'Team edX',
43, 3, 6, 0, 8.4, 2, '2015-04-24', '2015-08-05'),
('ed_xavier', 'Edward Xavier', 'edX/DemoX/Demo_Course', 'honor', ['has_potential'], 'Team edX',
43, 3, 6, 0, 8.4, 2, '2015-04-24', '2015-08-05',
10, 'French', 'Berlin', 1976, 'Bachelors', 'Male', '123 Sesame St', 'Springfield', 'France',
'I\'ve always wanted to play the piano.'),
('ed_xavier', 'Edward Xavier', 'edX/DemoX/Demo_Course', 'verified'),
)
@ddt.unpack
def test_get_user(self, username, name, course_id, enrollment_mode, segments=None, cohort=None,
problems_attempted=None, problems_completed=None, videos_viewed=None,
discussion_contributions=None, problem_attempts_per_completed=None,
attempt_ratio_order=None, enrollment_date=None, last_updated=None):
attempt_ratio_order=None, enrollment_date=None, last_updated=None,
user_id=None, language=None, location=None,
year_of_birth=None, level_of_education=None, gender=None,
mailing_address=None, city=None, country=None, goals=None):

self.create_learners([{
"username": username,
Expand All @@ -134,6 +161,16 @@ def test_get_user(self, username, name, course_id, enrollment_mode, segments=Non
"problem_attempts_per_completed": problem_attempts_per_completed,
"attempt_ratio_order": attempt_ratio_order,
"enrollment_date": enrollment_date,
"user_id": user_id,
"language": language,
"location": location,
"year_of_birth": year_of_birth,
"level_of_education": level_of_education,
"gender": gender,
"mailing_address": mailing_address,
"city": city,
"country": country,
"goals": goals,
}])
self.create_update_index(last_updated)

Expand All @@ -157,6 +194,16 @@ def test_get_user(self, username, name, course_id, enrollment_mode, segments=Non
},
"enrollment_date": enrollment_date,
"last_updated": last_updated,
"user_id": user_id,
"language": language,
"location": location,
"year_of_birth": year_of_birth,
"level_of_education": level_of_education,
"gender": gender,
"mailing_address": mailing_address,
"city": city,
"country": country,
"goals": goals,
}
self.assertDictEqual(expected, response.data)

Expand Down
20 changes: 20 additions & 0 deletions analytics_data_api/v0/views/learners.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,16 @@ class LearnerView(LastUpdateMixin, CourseViewMixin, generics.RetrieveAPIView):
example, "audit" or "verified").
* name: The learner's full name.
* email: The learner's email address.
* user_id: The learner's numeric user ID.
* language: The learner's preferred language.
* location: The learner's reported location.
* year_of_birth: The learner's reported year of birth.
* level_of_education: The learner's reported level of education.
* gender: The learner's reported gender.
* mailing_address: The learner's reported mailing address.
* city: The learner's reported city.
* country: The learner's reported country.
* goals: The learner's reported goals.
* segments: Classification, based on engagement, of this learner's
work in this course (for example, "highly_engaged" or
"struggling").
Expand Down Expand Up @@ -142,6 +152,16 @@ class LearnerListView(LastUpdateMixin, CourseViewMixin, generics.ListAPIView):
example, "audit" or "verified").
* name: The learner's full name.
* email: The learner's email address.
* user_id: The learner's numeric user ID.
* language: The learner's preferred language.
* location: The learner's reported location.
* year_of_birth: The learner's reported year of birth.
* level_of_education: The learner's reported level of education.
* gender: The learner's reported gender.
* mailing_address: The learner's reported mailing address.
* city: The learner's reported city.
* country: The learner's reported country.
* goals: The learner's reported goals.
* segments: Classification, based on engagement, of each learner's
work in this course (for example, "highly_engaged" or
"struggling").
Expand Down

0 comments on commit 07fe6a7

Please sign in to comment.