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
d139a10c
Commit
d139a10c
authored
Oct 20, 2015
by
Sven Marnach
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Configure pylint and make it happy.
parent
dbe54692
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
43 additions
and
14 deletions
+43
-14
activetable/__init__.py
+4
-0
activetable/activetable.py
+12
-5
activetable/cells.py
+13
-9
pylintrc
+14
-0
No files found.
activetable/__init__.py
View file @
d139a10c
"""ActiveTable XBlock top-level package.
See activetable.activetable for more information.
"""
from
.activetable
import
ActiveTableXBlock
activetable/activetable.py
View file @
d139a10c
...
...
@@ -14,7 +14,7 @@ from xblockutils.studio_editable import StudioEditableXBlockMixin
from
.cells
import
NumericCell
from
.parsers
import
ParseError
,
parse_table
,
parse_number_list
loader
=
ResourceLoader
(
__name__
)
loader
=
ResourceLoader
(
__name__
)
# pylint: disable=invalid-name
class
ActiveTableXBlock
(
StudioEditableXBlockMixin
,
XBlock
):
...
...
@@ -22,7 +22,7 @@ class ActiveTableXBlock(StudioEditableXBlockMixin, XBlock):
table_definition
=
String
(
display_name
=
'Table definition'
,
help
=
'The definition of the table in Python-like syntax.'
,
# TODO(smarnach): proper help
help
=
'The definition of the table in Python-like syntax.'
,
scope
=
Scope
.
content
,
multiline_editor
=
True
,
resettable_editor
=
False
,
...
...
@@ -82,6 +82,8 @@ class ActiveTableXBlock(StudioEditableXBlockMixin, XBlock):
self
.
_column_widths
=
None
self
.
_row_heights
=
None
self
.
response_cells
=
None
self
.
parse_fields
()
self
.
postprocess_table
()
def
parse_fields
(
self
):
"""Parse the user-provided fields into more processing-friendly structured data."""
...
...
@@ -98,6 +100,12 @@ class ActiveTableXBlock(StudioEditableXBlockMixin, XBlock):
self
.
_row_heights
=
parse_number_list
(
self
.
row_heights
)
else
:
self
.
_row_heights
=
[
36
]
*
(
len
(
self
.
tbody
)
+
1
)
def
postprocess_table
(
self
):
"""Augment the parsed table definition with further information.
The additional information is taken from other content and student state fields.
"""
self
.
response_cells
=
{}
for
row
,
height
in
zip
(
self
.
tbody
,
self
.
_row_heights
[
1
:]):
row
[
'height'
]
=
height
...
...
@@ -122,7 +130,6 @@ class ActiveTableXBlock(StudioEditableXBlockMixin, XBlock):
def
student_view
(
self
,
context
=
None
):
"""Render the table."""
self
.
parse_fields
()
context
=
dict
(
help_text
=
self
.
help_text
,
total_width
=
sum
(
self
.
_column_widths
)
if
self
.
_column_widths
else
None
,
...
...
@@ -143,12 +150,11 @@ class ActiveTableXBlock(StudioEditableXBlockMixin, XBlock):
return
frag
@XBlock.json_handler
def
check_answers
(
self
,
data
,
suffix
=
''
):
def
check_answers
(
self
,
data
,
unused_
suffix
=
''
):
"""Check the answers given by the student.
This handler is called when the "Check" button is clicked.
"""
self
.
parse_fields
()
correct_dict
=
{
cell_id
:
self
.
response_cells
[
cell_id
]
.
check_response
(
value
)
for
cell_id
,
value
in
data
.
iteritems
()
...
...
@@ -166,6 +172,7 @@ class ActiveTableXBlock(StudioEditableXBlockMixin, XBlock):
properties of this XBlock.
"""
def
add_error
(
msg
):
"""Add a validation error."""
validation
.
add
(
ValidationMessage
(
ValidationMessage
.
ERROR
,
msg
))
try
:
parse_table
(
data
.
table_definition
)
...
...
activetable/cells.py
View file @
d139a10c
...
...
@@ -7,6 +7,8 @@ classes themselves.
"""
from
__future__
import
absolute_import
,
division
,
unicode_literals
import
decimal
class
StaticCell
(
object
):
"""A static cell with a fixed value in the table body."""
...
...
@@ -23,32 +25,34 @@ class NumericCell(object):
is_static
=
False
placeholder
=
'numeric response'
def
__init__
(
self
,
answer
,
tolerance
=
None
,
min_significant_digits
=
None
,
max_significant_digits
=
None
):
def
__init__
(
self
,
answer
,
tolerance
=
None
,
min_significant_digits
=
None
,
max_significant_digits
=
None
):
"""Set the correct answer and the allowed relative tolerance in percent."""
self
.
answer
=
answer
self
.
abs_tolerance
=
None
self
.
set_tolerance
(
tolerance
)
self
.
min_significant_digits
=
min_significant_digits
self
.
max_significant_digits
=
max_significant_digits
def
set_tolerance
(
self
,
tolerance
):
if
tolerance
is
None
:
self
.
abs_tolerance
=
None
else
:
"""Set the tolerance to the specified value, if it is not None."""
if
tolerance
is
not
None
:
self
.
abs_tolerance
=
abs
(
self
.
answer
)
*
tolerance
/
100.0
def
check_response
(
self
,
student_response
):
"""Return a Boolean value indicating whether the student response is correct."""
try
:
r
=
float
(
student_response
)
value
=
float
(
student_response
)
except
ValueError
:
return
False
if
self
.
min_significant_digits
or
self
.
max_significant_digits
:
d
=
len
(
decimal
.
Decimal
(
student_response
)
.
as_tuple
()
.
digits
)
if
self
.
min_significant_digits
and
d
<
self
.
min_significant_digits
:
d
igits
=
len
(
decimal
.
Decimal
(
student_response
)
.
as_tuple
()
.
digits
)
# pylint: disable=no-member
if
self
.
min_significant_digits
and
d
igits
<
self
.
min_significant_digits
:
return
False
if
self
.
max_significant_digits
and
d
>
self
.
max_significant_digits
:
if
self
.
max_significant_digits
and
d
igits
>
self
.
max_significant_digits
:
return
False
return
abs
(
r
-
self
.
answer
)
<=
self
.
abs_tolerance
return
abs
(
value
-
self
.
answer
)
<=
self
.
abs_tolerance
class
StringCell
(
object
):
...
...
pylintrc
0 → 100644
View file @
d139a10c
[REPORTS]
reports=no
[FORMAT]
max-line-length=100
[MESSAGES CONTROL]
disable=
I,
too-few-public-methods,
too-many-ancestors
[VARIABLES]
dummy-variables-rgx=_$|dummy|unused
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