Skip to content
This repository was archived by the owner on May 1, 2024. It is now read-only.

Commit 8cb6a33

Browse files
authored
Merge pull request #129 from open-craft/jill/learner-api-add-fields
Added 10 new userprofile fields to RosterEntry
2 parents 7373406 + 4abcb74 commit 8cb6a33

5 files changed

Lines changed: 118 additions & 1 deletion

File tree

analytics_data_api/management/commands/create_elasticsearch_learners_indices.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ def handle(self, *args, **options):
2929
'name': {
3030
'type': 'string'
3131
},
32+
'user_id': {
33+
'type': 'integer', 'index': 'not_analyzed'
34+
},
3235
'username': {
3336
'type': 'string', 'index': 'not_analyzed'
3437
},
@@ -41,6 +44,33 @@ def handle(self, *args, **options):
4144
'enrollment_mode': {
4245
'type': 'string', 'index': 'not_analyzed', 'doc_values': True
4346
},
47+
'language': {
48+
'type': 'string', 'index': 'not_analyzed'
49+
},
50+
'location': {
51+
'type': 'string', 'index': 'not_analyzed'
52+
},
53+
'year_of_birth': {
54+
'type': 'integer', 'index': 'not_analyzed'
55+
},
56+
'level_of_education': {
57+
'type': 'string', 'index': 'not_analyzed'
58+
},
59+
'gender': {
60+
'type': 'string', 'index': 'not_analyzed'
61+
},
62+
'mailing_address': {
63+
'type': 'string', 'index': 'not_analyzed'
64+
},
65+
'city': {
66+
'type': 'string', 'index': 'not_analyzed'
67+
},
68+
'country': {
69+
'type': 'string', 'index': 'not_analyzed'
70+
},
71+
'goals': {
72+
'type': 'string', 'index': 'not_analyzed'
73+
},
4474
'segments': {
4575
'type': 'string'
4676
},

analytics_data_api/v0/models.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,9 +249,19 @@ def get_last_updated(cls):
249249
class RosterEntry(DocType):
250250

251251
course_id = String()
252+
user_id = Integer()
252253
username = String()
253254
name = String()
254255
email = String()
256+
language = String()
257+
location = String()
258+
year_of_birth = Integer()
259+
level_of_education = String()
260+
gender = String()
261+
mailing_address = String()
262+
city = String()
263+
country = String()
264+
goals = String()
255265
enrollment_mode = String()
256266
cohort = String()
257267
segments = String() # segments is an array/list of strings

analytics_data_api/v0/serializers.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,11 +342,21 @@ class LastUpdatedSerializer(serializers.Serializer):
342342

343343
# pylint: disable=abstract-method
344344
class LearnerSerializer(serializers.Serializer):
345+
user_id = serializers.IntegerField()
345346
username = serializers.CharField()
346347
enrollment_mode = serializers.CharField()
347348
name = serializers.CharField()
348349
account_url = serializers.SerializerMethodField()
349350
email = serializers.CharField()
351+
language = serializers.CharField()
352+
location = serializers.CharField()
353+
year_of_birth = serializers.IntegerField()
354+
level_of_education = serializers.CharField()
355+
gender = serializers.CharField()
356+
mailing_address = serializers.CharField()
357+
city = serializers.CharField()
358+
country = serializers.CharField()
359+
goals = serializers.CharField()
350360
segments = serializers.SerializerMethodField()
351361
engagements = serializers.SerializerMethodField()
352362
enrollment_date = serializers.DateTimeField(format=settings.DATE_FORMAT)

analytics_data_api/v0/tests/views/test_learners.py

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,16 @@ def _create_learner(
4747
attempt_ratio_order=0,
4848
videos_viewed=0,
4949
enrollment_date='2015-01-28',
50+
user_id=None,
51+
language=None,
52+
location=None,
53+
year_of_birth=None,
54+
level_of_education=None,
55+
gender=None,
56+
mailing_address=None,
57+
city=None,
58+
country=None,
59+
goals=None,
5060
):
5161
"""Create a single learner roster entry in the elasticsearch index."""
5262
body = {
@@ -61,6 +71,16 @@ def _create_learner(
6171
'attempt_ratio_order': attempt_ratio_order,
6272
'videos_viewed': videos_viewed,
6373
'enrollment_date': enrollment_date,
74+
"user_id": user_id,
75+
"language": language,
76+
"location": location,
77+
"year_of_birth": year_of_birth,
78+
"level_of_education": level_of_education,
79+
"gender": gender,
80+
"mailing_address": mailing_address,
81+
"city": city,
82+
"country": country,
83+
"goals": goals,
6484
}
6585

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

123150
self.create_learners([{
124151
"username": username,
@@ -134,6 +161,16 @@ def test_get_user(self, username, name, course_id, enrollment_mode, segments=Non
134161
"problem_attempts_per_completed": problem_attempts_per_completed,
135162
"attempt_ratio_order": attempt_ratio_order,
136163
"enrollment_date": enrollment_date,
164+
"user_id": user_id,
165+
"language": language,
166+
"location": location,
167+
"year_of_birth": year_of_birth,
168+
"level_of_education": level_of_education,
169+
"gender": gender,
170+
"mailing_address": mailing_address,
171+
"city": city,
172+
"country": country,
173+
"goals": goals,
137174
}])
138175
self.create_update_index(last_updated)
139176

@@ -157,6 +194,16 @@ def test_get_user(self, username, name, course_id, enrollment_mode, segments=Non
157194
},
158195
"enrollment_date": enrollment_date,
159196
"last_updated": last_updated,
197+
"user_id": user_id,
198+
"language": language,
199+
"location": location,
200+
"year_of_birth": year_of_birth,
201+
"level_of_education": level_of_education,
202+
"gender": gender,
203+
"mailing_address": mailing_address,
204+
"city": city,
205+
"country": country,
206+
"goals": goals,
160207
}
161208
self.assertDictEqual(expected, response.data)
162209

analytics_data_api/v0/views/learners.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,16 @@ class LearnerView(LastUpdateMixin, CourseViewMixin, generics.RetrieveAPIView):
6262
example, "audit" or "verified").
6363
* name: The learner's full name.
6464
* email: The learner's email address.
65+
* user_id: The learner's numeric user ID.
66+
* language: The learner's preferred language.
67+
* location: The learner's reported location.
68+
* year_of_birth: The learner's reported year of birth.
69+
* level_of_education: The learner's reported level of education.
70+
* gender: The learner's reported gender.
71+
* mailing_address: The learner's reported mailing address.
72+
* city: The learner's reported city.
73+
* country: The learner's reported country.
74+
* goals: The learner's reported goals.
6575
* segments: Classification, based on engagement, of this learner's
6676
work in this course (for example, "highly_engaged" or
6777
"struggling").
@@ -139,6 +149,16 @@ class LearnerListView(LastUpdateMixin, CourseViewMixin, generics.ListAPIView):
139149
example, "audit" or "verified").
140150
* name: The learner's full name.
141151
* email: The learner's email address.
152+
* user_id: The learner's numeric user ID.
153+
* language: The learner's preferred language.
154+
* location: The learner's reported location.
155+
* year_of_birth: The learner's reported year of birth.
156+
* level_of_education: The learner's reported level of education.
157+
* gender: The learner's reported gender.
158+
* mailing_address: The learner's reported mailing address.
159+
* city: The learner's reported city.
160+
* country: The learner's reported country.
161+
* goals: The learner's reported goals.
142162
* segments: Classification, based on engagement, of each learner's
143163
work in this course (for example, "highly_engaged" or
144164
"struggling").

0 commit comments

Comments
 (0)