def find_favourite_word(self, wordcloud=True): statements = self.statement_set.filter(procedural=False) if self.current_member: # For current members, we limit to the last two years for better # comparison, and require at least 2,500 total words. statements = statements.filter(time__gte=datetime.datetime.now() - datetime.timedelta(weeks=100)) min_words = 2500 else: # For ex-members, we use everything they said min_words = 5000 total_words = sum((s.wordcount for s in statements)) if total_words < min_words: self.del_info('favourite_word') self.del_info('wordcloud') return self.set_info('favourite_word', text_utils.most_frequent_word(statements)) if wordcloud: image = text_utils.statements_to_cloud(statements) path = os.path.join(self.WORDCLOUD_PATH, "%s.png" % (self.slug if self.slug else self.id)) fullpath = os.path.join(settings.MEDIA_ROOT, path) with open(fullpath, 'wb') as f: f.write(image) self.set_info('wordcloud', path)
def get_wordoftheday(self): if not self.most_frequent_word: self.most_frequent_word = text_utils.most_frequent_word(self.statement_set.filter(procedural=False)) if self.most_frequent_word: self.save() return self.most_frequent_word
def find_favourite_word(self): self.set_info('favourite_word', text_utils.most_frequent_word(self.statement_set.all()))
def get_wordoftheday(self): if not self.wordoftheday: self.wordoftheday = text_utils.most_frequent_word(self.statement_set.all()) if self.wordoftheday: self.save() return self.wordoftheday
def get_wordoftheday(self): if not self.wordoftheday: self.wordoftheday = text_utils.most_frequent_word(self.statement_set.filter(speaker=False)) if self.wordoftheday: self.save() return self.wordoftheday