Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
X
xblock-activetable
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
xblock-activetable
Commits
a3c5bffd
Commit
a3c5bffd
authored
Oct 21, 2015
by
Sven Marnach
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add grading functionality.
parent
d872ded2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
40 additions
and
17 deletions
+40
-17
activetable/activetable.py
+31
-4
activetable/static/js/src/activetable.js
+9
-13
No files found.
activetable/activetable.py
View file @
a3c5bffd
...
...
@@ -71,15 +71,32 @@ class ActiveTableXBlock(StudioEditableXBlockMixin, XBlock):
scope
=
Scope
.
content
,
default
=
1.0
,
)
max_score
=
Float
(
display_name
=
'Maximum score'
,
help
=
'The number of points students will be awarded when solving all fields correctly. '
'For partially correct attempts, the score will be pro-rated.'
,
scope
=
Scope
.
settings
,
default
=
1.0
,
)
editable_fields
=
[
'table_definition'
,
'help_text'
,
'column_widths'
,
'row_heights'
,
'default_tolerance'
'display_name'
,
'table_definition'
,
'help_text'
,
'column_widths'
,
'row_heights'
,
'default_tolerance'
,
'max_score'
,
]
# Dictionary mapping cell ids to the student answers.
answers
=
Dict
(
scope
=
Scope
.
user_state
)
# Number of correct answers.
num_correct_answers
=
Integer
(
scope
=
Scope
.
user_state
)
# The number of points awarded.
score
=
Float
(
scope
=
Scope
.
user_state
)
has_score
=
True
def
__init__
(
self
,
*
args
,
**
kwargs
):
super
(
ActiveTableXBlock
,
self
)
.
__init__
(
*
args
,
**
kwargs
)
...
...
@@ -152,6 +169,8 @@ class ActiveTableXBlock(StudioEditableXBlockMixin, XBlock):
frag
.
initialize_js
(
'ActiveTableXBlock'
,
dict
(
num_correct_answers
=
self
.
num_correct_answers
,
num_total_answers
=
len
(
self
.
answers
)
if
self
.
answers
is
not
None
else
None
,
score
=
self
.
score
,
max_score
=
self
.
max_score
,
))
return
frag
...
...
@@ -161,15 +180,23 @@ class ActiveTableXBlock(StudioEditableXBlockMixin, XBlock):
This handler is called when the "Check" button is clicked.
"""
correct
_dict
=
{
correct
=
{
cell_id
:
self
.
response_cells
[
cell_id
]
.
check_response
(
value
)
for
cell_id
,
value
in
data
.
iteritems
()
}
# Since the previous statement executed without error, the data is well-formed enough to be
# stored. We now know it's a dictionary and all the keys are valid cell ids.
self
.
answers
=
data
self
.
num_correct_answers
=
sum
(
correct_dict
.
itervalues
())
return
correct_dict
self
.
num_correct_answers
=
sum
(
correct
.
itervalues
())
self
.
score
=
self
.
num_correct_answers
*
self
.
max_score
/
len
(
correct
)
self
.
runtime
.
publish
(
self
,
'grade'
,
dict
(
value
=
self
.
score
,
max_value
=
self
.
max_score
))
return
dict
(
correct
=
correct
,
num_correct_answers
=
self
.
num_correct_answers
,
num_total_answers
=
len
(
correct
),
score
=
self
.
score
,
max_score
=
self
.
max_score
,
)
def
validate_field_data
(
self
,
validation
,
data
):
"""Validate the data entered by the user.
...
...
activetable/static/js/src/activetable.js
View file @
a3c5bffd
...
...
@@ -3,25 +3,25 @@ function ActiveTableXBlock(runtime, element, init_args) {
var
checkHandlerUrl
=
runtime
.
handlerUrl
(
element
,
'check_answers'
);
function
updateStatus
(
num_total
,
num_correct
)
{
function
updateStatus
(
data
)
{
var
$status
=
$
(
'.status'
,
element
);
var
$status_message
=
$
(
'.status-message'
,
element
);
if
(
num_total
==
num_correct
)
{
if
(
data
.
num_total_answers
==
data
.
num_correct_answers
)
{
$status
.
removeClass
(
'incorrect'
).
addClass
(
'correct'
);
$status
.
text
(
'correct'
);
$status_message
.
text
(
'Great job!'
);
$status_message
.
text
(
'Great job!
('
+
data
.
score
+
'/'
+
data
.
max_score
+
' points)
'
);
}
else
{
$status
.
removeClass
(
'correct'
).
addClass
(
'incorrect'
);
$status
.
text
(
'incorrect'
);
$status_message
.
text
(
'You have '
+
num_correct
+
' out of '
+
num_total
+
' cells correct.'
'You have '
+
data
.
num_correct_answers
+
' out of '
+
data
.
num_total_answers
+
' cells correct. ('
+
data
.
score
+
'/'
+
data
.
max_score
+
' points)'
);
}
}
function
markResponseCells
(
correct_dict
)
{
var
num_total
=
0
,
num_correct
=
0
;
$
.
each
(
correct_dict
,
function
(
cell_id
,
correct
)
{
function
markResponseCells
(
data
)
{
$
.
each
(
data
.
correct
,
function
(
cell_id
,
correct
)
{
var
$cell
=
$
(
'#'
+
cell_id
,
element
);
$cell
.
removeClass
(
'right-answer wrong-answer unchecked'
);
if
(
correct
)
{
...
...
@@ -31,10 +31,8 @@ function ActiveTableXBlock(runtime, element, init_args) {
$cell
.
addClass
(
'wrong-answer'
);
$cell
.
prop
(
'title'
,
'incorrect'
);
}
num_total
+=
1
;
num_correct
+=
correct
;
});
updateStatus
(
num_total
,
num_correct
);
updateStatus
(
data
);
}
function
checkAnswers
(
e
)
{
...
...
@@ -58,7 +56,5 @@ function ActiveTableXBlock(runtime, element, init_args) {
$
(
'#activetable-help-button'
,
element
).
click
(
toggleHelp
);
$
(
'.action .check'
,
element
).
click
(
checkAnswers
);
if
(
init_args
.
num_total_answers
)
{
updateStatus
(
init_args
.
num_total_answers
,
init_args
.
num_correct_answers
);
}
if
(
init_args
.
num_total_answers
)
updateStatus
(
init_args
);
}
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