From 096d2ea2fdb2e00d9a891b42cc63b129f3760492 Mon Sep 17 00:00:00 2001 From: guange <8863824@gmail.com> Date: Fri, 18 Jan 2019 18:51:51 +0800 Subject: [PATCH] . --- chapter2/init.sql | 1 + chapter2/mysite/myapp/static/scripts/trend.js | 1 - chapter2/mysite/myapp/templates/myapp/result.html | 2 +- chapter3/spark.py | 10 ++++++++++ 4 files changed, 12 insertions(+), 2 deletions(-) diff --git a/chapter2/init.sql b/chapter2/init.sql index ee06b37..f9101e7 100644 --- a/chapter2/init.sql +++ b/chapter2/init.sql @@ -87,3 +87,4 @@ create table datas ( ) comment = '通用配置表'; insert into datas (`key`, data) values ('from_type', '{}'); insert into datas (`key`, data) values ('last_month_sell', '{}'); +insert into datas (`key`, data) values ('hour_sell', '{}'); diff --git a/chapter2/mysite/myapp/static/scripts/trend.js b/chapter2/mysite/myapp/static/scripts/trend.js index ae490be..57a47c2 100755 --- a/chapter2/mysite/myapp/static/scripts/trend.js +++ b/chapter2/mysite/myapp/static/scripts/trend.js @@ -82,7 +82,6 @@ $(function(){ - //主要症状 var histogramChart2 = echarts.init(document.getElementById('histogramChart2')); histogramChart2.setOption({ diff --git a/chapter2/mysite/myapp/templates/myapp/result.html b/chapter2/mysite/myapp/templates/myapp/result.html index 3b9384d..b9e3b2d 100644 --- a/chapter2/mysite/myapp/templates/myapp/result.html +++ b/chapter2/mysite/myapp/templates/myapp/result.html @@ -86,7 +86,7 @@
-
时段访问占比
+
时段购买占比

diff --git a/chapter3/spark.py b/chapter3/spark.py index 3b78bcc..6f1bda8 100644 --- a/chapter3/spark.py +++ b/chapter3/spark.py @@ -57,6 +57,15 @@ def collect_last_month_sells(spark): data[month] = jd_comment_count mysql_execute("update datas set data = '{}' where `key` = 'last_month_sell'".format( json.dumps(data,ensure_ascii=False) )) +def collect_hour_sells(spark): + data = {} + for i in range(24): + hour = "%02d" % (i) + df = spark.sql("select count(*) as N from jd_comment where comment_time like '% "+hour+":%'") + jd_comment_count = df.rdd.collect()[0]["N"] + data[hour] = jd_comment_count + + mysql_execute("update datas set data = '{}' where `key` = 'hour_sell'".format( json.dumps(data,ensure_ascii=False) )) def collect_crawl_info(spark): @@ -137,6 +146,7 @@ if __name__ == "__main__": collect_top10_sells(spark) collect_from_type(spark) collect_last_month_sells(spark) + collect_hour_sells(spark) count = 1 time.sleep(10)