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
e147b58b
Commit
e147b58b
authored
Jan 17, 2017
by
Tyler Hallada
Committed by
GitHub
Jan 17, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #154 from edx/thallada/fake-data-no-videos-option
Add --no-videos option to generate_fake_course_data command
parents
e6235e51
bbb67343
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
40 additions
and
10 deletions
+40
-10
Makefile
+1
-1
analytics_data_api/management/commands/generate_fake_course_data.py
+24
-9
analyticsdataserver/clients.py
+5
-0
analyticsdataserver/tests.py
+10
-0
No files found.
Makefile
View file @
e147b58b
...
...
@@ -70,4 +70,4 @@ demo: clean requirements loaddata
travis
:
clean test.requirements migrate
python manage.py set_api_key edx edx
python manage.py loaddata problem_response_answer_distribution
--database
=
analytics
python manage.py generate_fake_course_data
--num-weeks
=
1
python manage.py generate_fake_course_data
--num-weeks
=
1
--no-videos
analytics_data_api/management/commands/generate_fake_course_data.py
View file @
e147b58b
...
...
@@ -58,6 +58,13 @@ class Command(BaseCommand):
default
=
'ed_xavier'
,
help
=
'Username for which to generate fake data'
,
)
parser
.
add_argument
(
'--no-videos'
,
action
=
'store_false'
,
dest
=
'videos'
,
default
=
True
,
help
=
'Disables pulling video ids from the LMS server to generate fake video data and instead uses fake ids.'
)
def
generate_daily_data
(
self
,
course_id
,
start_date
,
end_date
):
# Use the preset ratios below to generate data in the specified demographics
...
...
@@ -308,18 +315,26 @@ class Command(BaseCommand):
logger
.
info
(
"Done!"
)
def
fake_video_ids_fallback
(
self
):
return
[
{
'video_id'
:
'0fac49ba'
,
'video_module_id'
:
'i4x-edX-DemoX-video-5c90cffecd9b48b188cbfea176bf7fe9'
}
]
def
handle
(
self
,
*
args
,
**
options
):
course_id
=
options
[
'course_id'
]
username
=
options
[
'username'
]
video
_ids
=
self
.
fetch_videos_from_course_blocks
(
course_id
)
if
not
video_id
s
:
logger
.
warning
(
"Falling back to fake video id due to Course Blocks API failure..."
)
video_ids
=
[
{
'video_id'
:
'0fac49ba'
,
'video_module_id'
:
'i4x-edX-DemoX-video-5c90cffecd9b48b188cbfea176bf7fe9'
}
]
video
s
=
options
[
'videos'
]
if
video
s
:
video_ids
=
self
.
fetch_videos_from_course_blocks
(
course_id
)
if
not
video_ids
:
logger
.
warning
(
"Falling back to fake video id due to Course Blocks API failure..."
)
video_ids
=
self
.
fake_video_ids_fallback
()
else
:
logger
.
info
(
"Option to generate videos with ids pulled from the LMS is disabled, using fake video ids..."
)
video_ids
=
self
.
fake_video_ids_fallback
()
start_date
=
timezone
.
now
()
-
datetime
.
timedelta
(
weeks
=
10
)
num_weeks
=
options
[
'num_weeks'
]
...
...
analyticsdataserver/clients.py
View file @
e147b58b
import
logging
from
requests.exceptions
import
RequestException
from
edx_rest_api_client.client
import
EdxRestApiClient
from
edx_rest_api_client.exceptions
import
HttpClientError
from
opaque_keys.edx.keys
import
UsageKey
...
...
@@ -40,6 +42,9 @@ class CourseBlocksApiClient(EdxRestApiClient):
else
:
logger
.
warning
(
"Course Blocks API failed to return video ids (
%
s)."
,
e
.
response
.
status_code
)
return
None
except
RequestException
as
e
:
logger
.
warning
(
"Course Blocks API request failed. Is the LMS running?: "
+
str
(
e
))
return
None
# Setup a terrible hack to silence mysterious flood of ImportErrors from stevedore inside edx-opaque-keys.
# (The UsageKey utility still works despite the import errors, so I think the errors are not important).
...
...
analyticsdataserver/tests.py
View file @
e147b58b
...
...
@@ -11,6 +11,7 @@ from django.db.utils import ConnectionHandler, DatabaseError
from
django.test
import
TestCase
from
django.test.utils
import
override_settings
from
rest_framework.authtoken.models
import
Token
from
requests.exceptions
import
ConnectionError
from
analytics_data_api.v0.models
import
CourseEnrollmentDaily
,
CourseEnrollmentByBirthYear
from
analyticsdataserver.clients
import
CourseBlocksApiClient
...
...
@@ -177,6 +178,15 @@ class ClientTests(TestCase):
self
.
assertEqual
(
videos
,
None
)
@responses.activate
@mock.patch
(
'analyticsdataserver.clients.logger'
)
def
test_all_videos_connection_error
(
self
,
logger
):
exception
=
ConnectionError
(
'LMS is dead'
)
responses
.
add
(
responses
.
GET
,
'http://example.com/blocks/'
,
body
=
exception
)
videos
=
self
.
client
.
all_videos
(
'course_id'
)
logger
.
warning
.
assert_called_with
(
'Course Blocks API request failed. Is the LMS running?: '
+
str
(
exception
))
self
.
assertEqual
(
videos
,
None
)
@responses.activate
def
test_all_videos_pass_through_bad_id
(
self
):
responses
.
add
(
responses
.
GET
,
'http://example.com/blocks/'
,
body
=
json
.
dumps
({
'blocks'
:
{
'block-v1:edX+DemoX+Demo_Course+type@video+block@5c90cffecd9b48b188cbfea176bf7fe9'
:
{
...
...
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