diff --git a/utils/cipingTotal.py b/utils/cipingTotal.py index 9e5e975..54931c3 100644 --- a/utils/cipingTotal.py +++ b/utils/cipingTotal.py @@ -23,9 +23,10 @@ def main(): # 格式整理 list_count = sorted(word_count.items(),key=lambda x:x[1],reverse=True) - + # list_count = [[key, str(value)] for key, value in list_count] + # return list_count for i in range(100): print(list_count[i],file=result) if __name__ == '__main__': - main() \ No newline at end of file + print(main()) \ No newline at end of file diff --git a/utils/getPublicData.py b/utils/getPublicData.py index 829978b..f24ca25 100644 --- a/utils/getPublicData.py +++ b/utils/getPublicData.py @@ -92,4 +92,6 @@ def getAllHotWords(): def getAllTopics(): data =[] - return data \ No newline at end of file + return data +if __name__ == '__main__': + print(getAllHotWords()) \ No newline at end of file diff --git a/utils/yuqingpredict.py b/utils/yuqingpredict.py index e78dd1e..f9feaab 100644 --- a/utils/yuqingpredict.py +++ b/utils/yuqingpredict.py @@ -44,15 +44,22 @@ def mergeTopics(article_topics, comment_topics):# 合并话题 merged_dict[topic['name']] += topic['value'] else: merged_dict[topic['name']] = topic['value'] - merged_list = [{'name': key, 'value': value} for key, value in merged_dict.items()] + merged_dict = sorted(merged_dict.items(), key=lambda item: item[1], reverse=True) + merged_list = [[key, str(value)] for key, value in merged_dict] return merged_list -def getTopicData(): - # 读取合并文件 merge.csv # 取前十个话题 - top_10_topics = pd.read_csv('./merged_topics.csv').head(10) - # 获取话题名称和对应的值 - X = top_10_topics['name'].tolist() - Y = top_10_topics['value'].tolist() - return X, Y +def getAllTopicData(): + # 读取合并文件 merge.csv + # data = [] + # df = pd.read_csv('./merged_topics.csv',encoding='utf8') + # for i in df.values: + # try: + # data.append([ + # re.search('[\u4e00-\u9fa5]+',str(i)).group(), + # re.search('\d+',str(i)).group() + # ]) + # except: + # continue + return mergeTopics(getTopicByArticle(), getTopicByComments()) def getTopicCreatedAtandpredictData(topic):# 统计特定话题的评论在每个日期的数量,并返回日期和对应的评论数量 createdAt = {} @@ -71,9 +78,9 @@ def getTopicCreatedAtandpredictData(topic):# 统计特定话题的评论在每 createdAt = {k: createdAt[k] for k in sorted(createdAt, key=lambda date: datetime.datetime.strptime(date, "%Y-%m-%d"))} createdAt.update(predict_future_values(createdAt)) sorted_data = {k: createdAt[k] for k in sorted(createdAt, key=lambda date: datetime.datetime.strptime(date, "%Y-%m-%d"))} - result_list = [0] * (len(sorted_data) - 5) + [1] * 5 - return topic,sorted_data,result_list - # return topic,list(createdAt.keys()),list(createdAt.values()),result_list + # result_list = [0] * (len(sorted_data) - 5) + [1] * 5 + print(list(createdAt.keys()),list(createdAt.values())) + return list(createdAt.keys()),list(createdAt.values()) def writeTopicsToCSV(topics, file_name): # 检查文件是否存在,如果存在则附加写入,否则新建一个 @@ -91,6 +98,7 @@ def writeTopicsToCSV(topics, file_name): writer.writerow(topic) if __name__ == '__main__': # 将话题数据写入 CSV 文件 - # merged_topics = mergeTopics(getTopicByArticle(), getTopicByComments()) + # print(mergeTopics(getTopicByArticle(), getTopicByComments())) # writeTopicsToCSV(merged_topics, 'merged_topics.csv') - print(getTopicCreatedAtandpredictData("生活")) + print(getAllTopicData()) + diff --git a/views/page/page.py b/views/page/page.py index c3d684c..260534f 100644 --- a/views/page/page.py +++ b/views/page/page.py @@ -6,6 +6,8 @@ from utils.getTableData import * from utils.getPublicData import getAllHotWords, getAllTopics from utils.getEchartsData import * from utils.getTopicPageData import * +from utils.yuqingpredict import * +from utils.getPublicData import getAllHotWords pb = Blueprint('page', __name__, @@ -38,6 +40,7 @@ def home(): def hotWord(): username = session.get('username') hotWordList = getAllHotWords() + print(hotWordList) defaultHotWord = hotWordList[0][0] if request.args.get('hotWord'): defaultHotWord = request.args.get('hotWord') @@ -51,7 +54,6 @@ def hotWord(): sentences = '正面' elif value < 0.5: sentences = '负面' - comments = getCommentFilterData(defaultHotWord) return render_template('hotWord.html', username=username, @@ -161,6 +163,34 @@ def yuqingChar(): x1Data=x1Data, y1Data=y1Data) +@pb.route('/yuqingpredict') +def yuqingpredict(): + username = session.get('username') + TopicList = getAllTopicData() + defaultTopic = TopicList[0][0] + if request.args.get('Topic'): + defaultTopic = request.args.get('Topic') + TopicLen = getTopicLen(defaultTopic) + X, Y = getTopicCreatedAtandpredictData(defaultTopic) + sentences = '' + value = SnowNLP(defaultTopic).sentiments + if value == 0.5: + sentences = '中性' + elif value > 0.5: + sentences = '正面' + elif value < 0.5: + sentences = '负面' + comments = getCommentFilterDataTopic(defaultTopic) + return render_template('yuqingpredict.html', + username=username, + hotWordList=TopicList, + defaultHotWord=defaultTopic, + hotWordLen=TopicLen, + sentences=sentences, + xData=X, + yData=Y, + comments=comments) + @pb.route('/articleCloud') def articleCloud(): diff --git a/views/page/templates/articleChar.html b/views/page/templates/articleChar.html index 06d251c..bbc0243 100644 --- a/views/page/templates/articleChar.html +++ b/views/page/templates/articleChar.html @@ -42,7 +42,7 @@
+<div class="form-group">
+ <label>Small</label>
+ <select class="form-control form-control-sm mb-3">
+ <option selected="">Open this select menu</option>
+ <option value="1">One</option>
+ <option value="2">Two</option>
+ <option value="3">Three</option>
+ </select>
+</div>
+<div class="form-group">
+ <label>Default</label>
+ <select class="form-control mb-3">
+ <option selected="">Open this select menu</option>
+ <option value="1">One</option>
+ <option value="2">Two</option>
+ <option value="3">Three</option>
+ </select>
+</div>
+<div class="form-group">
+ <label>Large</label>
+ <select class="form-control form-control-lg">
+ <option selected="">Open this select menu</option>
+ <option value="1">One</option>
+ <option value="2">Two</option>
+ <option value="3">Three</option>
+ </select>
+</div>
+
+<table id="datatable" class="table data-table table-striped table-bordered" >
+ <thead>
+ <tr>
+ <th>Name</th>
+ <th>Position</th>
+ <th>Office</th>
+ <th>Age</th>
+ <th>Start date</th>
+ <th>Salary</th>
+ </tr>
+ </thead>
+ <tbody>
+ <tr>
+ <td>Tiger Nixon</td>
+ <td>System Architect</td>
+ <td>Edinburgh</td>
+ <td>61</td>
+ <td>2011/04/25</td>
+ <td>$320,800</td>
+ </tr>
+ <tr>
+ <td>Garrett Winters</td>
+ <td>Accountant</td>
+ <td>Tokyo</td>
+ <td>63</td>
+ <td>2011/07/25</td>
+ <td>$170,750</td>
+ </tr>
+ <tr>
+ <td>Ashton Cox</td>
+ <td>Junior Technical Author</td>
+ <td>San Francisco</td>
+ <td>66</td>
+ <td>2009/01/12</td>
+ <td>$86,000</td>
+ </tr>
+ <tr>
+ <td>Cedric Kelly</td>
+ <td>Senior Javascript Developer</td>
+ <td>Edinburgh</td>
+ <td>22</td>
+ <td>2012/03/29</td>
+ <td>$433,060</td>
+ </tr>
+ <tr>
+ <td>Airi Satou</td>
+ <td>Accountant</td>
+ <td>Tokyo</td>
+ <td>33</td>
+ <td>2008/11/28</td>
+ <td>$162,700</td>
+ </tr>
+ <tr>
+ <td>Brielle Williamson</td>
+ <td>Integration Specialist</td>
+ <td>New York</td>
+ <td>61</td>
+ <td>2012/12/02</td>
+ <td>$372,000</td>
+ </tr>
+ <tr>
+ <td>Herrod Chandler</td>
+ <td>Sales Assistant</td>
+ <td>San Francisco</td>
+ <td>59</td>
+ <td>2012/08/06</td>
+ <td>$137,500</td>
+ </tr>
+ <tr>
+ <td>Rhona Davidson</td>
+ <td>Integration Specialist</td>
+ <td>Tokyo</td>
+ <td>55</td>
+ <td>2010/10/14</td>
+ <td>$327,900</td>
+ </tr>
+ <tr>
+ <td>Colleen Hurst</td>
+ <td>Javascript Developer</td>
+ <td>San Francisco</td>
+ <td>39</td>
+ <td>2009/09/15</td>
+ <td>$205,500</td>
+ </tr>
+ <tr>
+ <td>Sonya Frost</td>
+ <td>Software Engineer</td>
+ <td>Edinburgh</td>
+ <td>23</td>
+ <td>2008/12/13</td>
+ <td>$103,600</td>
+ </tr>
+ <tr>
+ <td>Jena Gaines</td>
+ <td>Office Manager</td>
+ <td>London</td>
+ <td>30</td>
+ <td>2008/12/19</td>
+ <td>$90,560</td>
+ </tr>
+ <tr>
+ <td>Quinn Flynn</td>
+ <td>Support Lead</td>
+ <td>Edinburgh</td>
+ <td>22</td>
+ <td>2013/03/03</td>
+ <td>$342,000</td>
+ </tr>
+ <tr>
+ <td>Charde Marshall</td>
+ <td>Regional Director</td>
+ <td>San Francisco</td>
+ <td>36</td>
+ <td>2008/10/16</td>
+ <td>$470,600</td>
+ </tr>
+ <tr>
+ <td>Haley Kennedy</td>
+ <td>Senior Marketing Designer</td>
+ <td>London</td>
+ <td>43</td>
+ <td>2012/12/18</td>
+ <td>$313,500</td>
+ </tr>
+ <tr>
+ <td>Tatyana Fitzpatrick</td>
+ <td>Regional Director</td>
+ <td>London</td>
+ <td>19</td>
+ <td>2010/03/17</td>
+ <td>$385,750</td>
+ </tr>
+ <tr>
+ <td>Michael Silva</td>
+ <td>Marketing Designer</td>
+ <td>London</td>
+ <td>66</td>
+ <td>2012/11/27</td>
+ <td>$198,500</td>
+ </tr>
+ <tr>
+ <td>Paul Byrd</td>
+ <td>Chief Financial Officer (CFO)</td>
+ <td>New York</td>
+ <td>64</td>
+ <td>2010/06/09</td>
+ <td>$725,000</td>
+ </tr>
+ <tr>
+ <td>Gloria Little</td>
+ <td>Systems Administrator</td>
+ <td>New York</td>
+ <td>59</td>
+ <td>2009/04/10</td>
+ <td>$237,500</td>
+ </tr>
+ <tr>
+ <td>Bradley Greer</td>
+ <td>Software Engineer</td>
+ <td>London</td>
+ <td>41</td>
+ <td>2012/10/13</td>
+ <td>$132,000</td>
+ </tr>
+ <tr>
+ <td>Dai Rios</td>
+ <td>Personnel Lead</td>
+ <td>Edinburgh</td>
+ <td>35</td>
+ <td>2012/09/26</td>
+ <td>$217,500</td>
+ </tr>
+</table>
+根据选择的话题从而查询出评论数据
+| 文章ID | +评论用户 | +评论性别 | +评论话题 | +评论内容 | +点赞量 |
|---|---|---|---|---|---|
| {{ i[0] }} | +{{ i[5] }} | ++ {% if i[6] =='f' %} + 女生 + {% else %} + 男生 + {% endif %} + | +{{ i[9] }} | +{{ i[4] }} | +👍{{ i[2] }} | +