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
5e6f3601
Commit
5e6f3601
authored
Apr 30, 2013
by
Vasyl Nakvasiuk
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Word Cloud: docstrings + pep8
parent
af8b9eca
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
54 additions
and
21 deletions
+54
-21
common/lib/xmodule/xmodule/word_cloud_module.py
+54
-21
No files found.
common/lib/xmodule/xmodule/word_cloud_module.py
View file @
5e6f3601
...
...
@@ -9,7 +9,6 @@ If student have answered - words he entered and cloud.
import
json
import
logging
from
lxml
import
etree
from
pkg_resources
import
resource_string
from
xmodule.raw_module
import
RawDescriptor
from
xmodule.x_module
import
XModule
...
...
@@ -25,24 +24,51 @@ def pretty_bool(value):
class
WordCloudDescriptorFields
(
object
):
# Name of poll to use in links to this poll
display_name
=
String
(
help
=
"Display name for this module"
,
scope
=
Scope
.
settings
)
num_inputs
=
Integer
(
help
=
"Number of inputs"
,
scope
=
Scope
.
settings
,
default
=
5
)
num_top_words
=
Integer
(
help
=
"Number of max words, which will be displayed."
,
scope
=
Scope
.
settings
,
default
=
250
)
display_student_percents
=
Boolean
(
help
=
"Dispaly usage percents for each word."
,
scope
=
Scope
.
settings
,
default
=
True
)
"""Word Cloud fields from xml for descriptor."""
display_name
=
String
(
help
=
"Display name for this module"
,
scope
=
Scope
.
settings
)
num_inputs
=
Integer
(
help
=
"Number of inputs."
,
scope
=
Scope
.
settings
,
default
=
5
)
num_top_words
=
Integer
(
help
=
"Number of max words, which will be displayed."
,
scope
=
Scope
.
settings
,
default
=
250
)
display_student_percents
=
Boolean
(
help
=
"Dispaly usage percents for each word."
,
scope
=
Scope
.
settings
,
default
=
True
)
class
WordCloudFields
(
object
):
submitted
=
Boolean
(
help
=
"Whether this student has posted words to the cloud"
,
scope
=
Scope
.
user_state
,
default
=
False
)
student_words
=
List
(
help
=
"Student answer"
,
scope
=
Scope
.
user_state
,
default
=
[])
all_words
=
Object
(
help
=
"All possible words from other students"
,
scope
=
Scope
.
content
)
top_words
=
Object
(
help
=
"Top N words for word cloud"
,
scope
=
Scope
.
content
)
submitted
=
Boolean
(
help
=
"Whether this student has posted words to the cloud."
,
scope
=
Scope
.
user_state
,
default
=
False
)
student_words
=
List
(
help
=
"Student answer."
,
scope
=
Scope
.
user_state
,
default
=
[]
)
all_words
=
Object
(
help
=
"All possible words from other students."
,
scope
=
Scope
.
content
)
top_words
=
Object
(
help
=
"Top N words for word cloud."
,
scope
=
Scope
.
content
)
class
WordCloudModule
(
WordCloudFields
,
WordCloudDescriptorFields
,
XModule
):
"""WordCloud
M
odule"""
"""WordCloud
Xm
odule"""
js
=
{
'coffee'
:
[
resource_string
(
__name__
,
'js/src/javascript_loader.coffee'
)],
'js'
:
[
resource_string
(
__name__
,
'js/src/word_cloud/logme.js'
),
...
...
@@ -61,7 +87,9 @@ class WordCloudModule(WordCloudFields, WordCloudDescriptorFields, XModule):
return
json
.
dumps
({
'status'
:
'success'
,
'submitted'
:
True
,
'display_student_percents'
:
pretty_bool
(
self
.
display_student_percents
),
'display_student_percents'
:
pretty_bool
(
self
.
display_student_percents
),
'student_words'
:
{
word
:
self
.
all_words
[
word
]
for
word
in
self
.
student_words
},
...
...
@@ -86,14 +114,19 @@ class WordCloudModule(WordCloudFields, WordCloudDescriptorFields, XModule):
"""Convert words dictionary for client API."""
list_to_return
=
[]
percents
=
0
current_num_top_words
=
len
(
top_words
)
for
num
,
word_tuple
in
enumerate
(
top_words
.
iteritems
()):
if
num
==
current_num_top_words
-
1
:
if
num
==
len
(
top_words
)
-
1
:
percent
=
100
-
percents
else
:
percent
=
round
(
100.0
*
word_tuple
[
1
]
/
total_count
)
percents
+=
percent
list_to_return
.
append
({
'text'
:
word_tuple
[
0
],
'size'
:
word_tuple
[
1
],
'percent'
:
percent
})
list_to_return
.
append
(
{
'text'
:
word_tuple
[
0
],
'size'
:
word_tuple
[
1
],
'percent'
:
percent
}
)
return
list_to_return
def
top_dict
(
self
,
dict_obj
,
amount
):
...
...
@@ -160,20 +193,20 @@ class WordCloudModule(WordCloudFields, WordCloudDescriptorFields, XModule):
})
def
get_html
(
self
):
"""
Renders parameters to template
."""
params
=
{
"""
Template rendering
."""
context
=
{
'element_id'
:
self
.
location
.
html_id
(),
'element_class'
:
self
.
location
.
category
,
'ajax_url'
:
self
.
system
.
ajax_url
,
'num_inputs'
:
int
(
self
.
num_inputs
),
'submitted'
:
self
.
submitted
}
self
.
content
=
self
.
system
.
render_template
(
'word_cloud.html'
,
params
)
self
.
content
=
self
.
system
.
render_template
(
'word_cloud.html'
,
context
)
return
self
.
content
class
WordCloudDescriptor
(
WordCloudDescriptorFields
,
RawDescriptor
):
"""Descriptor for WordCloud Xmodule."""
module_class
=
WordCloudModule
template_dir_name
=
'word_cloud'
stores_state
=
True
...
...
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