Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
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-platform
Commits
480a7b4e
Commit
480a7b4e
authored
Oct 11, 2012
by
David Ormsbee
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #861 from MITx/feature/ichuang/dump_grades
add django management command for dumping grades to CSV file
parents
941311f0
fdfe574c
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
79 additions
and
0 deletions
+79
-0
lms/djangoapps/instructor/management/__init__.py
+0
-0
lms/djangoapps/instructor/management/commands/__init__.py
+0
-0
lms/djangoapps/instructor/management/commands/dump_grades.py
+79
-0
No files found.
lms/djangoapps/instructor/management/__init__.py
0 → 100644
View file @
480a7b4e
lms/djangoapps/instructor/management/commands/__init__.py
0 → 100644
View file @
480a7b4e
lms/djangoapps/instructor/management/commands/dump_grades.py
0 → 100644
View file @
480a7b4e
#!/usr/bin/python
#
# django management command: dump grades to csv files
# for use by batch processes
import
os
,
sys
,
string
import
datetime
import
json
from
instructor.views
import
*
from
courseware.courses
import
get_course_by_id
from
xmodule.modulestore.django
import
modulestore
from
django.conf
import
settings
from
django.core.management.base
import
BaseCommand
class
Command
(
BaseCommand
):
help
=
"dump grades to CSV file. Usage: dump_grades course_id_or_dir filename dump_type
\n
"
help
+=
" course_id_or_dir: either course_id or course_dir
\n
"
help
+=
" filename: where the output CSV is to be stored
\n
"
# help += " start_date: end date as M/D/Y H:M (defaults to end of available data)"
help
+=
" dump_type: 'all' or 'raw' (see instructor dashboard)"
def
handle
(
self
,
*
args
,
**
options
):
# current grading logic and data schema doesn't handle dates
# datetime.strptime("21/11/06 16:30", "%m/%d/%y %H:%M")
print
"args = "
,
args
course_id
=
'MITx/8.01rq_MW/Classical_Mechanics_Reading_Questions_Fall_2012_MW_Section'
fn
=
"grades.csv"
get_raw_scores
=
False
if
len
(
args
)
>
0
:
course_id
=
args
[
0
]
if
len
(
args
)
>
1
:
fn
=
args
[
1
]
if
len
(
args
)
>
2
:
get_raw_scores
=
args
[
2
]
.
lower
()
==
'raw'
request
=
self
.
DummyRequest
()
try
:
course
=
get_course_by_id
(
course_id
)
except
Exception
as
err
:
if
course_id
in
modulestore
()
.
courses
:
course
=
modulestore
()
.
courses
[
course_id
]
else
:
print
"-----------------------------------------------------------------------------"
print
"Sorry, cannot find course
%
s"
%
course_id
print
"Please provide a course ID or course data directory name, eg content-mit-801rq"
return
print
"-----------------------------------------------------------------------------"
print
"Dumping grades from
%
s to file
%
s (get_raw_scores=
%
s)"
%
(
course
.
id
,
fn
,
get_raw_scores
)
datatable
=
get_student_grade_summary_data
(
request
,
course
,
course
.
id
,
get_raw_scores
=
get_raw_scores
)
fp
=
open
(
fn
,
'w'
)
writer
=
csv
.
writer
(
fp
,
dialect
=
'excel'
,
quotechar
=
'"'
,
quoting
=
csv
.
QUOTE_ALL
)
writer
.
writerow
(
datatable
[
'header'
])
for
datarow
in
datatable
[
'data'
]:
encoded_row
=
[
unicode
(
s
)
.
encode
(
'utf-8'
)
for
s
in
datarow
]
writer
.
writerow
(
encoded_row
)
fp
.
close
()
print
"Done:
%
d records dumped"
%
len
(
datatable
[
'data'
])
class
DummyRequest
(
object
):
META
=
{}
def
__init__
(
self
):
return
def
get_host
(
self
):
return
'edx.mit.edu'
def
is_secure
(
self
):
return
False
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