This commit is contained in:
guange 2019-01-18 17:28:06 +08:00
parent 69117310d9
commit bf92a7e7e4
4 changed files with 25 additions and 4 deletions

View File

@ -86,3 +86,4 @@ create table datas (
PRIMARY KEY (`id`)
) comment = '通用配置表';
insert into datas (`key`, data) values ('from_type', '{}');
insert into datas (`key`, data) values ('last_month_sell', '{}');

View File

@ -145,7 +145,6 @@ $(function(){
]
})
//传染病发病趋势
if (document.getElementById('lineChart1')) {
var lineChart1 = echarts.init(document.getElementById('lineChart1'));
if(lineChart1){
@ -356,7 +355,7 @@ $(function(){
var lineChart2 = echarts.init(document.getElementById('lineChart2'));
lineChart2.setOption({
title: {
text: '购买趋势',
text: '前5月购买趋势',
textStyle:{
fontSize:16,
color:'#32cd32'
@ -424,7 +423,7 @@ $(function(){
],
series : [
{
name:'购买趋势',
name:'前5月购买趋势',
type:'line',
smooth:true,
itemStyle: {normal: {areaStyle: {type: 'default'}}},

View File

@ -69,7 +69,7 @@
<div class="div_any">
<div class="left div_any01" style="width:100%;">
<div class="div_any_child" style="width:98%;position:relative;height: 420px;">
<div class="div_any_title"><img src="{% static "images/title_17.png" %}">TOP10商品排行</div>
<div class="div_any_title"><img src="{% static "images/title_17.png" %}">商品销售排行</div>
<div id="histogramChart3" style="width: 55%;display: inline-block;height: 400px;margin-top: 15px;"></div>
<div id="lineChart2" style="width: 38%;height: 90%;display: inline-block;"></div>
</div>

View File

@ -38,6 +38,26 @@ def getYesterday(day):
yesterday=today-oneday
return yesterday.strftime('%Y-%m-%d')
def get_last_month(num):
date = datetime.datetime.now()
year = date.year
month = date.month
month = month - num
if month<=0:
month = 12 - (num-1)
year -= 1
return "%d-%d" % (year, month)
def collect_last_month_sells(spark):
data = {}
for i in range(5):
month = get_last_month(i)
df = spark.sql("select count(*) as N from jd_comment where comment_time like '"+month+"%' ")
jd_comment_count = df.rdd.collect()[0]["N"]
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_crawl_info(spark):
df = spark.sql("select count(*) as N from jd_comment")
@ -116,6 +136,7 @@ if __name__ == "__main__":
get_last_day_count(spark)
collect_top10_sells(spark)
collect_from_type(spark)
collect_last_month_sells(spark)
count = 1
time.sleep(10)