Commit 9b974916 by Vasyl Nakvasiuk

add more docstrings

parent b2730117
...@@ -11,13 +11,11 @@ Stunent can change his answer. ...@@ -11,13 +11,11 @@ Stunent can change his answer.
import json import json
import logging import logging
import re import re
from collections import OrderedDict
from lxml import etree from lxml import etree
from pkg_resources import resource_string from pkg_resources import resource_string
from xmodule.x_module import XModule from xmodule.x_module import XModule
from xmodule.stringify import stringify_children
from xmodule.mako_module import MakoModuleDescriptor from xmodule.mako_module import MakoModuleDescriptor
from xmodule.xml_module import XmlDescriptor from xmodule.xml_module import XmlDescriptor
from xblock.core import Scope, String, Object, Boolean, List, Integer from xblock.core import Scope, String, Object, Boolean, List, Integer
...@@ -51,6 +49,7 @@ class WordCloudModule(WordCloudFields, XModule): ...@@ -51,6 +49,7 @@ class WordCloudModule(WordCloudFields, XModule):
js_module_name = "WordCloud" js_module_name = "WordCloud"
def get_state_json(self): def get_state_json(self):
"""Return success json answer for client."""
if self.submitted: if self.submitted:
return json.dumps({ return json.dumps({
'status': 'success', 'status': 'success',
...@@ -65,6 +64,7 @@ class WordCloudModule(WordCloudFields, XModule): ...@@ -65,6 +64,7 @@ class WordCloudModule(WordCloudFields, XModule):
return json.dumps({}) return json.dumps({})
def good_word(self, word): def good_word(self, word):
"""Convert raw word to suitable word."""
return word.strip().lower() return word.strip().lower()
# TODO: use or remove # TODO: use or remove
...@@ -78,6 +78,7 @@ class WordCloudModule(WordCloudFields, XModule): ...@@ -78,6 +78,7 @@ class WordCloudModule(WordCloudFields, XModule):
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 dict( return dict(
sorted( sorted(
dict_obj.iteritems(), dict_obj.iteritems(),
...@@ -129,10 +130,11 @@ class WordCloudModule(WordCloudFields, XModule): ...@@ -129,10 +130,11 @@ class WordCloudModule(WordCloudFields, XModule):
else: else:
temp_all_words[word] = 1 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,
int(self.num_top_words)) int(self.num_top_words))
# 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_json()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment