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
ed23aef6
Commit
ed23aef6
authored
Apr 10, 2013
by
Vasyl Nakvasiuk
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
use post.getlist word wordcloud param
parent
328b5b3d
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
26 deletions
+15
-26
common/lib/xmodule/xmodule/word_cloud_module.py
+15
-26
No files found.
common/lib/xmodule/xmodule/word_cloud_module.py
View file @
ed23aef6
...
@@ -27,7 +27,7 @@ class WordCloudFields(object):
...
@@ -27,7 +27,7 @@ class WordCloudFields(object):
# Name of poll to use in links to this poll
# Name of poll to use in links to this poll
display_name
=
String
(
help
=
"Display name for this module"
,
scope
=
Scope
.
settings
)
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_inputs
=
Integer
(
help
=
"Number of inputs"
,
scope
=
Scope
.
settings
,
default
=
5
)
num_top_words
=
Integer
(
help
=
"
Number of inputs
"
,
scope
=
Scope
.
settings
,
default
=
250
)
num_top_words
=
Integer
(
help
=
"
TODO
"
,
scope
=
Scope
.
settings
,
default
=
250
)
submitted
=
Boolean
(
help
=
"Whether this student has posted words to the cloud"
,
scope
=
Scope
.
user_state
,
default
=
False
)
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
=
[])
student_words
=
List
(
help
=
"Student answer"
,
scope
=
Scope
.
user_state
,
default
=
[])
...
@@ -48,7 +48,7 @@ class WordCloudModule(WordCloudFields, XModule):
...
@@ -48,7 +48,7 @@ class WordCloudModule(WordCloudFields, XModule):
css
=
{
'scss'
:
[
resource_string
(
__name__
,
'css/word_cloud/display.scss'
)]}
css
=
{
'scss'
:
[
resource_string
(
__name__
,
'css/word_cloud/display.scss'
)]}
js_module_name
=
"WordCloud"
js_module_name
=
"WordCloud"
def
get_state
_json
(
self
):
def
get_state
(
self
):
"""Return success json answer for client."""
"""Return success json answer for client."""
if
self
.
submitted
:
if
self
.
submitted
:
return
json
.
dumps
({
return
json
.
dumps
({
...
@@ -57,7 +57,7 @@ class WordCloudModule(WordCloudFields, XModule):
...
@@ -57,7 +57,7 @@ class WordCloudModule(WordCloudFields, XModule):
word
:
self
.
all_words
[
word
]
for
word
:
self
.
all_words
[
word
]
for
word
in
self
.
student_words
word
in
self
.
student_words
},
},
'total_count'
:
sum
(
self
.
all_words
.
values
()),
'total_count'
:
sum
(
self
.
all_words
.
iter
values
()),
'top_words'
:
self
.
prepare_words
(
self
.
top_words
)
'top_words'
:
self
.
prepare_words
(
self
.
top_words
)
})
})
else
:
else
:
...
@@ -67,52 +67,44 @@ class WordCloudModule(WordCloudFields, XModule):
...
@@ -67,52 +67,44 @@ class WordCloudModule(WordCloudFields, XModule):
"""Convert raw word to suitable word."""
"""Convert raw word to suitable word."""
return
word
.
strip
()
.
lower
()
return
word
.
strip
()
.
lower
()
# TODO: use or remove
# real_words = re.findall('\w+', word)
# if real_words:
# return real_words[0].lower()
def
prepare_words
(
self
,
words
):
def
prepare_words
(
self
,
words
):
"""Convert words dictionary
more handy for client
."""
"""Convert words dictionary
for client API
."""
return
[{
'text'
:
word
,
'size'
:
count
}
for
return
[{
'text'
:
word
,
'size'
:
count
}
for
word
,
count
in
words
.
iteritems
()]
word
,
count
in
words
.
iteritems
()]
def
top_dict
(
self
,
dict_obj
,
amount
):
def
top_dict
(
self
,
dict_obj
,
amount
):
"""Return new dict: top of dict using dict value."""
"""Return new dict: top of dict using dict value."""
# TODO: optimize this - don't use sorting.
return
dict
(
return
dict
(
sorted
(
sorted
(
dict_obj
.
ite
rite
ms
(),
dict_obj
.
items
(),
key
=
lambda
x
:
x
[
1
],
key
=
lambda
x
:
x
[
1
],
reverse
=
True
reverse
=
True
)[:
amount
]
)[:
amount
]
)
)
def
handle_ajax
(
self
,
dispatch
,
ge
t
):
def
handle_ajax
(
self
,
dispatch
,
pos
t
):
"""Ajax handler.
"""Ajax handler.
Args:
Args:
dispatch: string request slug
dispatch: string request slug
ge
t: dict request get parameters
pos
t: dict request get parameters
Returns:
Returns:
json string
json string
"""
"""
if
dispatch
==
'submit'
:
if
dispatch
==
'submit'
:
if
self
.
submitted
:
if
self
.
submitted
:
# TODO: error standart.
return
json
.
dumps
({
return
json
.
dumps
({
'status'
:
'fail'
,
'status'
:
'fail'
,
'error'
:
'You have already post your data.'
'error'
:
'You have already post
ed
your data.'
})
})
# Student words from client.
# Student words from client.
raw_student_words
=
json
.
loads
(
get
.
lists
()[
0
][
0
])[
'data'
]
student_words
=
filter
(
None
,
map
(
self
.
good_word
,
raw_student_words
))
if
not
student_words
:
raw_student_words
=
post
.
getlist
(
'student_words[]'
)
return
json
.
dumps
({
student_words
=
filter
(
None
,
map
(
self
.
good_word
,
raw_student_words
))
'status'
:
'fail'
,
'error'
:
'Empty students words.'
})
self
.
student_words
=
student_words
self
.
student_words
=
student_words
...
@@ -125,10 +117,7 @@ class WordCloudModule(WordCloudFields, XModule):
...
@@ -125,10 +117,7 @@ class WordCloudModule(WordCloudFields, XModule):
# Save in all_words.
# Save in all_words.
for
word
in
self
.
student_words
:
for
word
in
self
.
student_words
:
if
word
in
temp_all_words
:
temp_all_words
[
word
]
=
temp_all_words
.
get
(
word
,
0
)
+
1
temp_all_words
[
word
]
+=
1
else
:
temp_all_words
[
word
]
=
1
# Update top_words.
# Update top_words.
self
.
top_words
=
self
.
top_dict
(
temp_all_words
,
self
.
top_words
=
self
.
top_dict
(
temp_all_words
,
...
@@ -137,7 +126,7 @@ class WordCloudModule(WordCloudFields, XModule):
...
@@ -137,7 +126,7 @@ class WordCloudModule(WordCloudFields, XModule):
# Save all_words in database.
# Save all_words in database.
self
.
all_words
=
temp_all_words
self
.
all_words
=
temp_all_words
return
self
.
get_state
_json
()
return
self
.
get_state
()
else
:
else
:
return
json
.
dumps
({
return
json
.
dumps
({
'status'
:
'fail'
,
'status'
:
'fail'
,
...
@@ -150,7 +139,7 @@ class WordCloudModule(WordCloudFields, XModule):
...
@@ -150,7 +139,7 @@ class WordCloudModule(WordCloudFields, XModule):
'element_id'
:
self
.
location
.
html_id
(),
'element_id'
:
self
.
location
.
html_id
(),
'element_class'
:
self
.
location
.
category
,
'element_class'
:
self
.
location
.
category
,
'ajax_url'
:
self
.
system
.
ajax_url
,
'ajax_url'
:
self
.
system
.
ajax_url
,
'configuration_json'
:
self
.
get_state
_json
(),
'configuration_json'
:
self
.
get_state
(),
'num_inputs'
:
int
(
self
.
num_inputs
),
'num_inputs'
:
int
(
self
.
num_inputs
),
}
}
self
.
content
=
self
.
system
.
render_template
(
'word_cloud.html'
,
params
)
self
.
content
=
self
.
system
.
render_template
(
'word_cloud.html'
,
params
)
...
...
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