From 22ede2c39420529dc2873411fd7983b239b0a178 Mon Sep 17 00:00:00 2001 From: guange <8863824@gmail.com> Date: Fri, 18 Jan 2019 14:03:00 +0800 Subject: [PATCH] . --- chapter2/mysite/myapp/static/scripts/index.js | 70 +++---------------- .../mysite/myapp/templates/myapp/crawl.html | 3 + chapter2/mysite/myapp/views.py | 13 +++- chapter3/spark.py | 4 ++ 4 files changed, 28 insertions(+), 62 deletions(-) diff --git a/chapter2/mysite/myapp/static/scripts/index.js b/chapter2/mysite/myapp/static/scripts/index.js index 522a704..5466f92 100755 --- a/chapter2/mysite/myapp/static/scripts/index.js +++ b/chapter2/mysite/myapp/static/scripts/index.js @@ -65,7 +65,7 @@ function init(){ var lineChart = echarts.init(document.getElementById('lineChart')); lineChart.setOption({ - color:["#87cefa","#ff7f50","#32cd32","#da70d6",], + color:["#ff7f50","#32cd32","#da70d6","#87cefa",], legend: { y : '260', x : 'center', @@ -73,7 +73,7 @@ function init(){ color : '#ffffff', }, - data : ['厦门第一医院','厦门中山医院','厦门中医院','厦门第五医院',], + data : ['评论量'], }, calculable : false, tooltip : { @@ -109,7 +109,7 @@ function init(){ xAxis: [ { type: 'category', - data : ['8:00','10:00','12:00','14:00','16:00','18:00','20:00','22:00'], + data : ['四天前','三天前','二天前','昨天','今天'], axisLine:{ lineStyle:{ color: '#034c6a' @@ -142,7 +142,7 @@ function init(){ }, series : [ { - name:'厦门第一医院', + name:'评论量', type:'line', smooth:true, itemStyle: { @@ -152,47 +152,9 @@ function init(){ } } }, - data:[15, 0, 20, 45, 22.1, 25, 70, 55, 76] + data: last_day_comment }, - { - name:'厦门中山医院', - type:'line', - smooth:true, - itemStyle: { - normal: { - lineStyle: { - shadowColor : 'rgba(0,0,0,0.4)' - } - } - }, - data:[25, 10, 30, 55, 32.1, 35, 80, 65, 76] - }, - { - name:'厦门中医院', - type:'line', - smooth:true, - itemStyle: { - normal: { - lineStyle: { - shadowColor : 'rgba(0,0,0,0.4)' - } - } - }, - data:[35, 20, 40, 65, 42.1, 45, 90, 75, 96] - }, - { - name:'厦门第五医院', - type:'line', - smooth:true, - itemStyle: { - normal: { - lineStyle: { - shadowColor : 'rgba(0,0,0,0.4)' - } - } - }, - data:[45, 30, 50, 75, 52.1, 55, 100, 85, 106] - } + ] }); @@ -304,7 +266,7 @@ function init(){ color : '#ffffff', }, - data : ['手机','笔记本',], + data : ['评论'], }, calculable : false, tooltip : { @@ -373,7 +335,7 @@ function init(){ }, series : [ { - name:'手机', + name:'评论', type:'line', smooth:true, itemStyle: { @@ -383,22 +345,10 @@ function init(){ } } }, - data:[15, 0, 20, 45, 22.1,] - }, - { - name:'笔记本', - type:'line', - smooth:true, - itemStyle: { - normal: { - lineStyle: { - shadowColor : 'rgba(0,0,0,0.4)' - } - } - }, - data:[25, 10, 30, 55, 32.1, ] + data: last_day_product }, + ] }); diff --git a/chapter2/mysite/myapp/templates/myapp/crawl.html b/chapter2/mysite/myapp/templates/myapp/crawl.html index 0f7b60e..f487c0a 100644 --- a/chapter2/mysite/myapp/templates/myapp/crawl.html +++ b/chapter2/mysite/myapp/templates/myapp/crawl.html @@ -9,6 +9,9 @@ diff --git a/chapter2/mysite/myapp/views.py b/chapter2/mysite/myapp/views.py index eec3022..e0fb74c 100644 --- a/chapter2/mysite/myapp/views.py +++ b/chapter2/mysite/myapp/views.py @@ -13,10 +13,19 @@ def crawl(request): crawl_info = CrawlInfos.objects.order_by('-id').first() platform_info = get_platform_info() news = News.objects.order_by('-id').all()[0:20] - last_day_counts = LastDayCounts.objects.all() + last_day_counts = LastDayCounts.objects.order_by("last_day").all() + + last_day_product = [] + last_day_comment = [] + for last_day in last_day_counts: + last_day_product.append(last_day.product_c) + last_day_comment.append(last_day.comment_c) + return render(request, 'myapp/crawl.html', {"crawl_info": crawl_info, "platform_info":json.dumps(platform_info), - "news": news}) + "news": news, + "last_day_product":json.dumps(last_day_product), + "last_day_comment": json.dumps(last_day_comment)}) def result(request): return render(request, 'myapp/result.html') \ No newline at end of file diff --git a/chapter3/spark.py b/chapter3/spark.py index 2969268..d7e763d 100644 --- a/chapter3/spark.py +++ b/chapter3/spark.py @@ -73,6 +73,8 @@ def get_last_day_count(spark): df = spark.sql("select count(*) as N from jd_comment where created_at like '"+getYesterday(i+1)+"%'") jd_comment_last_count = df.rdd.collect()[0]["N"] + mysql_execute("update last_day_counts set product_c = {}, comment_c = {} where last_day = {}".format( + jd_last_count, jd_comment_last_count, i+1)) if __name__ == "__main__": @@ -91,6 +93,8 @@ if __name__ == "__main__": collect_crawl_info(spark) collect_news(spark) + get_last_day_count(spark) + time.sleep(10) spark.stop() \ No newline at end of file