lujian
parent
3489845ae8
commit
cd49025acb
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,20 +0,0 @@
|
||||
from flask import Flask, render_template
|
||||
from mydb import MyDB
|
||||
from flask import jsonify
|
||||
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
@app.route('/')
|
||||
def hello():
|
||||
return render_template('province_top.html')
|
||||
|
||||
|
||||
@app.route('/province_topn_curconfirm')
|
||||
def get_province_curconfirm_topn():
|
||||
mydb = MyDB('localhost', 'root', 'lujian123', 'covid19_datas_guangxi')
|
||||
results = mydb.get_province_curconfirm_top5() # results : []
|
||||
return jsonify(pub_date=results[0][2], privinces=[x[0] for x in results], curConfirms=[x[1] for x in results])
|
||||
|
||||
|
||||
app.run()
|
@ -1,61 +0,0 @@
|
||||
import pymysql
|
||||
from datetime import datetime, timedelta
|
||||
import time
|
||||
|
||||
|
||||
class MyDB:
|
||||
def __init__(self, host, user, passwd, db):
|
||||
self.conn = pymysql.connect(host, user, passwd, db)
|
||||
self.cursor = self.conn.cursor()
|
||||
|
||||
def __del__(self):
|
||||
self.conn.close()
|
||||
|
||||
# 获取当然日期
|
||||
def get_cur_date(self):
|
||||
date = datetime.today()
|
||||
curdate = date.strftime('%Y.%m.%d')
|
||||
return curdate
|
||||
|
||||
# 获取前N天的日期
|
||||
def get_pren_date(self, n=1):
|
||||
predate = datetime.today() + timedelta(-n)
|
||||
predate = predate.strftime('%Y.%m.%d')
|
||||
return predate
|
||||
|
||||
# 获取现有确诊人数最多的5个省份
|
||||
def get_province_curconfirm_top5(self):
|
||||
curdate = self.get_cur_date() # 获取当天的日期
|
||||
sql = "select area,curConfirm,pub_date from province_daily_datas where pub_date like '%s' order by curConfirm desc limit 5" % (curdate + '%')
|
||||
print('+++ sql: %s' % sql)
|
||||
|
||||
results = []
|
||||
try:
|
||||
self.cursor.execute(sql)
|
||||
results = self.cursor.fetchall()
|
||||
|
||||
n = 1
|
||||
|
||||
while len(results) <= 0:
|
||||
predate = self.get_pren_date(n)
|
||||
sql = "select area,curConfirm,pub_date from province_daily_datas where pub_date like '%s' order by curConfirm desc limit 5" % (predate + '%')
|
||||
print('+++ presql: %s' % sql)
|
||||
|
||||
self.cursor.execute(sql)
|
||||
results = self.cursor.fetchall()
|
||||
n += 1
|
||||
|
||||
if n >= 30:
|
||||
break
|
||||
else:
|
||||
time.sleep(1)
|
||||
|
||||
except Exception as e:
|
||||
print(e)
|
||||
|
||||
return results
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
mydb = MyDB('127.0.0.1', 'root', 'lujian123', 'covid19_datas_guangxi')
|
||||
results = mydb.get_province_curconfirm_top5() # results : []
|
File diff suppressed because it is too large
Load Diff
@ -1,65 +0,0 @@
|
||||
var myCharts1 = echarts.init(document.getElementById("main1"));
|
||||
|
||||
var option1 = {
|
||||
title: {
|
||||
text: '现有确诊人数Top5的省份',
|
||||
subtext: '',
|
||||
left: 'center',
|
||||
textStyle:{
|
||||
color:'#FF0000',
|
||||
fontFamily:'微软雅黑'
|
||||
}
|
||||
},
|
||||
tooltip: {
|
||||
trigger: 'item',
|
||||
formatter: '{a} <br/>{b} : {c} ({d}%)'
|
||||
},
|
||||
legend: {
|
||||
type: 'scroll',
|
||||
orient: 'vertical',
|
||||
right: 10,
|
||||
top: 20,
|
||||
bottom: 20,
|
||||
data: []
|
||||
},
|
||||
series: [
|
||||
{
|
||||
name: '省份',
|
||||
type: 'pie',
|
||||
radius: '55%',
|
||||
center: ['40%', '50%'],
|
||||
data: [],
|
||||
emphasis: {
|
||||
itemStyle: {
|
||||
shadowBlur: 10,
|
||||
shadowOffsetX: 0,
|
||||
shadowColor: 'rgba(0, 0, 0, 0.5)'
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
// 向后台发起请求,获取数据
|
||||
$.ajax({
|
||||
cache: false,
|
||||
type:"GET",
|
||||
url:"/province_topn_curconfirm",
|
||||
data: null,
|
||||
dataType : "json",
|
||||
async: false,
|
||||
error: function(request) {
|
||||
alert("发送请求失败!");
|
||||
},
|
||||
success: function(result) {
|
||||
// pub_date, privinces, curConfirms
|
||||
option1.title.subtext = "数据更新时间: " + result.pub_date
|
||||
for(i=0; i<result.privinces.length; ++i) {
|
||||
option1.legend.data.push(result.privinces[i])
|
||||
option1.series[0].data.push({name:result.privinces[i], value:result.curConfirms[i]})
|
||||
}
|
||||
console.info(result)
|
||||
}
|
||||
});
|
||||
|
||||
myCharts1.setOption(option1);
|
Loading…
Reference in new issue