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
0e46ca30
Commit
0e46ca30
authored
Jan 15, 2016
by
Daniel Friedman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add commands for creating/deleting es indices
parent
b857f029
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
124 additions
and
74 deletions
+124
-74
analytics_data_api/management/commands/create_elasticsearch_learners_indices.py
+96
-0
analytics_data_api/management/commands/delete_elasticsearch_learners_indices.py
+14
-0
analytics_data_api/management/utils.py
+11
-0
analytics_data_api/v0/tests/views/test_learners.py
+3
-74
No files found.
analytics_data_api/management/commands/create_elasticsearch_learners_indices.py
0 → 100644
View file @
0e46ca30
from
elasticsearch
import
Elasticsearch
from
django.conf
import
settings
from
django.core.management.base
import
BaseCommand
,
CommandError
from
analytics_data_api.management.utils
import
elasticsearch_settings_defined
class
Command
(
BaseCommand
):
help
=
'Creates Elasticsearch indices used by the Analytics Data API.'
def
handle
(
self
,
*
args
,
**
options
):
if
not
elasticsearch_settings_defined
():
raise
CommandError
(
'You must define settings.ELASTICSEARCH_LEARNERS_HOST, '
'settings.ELASTICSEARCH_LEARNERS_INDEX, and settings.ELASTICSEARCH_LEARNERS_UPDATE_INDEX'
)
es
=
Elasticsearch
([
settings
.
ELASTICSEARCH_LEARNERS_HOST
])
if
es
.
indices
.
exists
(
settings
.
ELASTICSEARCH_LEARNERS_INDEX
):
self
.
stderr
.
write
(
'"{}" index already exists.'
.
format
(
settings
.
ELASTICSEARCH_LEARNERS_INDEX
))
else
:
es
.
indices
.
create
(
index
=
settings
.
ELASTICSEARCH_LEARNERS_INDEX
,
body
=
{
'mappings'
:
{
'roster_entry'
:
{
'properties'
:
{
'name'
:
{
'type'
:
'string'
},
'username'
:
{
'type'
:
'string'
,
'index'
:
'not_analyzed'
},
'email'
:
{
'type'
:
'string'
,
'index'
:
'not_analyzed'
,
'doc_values'
:
True
},
'course_id'
:
{
'type'
:
'string'
,
'index'
:
'not_analyzed'
},
'enrollment_mode'
:
{
'type'
:
'string'
,
'index'
:
'not_analyzed'
,
'doc_values'
:
True
},
'segments'
:
{
'type'
:
'string'
},
'cohort'
:
{
'type'
:
'string'
,
'index'
:
'not_analyzed'
,
'doc_values'
:
True
},
'discussion_contributions'
:
{
'type'
:
'integer'
,
'doc_values'
:
True
},
'problems_attempted'
:
{
'type'
:
'integer'
,
'doc_values'
:
True
},
'problems_completed'
:
{
'type'
:
'integer'
,
'doc_values'
:
True
},
'problem_attempts_per_completed'
:
{
'type'
:
'float'
,
'doc_values'
:
True
},
'attempt_ratio_order'
:
{
'type'
:
'integer'
,
'doc_values'
:
True
},
'videos_viewed'
:
{
'type'
:
'integer'
,
'doc_values'
:
True
},
'enrollment_date'
:
{
'type'
:
'date'
,
'doc_values'
:
True
},
}
}
}
}
)
if
es
.
indices
.
exists
(
settings
.
ELASTICSEARCH_LEARNERS_UPDATE_INDEX
):
self
.
stderr
.
write
(
'"{}" index already exists.'
.
format
(
settings
.
ELASTICSEARCH_LEARNERS_UPDATE_INDEX
))
else
:
es
.
indices
.
create
(
index
=
settings
.
ELASTICSEARCH_LEARNERS_UPDATE_INDEX
,
body
=
{
'mappings'
:
{
'marker'
:
{
'properties'
:
{
'date'
:
{
'type'
:
'date'
,
'doc_values'
:
True
},
'target_index'
:
{
'type'
:
'string'
},
}
}
}
}
)
analytics_data_api/management/commands/delete_elasticsearch_learners_indices.py
0 → 100644
View file @
0e46ca30
from
elasticsearch
import
Elasticsearch
from
django.conf
import
settings
from
django.core.management.base
import
BaseCommand
class
Command
(
BaseCommand
):
help
=
'Removes Elasticsearch indices used by the Analytics Data API'
def
handle
(
self
,
*
args
,
**
options
):
es
=
Elasticsearch
([
settings
.
ELASTICSEARCH_LEARNERS_HOST
])
for
index
in
[
settings
.
ELASTICSEARCH_LEARNERS_INDEX
,
settings
.
ELASTICSEARCH_LEARNERS_UPDATE_INDEX
]:
if
es
.
indices
.
exists
(
settings
.
ELASTICSEARCH_LEARNERS_UPDATE_INDEX
):
es
.
indices
.
delete
(
index
=
index
)
analytics_data_api/management/utils.py
0 → 100644
View file @
0e46ca30
from
django.conf
import
settings
def
elasticsearch_settings_defined
():
return
all
(
setting
is
not
None
for
setting
in
(
settings
.
ELASTICSEARCH_LEARNERS_HOST
,
settings
.
ELASTICSEARCH_LEARNERS_INDEX
,
settings
.
ELASTICSEARCH_LEARNERS_UPDATE_INDEX
)
)
analytics_data_api/v0/tests/views/test_learners.py
View file @
0e46ca30
...
...
@@ -12,6 +12,7 @@ import pytz
from
rest_framework
import
status
from
django.conf
import
settings
from
django.core
import
management
from
analyticsdataserver.tests
import
TestCaseWithAuthentication
from
analytics_data_api.constants
import
engagement_entity_types
,
engagement_events
...
...
@@ -25,80 +26,8 @@ class LearnerAPITestMixin(object):
"""Creates the index and defines a mapping."""
super
(
LearnerAPITestMixin
,
self
)
.
setUp
()
self
.
_es
=
Elasticsearch
([
settings
.
ELASTICSEARCH_LEARNERS_HOST
])
for
index
in
[
settings
.
ELASTICSEARCH_LEARNERS_INDEX
,
settings
.
ELASTICSEARCH_LEARNERS_UPDATE_INDEX
]:
# ensure the test index is deleted
def
delete_index
(
to_delete
):
if
self
.
_es
.
indices
.
exists
(
index
=
to_delete
):
self
.
_es
.
indices
.
delete
(
index
=
to_delete
)
self
.
addCleanup
(
delete_index
,
index
)
self
.
_es
.
indices
.
create
(
index
=
index
)
self
.
_es
.
indices
.
put_mapping
(
index
=
settings
.
ELASTICSEARCH_LEARNERS_INDEX
,
doc_type
=
'roster_entry'
,
body
=
{
'properties'
:
{
'name'
:
{
'type'
:
'string'
},
'username'
:
{
'type'
:
'string'
,
'index'
:
'not_analyzed'
},
'email'
:
{
'type'
:
'string'
,
'index'
:
'not_analyzed'
,
'doc_values'
:
True
},
'course_id'
:
{
'type'
:
'string'
,
'index'
:
'not_analyzed'
},
'enrollment_mode'
:
{
'type'
:
'string'
,
'index'
:
'not_analyzed'
,
'doc_values'
:
True
},
'segments'
:
{
'type'
:
'string'
},
'cohort'
:
{
'type'
:
'string'
,
'index'
:
'not_analyzed'
,
'doc_values'
:
True
},
'discussion_contributions'
:
{
'type'
:
'integer'
,
'doc_values'
:
True
},
'problems_attempted'
:
{
'type'
:
'integer'
,
'doc_values'
:
True
},
'problems_completed'
:
{
'type'
:
'integer'
,
'doc_values'
:
True
},
'problem_attempts_per_completed'
:
{
'type'
:
'float'
,
'doc_values'
:
True
},
'attempt_ratio_order'
:
{
'type'
:
'integer'
,
'doc_values'
:
True
},
'videos_viewed'
:
{
'type'
:
'integer'
,
'doc_values'
:
True
},
'enrollment_date'
:
{
'type'
:
'date'
,
'doc_values'
:
True
},
}
}
)
self
.
_es
.
indices
.
put_mapping
(
index
=
settings
.
ELASTICSEARCH_LEARNERS_UPDATE_INDEX
,
doc_type
=
'marker'
,
body
=
{
'properties'
:
{
'date'
:
{
'type'
:
'date'
,
'doc_values'
:
True
},
'target_index'
:
{
'type'
:
'string'
},
}
}
)
management
.
call_command
(
'create_elasticsearch_learners_indices'
)
self
.
addCleanup
(
lambda
:
management
.
call_command
(
'delete_elasticsearch_learners_indices'
))
def
_create_learner
(
self
,
...
...
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