疫情统计可视化(三)
疫情统计可视化——第三阶段
时间日志记录:
PSP2.2(前) |
Personal SoftWare Process Stages |
Time |
Planning | 计划 | |
|
|
5m |
Development | 开发 | |
|
|
2h |
|
|
|
|
|
|
|
|
10m |
|
|
1h |
|
|
1h |
|
|
10m |
|
|
1h |
Reporting | 报告 | |
|
|
|
|
|
|
Improvement Plan |
|
20m |
合计 | 5h45m |
PSP2.2(后) |
Personal SoftWare Process Stages |
Time |
Planning | 计划 | |
|
|
5m |
Development | 开发 | |
|
|
7h |
|
|
|
|
|
|
|
|
10m |
|
|
1h |
|
|
1.5h |
|
|
10m |
|
|
1h |
Reporting | 报告 | |
|
|
|
|
|
|
Improvement Plan |
|
10m |
合计 | 11h05m |
设计思想:
1.购买并配置阿里云服务器,教程可百度。
2.用Python写的爬虫代码爬取全球数据,并存到服务器数据库。之前博客有。编写移动端代码,连接和web同一个服务器数据库以获取数据,并实现基本的查询显示。
项目代码:
爬虫的:
import pymysql import requests import json # 放入要爬的url url_foreign = "https://api.inews.qq.com/newsqa/v1/automation/foreign/country/ranklist" url_inside = "https://view.inews.qq.com/g2/getOnsInfo?name=disease_h5" # 设置header做一个防爬机制 header = {"user-agent": "Mozilla/5.0 (Linux; Android 8.0.0; Pixel 2 XL Build/OPD1.170816.004) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.116 Mobile Safari/537.36"} # 获取response的json response_foreign = requests.get(url_foreign, headers=header) response_inside = requests.get(url_inside,headers=header) data_foreign = json.loads(response_foreign.content.decode()) data_str_foreign = data_foreign['data'] data_inside = json.loads(response_inside.content.decode()) data_str_inside = data_inside['data'] data_json_inside = json.loads(data_str_inside) # 连接数据库 db = pymysql.connect(host='39.97.109.245', port=3306, user='root', password='0608', db='yiqing', charset='utf8') #使用cursor方法生成一个游标 cursor = db.cursor() confirmed_total = 0 suspected_total = 0 dead_total = 0 healed_total = 0 # 更新时间 lastUpdateTime = data_json_inside['lastUpdateTime'] # 取出外国的数据 for foreignData in data_str_foreign: countryName = foreignData['name'] confirmed = foreignData['confirm'] confirmed_total += confirmed suspected = foreignData['suspect'] suspected_total += suspected dead = foreignData['dead'] dead_total += dead healed = foreignData['heal'] healed_total += healed # 将外国数据上传到数据库 sql = "insert into worlddata(id,countryname,confirmed,suspected,dead,healed,lastupdateTime) values({},'{}','{}','{}','{}', '{}','{}')".format(0, countryName, confirmed, suspected, dead, healed, lastUpdateTime) cursor.execute(sql) db.commit() # 取出中国的数据 ChinaName = data_json_inside['areaTree'][0]['name'] china_confirmed = data_json_inside['areaTree'][0]['total']['confirm'] confirmed_total += china_confirmed china_suspected = data_json_inside['areaTree'][0]['total']['suspect'] suspected_total += china_suspected china_healed = data_json_inside['areaTree'][0]['total']['heal'] healed_total += china_healed china_dead = data_json_inside['areaTree'][0]['total']['dead'] dead_total += dead_total # 将中国数据上传到数据库 sql_china = "insert into worlddata(id,countryname,confirmed,suspected,dead,healed,lastupdateTime) values({},'{}','{}','{}','{}', '{}','{}')".format( 0, ChinaName, china_confirmed, china_suspected, china_dead, china_dead, lastUpdateTime) cursor.execute(sql_china) db.commit() # 将汇总数据上传到数据库 sql_total = "insert into worlddata(id,countryname,confirmed,suspected,dead,healed,lastupdateTime) values({},'{}','{}','{}','{}', '{}','{}')".format(0, 0, confirmed_total, suspected_total, dead_total, healed_total, lastUpdateTime) cursor.execute(sql_total) db.commit()
截图:
个人总结:
as在虚拟机演示的时候不能安装项目的安装包,百度了一下,取消setting build instant run里的勾选框,解决了问题。在编程过程中有很多问题都是一点一点百度,向别人请教,参考的别人代码才完成的。从WEB开发到APP开发再到部署到服务器,整个体验了一波如何构造一个小型项目,收益很大。由于安卓开发不是很熟练,所以花费了大量时间在查找资料和学习示例代码上,因为对安卓组件的不熟悉,每做一个都要百度一下这个组件怎么使用,也是极大的浪费了时间。以后会抓紧学习安卓开发,争取做出更好的APP。