def get_comment_date_count(): for comment in Comment.select(): year_month = str(comment.create_time)[0:7] try: cdc = CommentDateCount.get_by_id(year_month) cdc.total += 1 cdc.save() except CommentDateCount.DoesNotExist: CommentDateCount.create(year_month=year_month, total=1) comments_total = Comment.select().count() for cdc in CommentDateCount.select(): cdc.percentage = calculate_percentage(comments_total, cdc.total) cdc.save()
def get_order_days_count(): for comment in Comment.select().where(Comment.order_days.is_null(False)): order_days = comment.order_days try: odc = OrderDaysCount.get_by_id(order_days) odc.total += 1 odc.save() except OrderDaysCount.DoesNotExist: OrderDaysCount.create(order_days=order_days, total=1) order_total = Comment.select().where( Comment.order_days.is_null(False)).count() for odc in OrderDaysCount.select(): odc.percentage = calculate_percentage(order_total, odc.total) odc.save()
def get_order_date_count(): for comment in Comment.select().where(Comment.order_time.is_null(False)): year_month = str(comment.order_time)[0:7] try: odc = OrderDateCount.get_by_id(year_month) odc.total += 1 odc.save() except OrderDateCount.DoesNotExist: OrderDateCount.create(year_month=year_month, total=1) order_total = Comment.select().where( Comment.order_time.is_null(False)).count() for odc in OrderDateCount.select(): odc.percentage = calculate_percentage(order_total, odc.total) odc.save()
def get_after_days_count(): for comment in Comment.select().where(Comment.after_days.is_null(False)): after_days = comment.after_days try: adc = AfterDaysCount.get_by_id(after_days) adc.total += 1 adc.save() except AfterDaysCount.DoesNotExist: AfterDaysCount.create(after_days=after_days, total=1) after_total = Comment.select().where( Comment.after_days.is_null(False)).count() for adc in AfterDaysCount.select(): adc.percentage = calculate_percentage(after_total, adc.total) adc.save()
def get_user_device_count(): total = Comment.select().where(Comment.user_device.is_null(False)).count() android = Comment.select().where(Comment.user_device == 'Android').count() ios = Comment.select().where(Comment.user_device == 'iOS').count() other = Comment.select().where(Comment.user_device == 'other').count() android_percentage = calculate_percentage(total, android) ios_percentage = calculate_percentage(total, ios) other_percentage = calculate_percentage(total, other) UserDeviceCount.create(total=total, android=android, ios=ios, other=other, android_percentage=android_percentage, ios_percentage=ios_percentage, other_percentage=other_percentage)
def get_all_comments_words(): content = '' for comment in Comment.select(): content += comment.content + '\n' # 基于TF-IDF算法的关键词抽取 jieba.analyse.set_stop_words(DATA_ANALYZE_DIR + '/custom_cn_stopwords.txt') tags = jieba.analyse.extract_tags(content, topK=200) for tag in tags: AllCommentsWords.create(word=tag)
def get_non_five_star_comments_words(): content = '' for comment in Comment.select().where((Comment.star.in_([1, 2, 3, 4]))): content += comment.content + '\n' if comment.after_content is not None: content += comment.after_content + '\n' # 基于TF-IDF算法的关键词抽取 jieba.analyse.set_stop_words(DATA_ANALYZE_DIR + '/custom_cn_stopwords.txt') tags = jieba.analyse.extract_tags(content, topK=200) for tag in tags: NonFiveStarCommentsWords.create(word=tag)
def get_ios_comments_words(): content = '' for comment in Comment.select().where(Comment.user_device == 'iOS'): content += comment.content + '\n' if comment.after_content is not None: content += comment.after_content + '\n' # 基于TF-IDF算法的关键词抽取 jieba.analyse.set_stop_words(DATA_ANALYZE_DIR + '/custom_cn_stopwords.txt') tags = jieba.analyse.extract_tags(content, topK=200) for tag in tags: IosCommentsWords.create(word=tag)
def get_all_comments_wordcloud(): content = '' for comment in Comment.select(): content += comment.content + '\n' wordcloud = WordCloud(font_path=FONT_DIR + '/NotoSansCJKsc-Regular.otf', width=7200, height=2400, stopwords=get_stopwords_set(), background_color='white', collocations=False) # 使用jieba分词的默认精确模式 wordcloud.generate(' '.join(jieba.lcut(content))) wordcloud.to_file(IMAGE_DIR + '/iPhone11_all_comments_wordcloud.png')
def get_non_five_star_comments_wordcloud(): content = '' for comment in Comment.select().where((Comment.star.in_([1, 2, 3, 4]))): content += comment.content + '\n' if comment.after_content is not None: content += comment.after_content + '\n' wordcloud = WordCloud(font_path=FONT_DIR + '/NotoSansCJKsc-Regular.otf', width=4000, height=2400, stopwords=get_stopwords_set(), background_color='white', collocations=False) # 使用jieba分词的默认精确模式 wordcloud.generate(' '.join(jieba.lcut(content))) wordcloud.to_file(IMAGE_DIR + '/iPhone11_non_five_star_comments_wordcloud.png')